Linux Scapy Guards Your Servers (part 2)
Building a Scapy ToolboxScapy is a flexible tool for both capturing and generating network traffic, and performing whatever type of analysis you want. In Part 2 Paul Ferrill goes deeper into designing custom tests with just a few lines of code.
With Scapy you can both capture and generate network traffic. In some cases it's necessary to generate a particular traffic stream and then watch what comes back. With Scapy you can build that type of tool with just a few lines of code. It will be helpful to define a few terms before we get too far in order to better understand what Scapy is doing. The OSI seven-layer protocol model is used by Scapy in determining how to construct and interpret the bits flowing across the wire. The physical layer is also known layer 1 and is where things like media, either wired or wireless, connectors and signal levels are defined. Layer two, referred to as the data link layer, is where frames of data travel and use a unique physical or MAC address to identify each node. The next layer up is layer three and is referred to as the network layer. This is the level where you have logical addressing, commonly known as an IP address.
>>> arping("192.168.1.0/24", timeout=2)
We can package up that single line command into a running Python program that will accept a target IP address as a parameter as follows:
#!/usr/bin/python from scapy.all import * def usage(): print "Usage: arp-ping.py 192.168.1.0/24" sys.exit(1) if len(sys.argv) != 2: usage() range = sys.argv arping(range, timeout=2)
We could wrap a GUI using Tk around the same functionality with a little more code like this:
from Tkinter import * from scapy.all import conf,arping conf.verb=0 def PingARP(): global myping print str(dst.get()) ans,unans=arping(str(dst.get())) for snd,rcv in ans: textbox.insert(END, rcv.sprintf("%Ether.src% %ARP.psrc%\n")) print rcv.sprintf("%Ether.src% \i %ARP.psrc%\n") root.update() root = Tk() root.wm_resizable(0, 0) frame = frame = Frame(root) label = Label(frame, text="IP address").pack(side=LEFT) dst = Entry(frame) dst.pack(side=LEFT, fill=X, expand=True) frame.pack(fill=X, expand=True) frame = frame = Frame(root) button = Button(frame, text="ARP Ping", command=PingARP) frame.pack(fill=X) frame2 = frame2 = Frame(root) scrollbar = Scrollbar(frame2) scrollbar.pack(side=RIGHT, fill=Y) textbox = Text(frame2) textbox.pack(side=RIGHT, fill=BOTH, expand=True) textbox.config(yscrollcommand=scrollbar.set) scrollbar.config(command=textbox.yview) frame2.pack(fill=BOTH, expand=True) button.pack() frame.pack() root.mainloop()
One last modification to this code changes the default ping to use another Scapy feature that looks for any node with their adapter set to promiscuous mode. That would be a sign of potential threats on your network running a tool like Wireshark. To do this we add the module promiscping to our import line and change one line in the PingARP routine as follows:
Now we have a useful network forensics tool with a relatively small amount of programming. You can use the same basic framework wrapped around any of Scapy's commands to build your own tools.
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
- 1Linux Top 3: GNOME 3.12 and New Betas for Ubuntu 14.04 and OpenMandriva Lx 2014.0
- 2Linux Top 3: Linus Lashes out, Linux 3.14 Gets PIE and Ubuntu One is Done.
- 3Linux Top 3: Ubuntu 14.04, Debian Gives Squeeze More Life and Red Hat Goes Atomic
- 4Linux Top 3: CoreOS, Oracle Enterprise Linux 7 and Ubuntu 14.10
- 5Linux Top 3: Debian Gives Up on Upstart, Ubuntu and Linux Kernel Updates