-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmitm.py
62 lines (52 loc) · 2.03 KB
/
gmitm.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
from scapy.config import conf
from scapy.all import PcapWriter, AsyncSniffer
import os
import datetime
RESPOND = 1
FORWARD = 2
IGNORE = 3
class iface():
def __init__(self, name):
self.name = name
self.sock = conf.L2socket(name)
self.sniff = None
class gmitm():
def __init__(self, elab, iface1, iface2):
self.elab = elab
self.iface1 = iface(iface1)
self.iface2 = iface(iface2)
self.pcapfile = PcapWriter("./loot/" + datetime.datetime.now().strftime("%d/%m/%Y-%H:%M:%S") + "-loot.pcap")
def stop(self):
os.system("iptables -D INPUT -j ACCEPT")
os.system("iptables -D OUTPUT -j ACCEPT")
os.system("iptables -D FORWARD -j ACCEPT")
self.iface1.sniff.stop()
self.iface2.sniff.stop()
def start(self):
os.system("iptables -A INPUT -j DROP")
os.system("iptables -A OUTPUT -j DROP")
os.system("iptables -A FORWARD -j DROP")
os.system("ip link set eth0 up")
os.system("ip link set eth1 up")
def initelab1(packet):
self.elaboration(self.iface1, self.iface2, packet)
self.iface1.sniff = AsyncSniffer(iface=self.iface1.name, prn=initelab1, filter="inbound")
def initelab2(packet):
self.elaboration(self.iface2, self.iface1, packet)
self.iface2.sniff = AsyncSniffer(iface=self.iface2.name, prn=initelab2, filter="inbound")
self.iface1.sniff.start()
self.iface2.sniff.start()
def elaboration(self, srciface, dstiface, originpacket):
operation, elabpacket, save = self.elab(srcinterface.name, originpacket)
try:
if operation == RESPOND:
srciface.sock.send(elabpacket)
elif operation == IGNORE:
pass
elif operation == FORWARD:
dstiface.sock.send(elabpacket)
except:
pass
if save == True:
self.pcapfile.write(elabpacket)
self.pcapfile.flush()