Importing packets from trace files with scapy

Scapy is amazingly flexible when it comes to creating packets, but in some cases you may want to mangle or change packets that you’ve sniffed and saved in a trace file. Scapy currently supports .cap and .pcap files, but unfortunately no .pcapng files (yet…).  Reading these files are possible through the rdpcap() function:

*Thanks to packetlife.net for the iBGP capture found here.

Continue reading

TFTP copy from a non-global VRF

I’ve been running a Cisco CSR-1000v box on my Mac in Parallels for a bit now. I love the convenience of being able to test on a real IOS XE device anywhere I am (airplane, coffee shop, maybe even my office)! I’ve been running the CSR-1000v since version 3.09 and I wanted to upgrade to 3.12.0S since it’s got some new features, bug fixes, and most importantly (for me) a lower memory footprint. I downloaded the new .bin file and proceeded to try and upgrade the image as I would any physical device, with TFTP. Well, here’s how well that went:

Continue reading

Quick and Easy “show ip route” with Concise Output

For those of you Cisco IOS ninjas that can differentiate the show ip route table codes in your sleep, the first several lines of this command output are just a nuisance. Here’s a quick way to remove that unnecessary text from the output so you can get straight to finding out where your traffic is headed. And all with just a few additional keystrokes to the end of the command:

# show ip route | e -

Continue reading

Sync Wireshark Profile Settings with Dropbox

In this day and age you probably have more than one computer (laptop, VM, home desktop??). Also, if you’re like me you probably have Wireshark installed on anything you can get your hands on! It can be a bit of a pain to keep your favorite Wireshark settings such as protocol options, coloring rules, and saved display filters up to date with each Wireshark installation. Using Dropbox (or a similar service) you can easily keep your Wireshark profiles in sync on all computers. Continue reading

Scapy p.01 – Scapy Introduction and Overview

What is Scapy?

No one can introduce Scapy better than the creator or the project himself:

“Scapy is a powerful interactive packet manipulation program. It is able to forge or decode packets of a wide number of protocols, send them on the wire, capture them, match requests and replies, and much more. It can easily handle most classical tasks like scanning, tracerouting, probing, unit tests, attacks or network discovery…

It also performs very well at a lot of other specific tasks that most other tools can’t handle, like sending invalid frames, injecting your own 802.11 frames, combining technics (VLAN hopping+ARP cache poisoning, VOIP decoding on WEP encrypted channel, …), etc.

– Phil @ secdev.org

Continue reading

Scapy p.02 – Installing Python and Scapy

Installing Python

Scapy was originally written for python2, but thanks to this wonderful project, you can now use scapy with python3.6! I will prefer python3.6 in examples but will also include notes about big differences between each python version and scapy if they exist.

If you’re using a Mac or running some version of *nix you probably already have python 2 (and maybe even python 3) installed. To check, open a terminal and type python3 or python. You should see something like this:

If you are running Windows or for some other reason do not have Python installed already, go to the Python download page and grab the installer for your platform.

Continue reading

Scapy p.03 – Scapy Interactive Mode

Running Scapy

Scapy can be run in two different modes, interactively from a terminal window and programmatically from a Python script. Let’s start getting familiar with Scapy using the interactive mode.

The original (py2) scapy came with a short script to start interactive mode so from your terminal you can just type scapy:

 

However the scapy3k installer doesn’t provide this so I recommend adding a similar shortcut:

Paste the following & :wq

And make it executable so you can run:

Continue reading

Scapy p.04 – Looking at Packets

Packets, Layers, and Fields. Oh My!

Scapy uses Python dictionaries as the data structure for packets. Each packet is a collection of nested dictionaries with each layer being a child dictionary of the previous layer, built from the lowest layer up. Visualizing the nested packet layers would look something like this:
pkt-layers

 

Each field (such as the Ethernet ‘dst’ value or ICMP ‘type’ value) is a key:value pair in the appropriate layer. These fields (and nested layers) are all mutable so we can reassign them in place using the assignment operator. Scapy has packet methods for viewing the layers and fields that I will introduce next.

Packet summary() and show() Methods

Now let’s go back to our pkt and have some fun with it using Scapy’s Interactive mode. We already know that using the summary() method will give us a quick look at the packet’s layers:

 

Continue reading

Scapy p.05 – Sending our First Packet; ARP Response

With a good understanding of how to view our packets we can now move onto some packet generation. Let’s talk a bit about sniffing first and how existing packets are our best tool for creating new ones.

Sniff() function arguments

We’ve used the sniff() function a couple times already to capture some packets for viewing. I’m going to explain a little bit more about the sniff() function and its arguments. Continue reading

Scapy p.06 – Sending and Receiving with Scapy

We’ve sniffed some packets, dig down into packet layers and fields, and even sent some packets. Great job! It’s time to step up our game with Scapy and start really using some of the power Scapy contains. Please Note: this next example is for education and example only. Please be responsible on your network, especially at work!

Scapy Send/Receive Function

Let’s get familiar with the sr(), sr1(), srp(), and srp1() functions. Just like the send(), function, the ‘p’ at the end of the function name means that we’re sending at L2 instead of L3. The functions with a ‘1’ in them mean that Scapy will send the specified packet and end after receiving 1 answer/response instead of continuing to listen for answers/responses. I’ll reference both functions as sr(), but the examples will use the correct function.

Continue reading