-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (51 loc) · 1.83 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from netfilterqueue import NetfilterQueue
from scapy.all import *
import urllib3
from io import BytesIO
from http.client import HTTPResponse
import untangle
class BytesIOSocket:
def __init__(self, content):
self.handle = BytesIO(content)
def makefile(self, mode):
return self.handle
def response_from_bytes(data):
sock = BytesIOSocket(data)
http_response = HTTPResponse(sock)
http_response.begin()
return urllib3.HTTPResponse.from_httplib(http_response)
def intercept(packet):
payload = packet.get_payload()
# print('[+] Packet has arrived: ')
# print(payload.hex()) # Prints something like: 45000034a5b340003906b73c02142c78ac140a340050b024...
# print(packet) # Prints something like: TCP packet, 152 bytes
spkt = IP(payload)
if spkt.haslayer('TCP'):
payload = spkt['IP']['TCP'].payload
if len(payload) > 0:
load_bytes = payload.load
try:
if load_bytes.startswith(b'HTTP/1.0') or load_bytes.startswith(b'HTTP/1.0'):
# TODO Debug to find the fileds of response
response = response_from_bytes(load_bytes)
print(response.headers)
#print(response.data)
xml_obj =
elif load_bytes.startswith(b'POST'):
request = load_bytes.decode().split('\r\n\r\n')
request_header = request[0]
request_content = request[1]
print(request_header)
print('-'*78)
except ValueError:
pass
packet.accept()
nfqueue = NetfilterQueue()
nfqueue.bind(0, intercept)
try:
print('[+] Waiting for packets...')
nfqueue.run()
except KeyboardInterrupt:
print('[?] Shutting down...')
except Exception as e:
print(e)