Skip to content

Instantly share code, notes, and snippets.

@sdcampbell
Forked from MarkBaggett/scapy_helper.py
Created December 29, 2018 02:49
Show Gist options
  • Save sdcampbell/2b62a22c4378639161c9bc5ce0d3dbc4 to your computer and use it in GitHub Desktop.
Save sdcampbell/2b62a22c4378639161c9bc5ce0d3dbc4 to your computer and use it in GitHub Desktop.
Python - SCAPY - Full Packet Session Reassembly
#From here https://pen-testing.sans.org/blog/2017/10/13/scapy-full-duplex-stream-reassembly
def full_duplex(p):
sess = "Other"
if 'Ether' in p:
if 'IP' in p:
if 'TCP' in p:
sess = str(sorted(["TCP", p[IP].src, p[TCP].sport, p[IP].dst, p[TCP].dport],key=str))
elif 'UDP' in p:
sess = str(sorted(["UDP", p[IP].src, p[UDP].sport, p[IP].dst, p[UDP].dport] ,key=str))
elif 'ICMP' in p:
sess = str(sorted(["ICMP", p[IP].src, p[IP].dst, p[ICMP].code, p[ICMP].type, p[ICMP].id] ,key=str))
else:
sess = str(sorted(["IP", p[IP].src, p[IP].dst, p[IP].proto] ,key=str))
elif 'ARP' in p:
sess = str(sorted(["ARP", p[ARP].psrc, p[ARP].pdst],key=str))
else:
sess = p.sprintf("Ethernet type=%04xr,Ether.type%")
return sess
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment