def do_run(self, args): """ execute module """ print( display_messages( "setting interface: {} monitor momde".format( setcolor(self.options.get("interface")[0], color="green") ), info=True, ) ) self.set_monitor_mode("monitor") print(display_messages("starting Channel Hopping ", info=True)) self.p = Process( target=self.channel_hopper, args=(self.options.get("interface")[0],) ) self.p.daemon = True self.p.start() print(display_messages("sniffing... ", info=True)) sniff( iface=self.options.get("interface")[0], prn=self.sniffAp, timeout=None if int(self.options.get("timeout")[0]) == 0 else int(self.options.get("timeout")[0]), ) self.p.terminate() self.set_monitor_mode() print(display_messages("thread sniffing successfully stopped", info=True))
def do_info(self, args): """ get info custom captiveflask portals """ if args: plugin_name = args.split()[0] if not plugin_name in self.plugins_remote: print( display_messages( "plugin: {} not found ".format(plugin_name), error=True ) ) return print(display_messages("Information", info=True, sublime=True)) list_keys = [ "Name", "Author", "Version", "Installed", "Preview", "Description", ] for item in list_keys: print( " {} : {}".format( setcolor(item, color="blue"), setcolor( self.plugins_remote[plugin_name][item.lower()], color="yellow", ), ) ) print("\n")
def do_install(self, args): """ install custom captiveflask portals """ if not path.isdir(self.captiveflask_path): print( display_messages( "directory {} not found".format(self.captiveflask_path), error=True ) ) return if args: plugin_name = args.split()[0] if not plugin_name in self.plugins_remote: print( display_messages( "plugin: {} not found ".format(plugin_name), error=True ) ) return self.installPluginByName(plugin_name) return self.show_help_command("help_extra_captiveflask") anwer_question = input("So, do you want to install all plugins ? (Y/N): ") if anwer_question.lower() != "y": return for plugin in self.plugins_remote: self.installPluginByName(plugin) return self.show_help_command("help_extra_captiveflask")
def run(self): self.started = True server_address = self.dhcp_conf["router"] server_port = 67 client_port = 68 # log.debug('Listen on %s:%s (-> %s)', server_address, server_port, client_port) self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) self.sock.bind(("", server_port)) self.sock.setsockopt( socket.SOL_SOCKET, socket.SO_BINDTODEVICE, str(self.iface + "\0").encode() ) print(display_messages("starting {}".format(self.objectName()), info=True)) # self.DHCP._request.connect(self.get_DHCP_Response) self.DHCPProtocol.connection_made(self.sock) # log.debug("Starting UDP server") while self.started: try: message, address = self.sock.recvfrom(1024) self.DHCPProtocol.datagram_received(message, address) except Exception as e: # OSError: [Errno 9] Bad file descriptor when close socket print(display_messages("socket error: {}".format(e), error=True))
def parser_args_func(parse_args, config): if parse_args.nocolors: set_nocolors() if parse_args.wireless_mode: if parse_args.wireless_mode in config.get_all_childname("ap_mode"): config.set_one("ap_mode", parse_args.wireless_mode, True) print( display_messages( "Wireless Mode: {}".format( setcolor(parse_args.wireless_mode, color="ciano")), info=True, )) if parse_args.restmode: if not (parse_args.password): print( display_messages( "{} \n rest mode require a valid password.".format( setcolor("password invalid", color="red")), info=True, )) exit(0) set_nocolors() config.set_one("ap_mode", "restapi", True) config.set("rest_api_settings", "PASSWORD", parse_args.password) config.set("rest_api_settings", "USERNAME", parse_args.username) config.set("rest_api_settings", "port", parse_args.restport) server_restapi = RestControllerAPI("wp3API", config) thead = threading.Thread(target=server_restapi.run) thead.setDaemon(True) thead.start()
def do_run(self, args): """ execute deauth module attack """ client_mac = self.options.get("client")[0] target_mac = self.options.get("target")[0] interface = self.options.get("interface")[0] print(display_messages("Options", info=True, sublime=True)) print( display_messages("client:| {} |".format( setcolor(client_mac, color="blue")), info=True)) print( display_messages("target:| {} |".format( setcolor(target_mac, color="red")), info=True)) if "00:00:00:00:00:00" in self.options.get("target")[0]: print( display_messages("please, select a target to deauth attack ", error=True)) return print( display_messages( "enable interface: {} to monitor mode".format(interface), info=True)) self.set_monitor_mode("monitor") self.thread_deauth = ThreadDeauth(target_mac, client_mac, interface) self.thread_deauth.setObjectName("wifideauth") self.thread_deauth.start()
def showDataOutputScan(self): os.system("clear") self.table_output = [] self.table_station = [] for bssid, info in self.aps.items(): if not "(not associated)" in bssid: self.table_output.append( [info["channel"], info["ssid"], bssid, info["rssi"], info["enc"]] ) display_tabulate(self.table_headers_wifi, self.table_output) print("\n") for bssid, info in self.aps.items(): if "STA" in info: self.table_station.append( [ info["STA"]["BSSID"], info["STA"]["Station"], info["STA"]["PWR"], info["STA"]["Frames"], info["STA"]["Probe"], ] ) if len(self.table_station) > 0: display_tabulate(self.table_headers_STA, self.table_station) print(display_messages("press CTRL+C to stop scanning", info=True))
def Configure(self): """ configure interface and dhcpd for mount Access Point """ self.ifaceHostapd = self.conf.get("accesspoint", "interface") self.SettingsAP = { "interface": [ "ifconfig %s up" % (self.ifaceHostapd), "ifconfig %s %s netmask %s" % (self.ifaceHostapd, self.DHCP["router"], self.DHCP["netmask"]), "ifconfig %s mtu 1400" % (self.ifaceHostapd), "route add -net %s netmask %s gw %s" % (self.DHCP["subnet"], self.DHCP["netmask"], self.DHCP["router"]), ], "kill": [ "{} -w --flush".format(self.getIptablesPath), "{} -w --table nat --flush".format(self.getIptablesPath), "{} -w --delete-chain".format(self.getIptablesPath), "{} -w --table nat --delete-chain".format(self.getIptablesPath), "killall dhpcd 2>/dev/null", "ifconfig {} down".format(self.ifaceHostapd), "ifconfig {} up".format(self.ifaceHostapd), "ifconfig {} 0".format(self.ifaceHostapd), ], "hostapd": [ "interface={}\n".format(self.ifaceHostapd), "ssid={}\n".format(self.conf.get("accesspoint", "ssid")), "channel={}\n".format(self.conf.get("accesspoint", "channel")), "bssid={}\n".format(self.conf.get("accesspoint", "bssid")), ], "dhcp-server": [ "authoritative;\n", "default-lease-time {};\n".format(self.DHCP["leasetimeDef"]), "max-lease-time {};\n".format(self.DHCP["leasetimeMax"]), "subnet %s netmask %s {\n" % (self.DHCP["subnet"], self.DHCP["netmask"]), "option routers {};\n".format(self.DHCP["router"]), "option subnet-mask {};\n".format(self.DHCP["netmask"]), "option broadcast-address {};\n".format(self.DHCP["broadcast"]), 'option domain-name "%s";\n' % (self.conf.get("accesspoint", "ssid")), "option domain-name-servers {};\n".format("8.8.8.8"), "range {};\n".format(self.DHCP["range"].replace("/", " ")), "}", ], } print(display_messages("enable forwarding in iptables...", sucess=True)) Linux.set_ip_forward(1) # clean iptables settings for line in self.SettingsAP["kill"]: exec_bash(line) # set interface using ifconfig for line in self.SettingsAP["interface"]: exec_bash(line) # check if dhcp option is enabled. if self.conf.get("accesspoint", "dhcp_server", format=bool): with open(C.DHCPCONF_PATH, "w") as dhcp: for line in self.SettingsAP["dhcp-server"]: dhcp.write(line) dhcp.close() if not path.isdir("/etc/dhcp/"): mkdir("/etc/dhcp") move(C.DHCPCONF_PATH, "/etc/dhcp/")
def do_dump(self, args): """ap: dump informations from client connected on AP """ self.options["target"][0] = None if len(args.split()) > 0: mac_addr = args.split()[0] if Refactor.check_is_mac(mac_addr): self.options["target"][0] = mac_addr if not self.options.get("target")[0]: print( display_messages( "the MAC: {} address format is invalid.".format( mac_addr), error=True, )) return self.targets = [self.options.get("target")[0]] else: self.targets = list( Refactor.readFileDataToJson(C.CLIENTS_CONNECTED).keys()) self.output_commands = {} self.iface = self.conf.get("accesspoint", "interface") self.args_template = "iw dev {} station get {}" for mac in self.targets: self.output_commands[mac] = os.popen( self.args_template.format(self.iface, mac)).read() for mac in self.output_commands: self.showResultData(self.output_commands.get(mac))
def set_monitor_mode(self, mode="manager"): if not self.options.get("interface")[0] in Linux.get_interfaces().get("all"): print(display_messages("the interface not found!", error=True)) sys.exit(1) os.system("ifconfig {} down".format(self.options.get("interface")[0])) os.system("iwconfig {} mode {}".format(self.options.get("interface")[0], mode)) os.system("ifconfig {} up".format(self.options.get("interface")[0]))
def run(self): port = int(os.getenv("PORT", 53)) upstream = os.getenv("UPSTREAM", "8.8.8.8") zone_file = Path(C.DNSHOSTS) self.logger_dns = LocalDNSLogger(self.sendRequests) self.resolver = Resolver(upstream, zone_file, self.sendRequests) self.udp_server = DNSServer(self.resolver, port=port, logger=self.logger_dns) self.tcp_server = DNSServer(self.resolver, port=port, logger=self.logger_dns, tcp=True) print( display_messages("starting {}".format(self.objectName()), info=True)) # logger.info('starting DNS server on port %d, upstream DNS server "%s"', port, upstream) self.udp_server.start_thread() self.tcp_server.start_thread() try: while self.udp_server.isAlive(): sleep(1) except KeyboardInterrupt: pass
def stop(self): self.udp_server.stop() self.tcp_server.stop() print( display_messages("thread {} successfully stopped".format( self.objectName()), info=True))
def do_plugins(self, args=str): """network: show all available plugins """ headers_table, output_table = ["Name", "Active", "Description"], [] headers_plugins, output_plugins = ["Name", "Active"], [] all_plugins, config_instance = None, None for plugin_name, plugin_info in self.root.mitm_controller.getInfo().items(): status_plugin = self.root.conf.get("mitm_modules", plugin_name, format=bool) output_table.append( [ plugin_name, setcolor("True", color="green") if status_plugin else setcolor("False", color="red"), plugin_info["Description"][:50] + "..." if len(plugin_info["Description"]) > 50 else plugin_info["Description"], ] ) if ( self.root.mitm_controller.getInfo()[plugin_name]["Config"] != None and status_plugin ): config_instance = self.root.mitm_controller.getInfo()[plugin_name][ "Config" ] all_plugins = self.root.mitm_controller.getInfo()[plugin_name][ "Config" ].get_all_childname("plugins") print(display_messages("Available Plugins:", info=True, sublime=True)) display_tabulate(headers_table, output_table) if not all_plugins: return for plugin_name in all_plugins: status_plugin = config_instance.get("plugins", plugin_name, format=bool) output_plugins.append( [ plugin_name, setcolor("True", color="green") if status_plugin else setcolor("False", color="red"), ] ) print(display_messages("Sniffkin3 plugins:", info=True, sublime=True)) return display_tabulate(headers_plugins, output_plugins)
def stop(self): self.started = False Refactor.writeFileDataToJson(C.CLIENTS_CONNECTED, {}, "w") print( display_messages("thread {} successfully stopped".format( self.objectName()), info=True)) self.sock.close()
def get_Hostapd_Response(self, data): if self.conf.get("accesspoint", "status_ap", format=bool): print( display_messages( "{} client has left AP ".format(setcolor(data, color="red")), info=True, ) )
def stop(self): print( display_messages("thread {} successfully stopped".format( self.objectName()), info=True)) if hasattr(self, "procHostapd"): self.started = False self.procHostapd.terminate()
def do_list(self, args): """ show all avaliable templates from github """ if not path.isfile(self.save_path): print( display_messages( "can't find downloaded file: {}".format(self.save_path), error=True ) ) return config = SettingsINI(self.config_file_ini) plugins_installed = self.config_default.get_all_childname("plugins") self.plugins_remote = {} for plugin in config.get_all_childname("plugins"): self.plugins_remote[plugin] = {} for info in config.get_all_childname("info_{}".format(plugin)): self.plugins_remote[plugin][info] = config.get( "info_{}".format(plugin), info ) self.plugins_remote[plugin]["installed"] = ( setcolor("True", color="green") if plugin in plugins_installed else setcolor("False", color="red") ) self.table_output = [] for plugin in self.plugins_remote: self.table_output.append( [ self.plugins_remote[plugin]["name"], self.plugins_remote[plugin]["author"], self.plugins_remote[plugin]["installed"], self.plugins_remote[plugin]["preview"], ] ) if len(self.table_output) > 0: print( display_messages( "Available Customs CaptiveFlask:", info=True, sublime=True ) ) display_tabulate(self.table_headers, self.table_output)
def get_DHCPoutPut(self, data): self._connected[data["MAC"]] = data if self.conf.get("accesspoint", "status_ap", format=bool): print( display_messages( "{} client join the AP ".format( setcolor(data["MAC"], color="green")), info=True, ))
def do_rm(self, args): """ remove a domain from list dns spoof """ if not self.options.get("domains")[0]: return print( display_messages("the list of domains is empty", error=True)) targets = self.options.get("domains")[0].split(",") try: targets.remove(args) if targets != []: self.options["domains"][0] = ",".join(targets) else: self.options["domains"][0] = None except ValueError: return print( display_messages( "the value {} not in the domains list".format(args), error=True))
def stop(self): print( display_messages("thread {} successfully stopped".format( self.objectName()), info=True)) if hasattr(self, "procThread"): self.procThread.terminate() self.procThread.waitForFinished() self.procThread.kill()
def showResultData(self, data): try: rdata = self.getDataFromOutput(data) except IndexError: print( display_messages("cannot tracked: client not found.", error=True)) return mac_addr = list(rdata.keys())[0] print( display_messages("peer: [{}]".format( setcolor(mac_addr, color="green")), info=True)) for item in rdata: for key, value in rdata[item].items(): print(" {} : {}".format(setcolor(key, color="blue"), setcolor(value, color="yellow"))) if rdata: print("\n")
def installPluginByName(self, plugin_name): print( display_messages( "Install plugin:: {}".format( setcolor(plugin_name, color="yellow")), info=True, sublime=True, )) source = "{}/plugins/{}.py".format(self.extracted_filepath, plugin_name) destination = "{}/{}.py".format(self.captiveflask_path, plugin_name) dest = copyfile(source, destination) print( display_messages("copy content file to {}".format(dest), info=True)) folder_plugin = "{}/templates/{}".format(self.extracted_filepath, plugin_name) copy_tree(folder_plugin, "config/templates/{}".format(plugin_name)) print( display_messages( "copy content directory to {}".format( "config/templates/{}".format(plugin_name)), info=True, )) self.config_default.set("plugins", plugin_name, False) config = SettingsINI(self.config_file_ini) if config.get_all_childname("set_{}".format(plugin_name)) != []: for language in config.get_all_childname( "set_{}".format(plugin_name)): self.config_default.set("set_{}".format(plugin_name), language, False) self.config_default.set("set_{}".format(plugin_name), "Default", True) print( display_messages( "plugin install {}".format(setcolor("sucessful", color="green")), info=True, ))
def do_update(self, args): """core: pulling updates from remote git repository """ if not self.check_deps_pip(): print(display_messages("pip3: command not found", error=True)) print( display_messages( "Pip3 is not installed, check that you’ve installed all the necessary prerequisite packages, which include python3-dev, libffi-dev, and libssl-dev.", info=True, )) return branch = None if args: branch = args.split()[0] if not branch in self.options.get("branches"): print( display_messages( "branch: {} not found! ".format( setcolor(branch, color="red")), info=True, )) return if not branch: branch = self.options.get("default_branch")[0] print( display_messages("pulling updates from remote git repository", info=True)) print( display_messages( "from branch: {}".format(setcolor(branch, color="green")), info=True, )) anwer_question = input( "So, do you want to continue to update ? (Y/N): ") if anwer_question.lower() != "y": return os.system(self.options.get("urlparser").format(branch)) self.root.do_exit([])
def start(self): self.procHostapd = QProcess(self) self.procHostapd.setProcessChannelMode(QProcess.MergedChannels) self.procHostapd.start( list(self.cmd.keys())[0], self.cmd[list(self.cmd.keys())[0]]) self.procHostapd.readyReadStandardOutput.connect( self.read_OutputCommand) self.started = True print( display_messages("starting hostpad pid: [{}]".format( self.procHostapd.pid()), sucess=True))
def all_modules(): modules = import_submodules(__name__) for module in modules: try: # print(module) if not (os.path.isdir(module.replace(".", "/"))): current_module = modules[module].ModPump() except AttributeError: print( display_messages( "Module {} not has `ModPump` class!".format(module), error=True))
def do_download(self, args): """ download all avaliable templates""" url = C.URL_EXTRA_CAPTIVEFLASK chunk_size = 128 print( display_messages( "downloading templates on {} ".format(self.save_path), info=True ) ) try: r = requests.get(url, stream=True) except Exception as e: print(display_messages(e, error=True)) return with open(self.save_path, "wb") as fd: for chunk in r.iter_content(chunk_size=chunk_size): fd.write(chunk) if not path.isfile(self.save_path): print(display_messages("error when try download templates", error=True)) return print(display_messages("extra captiveflask download successful.", sucess=True)) print(display_messages("extracting files from zip archive", info=True)) path_to_zip_file = tempfile.gettempdir() + "/master.zip" with ZipFile(path_to_zip_file, "r") as zip_ref: zip_ref.extractall(tempfile.gettempdir()) print( display_messages( "extracted files on : {}".format(self.extracted_filepath), info=True ) )
def parser_args_func(parse_args): if parse_args.nocolors: set_nocolors() if parse_args.wireless_mode: if parse_args.wireless_mode in conf.get_all_childname("ap_mode"): conf.set_one("ap_mode", parse_args.wireless_mode, True) print( display_messages( "Wireless Mode: {}".format( setcolor(parse_args.wireless_mode, color="ciano")), info=True, ))
def do_kill(self, args): """core: terminate a module in background by id""" if len(self.root.threads["Modules"]) > 0: try: module_name = args.split()[0] except Exception: return module_instance = None if module_name in list(self.root.threads.get("Modules").keys()): module_instance = self.root.threads["Modules"].get(module_name) if not module_instance: print( display_messages( "the module {} was not found.".format( setcolor(module_name, color="orange")), error=True, )) return return module_instance.do_stop([]) print( display_messages("there are no module running in the background", error=True))
def setIptables(self): # this mehtod is called when post start all threads self.interfacesLink = Refactor.get_interfaces() print( display_messages("sharing internet connection with NAT...", info=True)) self.ifaceHostapd = self.conf.get("accesspoint", "interface") iptables_file = { "iptables.ipv4.nat": [ "# Generated by iptables-save v1.6.0 on Sun Jun 5 11:18:08 2016" "*nat" ":PREROUTING ACCEPT [123:11003]" ":INPUT ACCEPT [5:1402]" ":OUTPUT ACCEPT [2:152]" ":POSTROUTING ACCEPT [0:0]" ":DOCKER - [0:0]" "-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER" "-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER" "-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE" "-A POSTROUTING -o $inet -j MASQUERADE" "COMMIT" "# Completed on Sun Jun 5 11:18:08 2016" "# Generated by iptables-save v1.6.0 on Sun Jun 5 11:18:08 2016" "*filter" ":INPUT ACCEPT [320:23582]" ":FORWARD ACCEPT [0:0]" ":OUTPUT ACCEPT [194:28284]" ":DOCKER - [0:0]" "-A FORWARD -o docker0 -j DOCKER" "-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT" "-A FORWARD -i docker0 ! -o docker0 -j ACCEPT" "-A FORWARD -i docker0 -o docker0 -j ACCEPT" "-A FORWARD -i $inet -o $wlan -m state --state RELATED,ESTABLISHED -j ACCEPT" "-A FORWARD -i $wlan -o $inet -j ACCEPT" "COMMIT" "# Completed on Sun Jun 5 11:18:08 2016" ] } with open(C.DOCKERIPTABLESPATH, "w") as f: for line in iptables_file["iptables.ipv4.nat"]: try: if "$inet" in line: line = line.replace( "$inet", self.interfacesLink["activated"][0]) if "$wlan" in line: line = line.replace("$wlan", self.ifaceHostapd) f.write("{}\n".format(line)) except Exception: pass f.close() popen("iptables-restore < {}".format(C.DOCKERIPTABLESPATH))
def do_ap(self, args): """ap: show all variable and status from AP """ headers_table, output_table = ( ["BSSID", "SSID", "Channel", "Interface", "Status", "Security"], [], ) print( display_messages("Settings AccessPoint:", info=True, sublime=True)) status_ap = self.root.conf.get("accesspoint", "status_ap", format=bool) output_table.append([ self.root.conf.get("accesspoint", self.root.commands["bssid"]), self.root.conf.get("accesspoint", self.root.commands["ssid"]), self.root.conf.get("accesspoint", self.root.commands["channel"]), self.root.conf.get("accesspoint", self.root.commands["interface"]), setcolor("is Running", color="green") if status_ap else setcolor("not Running", color="red"), self.root.conf.get("accesspoint", self.root.commands["security"]), ]) display_tabulate(headers_table, output_table) enable_security = self.root.conf.get("accesspoint", self.root.commands["security"], format=bool) if enable_security: headers_sec, output_sec = ( ["wpa_algorithms", "wpa_sharedkey", "wpa_type"], [], ) output_sec.append([ self.root.conf.get("accesspoint", "wpa_algorithms"), self.root.conf.get("accesspoint", "wpa_sharedkey"), self.root.conf.get("accesspoint", "wpa_type"), ]) print( display_messages("Settings Security:", info=True, sublime=True)) display_tabulate(headers_sec, output_sec) self.show_help_command("help_security_command")