All Projects → KimiNewt → Pyshark

KimiNewt / Pyshark

Licence: mit
Python wrapper for tshark, allowing python packet parsing using wireshark dissectors

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pyshark

Cuishark
A protocol analyzer like a wireshark on CUI. cuishark is using libwireshark to analyze packets. https://cuishark.slankdev.net
Stars: ✭ 208 (-83.83%)
Mutual labels:  packet-capture, wireshark
Node Webshark
webShark UI + API for NodeJS
Stars: ✭ 26 (-97.98%)
Mutual labels:  packet-capture, wireshark
Etl2pcapng
Utility that converts an .etl file containing a Windows network packet capture into .pcapng format.
Stars: ✭ 228 (-82.27%)
Mutual labels:  packet-capture, wireshark
Wireshark
Read-only mirror of Wireshark's Git repository at https://gitlab.com/wireshark/wireshark. GitHub won't let us disable pull requests. ☞ THEY WILL BE IGNORED HERE ☜ Please upload them at GitLab.
Stars: ✭ 4,009 (+211.74%)
Mutual labels:  packet-capture, wireshark
rvi capture
rvictl for Linux and Windows: capture packets sent/received by iOS devices
Stars: ✭ 124 (-90.36%)
Mutual labels:  wireshark, packet-capture
Orchid
Orchid: VPN, Personal Firewall
Stars: ✭ 333 (-74.11%)
Mutual labels:  packet-capture
Mpsec
One Stop MPTCP Service : MPSec
Stars: ✭ 18 (-98.6%)
Mutual labels:  packet-capture
Esp wifi repeater
A full functional WiFi Repeater (correctly: a WiFi NAT Router)
Stars: ✭ 3,818 (+196.89%)
Mutual labels:  wireshark
Ethical Hacking Tools
Complete Listing and Usage of Tools used for Ethical Hacking
Stars: ✭ 272 (-78.85%)
Mutual labels:  wireshark
Snifter
Snifter is a raw socket IP packet capturing library/app for Windows, with a tiny CPU and memory footprint
Stars: ✭ 38 (-97.05%)
Mutual labels:  packet-capture
Netsniff Ng
A Swiss army knife for your daily Linux network plumbing.
Stars: ✭ 915 (-28.85%)
Mutual labels:  packet-capture
Wirefilter
An execution engine for Wireshark-like filters
Stars: ✭ 677 (-47.36%)
Mutual labels:  wireshark
N2disk
Open source components and extensions for n2disk
Stars: ✭ 413 (-67.88%)
Mutual labels:  packet-capture
Nfstream
NFStream: a Flexible Network Data Analysis Framework.
Stars: ✭ 622 (-51.63%)
Mutual labels:  packet-capture
Crafter
🔬 An R package to work with PCAPs
Stars: ✭ 27 (-97.9%)
Mutual labels:  packet-capture
Computer Networking A Top Down Approach Notes
《计算机网络-自顶向下方法(原书第6版)》编程作业,Wireshark实验文档的翻译和解答。
Stars: ✭ 3,890 (+202.49%)
Mutual labels:  wireshark
Homer
HOMER - 100% Open-Source SIP / VoIP Packet Capture & Monitoring
Stars: ✭ 855 (-33.51%)
Mutual labels:  packet-capture
Arkime
Arkime (formerly Moloch) is an open source, large scale, full packet capturing, indexing, and database system.
Stars: ✭ 4,994 (+288.34%)
Mutual labels:  packet-capture
Ostinato
Ostinato - Packet/Traffic Generator and Analyzer
Stars: ✭ 513 (-60.11%)
Mutual labels:  wireshark
Scapy
Scapy: the Python-based interactive packet manipulation program & library. Supports Python 2 & Python 3.
Stars: ✭ 6,932 (+439.04%)
Mutual labels:  packet-capture

pyshark

Join the chat at https://gitter.im/pyshark_gitter/Lobby Build Status

Python wrapper for tshark, allowing python packet parsing using wireshark dissectors.

Extended documentation: http://kiminewt.github.io/pyshark

Python2 deprecation - This package no longer supports Python2. If you wish to still use it in Python2, you can:

  • Use version 0.3.8
  • Install pyshark-legacy via pypi
  • Clone the pyshark-legacy [repo (https://github.com/KimiNewt/pyshark-legacy)], where bugfixes will be applied.

Looking for contributors - for various reasons I have a hard time finding time to maintain and enhance the package at the moment. Any pull-requests will be reviewed and if any one is interested and is suitable, I will be happy to include them in the project. Feel free to mail me at dorgreen1 at gmail.

There are quite a few python packet parsing modules, this one is different because it doesn't actually parse any packets, it simply uses tshark's (wireshark command-line utility) ability to export XMLs to use its parsing.

This package allows parsing from a capture file or a live capture, using all wireshark dissectors you have installed. Tested on windows/linux.

Installation

All Platforms

Simply run the following to install the latest from pypi

pip install pyshark

Or install from the git repository:

git clone https://github.com/KimiNewt/pyshark.git
cd pyshark/src
python setup.py install

Mac OS X

You may have to install libxml which can be unexpected. If you receive an error from clang or an error message about libxml, run the following:

xcode-select --install
pip install libxml

You will probably have to accept a EULA for XCode so be ready to click an "Accept" dialog in the GUI.

Usage

Reading from a capture file:

>>> import pyshark
>>> cap = pyshark.FileCapture('/tmp/mycapture.cap')
>>> cap
<FileCapture /tmp/mycapture.cap (589 packets)>
>>> print cap[0]
Packet (Length: 698)
Layer ETH:
        Destination: BLANKED
        Source: BLANKED
        Type: IP (0x0800)
Layer IP:
        Version: 4
        Header Length: 20 bytes
        Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
        Total Length: 684
        Identification: 0x254f (9551)
        Flags: 0x00
        Fragment offset: 0
        Time to live: 1
        Protocol: UDP (17)
        Header checksum: 0xe148 [correct]
        Source: BLANKED
        Destination: BLANKED
  ...

Other options

  • param keep_packets: Whether to keep packets after reading them via next(). Used to conserve memory when reading large caps.
  • param input_file: Either a path or a file-like object containing either a packet capture file (PCAP, PCAP-NG..) or a TShark xml.
  • param display_filter: A display (wireshark) filter to apply on the cap before reading it.
  • param only_summaries: Only produce packet summaries, much faster but includes very little information
  • param disable_protocol: Disable detection of a protocol (tshark > version 2)
  • param decryption_key: Key used to encrypt and decrypt captured traffic.
  • param encryption_type: Standard of encryption used in captured traffic (must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK.
  • param tshark_path: Path of the tshark binary

Reading from a live interface:

>>> capture = pyshark.LiveCapture(interface='eth0')
>>> capture.sniff(timeout=50)
>>> capture
<LiveCapture (5 packets)>
>>> capture[3]
<UDP/HTTP Packet>

for packet in capture.sniff_continuously(packet_count=5):
    print 'Just arrived:', packet

Other options

  • param interface: Name of the interface to sniff on. If not given, takes the first available.
  • param bpf_filter: BPF filter to use on packets.
  • param display_filter: Display (wireshark) filter to use.
  • param only_summaries: Only produce packet summaries, much faster but includes very little information
  • param disable_protocol: Disable detection of a protocol (tshark > version 2)
  • param decryption_key: Key used to encrypt and decrypt captured traffic.
  • param encryption_type: Standard of encryption used in captured traffic (must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK).
  • param tshark_path: Path of the tshark binary
  • param output_file: Additionally save captured packets to this file.

Reading from a live interface using a ring buffer

>>> capture = pyshark.LiveRingCapture(interface='eth0')
>>> capture.sniff(timeout=50)
>>> capture
<LiveCapture (5 packets)>
>>> capture[3]
<UDP/HTTP Packet>

for packet in capture.sniff_continuously(packet_count=5):
    print 'Just arrived:', packet

Other options

  • param ring_file_size: Size of the ring file in kB, default is 1024
  • param num_ring_files: Number of ring files to keep, default is 1
  • param ring_file_name: Name of the ring file, default is /tmp/pyshark.pcap
  • param interface: Name of the interface to sniff on. If not given, takes the first available.
  • param bpf_filter: BPF filter to use on packets.
  • param display_filter: Display (wireshark) filter to use.
  • param only_summaries: Only produce packet summaries, much faster but includes very little information
  • param disable_protocol: Disable detection of a protocol (tshark > version 2)
  • param decryption_key: Key used to encrypt and decrypt captured traffic.
  • param encryption_type: Standard of encryption used in captured traffic (must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK).
  • param tshark_path: Path of the tshark binary
  • param output_file: Additionally save captured packets to this file.

Reading from a live remote interface:

>>> capture = pyshark.RemoteCapture('192.168.1.101', 'eth0')
>>> capture.sniff(timeout=50)
>>> capture

Other options

  • param remote_host: The remote host to capture on (IP or hostname). Should be running rpcapd.
  • param remote_interface: The remote interface on the remote machine to capture on. Note that on windows it is not the device display name but the true interface name (i.e. \Device\NPF_..).
  • param remote_port: The remote port the rpcapd service is listening on
  • param bpf_filter: A BPF (tcpdump) filter to apply on the cap before reading.
  • param only_summaries: Only produce packet summaries, much faster but includes very little information
  • param disable_protocol: Disable detection of a protocol (tshark > version 2)
  • param decryption_key: Key used to encrypt and decrypt captured traffic.
  • param encryption_type: Standard of encryption used in captured traffic (must be either 'WEP', 'WPA-PWD', or 'WPA-PWK'. Defaults to WPA-PWK).
  • param tshark_path: Path of the tshark binary

Accessing packet data:

Data can be accessed in multiple ways. Packets are divided into layers, first you have to reach the appropriate layer and then you can select your field.

All of the following work:

>>> packet['ip'].dst
192.168.0.1
>>> packet.ip.src
192.168.0.100
>>> packet[2].src
192.168.0.100

To test whether a layer is in a packet, you can use its name:

>>> 'IP' in packet
True

To see all possible field names, use the packet.layer.field_names attribute (i.e. packet.ip.field_names) or the autocomplete function on your interpreter.

You can also get the original binary data of a field, or a pretty description of it:

>>> p.ip.addr.showname
Source or Destination Address: 10.0.0.10 (10.0.0.10)
# And some new attributes as well:
>>> p.ip.addr.int_value
167772170
>>> p.ip.addr.binary_value
'\n\x00\x00\n'

Decrypting packet captures

Pyshark supports automatic decryption of traces using the WEP, WPA-PWD, and WPA-PSK standards (WPA-PWD is the default).

>>> cap1 = pyshark.FileCapture('/tmp/capture1.cap', decryption_key='password')
>>> cap2 = pyshark.LiveCapture(interface='wi0', decryption_key='password', encryption_type='wpa-psk')

A tuple of supported encryption standards, SUPPORTED_ENCRYPTION_STANDARDS, exists in each capture class.

>>> pyshark.FileCapture.SUPPORTED_ENCRYPTION_STANDARDS
('wep', 'wpa-pwd', 'wpa-psk')
>>> pyshark.LiveCapture.SUPPORTED_ENCRYPTION_STANDARDS
('wep', 'wpa-pwd', 'wpa-psk')

Reading from a file using a display filter

Pyshark display filters can be helpful in analyzing application focused traffic. BPF filters do not offer as much flexibility as Wireshark's display filters.

>>> cap1 = pyshark.FileCapture('/tmp/capture1.cap', display_filter="dns")
>>> cap2 = pyshark.LiveCapture(interface='en0', display_filter="tcp.analysis.retransmission")

License

This project is licensed under MIT. Contributions to this project are accepted under the same license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].