From 4218e4ed07328d50906705b3ffcb07de5d7ac6ed Mon Sep 17 00:00:00 2001 From: SecureThisShit Date: Tue, 12 Dec 2017 18:21:56 +0100 Subject: [PATCH 1/7] Added Backup of old hostapd.conf Added Backup of old hostapd.conf & Restore at stop. --- mitmAP.py | 78 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/mitmAP.py b/mitmAP.py index 8d42fbb..94271f3 100644 --- a/mitmAP.py +++ b/mitmAP.py @@ -4,19 +4,13 @@ import time import subprocess -header = """ - _ _ ___ ______ - (_) | / _ \ | ___ \\ - _ __ ___ _| |_ _ __ ___ / /_\ \| |_/ / -| '_ ` _ \| | __| '_ ` _ \| _ || __/ -| | | | | | | |_| | | | | | | | || | -|_| |_| |_|_|\__|_| |_| |_\_| |_/\_| 2.2 -""" - -try: - print(header + " by David Schütz (@xdavidhu)\n") -except: - print(header + " by @xdavidhu\n") +print(" _ _ ___ ______ \n" + + " (_) | / _ \ | ___ \\\n" + + " _ __ ___ _| |_ _ __ ___ / /_\ \| |_/ /\n" + + "| '_ ` _ \| | __| '_ ` _ \| _ || __/ \n" + + "| | | | | | | |_| | | | | | | | || | \n" + + "|_| |_| |_|_|\__|_| |_| |_\_| |_/\_| 2.2\n" + + " by David Schuetz (@xdavidhu)\n") sudo = "/usr/bin/sudo" tee = "/usr/bin/tee" @@ -101,30 +95,37 @@ def append_file(path, s): #/DNSMASQ CONFIG #HOSTAPD CONFIG - ssid = input("[?] Please enter the SSID for the AP: ") - while True: - channel = input("[?] Please enter the channel for the AP: ") - if channel.isdigit(): - break - else: - print("[!] Please enter a channel number.") - hostapd_wpa = input("[?] Enable WPA2 encryption? y/N: ") - hostapd_wpa = hostapd_wpa.lower() - if hostapd_wpa == "y": - canBreak = False - while not canBreak: - wpa_passphrase = input("[?] Please enter the WPA2 passphrase for the AP: ") - if len(wpa_passphrase) < 8: - print("[!] Please enter minimum 8 characters for the WPA2 passphrase.") + hostapd_config = input("[?] Create new HOSTAPD config file at '/etc/hostapd/hostapd.conf' Y/n: ") + hostapd_config = hostapd_config.lower() + if hostapd_config == "y" or hostapd_config == "": + print("[I] Backing up hostapd.conf...") + os.system("sudo cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.backup") + ssid = input("[?] Please enter the SSID for the AP: ") + while True: + channel = input("[?] Please enter the channel for the AP: ") + if channel.isdigit(): + break else: - canBreak = True - hostapd_file = "interface=" + ap_iface + "\ndriver=nl80211\nssid=" + ssid + "\nhw_mode=g\nchannel=" + channel + "\nmacaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\nwpa=2\nwpa_passphrase=" + wpa_passphrase + "\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP\nrsn_pairwise=CCMP\n" + print("[!] Please enter a channel number.") + hostapd_wpa = input("[?] Enable WPA2 encryption? y/N: ") + hostapd_wpa = hostapd_wpa.lower() + if hostapd_wpa == "y": + canBreak = False + while not canBreak: + wpa_passphrase = input("[?] Please enter the WPA2 passphrase for the AP: ") + if len(wpa_passphrase) < 8: + print("[!] Please enter minimum 8 characters for the WPA2 passphrase.") + else: + canBreak = True + hostapd_file = "interface=" + ap_iface + "\ndriver=nl80211\nssid=" + ssid + "\nhw_mode=g\nchannel=" + channel + "\nmacaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\nwpa=2\nwpa_passphrase=" + wpa_passphrase + "\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP\nrsn_pairwise=CCMP\n" + else: + hostapd_file = "interface=" + ap_iface + "\ndriver=nl80211\nssid=" + ssid + "\nhw_mode=g\nchannel=" + channel + "\nmacaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\n" + print("[I] Deleting old config file...") + os.system("sudo rm /etc/hostapd/hostapd.conf > /dev/null 2>&1") + print("[I] Writing config file...") + write_file("/etc/hostapd/hostapd.conf", hostapd_file) else: - hostapd_file = "interface=" + ap_iface + "\ndriver=nl80211\nssid=" + ssid + "\nhw_mode=g\nchannel=" + channel + "\nmacaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\n" - print("[I] Deleting old config file...") - os.system("sudo rm /etc/hostapd/hostapd.conf > /dev/null 2>&1") - print("[I] Writing config file...") - write_file("/etc/hostapd/hostapd.conf", hostapd_file) + print("[I] Skipping..") #/HOSTAPD CONFIG #IPTABLES @@ -329,6 +330,9 @@ def append_file(path, s): if ssl_dns_if == "y": print("[I] Restoring old " + script_path + "src/dns2proxy/spoof.cfg...") os.system("sudo mv " + script_path + "src/dns2proxy/spoof.cfg.backup " + script_path + "src/dns2proxy/spoof.cfg") + if hostapd_config == "y" or hostapd_config == "": + print("[I] Restoring old hostapd...") + os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") if wireshark_if == "y" or wireshark_if == "": os.system("sudo screen -S mitmap-wireshark -X stuff '^C\n'") if driftnet_if == "y" or driftnet_if == "": @@ -391,6 +395,9 @@ def append_file(path, s): os.system("sudo mv /etc/NetworkManager/NetworkManager.conf.backup /etc/NetworkManager/NetworkManager.conf > /dev/null 2>&1") else: os.system("sudo rm /etc/NetworkManager/NetworkManager.conf > /dev/null 2>&1") + print("[I] Restoring old hostapd.conf") + if os.path.isfile("/etc/hostapd/hostapd.conf.backup"): + os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") print("[I] Restarting NetworkManager...") os.system("sudo service network-manager restart") print("[I] Stopping DNSMASQ server...") @@ -411,3 +418,4 @@ def append_file(path, s): os.system("sudo iptables --delete-chain") os.system("sudo iptables --table nat --delete-chain") print("[I] mitmAP stopped.") + From 35b48d2a2006ae8adde93c4f4cb18581de0ef5dd Mon Sep 17 00:00:00 2001 From: SecureThisShit Date: Tue, 12 Dec 2017 18:31:19 +0100 Subject: [PATCH 2/7] Hostapd backup & Restore added Hostapd backup & Restore added --- mitmAP_rpi.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mitmAP_rpi.py b/mitmAP_rpi.py index bebb269..b64ebc8 100644 --- a/mitmAP_rpi.py +++ b/mitmAP_rpi.py @@ -85,6 +85,8 @@ #/DNSMASQ CONFIG #HOSTAPD CONFIG + print("[I] Backing up hostapd.conf...") + os.system("sudo cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.backup") ssid = input("[?] Please enter the SSID for the AP: ") while True: channel = input("[?] Please enter the channel for the AP: ") @@ -324,6 +326,8 @@ os.system("sudo screen -S mitmap-driftnet -X stuff '^C\n'") if tshark_if == "y" or tshark_if == "": os.system("sudo screen -S mitmap-tshark -X stuff '^C\n'") + print("[I] Restoring old hostapd...") + os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") # print("[I] Restoring old NetworkManager.cfg") # os.system("sudo mv /etc/NetworkManager/NetworkManager.conf.backup /etc/NetworkManager/NetworkManager.conf") # print("[I] Restarting NetworkManager...") @@ -390,6 +394,8 @@ os.system("sudo wondershaper clear " + ap_iface + " > /dev/null 2>&1") except: pass + print("[I] Restoring old hostapd...") + os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") print("[I] Flushing iptables rules...") os.system("sudo iptables --flush") os.system("sudo iptables --flush -t nat") From e41c543a171c031cf0eacb5a2091bbe960759226 Mon Sep 17 00:00:00 2001 From: SecureThisShit Date: Tue, 12 Dec 2017 18:40:07 +0100 Subject: [PATCH 3/7] Added hostapd.conf Backup & Restore Added hostapd.conf Backup & Restore --- mitmAP.py | 82 +++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 42 deletions(-) diff --git a/mitmAP.py b/mitmAP.py index 94271f3..75cfee7 100644 --- a/mitmAP.py +++ b/mitmAP.py @@ -4,13 +4,19 @@ import time import subprocess -print(" _ _ ___ ______ \n" + - " (_) | / _ \ | ___ \\\n" + - " _ __ ___ _| |_ _ __ ___ / /_\ \| |_/ /\n" + - "| '_ ` _ \| | __| '_ ` _ \| _ || __/ \n" + - "| | | | | | | |_| | | | | | | | || | \n" + - "|_| |_| |_|_|\__|_| |_| |_\_| |_/\_| 2.2\n" + - " by David Schuetz (@xdavidhu)\n") +header = """ + _ _ ___ ______ + (_) | / _ \ | ___ \\ + _ __ ___ _| |_ _ __ ___ / /_\ \| |_/ / +| '_ ` _ \| | __| '_ ` _ \| _ || __/ +| | | | | | | |_| | | | | | | | || | +|_| |_| |_|_|\__|_| |_| |_\_| |_/\_| 2.2 +""" + +try: + print(header + " by David Schütz (@xdavidhu)\n") +except: + print(header + " by @xdavidhu\n") sudo = "/usr/bin/sudo" tee = "/usr/bin/tee" @@ -95,37 +101,32 @@ def append_file(path, s): #/DNSMASQ CONFIG #HOSTAPD CONFIG - hostapd_config = input("[?] Create new HOSTAPD config file at '/etc/hostapd/hostapd.conf' Y/n: ") - hostapd_config = hostapd_config.lower() - if hostapd_config == "y" or hostapd_config == "": - print("[I] Backing up hostapd.conf...") + print("[I] Backing up hostapd.conf...") os.system("sudo cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.backup") - ssid = input("[?] Please enter the SSID for the AP: ") - while True: - channel = input("[?] Please enter the channel for the AP: ") - if channel.isdigit(): - break - else: - print("[!] Please enter a channel number.") - hostapd_wpa = input("[?] Enable WPA2 encryption? y/N: ") - hostapd_wpa = hostapd_wpa.lower() - if hostapd_wpa == "y": - canBreak = False - while not canBreak: - wpa_passphrase = input("[?] Please enter the WPA2 passphrase for the AP: ") - if len(wpa_passphrase) < 8: - print("[!] Please enter minimum 8 characters for the WPA2 passphrase.") - else: - canBreak = True - hostapd_file = "interface=" + ap_iface + "\ndriver=nl80211\nssid=" + ssid + "\nhw_mode=g\nchannel=" + channel + "\nmacaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\nwpa=2\nwpa_passphrase=" + wpa_passphrase + "\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP\nrsn_pairwise=CCMP\n" + ssid = input("[?] Please enter the SSID for the AP: ") + while True: + channel = input("[?] Please enter the channel for the AP: ") + if channel.isdigit(): + break else: - hostapd_file = "interface=" + ap_iface + "\ndriver=nl80211\nssid=" + ssid + "\nhw_mode=g\nchannel=" + channel + "\nmacaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\n" - print("[I] Deleting old config file...") - os.system("sudo rm /etc/hostapd/hostapd.conf > /dev/null 2>&1") - print("[I] Writing config file...") - write_file("/etc/hostapd/hostapd.conf", hostapd_file) + print("[!] Please enter a channel number.") + hostapd_wpa = input("[?] Enable WPA2 encryption? y/N: ") + hostapd_wpa = hostapd_wpa.lower() + if hostapd_wpa == "y": + canBreak = False + while not canBreak: + wpa_passphrase = input("[?] Please enter the WPA2 passphrase for the AP: ") + if len(wpa_passphrase) < 8: + print("[!] Please enter minimum 8 characters for the WPA2 passphrase.") + else: + canBreak = True + hostapd_file = "interface=" + ap_iface + "\ndriver=nl80211\nssid=" + ssid + "\nhw_mode=g\nchannel=" + channel + "\nmacaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\nwpa=2\nwpa_passphrase=" + wpa_passphrase + "\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP\nrsn_pairwise=CCMP\n" else: - print("[I] Skipping..") + hostapd_file = "interface=" + ap_iface + "\ndriver=nl80211\nssid=" + ssid + "\nhw_mode=g\nchannel=" + channel + "\nmacaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\n" + print("[I] Deleting old config file...") + os.system("sudo rm /etc/hostapd/hostapd.conf > /dev/null 2>&1") + print("[I] Writing config file...") + write_file("/etc/hostapd/hostapd.conf", hostapd_file) #/HOSTAPD CONFIG #IPTABLES @@ -330,9 +331,6 @@ def append_file(path, s): if ssl_dns_if == "y": print("[I] Restoring old " + script_path + "src/dns2proxy/spoof.cfg...") os.system("sudo mv " + script_path + "src/dns2proxy/spoof.cfg.backup " + script_path + "src/dns2proxy/spoof.cfg") - if hostapd_config == "y" or hostapd_config == "": - print("[I] Restoring old hostapd...") - os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") if wireshark_if == "y" or wireshark_if == "": os.system("sudo screen -S mitmap-wireshark -X stuff '^C\n'") if driftnet_if == "y" or driftnet_if == "": @@ -353,6 +351,8 @@ def append_file(path, s): os.system("sudo mv /etc/dnsmasq.conf.backup /etc/dnsmasq.conf > /dev/null 2>&1") print("[I] Deleting old '/etc/dnsmasq.hosts' file...") os.system("sudo rm /etc/dnsmasq.hosts > /dev/null 2>&1") + print("[I] Restoring old hostapd...") + os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") print("[I] Removeing speed limit from " + ap_iface + "...") os.system("sudo wondershaper clear " + ap_iface + " > /dev/null 2>&1") print("[I] Flushing iptables rules...") @@ -395,9 +395,6 @@ def append_file(path, s): os.system("sudo mv /etc/NetworkManager/NetworkManager.conf.backup /etc/NetworkManager/NetworkManager.conf > /dev/null 2>&1") else: os.system("sudo rm /etc/NetworkManager/NetworkManager.conf > /dev/null 2>&1") - print("[I] Restoring old hostapd.conf") - if os.path.isfile("/etc/hostapd/hostapd.conf.backup"): - os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") print("[I] Restarting NetworkManager...") os.system("sudo service network-manager restart") print("[I] Stopping DNSMASQ server...") @@ -407,6 +404,8 @@ def append_file(path, s): os.system("sudo mv /etc/dnsmasq.conf.backup /etc/dnsmasq.conf > /dev/null 2>&1") print("[I] Deleting old '/etc/dnsmasq.hosts' file...") os.system("sudo rm /etc/dnsmasq.hosts > /dev/null 2>&1") + print("[I] Restoring old hostapd...") + os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") try: print("[I] Removeing speed limit from " + ap_iface + "...") os.system("sudo wondershaper clear " + ap_iface + " > /dev/null 2>&1") @@ -418,4 +417,3 @@ def append_file(path, s): os.system("sudo iptables --delete-chain") os.system("sudo iptables --table nat --delete-chain") print("[I] mitmAP stopped.") - From 404da28bd706bdbcdaae2acd0fafaaec5392f9a0 Mon Sep 17 00:00:00 2001 From: SecureThisShit Date: Tue, 12 Dec 2017 18:44:58 +0100 Subject: [PATCH 4/7] Update mitmAP.py --- mitmAP.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mitmAP.py b/mitmAP.py index 75cfee7..0e4fb00 100644 --- a/mitmAP.py +++ b/mitmAP.py @@ -102,7 +102,7 @@ def append_file(path, s): #HOSTAPD CONFIG print("[I] Backing up hostapd.conf...") - os.system("sudo cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.backup") + os.system("sudo cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.backup") ssid = input("[?] Please enter the SSID for the AP: ") while True: channel = input("[?] Please enter the channel for the AP: ") @@ -352,7 +352,7 @@ def append_file(path, s): print("[I] Deleting old '/etc/dnsmasq.hosts' file...") os.system("sudo rm /etc/dnsmasq.hosts > /dev/null 2>&1") print("[I] Restoring old hostapd...") - os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") + os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") print("[I] Removeing speed limit from " + ap_iface + "...") os.system("sudo wondershaper clear " + ap_iface + " > /dev/null 2>&1") print("[I] Flushing iptables rules...") @@ -405,7 +405,7 @@ def append_file(path, s): print("[I] Deleting old '/etc/dnsmasq.hosts' file...") os.system("sudo rm /etc/dnsmasq.hosts > /dev/null 2>&1") print("[I] Restoring old hostapd...") - os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") + os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") try: print("[I] Removeing speed limit from " + ap_iface + "...") os.system("sudo wondershaper clear " + ap_iface + " > /dev/null 2>&1") From 25fd4db4e43b4fdb258d33104c18058611a22af9 Mon Sep 17 00:00:00 2001 From: SecureThisShit Date: Tue, 12 Dec 2017 18:59:11 +0100 Subject: [PATCH 5/7] Added if for restore Added if for restore --- mitmAP.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mitmAP.py b/mitmAP.py index 0e4fb00..5fc5d46 100644 --- a/mitmAP.py +++ b/mitmAP.py @@ -351,8 +351,9 @@ def append_file(path, s): os.system("sudo mv /etc/dnsmasq.conf.backup /etc/dnsmasq.conf > /dev/null 2>&1") print("[I] Deleting old '/etc/dnsmasq.hosts' file...") os.system("sudo rm /etc/dnsmasq.hosts > /dev/null 2>&1") - print("[I] Restoring old hostapd...") - os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") + if os.path.isfile("/etc/hostapd/hostapd.conf.backup"): + print("[I] Restoring old hostapd...") + os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") print("[I] Removeing speed limit from " + ap_iface + "...") os.system("sudo wondershaper clear " + ap_iface + " > /dev/null 2>&1") print("[I] Flushing iptables rules...") @@ -404,8 +405,9 @@ def append_file(path, s): os.system("sudo mv /etc/dnsmasq.conf.backup /etc/dnsmasq.conf > /dev/null 2>&1") print("[I] Deleting old '/etc/dnsmasq.hosts' file...") os.system("sudo rm /etc/dnsmasq.hosts > /dev/null 2>&1") - print("[I] Restoring old hostapd...") - os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") + if os.path.isfile("/etc/hostapd/hostapd.conf.backup"): + print("[I] Restoring old hostapd...") + os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") try: print("[I] Removeing speed limit from " + ap_iface + "...") os.system("sudo wondershaper clear " + ap_iface + " > /dev/null 2>&1") From d76a8485907ab8a443d8d1baa27f027525a5f4f0 Mon Sep 17 00:00:00 2001 From: SecureThisShit Date: Tue, 12 Dec 2017 19:04:58 +0100 Subject: [PATCH 6/7] Added if Statement for hostapd.conf restore Added if Statement for restore --- mitmAP_rpi.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mitmAP_rpi.py b/mitmAP_rpi.py index b64ebc8..49c6fb2 100644 --- a/mitmAP_rpi.py +++ b/mitmAP_rpi.py @@ -326,7 +326,8 @@ os.system("sudo screen -S mitmap-driftnet -X stuff '^C\n'") if tshark_if == "y" or tshark_if == "": os.system("sudo screen -S mitmap-tshark -X stuff '^C\n'") - print("[I] Restoring old hostapd...") + if os.path.isfile("/etc/hostapd/hostapd.conf.backup"): + print("[I] Restoring old hostapd...") os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") # print("[I] Restoring old NetworkManager.cfg") # os.system("sudo mv /etc/NetworkManager/NetworkManager.conf.backup /etc/NetworkManager/NetworkManager.conf") @@ -394,7 +395,8 @@ os.system("sudo wondershaper clear " + ap_iface + " > /dev/null 2>&1") except: pass - print("[I] Restoring old hostapd...") + if os.path.isfile("/etc/hostapd/hostapd.conf.backup"): + print("[I] Restoring old hostapd...") os.system("sudo mv /etc/hostapd/hostapd.conf.backup /etc/hostapd/hostapd.conf") print("[I] Flushing iptables rules...") os.system("sudo iptables --flush") From 7b2376dc7ba49d888c43b64e476813734a9c14db Mon Sep 17 00:00:00 2001 From: SecureThisShit Date: Tue, 12 Dec 2017 19:06:35 +0100 Subject: [PATCH 7/7] Update mitmAP_rpi.py --- mitmAP_rpi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mitmAP_rpi.py b/mitmAP_rpi.py index 49c6fb2..3c38e83 100644 --- a/mitmAP_rpi.py +++ b/mitmAP_rpi.py @@ -86,7 +86,7 @@ #HOSTAPD CONFIG print("[I] Backing up hostapd.conf...") - os.system("sudo cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.backup") + os.system("sudo cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.backup") ssid = input("[?] Please enter the SSID for the AP: ") while True: channel = input("[?] Please enter the channel for the AP: ")