From 38fe5c960c870222aa0321db92bf69cb2af48396 Mon Sep 17 00:00:00 2001 From: mh4x0f Date: Sun, 3 May 2020 18:36:33 -0300 Subject: [PATCH] added show up pydhcpserver log explanation --- CHANGELOG.md | 3 ++ config/app/config.ini | 1 + config/app/sniffkin3.ini | 10 ++--- logs/ap/pydhcp_server.log | 0 wifipumpkin3/__init__.py | 8 +++- wifipumpkin3/core/controls/threads.py | 28 ++++++++++--- wifipumpkin3/core/packets/dhcpserver.py | 42 +++++++++++-------- wifipumpkin3/core/packets/dnsserver.py | 6 ++- wifipumpkin3/core/servers/dhcp/dhcp.py | 21 ++++++++++ wifipumpkin3/core/servers/dhcp/pyDHCP.py | 3 ++ wifipumpkin3/core/servers/mitm/mitmmode.py | 8 +++- wifipumpkin3/core/servers/mitm/sniffkin3.py | 20 +++++++-- .../core/servers/proxy/captiveflask.py | 8 ++++ wifipumpkin3/core/utility/constants.py | 25 +++++++++++ .../core/wirelessmode/wirelessmode.py | 3 +- 15 files changed, 148 insertions(+), 38 deletions(-) create mode 100644 logs/ap/pydhcp_server.log diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ac86e0..643cdf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file. ## [1.0.x] - 2020-xx-xx ### Added +- added show up pydhcpserver log explanation [mh4x0f] +- added redirecting HTTPS traffic to captive portal [mh4x0f] - added new format table for pretty printing [mh4x0f] ### Changed @@ -17,6 +19,7 @@ All notable changes to this project will be documented in this file. ### Removed ### Fixed +- fixed better mode to print stop/start threads info [mh4x0f] - fixed AttributeError Sniffkin3 object has no attribute help_plugins [mh4x0f] - fixed set as default HOSTNAME key on leases object [mh4x0f] - fixed settings default status_ap values that change on #23 [mh4x0f] diff --git a/config/app/config.ini b/config/app/config.ini index 163a78c..ee9046d 100644 --- a/config/app/config.ini +++ b/config/app/config.ini @@ -74,6 +74,7 @@ pydns_server=light-blue, #000000 responder3=light-green, #000000 sniffkin3=light-yellow, #000000 captiveflask=light-cyan, #000000 +pydhcp_server=light-magenta, #000000 [dhcp] broadcast=10.0.0.255 diff --git a/config/app/sniffkin3.ini b/config/app/sniffkin3.ini index f1e2373..8838a02 100644 --- a/config/app/sniffkin3.ini +++ b/config/app/sniffkin3.ini @@ -1,9 +1,9 @@ [plugins] -emails=false -ftp=false -hexdump=false +emails=true +ftp=true +hexdump=true imageCap=false httpCap=true summary=false -kerberos=false -NTLMSSP=false +kerberos=true +NTLMSSP=true diff --git a/logs/ap/pydhcp_server.log b/logs/ap/pydhcp_server.log new file mode 100644 index 0000000..e69de29 diff --git a/wifipumpkin3/__init__.py b/wifipumpkin3/__init__.py index ed80b5c..8b3d9a0 100644 --- a/wifipumpkin3/__init__.py +++ b/wifipumpkin3/__init__.py @@ -182,13 +182,17 @@ class PumpkinShell(Qt.QObject, ConsoleUI): """ start access point """ if len(self.Apthreads["RogueAP"]) > 0: print(display_messages("the AP is running at full power.", error=True)) - return + return self.interfaces = Linux.get_interfaces() if not self.conf.get( "accesspoint", self.commands["interface"] ) in self.interfaces.get("all"): - print(display_messages("the interface not found or is unavailable ", error=True)) + print( + display_messages( + "the interface not found or is unavailable ", error=True + ) + ) sys.exit(1) if self.wireless_controller.Start() != None: diff --git a/wifipumpkin3/core/controls/threads.py b/wifipumpkin3/core/controls/threads.py index 6a300ee..5142fec 100644 --- a/wifipumpkin3/core/controls/threads.py +++ b/wifipumpkin3/core/controls/threads.py @@ -80,8 +80,11 @@ class ProcessThread(QThread): return "[New Thread {} ({})]".format(self.procThread.pid(), self.objectName()) def readProcessOutput(self): - self.data = str(self.procThread.readAllStandardOutput(), encoding="ascii") - self._ProcssOutput.emit(self.data) + try: + self.data = str(self.procThread.readAllStandardOutput(), encoding="ascii") + self._ProcssOutput.emit(self.data) + except Exception: + pass def getpid(self): """ return the pid of current process in background""" @@ -100,10 +103,21 @@ class ProcessThread(QThread): list(self.cmd.keys())[0], self.cmd[list(self.cmd.keys())[0]] ) self.procThread.readyReadStandardOutput.connect(self.readProcessOutput) - print("[New Thread {} ({})]".format(self.procThread.pid(), self.objectName())) + print( + display_messages( + "starting {} pid: [{}]".format( + self.objectName(), self.procThread.pid() + ), + sucess=True, + ) + ) def stop(self): - print("Thread::[{}] successfully stopped.".format(self.objectName())) + print( + display_messages( + "thread {} successfully stopped".format(self.objectName()), info=True + ) + ) if hasattr(self, "procThread"): self.procThread.terminate() self.procThread.waitForFinished() @@ -201,7 +215,11 @@ class ProcessHostapd(QObject): ) def stop(self): - print("Thread::[{}] successfully stopped.".format(self.objectName())) + print( + display_messages( + "thread {} successfully stopped".format(self.objectName()), info=True + ) + ) if hasattr(self, "procHostapd"): self.started = False self.procHostapd.terminate() diff --git a/wifipumpkin3/core/packets/dhcpserver.py b/wifipumpkin3/core/packets/dhcpserver.py index e68e8c3..ffd4d90 100644 --- a/wifipumpkin3/core/packets/dhcpserver.py +++ b/wifipumpkin3/core/packets/dhcpserver.py @@ -1,11 +1,8 @@ -import logging import socket from dhcplib.packet import DHCPPacket, _FORMAT_CONVERSION_DESERIAL, DHCP_OPTIONS_TYPES from dhcplib import net, getifaddrslib import ipaddress as ip from queue import Queue - -log = logging.getLogger(__name__) from PyQt5.QtCore import QThread, pyqtSignal, pyqtSlot, QProcess, QObject from wifipumpkin3.core.config.globalimport import * from wifipumpkin3.core.utility.printer import display_messages @@ -61,11 +58,12 @@ class IpAddressClass(object): class DHCPProtocol(QObject): _request = pyqtSignal(object) - def __init__(self, DHCPConf): + def __init__(self, DHCPConf, output): QObject.__init__(self) self.dhcp_conf = DHCPConf self.IPADDR = iter(IpAddressClass(self.dhcp_conf["range"])) self.leases = {} + self.output_signal = output self.queue = Queue() self.message = [] self.started = True @@ -75,17 +73,17 @@ class DHCPProtocol(QObject): def datagram_received(self, data, addr): packet = DHCPPacket(data) - log.debug("RECV from %s:\n%s\n", addr, packet) + self.output_signal.emit("RECV from {}:\n{}\n".format(addr, packet)) send = False mac = str(packet.get_hardware_address()) if mac not in self.leases.keys(): self.ip_client = next(self.IPADDR) - self.leases[mac] = {"MAC": mac, "IP": str(self.ip_client),"HOSTNAME" : "" } + self.leases[mac] = {"MAC": mac, "IP": str(self.ip_client), "HOSTNAME": ""} else: self.ip_client = self.leases[mac]["IP"] if packet.is_dhcp_discover_packet(): - log.debug("DISCOVER") + self.output_signal.emit("DISCOVER: packet from {}".format(self.ip_client)) packet.transform_to_dhcp_offer_packet() # self._request.emit(packet.) packet.set_option("yiaddr", self.ip_client) @@ -93,7 +91,12 @@ class DHCPProtocol(QObject): # self._request.emit(packet.__str__()) send = True elif packet.is_dhcp_request_packet(): - log.debug("REQUEST") + self.output_signal.emit( + "REQUEST: packet from {} to {}".format( + self.ip_client, self.dhcp_conf["router"] + ) + ) + # configure packet massage ack packet.transform_to_dhcp_ack_packet() packet.set_option("yiaddr", self.ip_client) packet.set_option("siaddr", self.dhcp_conf["router"]) @@ -104,17 +107,17 @@ class DHCPProtocol(QObject): packet.set_option( "ip_address_lease_time", int(self.dhcp_conf["leasetimeMax"]) ) + # getting hostname is exist on packet for key in self.leases.keys(): for item in self.leases[key].keys(): if self.leases[key][item] == str(self.ip_client): self.leases[key]["HOSTNAME"] = self.getHostnamePakcet(packet) break self._request.emit(self.leases[mac]) - self.queue.put(self.leases[mac]) Refactor.writeFileDataToJson(C.CLIENTS_CONNECTED, self.leases, "w") send = True if send: - log.debug("SEND to %s:\n%s\n", addr, packet) + self.output_signal.emit("SEND to {}:\n{}\n".format(addr, packet)) ipaddr, port = addr if ipaddr == "0.0.0.0": ipaddr = "255.255.255.255" @@ -138,23 +141,22 @@ class DHCPProtocol(QObject): if packet._get_option_name(option_id) == "hostname": return result - def error_received(exc): - log.error("ERROR", exc_info=exc) + def error_received(self, exc): + self.output_signal("ERROR: {}".format(exc)) class DHCPThread(QThread): + send_output = pyqtSignal(object) + def __init__(self, iface, DHCPconf): QThread.__init__(self) self.iface = iface self.dhcp_conf = DHCPconf - self.DHCPProtocol = DHCPProtocol(self.dhcp_conf) + self.DHCPProtocol = DHCPProtocol(self.dhcp_conf, self.send_output) self.started = False def run(self): self.started = True - logging.basicConfig() - log = logging.getLogger("dhcplib") - log.setLevel(logging.DEBUG) server_address = self.dhcp_conf["router"] server_port = 67 @@ -180,7 +182,7 @@ class DHCPThread(QThread): self.DHCPProtocol.datagram_received(message, address) except Exception as e: # OSError: [Errno 9] Bad file descriptor when close socket - pass + print(display_messages("socket error: {}".format(e), error=True)) def getpid(self): """ return the pid of current process in background""" @@ -193,5 +195,9 @@ class DHCPThread(QThread): def stop(self): self.started = False Refactor.writeFileDataToJson(C.CLIENTS_CONNECTED, {}, "w") - print("Thread::[{}] successfully stopped.".format(self.objectName())) + print( + display_messages( + "thread {} successfully stopped".format(self.objectName()), info=True + ) + ) self.sock.close() diff --git a/wifipumpkin3/core/packets/dnsserver.py b/wifipumpkin3/core/packets/dnsserver.py index 970f854..b5df2c1 100644 --- a/wifipumpkin3/core/packets/dnsserver.py +++ b/wifipumpkin3/core/packets/dnsserver.py @@ -294,4 +294,8 @@ class DNSServerThread(QThread): def stop(self): self.udp_server.stop() self.tcp_server.stop() - print("Thread::[{}] successfully stopped.".format(self.objectName())) + print( + display_messages( + "thread {} successfully stopped".format(self.objectName()), info=True + ) + ) diff --git a/wifipumpkin3/core/servers/dhcp/dhcp.py b/wifipumpkin3/core/servers/dhcp/dhcp.py index a460cb1..f349e38 100644 --- a/wifipumpkin3/core/servers/dhcp/dhcp.py +++ b/wifipumpkin3/core/servers/dhcp/dhcp.py @@ -6,6 +6,7 @@ from wifipumpkin3.core.utility.component import ComponentBlueprint from isc_dhcp_leases.iscdhcpleases import IscDhcpLeases from wifipumpkin3.core.controls.threads import ProcessThread from wifipumpkin3.exceptions.errors.dhcpException import DHCPServerSettingsError +from wifipumpkin3.core.widgets.default.logger_manager import LoggerManager # This file is part of the wifipumpkin3 Open Source Project. # wifipumpkin3 is licensed under the Apache 2.0. @@ -38,6 +39,22 @@ class DHCPServers(QtCore.QObject, ComponentBlueprint): self.DHCPConf = self.Settings.confingDHCP + self.loggermanager = LoggerManager.getInstance() + self.configure_logger() + + def configure_logger(self): + config_extra = self.loggermanager.getExtraConfig(self.ID) + config_extra["extra"]["session"] = self.parent.currentSessionID + + self.logger = StandardLog( + self.ID, + colorize=self.conf.get("settings", "log_colorize", format=bool), + serialize=self.conf.get("settings", "log_serialize", format=bool), + config=config_extra, + ) + self.logger.filename = self.LogFile + self.loggermanager.add(self.ID, self.logger) + def prereq(self): dh, gateway = self.DHCPConf["router"], Linux.get_interfaces()["gateway"] if gateway != None: @@ -49,6 +66,10 @@ class DHCPServers(QtCore.QObject, ComponentBlueprint): "DHCPServer", "dhcp same ip range address " ) + def LogOutput(self, data): + if self.conf.get("accesspoint", "status_ap", format=bool): + self.logger.info(data) + def isChecked(self): return self.conf.get("accesspoint", self.ID, format=bool) diff --git a/wifipumpkin3/core/servers/dhcp/pyDHCP.py b/wifipumpkin3/core/servers/dhcp/pyDHCP.py index 719c95a..c5ea980 100644 --- a/wifipumpkin3/core/servers/dhcp/pyDHCP.py +++ b/wifipumpkin3/core/servers/dhcp/pyDHCP.py @@ -1,3 +1,4 @@ +from wifipumpkin3.core.config.globalimport import * from wifipumpkin3.core.packets.dhcpserver import DHCPThread from wifipumpkin3.core.servers.dhcp.dhcp import DHCPServers from wifipumpkin3.core.utility.printer import display_messages, setcolor @@ -23,6 +24,7 @@ from wifipumpkin3.core.utility.printer import display_messages, setcolor class PyDHCP(DHCPServers): Name = "Python DHCP Server" ID = "pydhcp_server" + LogFile = C.LOG_PYDHCPSERVER def __init__(self, parent=0): super(PyDHCP, self).__init__(parent) @@ -54,4 +56,5 @@ class PyDHCP(DHCPServers): def boot(self): self.reactor = DHCPThread(self.ifaceHostapd, self.DHCPConf) self.reactor.DHCPProtocol._request.connect(self.get_DHCPoutPut) + self.reactor.send_output.connect(self.LogOutput) self.reactor.setObjectName(self.ID) diff --git a/wifipumpkin3/core/servers/mitm/mitmmode.py b/wifipumpkin3/core/servers/mitm/mitmmode.py index 03c4b06..a82367e 100644 --- a/wifipumpkin3/core/servers/mitm/mitmmode.py +++ b/wifipumpkin3/core/servers/mitm/mitmmode.py @@ -106,8 +106,12 @@ class MitmMode(Widget): ) except IndexError as e: pass - - print(display_messages("unknown sintax command: {}\n".format(proxy_name),error=True)) + + print( + display_messages( + "unknown sintax command: {}\n".format(proxy_name), error=True + ) + ) @property def getPlugins(self): diff --git a/wifipumpkin3/core/servers/mitm/sniffkin3.py b/wifipumpkin3/core/servers/mitm/sniffkin3.py index e39c255..1776775 100644 --- a/wifipumpkin3/core/servers/mitm/sniffkin3.py +++ b/wifipumpkin3/core/servers/mitm/sniffkin3.py @@ -195,11 +195,21 @@ class Sniffkin3Core(QtCore.QThread): self.plugins[plugin_load.Name] = plugin_load self.plugins[plugin_load.Name].output = self._ProcssOutput self.plugins[plugin_load.Name].session = self.session - print("\n[*] {} running on port 80/8080:\n".format(self.getID())) + + print( + display_messages( + "starting {} port: [80, 8080]".format(self.getID()), info=True + ) + ) for name in self.plugins.keys(): if self.config.get("plugins", name, format=bool): self.plugins[name].getInstance()._activated = True - print("TCPProxy::{0:17} status:On".format(name)) + print( + display_messages( + "sniffkin3 -> {0:10} activated".format(name), sucess=True + ) + ) + print("\n") q = queue.Queue() sniff = Thread(target=self.sniffer, args=(q,)) @@ -299,4 +309,8 @@ class Sniffkin3Core(QtCore.QThread): def stop(self): self.stopped = True - print("Thread::[{}] successfully stopped.".format(self.objectName())) + print( + display_messages( + "thread {} successfully stopped".format(self.objectName()), info=True + ) + ) diff --git a/wifipumpkin3/core/servers/proxy/captiveflask.py b/wifipumpkin3/core/servers/proxy/captiveflask.py index fda322e..fd2aba5 100644 --- a/wifipumpkin3/core/servers/proxy/captiveflask.py +++ b/wifipumpkin3/core/servers/proxy/captiveflask.py @@ -116,6 +116,14 @@ class CaptivePortal(ProxyMode): iface=IFACE, ip=IP_ADDRESS, port=PORT ) ) + print( + display_messages("redirecting HTTPS traffic to captive portal", info=True) + ) + self.add_default_rules( + "iptables -t nat -A PREROUTING -i {iface} -p tcp --dport 443 -j DNAT --to-destination {ip}:{port}".format( + iface=IFACE, ip=IP_ADDRESS, port=PORT + ) + ) self.runDefaultRules() def boot(self): diff --git a/wifipumpkin3/core/utility/constants.py b/wifipumpkin3/core/utility/constants.py index 8b91a36..f6f211c 100644 --- a/wifipumpkin3/core/utility/constants.py +++ b/wifipumpkin3/core/utility/constants.py @@ -74,6 +74,7 @@ DOCKERHOSTAPDCONF_PATH = "/etc/hostapd/hostapd.conf" # logging LOG_PUMPKINPROXY = user_config_dir + "/.config/wifipumpkin3/logs/ap/pumpkin_proxy.log" LOG_PYDNSSERVER = user_config_dir + "/.config/wifipumpkin3/logs/ap/pydns_server.log" +LOG_PYDHCPSERVER = user_config_dir + "/.config/wifipumpkin3/logs/ap/pydhcp_server.log" LOG_SNIFFKIN3 = user_config_dir + "/.config/wifipumpkin3/logs/ap/sniffkin3.log" LOG_CAPTIVEPO = user_config_dir + "/.config/wifipumpkin3/logs/ap/captiveportal.log" LOG_RESPONDER3 = user_config_dir + "/.config/wifipumpkin3/logs/ap/responder3.log" @@ -81,12 +82,36 @@ LOG_HOSTAPD = user_config_dir + "/.config/wifipumpkin3/logs/ap/hostapd.log" LOG_ALL = user_config_dir + "/.config/wifipumpkin3/logs/everything.log" +LOG_BASE = user_config_dir + "/.config/wifipumpkin3/logs/ap" + + +ALL_LOGSPATH = ( + LOG_PUMPKINPROXY, + LOG_PYDNSSERVER, + LOG_PYDHCPSERVER, + LOG_SNIFFKIN3, + LOG_SNIFFKIN3, + LOG_CAPTIVEPO, + LOG_RESPONDER3, + LOG_HOSTAPD, + LOG_ALL, +) + # APP SETTINGS CONFIG_INI = user_config_dir + "/.config/wifipumpkin3/config/app/config.ini" CONFIG_SK_INI = user_config_dir + "/.config/wifipumpkin3/config/app/sniffkin3.ini" CONFIG_PP_INI = user_config_dir + "/.config/wifipumpkin3/config/app/pumpkinproxy.ini" CONFIG_CP_INI = user_config_dir + "/.config/wifipumpkin3/config/app/captive-portal.ini" + +ALL_CONFIGSINI = { + "config": CONFIG_INI, + "sniffkin3": CONFIG_SK_INI, + "pumpkinproxy": CONFIG_PP_INI, + "captiveflask": CONFIG_CP_INI, +} + + TEMPLATES = "templates/fakeupdate/Windows_Update/Settins_WinUpdate.html" TEMPLATE_PH = "templates/phishing/custom/index.html" TEMPLATE_CLONE = "templates/phishing/web_server/index.html" diff --git a/wifipumpkin3/core/wirelessmode/wirelessmode.py b/wifipumpkin3/core/wirelessmode/wirelessmode.py index 61a5ecf..95fde64 100644 --- a/wifipumpkin3/core/wirelessmode/wirelessmode.py +++ b/wifipumpkin3/core/wirelessmode/wirelessmode.py @@ -92,7 +92,6 @@ class Mode(Qt.QObject): self.PostStart() def PostStart(self): - print("-------------------------------") # set configure iptables self.setIptables() # set AP status true @@ -115,7 +114,7 @@ class Mode(Qt.QObject): ech = ech.replace("$wlan", self.ifaceHostapd) if not "$inet" in ech: - system(ech) + popen(ech) except Exception as e: print(e)