forked from swisskyrepo/SSRFmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.py
34 lines (27 loc) · 1 KB
/
handler.py
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
import socket
import threading
import time
import logging
class Handler(threading.Thread):
def __init__(self, port):
threading.Thread.__init__(self)
logging.info("Handler listening on 0.0.0.0:{}".format(port))
self.connected = False
self.port = int(port)
def run(self):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.bind(('', self.port))
while True:
self.socket.listen(5)
self.client, address = self.socket.accept()
print("Handler> New session from {}".format( address[0] ))
self.connected = True
response = self.client.recv(255)
while response != b"":
print("\n{}\nShell > $ ".format(response.decode('utf_8', 'ignore').strip()), end='')
response = self.client.recv(255)
def send_command(self, cmd):
self.client.sendall(cmd.encode())
def kill(self):
self.client.close()
self.socket.close()