In this article we are going to discuss about Scapy Python Tool for Fabricating Handshake Method. Kali Linux 2018.3 has Scapy Python Tool ready to go, but it’s good to make sure you have all your dependencies in order. My copy of Kali didn’t have the Python ECDSA cryptography installed, for example. We don’t need it here, but I don’t like to have alerts when I fire up Scapy Python Tool. You can run this command before we get started:
# apt-get install graphviz imagemagick python-gnuplot python-pyx python-ecdsa
You can bring up the Scapy Python Tool interpreter interface by simply commanding scapy, but for this discussion, we’ll be importing its power into a Python script.
Scapy Python Tool is a sophisticated packet manipulation and crafting program. Scapy Python Tool is a Python program, but Python plays an even bigger role in Scapy as the syntax and interpreter for Scapy’s domain-specific language. What this means for the pen tester is a packet manipulator and forger with unmatched versatility because it allows you to literally write your own network tools, on the fly, with very few lines of code – and it leaves the interpretation up to you, instead of within the confines of what a tool author imagined.
What we’re doing here is a crash course in scripting with Python and Scapy, so don’t be intimidated. We will be covering Scapy and Python in detail in our upcoming articles. We’ll step through everything happening here in our NAC bypass scenario so that, when we fire up Scapy Python Tool in the future, it will quickly make sense. If you’re like me, you learn faster when you’re shoved into the pool. That being said, don’t neglect curling up with Scapy documentation and some hot cocoa. The documentation on Scapy is excellent.
As you know, we set up our captive portal listener and OS fingerprinter at 192.168.108.215. Let’s try to browse this address with an unmodified Firefox ESR in Kali and see what p0f picks up:
We can see in the very top line, representing the very first SYN packet received, that p0f has already identified us as a Linux client. Remember, p0f is looking at how the TCP packet is constructed, so we don’t need to wait for any HTTP requests to divulge system information. Linux fingerprints are all over the TCP three-way handshake, before the browser has even established a connection to the site.
In our example, we want to emulate an iPad (specifically, one running iOS 9.3.2 to match our user-agent spoof from earlier). Putting on our hacker hat (the white one, please), we can put two and two together:
- p0f has a database of signatures (p0f.fp) that it references in order to fingerprint a source.
- Scapy Python Tool allows us to construct TCP packets and, with a little scripting, we can tie together several Scapy lines into a single TCP three-way handshake utility.
We now have a recipe for our spoofing attack. Now, Scapy lets you construct communications in its interpreter, using the same syntax as Python, but what we’re going to do is fire up nano and put together a Python script that will import Scapy. We’ll discuss what’s happening here after we confirm the attack works:
from scapy.all import *
ip=IP(dst=CPIPADDRESS, flags=”DF”, ttl=64)
tcpopt=[(“MSS”,1460), (“NOP”,None), (“WScale”,2), (“NOP”,None), (“NOP”,None), (“Timestamp”,(123,0)), (“SAckOK”,””), (“EOL”,None)]
SYN=TCP(sport=SOURCEP, dport=80, flags=”S”, seq=1000, window=0xffff, options=tcpopt)
ACK=TCP(sport=SOURCEP, dport=80, flags=”A”, seq=SYNACK.ack+1, ack=SYNACK.seq+1, window=0xffff)
request=”GET / HTTP/1.1\r\nHost: ” + CPIPADDRESS + “\rMozilla/5.0 (iPad; CPU OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1 \r\n\r\n”
PUSH=TCP(sport=SOURCEP, dport=80, flags=”PA”, seq=1001, ack=0, window=0xffff)
RST=TCP(sport=SOURCEP, dport=80, flags=”R”, seq=1001, ack=0, window=0xffff)
Once I’m done typing this up in nano, I save it as a .py file and chmod it to allow execution. That’s it – the attack is ready:
The iptables outbound rule is set, and the script is ready to execute. Let it fly:
That’s it; not very climactic on this end. But, let’s take a look at the receiving end. Click Next for remaining process.