def __init__(self, config): self.config = config self.logpath = os.getcwd() + "/" + self.config[ "domain_name"] + "_" + self.config["phishing_domain"] + "/" #ensure log path exists if not os.path.exists(self.logpath): os.makedirs(self.logpath) # set up database connection self.db = MyDB(sqlite_file=self.logpath) self.websites = {} self.phishingsites = {} self.MINPORT = int(self.config["vhost_port_min"]) self.MAXPORT = int(self.config["vhost_port_max"])
def login(): if current_user.is_authenticated: return redirect(url_for('homepage')) if request.method == "POST" and request.form.has_key("username") and request.form.has_key("password"): username = request.form["username"] password = request.form["password"] user_id = MyDB.get_user_id_by_credentials( username, password ) if user_id is not None: isAdmin = MyDB.get_isAdmin_by_id(user_id) login_user( MyUser( user_id, username, isAdmin ), remember="no") red = redirect(url_for('homepage')) resp = make_response(red) resp.set_cookie('isAdmin',str(isAdmin)) return resp else: content = dict() return render_template("login.html", error=True, content=content) else: content = dict() return render_template("login.html", content=content)
def __init__(self, config): self.config = config self.logpath = os.getcwd() + "/" + self.config["domain_name"] + "_" + self.config["phishing_domain"] + "/" #ensure log path exists if not os.path.exists(self.logpath): os.makedirs(self.logpath) # set up database connection self.db = MyDB(sqlite_file=self.logpath) self.websites = {} self.phishingsites = {} self.MINPORT = int(self.config["vhost_port_min"]) self.MAXPORT = int(self.config["vhost_port_max"])
def login(): if current_user.is_authenticated(): return redirect(url_for("homepage")) if request.method == "POST" and request.form.has_key("username") and request.form.has_key("password"): username = request.form["username"] password = request.form["password"] user_id = MyDB.get_user_id_by_credentials(username, password) if user_id is not None: login_user(MyUser(user_id, username), remember="no") return redirect(url_for("homepage")) else: content = dict() return render_template("login.html", error=True, content=content) else: content = dict() return render_template("login.html", content=content)
class PhishingWebServer(): def __init__(self, config): self.config = config self.logpath = os.getcwd() + "/" + self.config[ "domain_name"] + "_" + self.config["phishing_domain"] + "/" #ensure log path exists if not os.path.exists(self.logpath): os.makedirs(self.logpath) if not os.path.exists(self.logpath + "logs/"): os.makedirs(self.logpath + "/logs") # set up database connection self.db = MyDB(sqlite_file=self.logpath) self.websites = {} self.phishingsites = {} self.MINPORT = int(self.config["vhost_port_min"]) self.MAXPORT = int(self.config["vhost_port_max"]) def getTemplates(self): templates = [] db_static_templates = self.db.getWebTemplates(ttype="static") db_dynamic_templates = self.db.getWebTemplates(ttype="dynamic") if (db_static_templates or db_dynamic_templates): for template in db_static_templates: parts = template.split("[-]") template_file = parts[0] + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile( template_file): templates.append(parts[0]) print "STATIC = [%s]" % (parts[0]) for template in db_dynamic_templates: parts = template.split("[-]") template_file = parts[0] + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile( template_file): templates.append(parts[0]) print "DYNAMIC = [%s]" % (parts[0]) else: for f in os.listdir(self.config["web_template_path"]): template_file = os.path.join(self.config["web_template_path"], f) + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile( template_file): templates.append( os.path.join(self.config["web_template_path"], f)) print "FIXED = [%s]" % (os.path.join( self.config["web_template_path"], f)) return templates def loadSites(self): templates = self.getTemplates() print # loop over each web template for f in templates: template_file = f + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile( template_file): print "Found the following web sites: [%s]" % template_file # read in the VHOST, LOGFILE, and REDIRECTURL VHOST = "" LOGFILE = "" REDIRECTURL = "" #PATH = self.config["web_template_path"] + f + "/" PATH = f + "/" with open(template_file, "r") as myfile: for line in myfile.readlines(): match = re.search("VHOST=", line) if match: VHOST = line.replace('"', "") VHOST = VHOST.split("=") VHOST = VHOST[1].lower().strip() match2 = re.search("LOGFILE=", line) if match2: LOGFILE = line.replace('"', "") LOGFILE = LOGFILE.split("=") LOGFILE = LOGFILE[1].strip() match3 = re.search("REDIRECTURL=", line) if match3: REDIRECTURL = line.replace('"', "") REDIRECTURL = REDIRECTURL.replace(r'\n', "\n") REDIRECTURL = REDIRECTURL.split("=") REDIRECTURL = REDIRECTURL[1].strip() self.websites[VHOST] = { 'path': PATH, 'port': 8000, 'logfile': LOGFILE, 'redirecturl': REDIRECTURL } def timedLogFormatter(timestamp, request): """ A custom request formatter. This is whats used when each request line is formatted. :param timestamp: :param request: A twisted.web.server.Request instance """ #referrer = _escape(request.getHeader(b"referer") or b"-") agent = _escape(request.getHeader(b"user-agent") or b"-") duration = round(time.time() - request.started, 4) line = (u'"%(ip)s" %(duration)ss "%(method)s %(uri)s %(protocol)s" ' u'%(code)d %(length)s "%(agent)s"' % dict(ip=_escape(request.getClientIP() or b"-"), duration=duration, method=_escape(request.method), uri=_escape(request.uri), protocol=_escape(request.clientproto), code=request.code, length=request.sentLength or u"-", agent=agent)) return line def start(self): self.loadSites() if self.config["ip"] == "0.0.0.0": self.config["ip"] = Utils.getIP() #define phishing sites for key in self.websites: self.phishingsites[key] = PhishingSite( self.config, key, self.websites[key]['path'], self.logpath, "logs/" + self.websites[key]['logfile'], self.db, self.websites[key]['redirecturl']).getResource() site_length = 0 for key in self.phishingsites: if (len(key) > site_length): site_length = len(key) # if we are doing port based print for key in self.phishingsites: for port in range(self.MINPORT, self.MAXPORT): try: site = Site(self.phishingsites[key], logPath=self.logpath + "logs/" + self.websites[key]['logfile'] + ".access") # site.logRequest = True reactor.listenTCP(port, site) print "Started website [%s] on [http://%s:%s]" % ( ('{:<%i}' % (site_length)).format(key), self.config["ip"], port) self.websites[key]['port'] = port break except twisted.internet.error.CannotListenError, ex: continue # if we are doing virtual hosts if (self.config["enable_host_based_vhosts"] == "1"): print root = vhost.NameVirtualHost() site_length += len("." + self.config["phishing_domain"]) # add each port based vhost to the nam based vhost for key in self.phishingsites: root.addHost( key + "." + self.config["phishing_domain"], proxy.ReverseProxyResource('localhost', self.websites[key]['port'], '')) print "Created VHOST [%s] -> [https://%s:%s]" % ( ('{:<%i}' % (site_length)).format(key + "." + self.config["phishing_domain"]), self.config["ip"], str(self.websites[key]['port'])) print "Created VHOST [%s] -> [http://%s:%s]" % ( ('{:<%i}' % (site_length)).format(key + "." + self.config["phishing_domain"]), self.config["ip"], str(self.websites[key]['port'])) # add a mapping for the base IP address to map to one of the sites if (self.phishingsites): root.addHost( self.config["ip"], proxy.ReverseProxyResource( 'localhost', int(self.websites[self.phishingsites.keys()[0]] ['port']), '')) try: site = Site(root, logPath=self.logpath + "logs/root.log.access") # ADD SSL CERT sslContext = ssl.DefaultOpenSSLContextFactory( self.config["cert_path"] + 'privkey.pem', self.config["cert_path"] + 'fullchain.pem', ) reactor.listenSSL(int(self.config["default_web_ssl_port"]), site, contextFactory=sslContext) reactor.listenTCP(int(self.config["default_web_port"]), site) except twisted.internet.error.CannotListenError, ex: print "ERROR: Could not start web service listener on port [" + int( self.config["default_web_ssl_port"]) + "]!" print "ERROR: Could not start web service listener on port [80]!" print ex print "ERROR: Host Based Virtual Hosting will not function!" else: print "ERROR: Could not start web service listener on port [" + int( self.config["default_web_ssl_port"]) + "]!" print "ERROR: Could not start web service listener on port [80]!" print "ERROR: Host Based Virtual Hosting will not function!"
class PhishingWebServer(): def __init__(self, config): self.config = config self.logpath = os.getcwd() + "/" + self.config[ "domain_name"] + "_" + self.config["phishing_domain"] + "/" #ensure log path exists if not os.path.exists(self.logpath): os.makedirs(self.logpath) if not os.path.exists(self.logpath + "logs/"): os.makedirs(self.logpath + "/logs") # set up database connection self.db = MyDB(sqlite_file=self.logpath) self.websites = {} self.phishingsites = {} self.MINPORT = int(self.config["vhost_port_min"]) self.MAXPORT = int(self.config["vhost_port_max"]) def getTemplates(self): templates = [] db_static_templates = self.db.getWebTemplates(ttype="static") db_dynamic_templates = self.db.getWebTemplates(ttype="dynamic") if (db_static_templates or db_dynamic_templates): for template in db_static_templates: parts = template.split("[-]") template_file = parts[0] + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile( template_file): templates.append(parts[0]) print("STATIC = [%s]" % (parts[0])) for template in db_dynamic_templates: parts = template.split("[-]") template_file = parts[0] + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile( template_file): templates.append(parts[0]) print("DYNAMIC = [%s]" % (parts[0])) else: for f in os.listdir(self.config["web_template_path"]): template_file = os.path.join(self.config["web_template_path"], f) + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile( template_file): templates.append( os.path.join(self.config["web_template_path"], f)) print("FIXED = [%s]" % (os.path.join(self.config["web_template_path"], f))) return templates def loadSites(self): templates = self.getTemplates() # loop over each web template print() for f in templates: template_file = f + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile( template_file): print("Found the following web sites: [%s]" % template_file) # read in the VHOST, LOGFILE, and REDIRECTURL VHOST = "" LOGFILE = "" REDIRECTURL = "" #PATH = self.config["web_template_path"] + f + "/" PATH = f + "/" with open(template_file, "r") as myfile: for line in myfile.readlines(): match = re.search("VHOST=", line) if match: VHOST = line.replace('"', "") VHOST = VHOST.split("=") VHOST = VHOST[1].lower().strip() match2 = re.search("LOGFILE=", line) if match2: LOGFILE = line.replace('"', "") LOGFILE = LOGFILE.split("=") LOGFILE = LOGFILE[1].strip() match3 = re.search("REDIRECTURL=", line) if match3: REDIRECTURL = line.replace('"', "") REDIRECTURL = REDIRECTURL.replace(r'\n', "\n") REDIRECTURL = REDIRECTURL.split("=") REDIRECTURL = REDIRECTURL[1].strip() self.websites[VHOST] = { 'path': PATH, 'port': 8000, 'logfile': LOGFILE, 'redirecturl': REDIRECTURL } def timedLogFormatter(timestamp, request): """ A custom request formatter. This is whats used when each request line is formatted. :param timestamp: :param request: A twisted.web.server.Request instance """ #referrer = _escape(request.getHeader(b"referer") or b"-") agent = _escape(request.getHeader(b"user-agent") or b"-") duration = round(time.time() - request.started, 4) line = ('"%(ip)s" %(duration)ss "%(method)s %(uri)s %(protocol)s" ' '%(code)d %(length)s "%(agent)s"' % dict(ip=_escape(request.getClientIP() or b"-"), duration=duration, method=_escape(request.method), uri=_escape(request.uri), protocol=_escape(request.clientproto), code=request.code, length=request.sentLength or "-", agent=agent)) return line def start(self): self.loadSites() if self.config["ip"] == "0.0.0.0": self.config["ip"] = Utils.getIP() #define phishing sites for key in self.websites: self.phishingsites[key] = PhishingSite( self.config, key, self.websites[key]['path'], self.logpath, "logs/" + self.websites[key]['logfile'], self.db, self.websites[key]['redirecturl']).getResource() site_length = 0 for key in self.phishingsites: if (len(key) > site_length): site_length = len(key) # if we are doing port based print() for key in self.phishingsites: for port in range(self.MINPORT, self.MAXPORT): try: site = Site(self.phishingsites[key], logPath=self.logpath + "logs/" + self.websites[key]['logfile'] + ".access") # site.logRequest = True reactor.listenTCP(port, site) print( "Started website [%s] on [http://%s:%s]" % (('{:<%i}' % (site_length)).format(key), self.config["ip"], port)) self.websites[key]['port'] = port break except twisted.internet.error.CannotListenError as ex: continue # if we are doing virtual hosts if (self.config["enable_host_based_vhosts"] == "1"): print() # GENERATING SSL CERTS ARE CURRENTLY BROKEN # TODO: Fix this # generate new certificates # domains = "" # cert_path = "/etc/letsencrypt/live/" # first = True # for key in self.phishingsites: # domains += "-d " + key + "." + self.config["phishing_domain"] + " " # if first: # cert_path += key + "." + self.config["phishing_domain"] + "/" # first = False # # cmd = self.config["certbot_path"] + " certonly --register-unsafely-without-email --non-interactive --agree-tos --standalone --force-renewal " + domains # # env = os.environ # print "Generating SSL CERT" # proc = subprocess.Popen(cmd, executable='/bin/bash', env=env, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True) # result = proc.communicate()[0] # m = re.search(r'.* (\/etc\/letsencrypt\/live\/[^\/]+\/).*fullchain.pem.*', result) # print result # # cert_path = m.group(1) root = vhost.NameVirtualHost() site_length += len("." + self.config["phishing_domain"]) # add each port based vhost to the nam based vhost for key in self.phishingsites: root.addHost( key + "." + self.config["phishing_domain"], proxy.ReverseProxyResource('localhost', self.websites[key]['port'], '')) # print "Created VHOST [%s] -> [https://%s:%s]" % (('{:<%i}' % (site_length)).format(key + "." + self.config["phishing_domain"]), self.config["ip"], str(self.websites[key]['port'])) print("Created VHOST [%s] -> [http://%s:%s]" % (('{:<%i}' % (site_length)).format(key + "." + self.config["phishing_domain"]), self.config["ip"], str(self.websites[key]['port']))) # add a mapping for the base IP address to map to one of the sites if (self.phishingsites): root.addHost( self.config["ip"], proxy.ReverseProxyResource( 'localhost', int(self.websites[list( self.phishingsites.keys())[0]]['port']), '')) try: site = Site(root, logPath=self.logpath + "logs/root.log.access") # # ADD SSL CERT # sslContext = ssl.DefaultOpenSSLContextFactory( # cert_path + 'privkey.pem', # cert_path + 'fullchain.pem', # ) # reactor.listenSSL(int(self.config["default_web_ssl_port"]), site, contextFactory=sslContext) reactor.listenTCP(int(self.config["default_web_port"]), site) except twisted.internet.error.CannotListenError as ex: # print "ERROR: Could not start web service listener on port [" + int(self.config["default_web_ssl_port"]) + "]!" print( "ERROR: Could not start web service listener on port [80]!" ) print(ex) print( "ERROR: Host Based Virtual Hosting will not function!") else: # print "ERROR: Could not start web service listener on port [" + int(self.config["default_web_ssl_port"]) + "]!" print( "ERROR: Could not start web service listener on port [80]!" ) print("ERROR: Host Based Virtual Hosting will not function!") print() print("Websites loaded and launched.") sys.stdout.flush() reactor.run()
def load_user(user_id): username = MyDB.get_username_by_id(user_id) return MyUser(user_id, username)
class PhishingWebServer(): def __init__(self, config): self.config = config self.logpath = os.getcwd() + "/" + self.config["domain_name"] + "_" + self.config["phishing_domain"] + "/" #ensure log path exists if not os.path.exists(self.logpath): os.makedirs(self.logpath) if not os.path.exists(self.logpath+"logs/"): os.makedirs(self.logpath+"/logs") # set up database connection self.db = MyDB(sqlite_file=self.logpath) self.websites = {} self.phishingsites = {} self.MINPORT = int(self.config["vhost_port_min"]) self.MAXPORT = int(self.config["vhost_port_max"]) def getTemplates(self): templates = [] db_static_templates = self.db.getWebTemplates(ttype="static") db_dynamic_templates = self.db.getWebTemplates(ttype="dynamic") if (db_static_templates or db_dynamic_templates): for template in db_static_templates: parts = template.split("[-]") template_file = parts[0] + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile(template_file): templates.append(parts[0]) print "STATIC = [%s]" % (parts[0]) for template in db_dynamic_templates: parts = template.split("[-]") template_file = parts[0] + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile(template_file): templates.append(parts[0]) print "DYNAMIC = [%s]" % (parts[0]) else: for f in os.listdir(self.config["web_template_path"]): template_file = os.path.join(self.config["web_template_path"], f) + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile(template_file): templates.append(os.path.join(self.config["web_template_path"], f)) print "FIXED = [%s]" % (os.path.join(self.config["web_template_path"], f)) return templates def loadSites(self): templates = self.getTemplates() print # loop over each web template for f in templates: template_file = f + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile(template_file): print "Found the following web sites: [%s]" % template_file # read in the VHOST, LOGFILE, and REDIRECTURL VHOST = "" LOGFILE = "" REDIRECTURL = "" #PATH = self.config["web_template_path"] + f + "/" PATH = f + "/" with open (template_file, "r") as myfile: for line in myfile.readlines(): match=re.search("VHOST=", line) if match: VHOST=line.replace('"', "") VHOST=VHOST.split("=") VHOST=VHOST[1].lower().strip() match2=re.search("LOGFILE=", line) if match2: LOGFILE=line.replace('"', "") LOGFILE=LOGFILE.split("=") LOGFILE=LOGFILE[1].strip() match3=re.search("REDIRECTURL=", line) if match3: REDIRECTURL=line.replace('"', "") REDIRECTURL=REDIRECTURL.replace(r'\n', "\n") REDIRECTURL=REDIRECTURL.split("=") REDIRECTURL=REDIRECTURL[1].strip() self.websites[VHOST] = {'path':PATH, 'port':8000, 'logfile':LOGFILE, 'redirecturl':REDIRECTURL} def timedLogFormatter(timestamp, request): """ A custom request formatter. This is whats used when each request line is formatted. :param timestamp: :param request: A twisted.web.server.Request instance """ referrer = _escape(request.getHeader(b"referer") or b"-") agent = _escape(request.getHeader(b"user-agent") or b"-") duration = round(time.time() - request.started, 4) line = ( u'"%(ip)s" %(duration)ss "%(method)s %(uri)s %(protocol)s" ' u'%(code)d %(length)s "%(agent)s"' % dict( ip=_escape(request.getClientIP() or b"-"), duration=duration, method=_escape(request.method), uri=_escape(request.uri), protocol=_escape(request.clientproto), code=request.code, length=request.sentLength or u"-", agent=agent )) return line def start(self): self.loadSites() if self.config["ip"] == "0.0.0.0": self.config["ip"]=Utils.getIP() #define phishing sites for key in self.websites: self.phishingsites[key] = PhishingSite(self.config, key, self.websites[key]['path'], self.logpath, "logs/" + self.websites[key]['logfile'], self.db, self.websites[key]['redirecturl']).getResource() site_length = 0 for key in self.phishingsites: if (len(key) > site_length): site_length = len(key) # if we are doing port based print for key in self.phishingsites: for port in range(self.MINPORT, self.MAXPORT): try: site = Site(self.phishingsites[key], logPath=self.logpath + "logs/" + self.websites[key]['logfile']+".access") # site.logRequest = True reactor.listenTCP(port, site) print "Started website [%s] on [http://%s:%s]" % (('{:<%i}' % (site_length)).format(key), self.config["ip"], port) self.websites[key]['port'] = port break except twisted.internet.error.CannotListenError, ex: continue # if we are doing virtual hosts if (self.config["enable_host_based_vhosts"] == "1"): print root = vhost.NameVirtualHost() site_length += len("." + self.config["phishing_domain"]) # add each port based vhost to the nam based vhost for key in self.phishingsites: root.addHost(key + "." + self.config["phishing_domain"], proxy.ReverseProxyResource('localhost', self.websites[key]['port'], '')) print "Created VHOST [%s] -> [http://%s:%s]" % (('{:<%i}' % (site_length)).format(key + "." + self.config["phishing_domain"]), self.config["ip"], str(self.websites[key]['port'])) # add a mapping for the base IP address to map to one of the sites if (self.phishingsites): root.addHost(self.config["ip"], proxy.ReverseProxyResource('localhost', int(self.websites[self.phishingsites.keys()[0]]['port']), '')) try: site = Site(root, logPath=self.logpath + "logs/root.log.access") # site.logRequest = True reactor.listenTCP(int(self.config["default_web_port"]), site) except twisted.internet.error.CannotListenError, ex: print "ERROR: Could not start web service listener on port [80]!" print "ERROR: Host Based Virtual Hosting will not function!" else: print "ERROR: Could not start web service listener on port [80]!" print "ERROR: Host Based Virtual Hosting will not function!"
def load_user(user_id): username = MyDB.get_username_by_id( user_id ) isAdmin = MyDB.get_isAdmin_by_id(user_id) return MyUser( user_id, username, isAdmin )
class PhishingWebServer(): def __init__(self, config): self.config = config self.logpath = os.getcwd() + "/" + self.config["domain_name"] + "_" + self.config["phishing_domain"] + "/" #ensure log path exists if not os.path.exists(self.logpath): os.makedirs(self.logpath) if not os.path.exists(self.logpath+"logs/"): os.makedirs(self.logpath+"/logs") # set up database connection self.db = MyDB(sqlite_file=self.logpath) self.websites = {} self.phishingsites = {} self.MINPORT = int(self.config["vhost_port_min"]) self.MAXPORT = int(self.config["vhost_port_max"]) def getTemplates(self): templates = [] db_static_templates = self.db.getWebTemplates(ttype="static") db_dynamic_templates = self.db.getWebTemplates(ttype="dynamic") if (db_static_templates or db_dynamic_templates): for template in db_static_templates: parts = template.split("[-]") template_file = parts[0] + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile(template_file): templates.append(parts[0]) print "STATIC = [%s]" % (parts[0]) for template in db_dynamic_templates: parts = template.split("[-]") template_file = parts[0] + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile(template_file): templates.append(parts[0]) print "DYNAMIC = [%s]" % (parts[0]) else: for f in os.listdir(self.config["web_template_path"]): template_file = os.path.join(self.config["web_template_path"], f) + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile(template_file): templates.append(os.path.join(self.config["web_template_path"], f)) print "FIXED = [%s]" % (os.path.join(self.config["web_template_path"], f)) return templates def loadSites(self): templates = self.getTemplates() print # loop over each web template for f in templates: template_file = f + "/CONFIG" if Utils.is_readable(template_file) and os.path.isfile(template_file): print "Found the following web sites: [%s]" % template_file # read in the VHOST, LOGFILE, and REDIRECTURL VHOST = "" LOGFILE = "" REDIRECTURL = "" #PATH = self.config["web_template_path"] + f + "/" PATH = f + "/" with open (template_file, "r") as myfile: for line in myfile.readlines(): match=re.search("VHOST=", line) if match: VHOST=line.replace('"', "") VHOST=VHOST.split("=") VHOST=VHOST[1].lower().strip() match2=re.search("LOGFILE=", line) if match2: LOGFILE=line.replace('"', "") LOGFILE=LOGFILE.split("=") LOGFILE=LOGFILE[1].strip() match3=re.search("REDIRECTURL=", line) if match3: REDIRECTURL=line.replace('"', "") REDIRECTURL=REDIRECTURL.replace(r'\n', "\n") REDIRECTURL=REDIRECTURL.split("=") REDIRECTURL=REDIRECTURL[1].strip() self.websites[VHOST] = {'path':PATH, 'port':8000, 'logfile':LOGFILE, 'redirecturl':REDIRECTURL} def timedLogFormatter(timestamp, request): """ A custom request formatter. This is whats used when each request line is formatted. :param timestamp: :param request: A twisted.web.server.Request instance """ #referrer = _escape(request.getHeader(b"referer") or b"-") agent = _escape(request.getHeader(b"user-agent") or b"-") duration = round(time.time() - request.started, 4) line = ( u'"%(ip)s" %(duration)ss "%(method)s %(uri)s %(protocol)s" ' u'%(code)d %(length)s "%(agent)s"' % dict( ip=_escape(request.getClientIP() or b"-"), duration=duration, method=_escape(request.method), uri=_escape(request.uri), protocol=_escape(request.clientproto), code=request.code, length=request.sentLength or u"-", agent=agent )) return line def start(self): self.loadSites() if self.config["ip"] == "0.0.0.0": self.config["ip"]=Utils.getIP() #define phishing sites for key in self.websites: self.phishingsites[key] = PhishingSite(self.config, key, self.websites[key]['path'], self.logpath, "logs/" + self.websites[key]['logfile'], self.db, self.websites[key]['redirecturl']).getResource() site_length = 0 for key in self.phishingsites: if (len(key) > site_length): site_length = len(key) # if we are doing port based print for key in self.phishingsites: for port in range(self.MINPORT, self.MAXPORT): try: site = Site(self.phishingsites[key], logPath=self.logpath + "logs/" + self.websites[key]['logfile']+".access") # site.logRequest = True reactor.listenTCP(port, site) print "Started website [%s] on [http://%s:%s]" % (('{:<%i}' % (site_length)).format(key), self.config["ip"], port) self.websites[key]['port'] = port break except twisted.internet.error.CannotListenError, ex: continue # if we are doing virtual hosts if (self.config["enable_host_based_vhosts"] == "1"): print # GENERATING SSL CERTS ARE CURRENTLY BROKEN # TODO: Fix this # generate new certificates # domains = "" # cert_path = "/etc/letsencrypt/live/" # first = True # for key in self.phishingsites: # domains += "-d " + key + "." + self.config["phishing_domain"] + " " # if first: # cert_path += key + "." + self.config["phishing_domain"] + "/" # first = False # # cmd = self.config["certbot_path"] + " certonly --register-unsafely-without-email --non-interactive --agree-tos --standalone --force-renewal " + domains # # env = os.environ # print "Generating SSL CERT" # proc = subprocess.Popen(cmd, executable='/bin/bash', env=env, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True) # result = proc.communicate()[0] # m = re.search(r'.* (\/etc\/letsencrypt\/live\/[^\/]+\/).*fullchain.pem.*', result) # print result # # cert_path = m.group(1) root = vhost.NameVirtualHost() site_length += len("." + self.config["phishing_domain"]) # add each port based vhost to the nam based vhost for key in self.phishingsites: root.addHost(key + "." + self.config["phishing_domain"], proxy.ReverseProxyResource('localhost', self.websites[key]['port'], '')) # print "Created VHOST [%s] -> [https://%s:%s]" % (('{:<%i}' % (site_length)).format(key + "." + self.config["phishing_domain"]), self.config["ip"], str(self.websites[key]['port'])) print "Created VHOST [%s] -> [http://%s:%s]" % (('{:<%i}' % (site_length)).format(key + "." + self.config["phishing_domain"]), self.config["ip"], str(self.websites[key]['port'])) # add a mapping for the base IP address to map to one of the sites if (self.phishingsites): root.addHost(self.config["ip"], proxy.ReverseProxyResource('localhost', int(self.websites[self.phishingsites.keys()[0]]['port']), '')) try: site = Site(root, logPath=self.logpath + "logs/root.log.access") # # ADD SSL CERT # sslContext = ssl.DefaultOpenSSLContextFactory( # cert_path + 'privkey.pem', # cert_path + 'fullchain.pem', # ) # reactor.listenSSL(int(self.config["default_web_ssl_port"]), site, contextFactory=sslContext) reactor.listenTCP(int(self.config["default_web_port"]), site) except twisted.internet.error.CannotListenError, ex: # print "ERROR: Could not start web service listener on port [" + int(self.config["default_web_ssl_port"]) + "]!" print "ERROR: Could not start web service listener on port [80]!" print ex print "ERROR: Host Based Virtual Hosting will not function!" else: # print "ERROR: Could not start web service listener on port [" + int(self.config["default_web_ssl_port"]) + "]!" print "ERROR: Could not start web service listener on port [80]!" print "ERROR: Host Based Virtual Hosting will not function!"