added show up pydhcpserver log explanation

This commit is contained in:
mh4x0f 2020-05-03 18:36:33 -03:00
parent f372012daf
commit 38fe5c960c
15 changed files with 148 additions and 38 deletions

View File

@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file.
## [1.0.x] - 2020-xx-xx ## [1.0.x] - 2020-xx-xx
### Added ### Added
- added show up pydhcpserver log explanation [mh4x0f]
- added redirecting HTTPS traffic to captive portal [mh4x0f]
- added new format table for pretty printing [mh4x0f] - added new format table for pretty printing [mh4x0f]
### Changed ### Changed
@ -17,6 +19,7 @@ All notable changes to this project will be documented in this file.
### Removed ### Removed
### Fixed ### Fixed
- fixed better mode to print stop/start threads info [mh4x0f]
- fixed AttributeError Sniffkin3 object has no attribute help_plugins [mh4x0f] - fixed AttributeError Sniffkin3 object has no attribute help_plugins [mh4x0f]
- fixed set as default HOSTNAME key on leases object [mh4x0f] - fixed set as default HOSTNAME key on leases object [mh4x0f]
- fixed settings default status_ap values that change on #23 [mh4x0f] - fixed settings default status_ap values that change on #23 [mh4x0f]

View File

@ -74,6 +74,7 @@ pydns_server=light-blue, #000000
responder3=light-green, #000000 responder3=light-green, #000000
sniffkin3=light-yellow, #000000 sniffkin3=light-yellow, #000000
captiveflask=light-cyan, #000000 captiveflask=light-cyan, #000000
pydhcp_server=light-magenta, #000000
[dhcp] [dhcp]
broadcast=10.0.0.255 broadcast=10.0.0.255

View File

@ -1,9 +1,9 @@
[plugins] [plugins]
emails=false emails=true
ftp=false ftp=true
hexdump=false hexdump=true
imageCap=false imageCap=false
httpCap=true httpCap=true
summary=false summary=false
kerberos=false kerberos=true
NTLMSSP=false NTLMSSP=true

View File

View File

@ -182,13 +182,17 @@ class PumpkinShell(Qt.QObject, ConsoleUI):
""" start access point """ """ start access point """
if len(self.Apthreads["RogueAP"]) > 0: if len(self.Apthreads["RogueAP"]) > 0:
print(display_messages("the AP is running at full power.", error=True)) print(display_messages("the AP is running at full power.", error=True))
return return
self.interfaces = Linux.get_interfaces() self.interfaces = Linux.get_interfaces()
if not self.conf.get( if not self.conf.get(
"accesspoint", self.commands["interface"] "accesspoint", self.commands["interface"]
) in self.interfaces.get("all"): ) 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) sys.exit(1)
if self.wireless_controller.Start() != None: if self.wireless_controller.Start() != None:

View File

@ -80,8 +80,11 @@ class ProcessThread(QThread):
return "[New Thread {} ({})]".format(self.procThread.pid(), self.objectName()) return "[New Thread {} ({})]".format(self.procThread.pid(), self.objectName())
def readProcessOutput(self): def readProcessOutput(self):
self.data = str(self.procThread.readAllStandardOutput(), encoding="ascii") try:
self._ProcssOutput.emit(self.data) self.data = str(self.procThread.readAllStandardOutput(), encoding="ascii")
self._ProcssOutput.emit(self.data)
except Exception:
pass
def getpid(self): def getpid(self):
""" return the pid of current process in background""" """ 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]] list(self.cmd.keys())[0], self.cmd[list(self.cmd.keys())[0]]
) )
self.procThread.readyReadStandardOutput.connect(self.readProcessOutput) 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): 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"): if hasattr(self, "procThread"):
self.procThread.terminate() self.procThread.terminate()
self.procThread.waitForFinished() self.procThread.waitForFinished()
@ -201,7 +215,11 @@ class ProcessHostapd(QObject):
) )
def stop(self): 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"): if hasattr(self, "procHostapd"):
self.started = False self.started = False
self.procHostapd.terminate() self.procHostapd.terminate()

View File

@ -1,11 +1,8 @@
import logging
import socket import socket
from dhcplib.packet import DHCPPacket, _FORMAT_CONVERSION_DESERIAL, DHCP_OPTIONS_TYPES from dhcplib.packet import DHCPPacket, _FORMAT_CONVERSION_DESERIAL, DHCP_OPTIONS_TYPES
from dhcplib import net, getifaddrslib from dhcplib import net, getifaddrslib
import ipaddress as ip import ipaddress as ip
from queue import Queue from queue import Queue
log = logging.getLogger(__name__)
from PyQt5.QtCore import QThread, pyqtSignal, pyqtSlot, QProcess, QObject from PyQt5.QtCore import QThread, pyqtSignal, pyqtSlot, QProcess, QObject
from wifipumpkin3.core.config.globalimport import * from wifipumpkin3.core.config.globalimport import *
from wifipumpkin3.core.utility.printer import display_messages from wifipumpkin3.core.utility.printer import display_messages
@ -61,11 +58,12 @@ class IpAddressClass(object):
class DHCPProtocol(QObject): class DHCPProtocol(QObject):
_request = pyqtSignal(object) _request = pyqtSignal(object)
def __init__(self, DHCPConf): def __init__(self, DHCPConf, output):
QObject.__init__(self) QObject.__init__(self)
self.dhcp_conf = DHCPConf self.dhcp_conf = DHCPConf
self.IPADDR = iter(IpAddressClass(self.dhcp_conf["range"])) self.IPADDR = iter(IpAddressClass(self.dhcp_conf["range"]))
self.leases = {} self.leases = {}
self.output_signal = output
self.queue = Queue() self.queue = Queue()
self.message = [] self.message = []
self.started = True self.started = True
@ -75,17 +73,17 @@ class DHCPProtocol(QObject):
def datagram_received(self, data, addr): def datagram_received(self, data, addr):
packet = DHCPPacket(data) 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 send = False
mac = str(packet.get_hardware_address()) mac = str(packet.get_hardware_address())
if mac not in self.leases.keys(): if mac not in self.leases.keys():
self.ip_client = next(self.IPADDR) 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: else:
self.ip_client = self.leases[mac]["IP"] self.ip_client = self.leases[mac]["IP"]
if packet.is_dhcp_discover_packet(): 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() packet.transform_to_dhcp_offer_packet()
# self._request.emit(packet.) # self._request.emit(packet.)
packet.set_option("yiaddr", self.ip_client) packet.set_option("yiaddr", self.ip_client)
@ -93,7 +91,12 @@ class DHCPProtocol(QObject):
# self._request.emit(packet.__str__()) # self._request.emit(packet.__str__())
send = True send = True
elif packet.is_dhcp_request_packet(): 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.transform_to_dhcp_ack_packet()
packet.set_option("yiaddr", self.ip_client) packet.set_option("yiaddr", self.ip_client)
packet.set_option("siaddr", self.dhcp_conf["router"]) packet.set_option("siaddr", self.dhcp_conf["router"])
@ -104,17 +107,17 @@ class DHCPProtocol(QObject):
packet.set_option( packet.set_option(
"ip_address_lease_time", int(self.dhcp_conf["leasetimeMax"]) "ip_address_lease_time", int(self.dhcp_conf["leasetimeMax"])
) )
# getting hostname is exist on packet
for key in self.leases.keys(): for key in self.leases.keys():
for item in self.leases[key].keys(): for item in self.leases[key].keys():
if self.leases[key][item] == str(self.ip_client): if self.leases[key][item] == str(self.ip_client):
self.leases[key]["HOSTNAME"] = self.getHostnamePakcet(packet) self.leases[key]["HOSTNAME"] = self.getHostnamePakcet(packet)
break break
self._request.emit(self.leases[mac]) self._request.emit(self.leases[mac])
self.queue.put(self.leases[mac])
Refactor.writeFileDataToJson(C.CLIENTS_CONNECTED, self.leases, "w") Refactor.writeFileDataToJson(C.CLIENTS_CONNECTED, self.leases, "w")
send = True send = True
if send: 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 ipaddr, port = addr
if ipaddr == "0.0.0.0": if ipaddr == "0.0.0.0":
ipaddr = "255.255.255.255" ipaddr = "255.255.255.255"
@ -138,23 +141,22 @@ class DHCPProtocol(QObject):
if packet._get_option_name(option_id) == "hostname": if packet._get_option_name(option_id) == "hostname":
return result return result
def error_received(exc): def error_received(self, exc):
log.error("ERROR", exc_info=exc) self.output_signal("ERROR: {}".format(exc))
class DHCPThread(QThread): class DHCPThread(QThread):
send_output = pyqtSignal(object)
def __init__(self, iface, DHCPconf): def __init__(self, iface, DHCPconf):
QThread.__init__(self) QThread.__init__(self)
self.iface = iface self.iface = iface
self.dhcp_conf = DHCPconf self.dhcp_conf = DHCPconf
self.DHCPProtocol = DHCPProtocol(self.dhcp_conf) self.DHCPProtocol = DHCPProtocol(self.dhcp_conf, self.send_output)
self.started = False self.started = False
def run(self): def run(self):
self.started = True self.started = True
logging.basicConfig()
log = logging.getLogger("dhcplib")
log.setLevel(logging.DEBUG)
server_address = self.dhcp_conf["router"] server_address = self.dhcp_conf["router"]
server_port = 67 server_port = 67
@ -180,7 +182,7 @@ class DHCPThread(QThread):
self.DHCPProtocol.datagram_received(message, address) self.DHCPProtocol.datagram_received(message, address)
except Exception as e: except Exception as e:
# OSError: [Errno 9] Bad file descriptor when close socket # OSError: [Errno 9] Bad file descriptor when close socket
pass print(display_messages("socket error: {}".format(e), error=True))
def getpid(self): def getpid(self):
""" return the pid of current process in background""" """ return the pid of current process in background"""
@ -193,5 +195,9 @@ class DHCPThread(QThread):
def stop(self): def stop(self):
self.started = False self.started = False
Refactor.writeFileDataToJson(C.CLIENTS_CONNECTED, {}, "w") 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() self.sock.close()

View File

@ -294,4 +294,8 @@ class DNSServerThread(QThread):
def stop(self): def stop(self):
self.udp_server.stop() self.udp_server.stop()
self.tcp_server.stop() self.tcp_server.stop()
print("Thread::[{}] successfully stopped.".format(self.objectName())) print(
display_messages(
"thread {} successfully stopped".format(self.objectName()), info=True
)
)

View File

@ -6,6 +6,7 @@ from wifipumpkin3.core.utility.component import ComponentBlueprint
from isc_dhcp_leases.iscdhcpleases import IscDhcpLeases from isc_dhcp_leases.iscdhcpleases import IscDhcpLeases
from wifipumpkin3.core.controls.threads import ProcessThread from wifipumpkin3.core.controls.threads import ProcessThread
from wifipumpkin3.exceptions.errors.dhcpException import DHCPServerSettingsError 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. # This file is part of the wifipumpkin3 Open Source Project.
# wifipumpkin3 is licensed under the Apache 2.0. # wifipumpkin3 is licensed under the Apache 2.0.
@ -38,6 +39,22 @@ class DHCPServers(QtCore.QObject, ComponentBlueprint):
self.DHCPConf = self.Settings.confingDHCP 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): def prereq(self):
dh, gateway = self.DHCPConf["router"], Linux.get_interfaces()["gateway"] dh, gateway = self.DHCPConf["router"], Linux.get_interfaces()["gateway"]
if gateway != None: if gateway != None:
@ -49,6 +66,10 @@ class DHCPServers(QtCore.QObject, ComponentBlueprint):
"DHCPServer", "dhcp same ip range address " "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): def isChecked(self):
return self.conf.get("accesspoint", self.ID, format=bool) return self.conf.get("accesspoint", self.ID, format=bool)

View File

@ -1,3 +1,4 @@
from wifipumpkin3.core.config.globalimport import *
from wifipumpkin3.core.packets.dhcpserver import DHCPThread from wifipumpkin3.core.packets.dhcpserver import DHCPThread
from wifipumpkin3.core.servers.dhcp.dhcp import DHCPServers from wifipumpkin3.core.servers.dhcp.dhcp import DHCPServers
from wifipumpkin3.core.utility.printer import display_messages, setcolor 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): class PyDHCP(DHCPServers):
Name = "Python DHCP Server" Name = "Python DHCP Server"
ID = "pydhcp_server" ID = "pydhcp_server"
LogFile = C.LOG_PYDHCPSERVER
def __init__(self, parent=0): def __init__(self, parent=0):
super(PyDHCP, self).__init__(parent) super(PyDHCP, self).__init__(parent)
@ -54,4 +56,5 @@ class PyDHCP(DHCPServers):
def boot(self): def boot(self):
self.reactor = DHCPThread(self.ifaceHostapd, self.DHCPConf) self.reactor = DHCPThread(self.ifaceHostapd, self.DHCPConf)
self.reactor.DHCPProtocol._request.connect(self.get_DHCPoutPut) self.reactor.DHCPProtocol._request.connect(self.get_DHCPoutPut)
self.reactor.send_output.connect(self.LogOutput)
self.reactor.setObjectName(self.ID) self.reactor.setObjectName(self.ID)

View File

@ -106,8 +106,12 @@ class MitmMode(Widget):
) )
except IndexError as e: except IndexError as e:
pass 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 @property
def getPlugins(self): def getPlugins(self):

View File

@ -195,11 +195,21 @@ class Sniffkin3Core(QtCore.QThread):
self.plugins[plugin_load.Name] = plugin_load self.plugins[plugin_load.Name] = plugin_load
self.plugins[plugin_load.Name].output = self._ProcssOutput self.plugins[plugin_load.Name].output = self._ProcssOutput
self.plugins[plugin_load.Name].session = self.session 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(): for name in self.plugins.keys():
if self.config.get("plugins", name, format=bool): if self.config.get("plugins", name, format=bool):
self.plugins[name].getInstance()._activated = True 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") print("\n")
q = queue.Queue() q = queue.Queue()
sniff = Thread(target=self.sniffer, args=(q,)) sniff = Thread(target=self.sniffer, args=(q,))
@ -299,4 +309,8 @@ class Sniffkin3Core(QtCore.QThread):
def stop(self): def stop(self):
self.stopped = True self.stopped = True
print("Thread::[{}] successfully stopped.".format(self.objectName())) print(
display_messages(
"thread {} successfully stopped".format(self.objectName()), info=True
)
)

View File

@ -116,6 +116,14 @@ class CaptivePortal(ProxyMode):
iface=IFACE, ip=IP_ADDRESS, port=PORT 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() self.runDefaultRules()
def boot(self): def boot(self):

View File

@ -74,6 +74,7 @@ DOCKERHOSTAPDCONF_PATH = "/etc/hostapd/hostapd.conf"
# logging # logging
LOG_PUMPKINPROXY = user_config_dir + "/.config/wifipumpkin3/logs/ap/pumpkin_proxy.log" 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_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_SNIFFKIN3 = user_config_dir + "/.config/wifipumpkin3/logs/ap/sniffkin3.log"
LOG_CAPTIVEPO = user_config_dir + "/.config/wifipumpkin3/logs/ap/captiveportal.log" LOG_CAPTIVEPO = user_config_dir + "/.config/wifipumpkin3/logs/ap/captiveportal.log"
LOG_RESPONDER3 = user_config_dir + "/.config/wifipumpkin3/logs/ap/responder3.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_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 # APP SETTINGS
CONFIG_INI = user_config_dir + "/.config/wifipumpkin3/config/app/config.ini" CONFIG_INI = user_config_dir + "/.config/wifipumpkin3/config/app/config.ini"
CONFIG_SK_INI = user_config_dir + "/.config/wifipumpkin3/config/app/sniffkin3.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_PP_INI = user_config_dir + "/.config/wifipumpkin3/config/app/pumpkinproxy.ini"
CONFIG_CP_INI = user_config_dir + "/.config/wifipumpkin3/config/app/captive-portal.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" TEMPLATES = "templates/fakeupdate/Windows_Update/Settins_WinUpdate.html"
TEMPLATE_PH = "templates/phishing/custom/index.html" TEMPLATE_PH = "templates/phishing/custom/index.html"
TEMPLATE_CLONE = "templates/phishing/web_server/index.html" TEMPLATE_CLONE = "templates/phishing/web_server/index.html"

View File

@ -92,7 +92,6 @@ class Mode(Qt.QObject):
self.PostStart() self.PostStart()
def PostStart(self): def PostStart(self):
print("-------------------------------")
# set configure iptables # set configure iptables
self.setIptables() self.setIptables()
# set AP status true # set AP status true
@ -115,7 +114,7 @@ class Mode(Qt.QObject):
ech = ech.replace("$wlan", self.ifaceHostapd) ech = ech.replace("$wlan", self.ifaceHostapd)
if not "$inet" in ech: if not "$inet" in ech:
system(ech) popen(ech)
except Exception as e: except Exception as e:
print(e) print(e)