mirror of https://github.com/dirtbags/netarch.git
Add HTTP resequencing example
This commit is contained in:
parent
bc0165d5ab
commit
344caeb0c4
|
@ -7,7 +7,6 @@ IP = scapy.IP
|
||||||
TCP = scapy.TCP
|
TCP = scapy.TCP
|
||||||
Raw = scapy.Raw
|
Raw = scapy.Raw
|
||||||
|
|
||||||
drop_pad = 'DROP'
|
|
||||||
|
|
||||||
class DropStringIO(StringIO.StringIO):
|
class DropStringIO(StringIO.StringIO):
|
||||||
"""StringIO with different padding.
|
"""StringIO with different padding.
|
||||||
|
@ -61,7 +60,7 @@ class TCP_Session:
|
||||||
p = self.pc.read()
|
p = self.pc.read()
|
||||||
if not p:
|
if not p:
|
||||||
return
|
return
|
||||||
return scapy.Ether(p[2])
|
return scapy.Ether(p[1])
|
||||||
|
|
||||||
def read_handshake(self):
|
def read_handshake(self):
|
||||||
# Read SYN
|
# Read SYN
|
||||||
|
@ -188,3 +187,25 @@ class HTTP_side:
|
||||||
self.headers[k] = v
|
self.headers[k] = v
|
||||||
if k.lower() == 'content-length':
|
if k.lower() == 'content-length':
|
||||||
self.pending_data = int(v)
|
self.pending_data = int(v)
|
||||||
|
|
||||||
|
|
||||||
|
def process_http(filename):
|
||||||
|
import pcap
|
||||||
|
|
||||||
|
pc = pcap.open(filename)
|
||||||
|
sess = TCP_Session(pc)
|
||||||
|
|
||||||
|
packets = []
|
||||||
|
current = [HTTP_side(), HTTP_side()]
|
||||||
|
for idx, chunk in sess:
|
||||||
|
c = current[idx]
|
||||||
|
while chunk:
|
||||||
|
chunk = c.process(chunk)
|
||||||
|
if c.complete:
|
||||||
|
packets.append((idx, c))
|
||||||
|
|
||||||
|
c = HTTP_side()
|
||||||
|
current[idx] = c
|
||||||
|
|
||||||
|
return packets
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue