Code Monkey home page Code Monkey logo

pcap-processor's Introduction

Pcap Processor

Read and process pcap files using this nifty tool.

This tool can read pcap files, process them internally and write them to one or more sinks. Currently there are mappers written for pcap length conversion and protocol normalization. I also have written sinks to write the pcap file to console, csv file or http endpoint.

usage: pcap-processor [-h] [--map {length,protocol}]
                      [--sink {console,kafka,http,csv,grpc}] [--version]
                      file [file ...]

Read and process pcap files using this nifty tool.

positional arguments:
  file                  pcap file to read

optional arguments:
  -h, --help            show this help message and exit
  --map {length,protocol}
                        enable a mapper with the given name. You can use this
                        option multiple times to enable more than one mappers
  --sink {console,kafka,http,csv,grpc}
                        enable a sink with the given name. You can use this
                        option multiple times to enable more than one sinks
  --version             show program's version number and exit

Note

Currently the pcap-processor reads only packets with IP or IPV6 layers. Feel free to modify the code based on your requirement. If you find any enhancement, please send a Pull Request.

Requirements

pcap-reader relies on external command line tool: tshark and some Python modules.

Install tshark using the following command in Ubuntu and its derivatives:

sudo apt install tshark

Install Python dependencies using the following command:

pip3 install -r requirements.txt

Research Work

This tool is developed as part of my research project. If you are using this tool in your research, please cite the following paper:

Citation:

Loganathan, G., Samarabandu, J., & Wang, X. (2018). Sequence to Sequence Pattern Learning Algorithm for Real-time Anomaly Detection in Network Traffic. In 2018 IEEE Canadian Conference on Electrical & Computer Engineering (CCECE) (CCECE 2018). Quebec City, Canada.

BibTex

@INPROCEEDINGS{Loga1805:Sequence,
AUTHOR="Gobinath Loganathan and Jagath Samarabandu and Xianbin Wang",
TITLE="Sequence to Sequence Pattern Learning Algorithm for Real-time Anomaly
Detection in Network Traffic",
BOOKTITLE="2018 IEEE Canadian Conference on Electrical \& Computer Engineering (CCECE)
(CCECE 2018)",
ADDRESS="Quebec City, Canada",
DAYS=13,
MONTH=may,
YEAR=2018,
KEYWORDS="Seq2Seq; Anomaly Detection",
ABSTRACT="Network intrusions can be modeled as anomalies in network traffic in which
the expected order of packets and their attributes deviate from regular
traffic. Algorithms that predict the next sequence of events based on
previous sequences are a promising avenue for detecting such anomalies. In
this paper, we present a novel multi-attribute model for predicting a
network packet sequence based on previous packets using a
sequence-to-sequence (Seq2Seq) encoder-decoder model. This model is trained
on an attack-free dataset to learn the normal sequence of packets in TCP
connections and then it is used to detect anomalous packets in TCP traffic.
We show that in DARPA 1999 dataset, the proposed multi-attribute Seq2Seq
model detects anomalous raw TCP packets which are part of intrusions with
97\% accuracy. Also, it can detect selected intrusions in real-time with
100\% accuracy and outperforms existing algorithms based on recurrent
neural network models such as LSTM."
}

Use Cases

Read a pcap file and send all packets to Apache Kafka:

python3 -m pcap_processor --sink kafka samples/cicids_2017.pcap

Read a pcap file, map protocols and write them to a CSV file:

python3 -m pcap_processor --map protocol --sink csv samples/cicids_2017.pcap

Mappers and sinks have their own properties. Please modify them in the relevant plugins/<file>.py.

For example, to change the output CSV file location, modify the self.path = "packets.csv" in pcap_processor/plugins/csv_sink.py.

pcap-processor's People

Contributors

slgobinath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pcap-processor's Issues

additional features

Hello, i want to extract additional features included in the NSL-KDD dataset from pcap file here is the features as follows:-

Duration length : (number of seconds) of the connection.

protocol-type : type of the protocol such as (tcp, udp, icmp)

src-bytes : number of data bytes from source to destination

srv-count : number of connections to the same service as the current connection in the past two seconds.

dst-host-same-src-port-rate : percentage of connections from the port ser-
vices to the destination host.
so how can i extract those features from pcap file
thanks in advance

Error while converting

I try to use your tools to convert CICIDS 2017 dataset to CSV file like KDD 99. But when I run python -m pcap_processor --map protocol --sink csv Wednesday-WorkingHours.pcap it returns to error ModuleNotFoundError: No module named 'pcap_processor.grpc'. Please tell me the solution. Thank you

Can't install dependencies and run it

While installing dependencies in requirements.txt the process gets stuck in:
Collecting pyshark (from -r requirements.txt (line 1)) Downloading https://files.pythonhosted.org/packages/d2/ed/acd141e42a4651e1a327eabba50c8faa8b2abb6b147da4258e97ef829a6f/pyshark-0.4.2.11-py3-none-any.whl Collecting kafka-python (from -r requirements.txt (line 2)) Downloading https://files.pythonhosted.org/packages/aa/34/12f219f7f9e68e79a54874d26fbe974db1ab4efac4e6dae665b421df48f9/kafka_python-2.0.1-py2.py3-none-any.whl (232kB) 100% |████████████████████████████████| 235kB 5.8MB/s Collecting grpcio (from -r requirements.txt (line 3)) Downloading https://files.pythonhosted.org/packages/f1/23/62d3e82fa4c505f3195315c8a774b2e656b556d174329aa98edb829e48bc/grpcio-1.29.0.tar.gz (19.6MB) 100% |████████████████████████████████| 19.6MB 88kB/s Collecting grpcio-tools (from -r requirements.txt (line 4)) Downloading https://files.pythonhosted.org/packages/ce/4f/a9563819484a281aa712fe57fe5e2bfc4eb1f881e8127d01a76d7847435c/grpcio-tools-1.29.0.tar.gz (2.0MB) 100% |████████████████████████████████| 2.0MB 883kB/s Collecting py (from pyshark->-r requirements.txt (line 1)) Downloading https://files.pythonhosted.org/packages/99/8d/21e1767c009211a62a8e3067280bfce76e89c9f876180308515942304d2d/py-1.8.1-py2.py3-none-any.whl (83kB) 100% |████████████████████████████████| 92kB 7.7MB/s Collecting lxml (from pyshark->-r requirements.txt (line 1)) Downloading https://files.pythonhosted.org/packages/ba/39/0b5d76e64681243db516491bc449eff847d2708b465b60465b31ca13522e/lxml-4.5.1-cp37-cp37m-manylinux1_x86_64.whl (5.5MB) 100% |████████████████████████████████| 5.5MB 347kB/s Requirement already satisfied: six>=1.5.2 in /usr/lib/python3/dist-packages (from grpcio->-r requirements.txt (line 3)) (1.12.0) Requirement already satisfied: protobuf>=3.5.0.post1 in /usr/lib/python3/dist-packages (from grpcio-tools->-r requirements.txt (line 4)) (3.6.1) Building wheels for collected packages: grpcio, grpcio-tools Running setup.py bdist_wheel for grpcio ... done Stored in directory: /root/.cache/pip/wheels/ed/06/79/e559ab3b10134903b88e2df2df1b7cc4d3f1a92a46972a09fb Running setup.py bdist_wheel for grpcio-tools ... /

error when execute

hello, I clone your work and run the requirements locally, including "requirements.txt", but I got an error

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.