forked from the-robot/sqliv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqliv.py
179 lines (139 loc) · 6.17 KB
/
sqliv.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
# SQLiv v2.1
# Ghost (github.com/Hadesy2k)
import argparse
import sys
from urllib.parse import urlparse
from typing import List, Optional, Dict, Any
from src import std
from src import scanner
from src import reverseip
from src import serverinfo
from src.web import search
from src.crawler import Crawler
class SQLiv:
def __init__(self):
"""Initialize search engine instances and crawler"""
self.bing = search.Bing()
self.google = search.Google()
self.yahoo = search.Yahoo()
self.crawler = Crawler()
def singlescan(self, url: str) -> Optional[List[Dict[str, Any]]]:
"""
Scan a single targeted domain for SQL injection vulnerabilities.
Args:
url: The URL to scan
Returns:
List of vulnerable URLs and their details if found, None otherwise
"""
if urlparse(url).query:
result = scanner.scan([url])
if result:
return result
print("") # Move carriage return to newline
std.stdout("No SQL injection vulnerability found")
if not std.stdin("Do you want to crawl and continue scanning? [Y/N]", ["Y", "N"], upper=True) == 'Y':
return None
# Crawl and scan the links
std.stdout(f"Going to crawl {url}")
urls = self.crawler.crawl(url)
if not urls:
std.stdout("Found no suitable URLs to test SQLi")
return None
std.stdout(f"Found {len(urls)} URLs from crawling")
vulnerables = scanner.scan(urls)
if not vulnerables:
std.stdout("No SQL injection vulnerability found")
return None
return vulnerables
def process_dork_scan(self, args: argparse.Namespace) -> None:
"""Handle scanning with dork search"""
std.stdout("Searching for websites with given dork")
engines = {
"bing": self.bing,
"google": self.google,
"yahoo": self.yahoo
}
if args.engine not in engines:
std.stderr("Invalid search engine")
sys.exit(1)
websites = engines[args.engine].search(args.dork, args.page)
std.stdout(f"{len(websites)} websites found")
vulnerables = scanner.scan(websites)
if not vulnerables:
if args.save_searches:
std.stdout("Saved as searches.txt")
std.dump(websites, "searches.txt")
sys.exit(0)
std.stdout("Scanning server information")
self.process_vulnerables(vulnerables)
def initparser(self) -> argparse.ArgumentParser:
"""Initialize and return argument parser"""
parser = argparse.ArgumentParser(description='SQLiv - Massive SQL injection vulnerability scanner')
parser.add_argument("-d", dest="dork", help="SQL injection dork", type=str, metavar="inurl:example")
parser.add_argument("-e", dest="engine", help="Search engine [Bing, Google, Yahoo]", type=str, metavar="bing, google, yahoo")
parser.add_argument("-p", dest="page", help="Number of websites to look for in search engine", type=int, default=10, metavar="100")
parser.add_argument("-t", dest="target", help="Scan target website", type=str, metavar="www.example.com")
parser.add_argument('-r', dest="reverse", help="Reverse domain lookup", action='store_true')
parser.add_argument('-o', dest="output", help="Output result to JSON file", type=str, metavar="result.json")
parser.add_argument('-s', dest="save_searches", help="Save search results even if no vulnerabilities found", action='store_true')
return parser
def process_reverse_lookup(self, args: argparse.Namespace) -> None:
"""Handle reverse domain lookup scanning"""
std.stdout(f"Finding domains with same server as {args.target}")
domains = reverseip.reverseip(args.target)
if not domains:
std.stdout("No domain found with reverse IP lookup")
sys.exit(0)
std.stdout(f"Found {len(domains)} websites")
std.stdout("Scanning multiple websites with crawling will take long")
if std.stdin("Do you want to save domains? [Y/N]", ["Y", "N"], upper=True) == 'Y':
std.stdout("Saved as domains.txt")
std.dump(domains, "domains.txt")
if not std.stdin("Do you want to start crawling? [Y/N]", ["Y", "N"], upper=True) == 'Y':
sys.exit(0)
vulnerables = []
for domain in domains:
vulnerables_temp = self.singlescan(domain)
if vulnerables_temp:
vulnerables.extend(vulnerables_temp)
std.stdout("Finished scanning all reverse domains")
if not vulnerables:
std.stdout("No vulnerable websites found from reverse domains")
sys.exit(0)
std.stdout("Scanning server information")
self.process_vulnerables(vulnerables)
def process_vulnerables(self, vulnerables: List) -> None:
"""Process and display vulnerable URLs"""
vulnerableurls = [result[0] for result in vulnerables]
table_data = serverinfo.check(vulnerableurls)
# Add database name to info
for result, info in zip(vulnerables, table_data):
info.insert(1, result[1])
std.fullprint(table_data)
return table_data
def main():
sqliv = SQLiv()
parser = sqliv.initparser()
args = parser.parse_args()
if args.dork and args.engine:
sqliv.process_dork_scan(args)
elif args.target and args.reverse:
sqliv.process_reverse_lookup(args)
elif args.target:
vulnerables = sqliv.singlescan(args.target)
if not vulnerables:
sys.exit(0)
std.stdout("Getting server info of domains (this may take a few minutes)")
table_data = serverinfo.check([args.target])
std.printserverinfo(table_data)
print("") # Space between tables
std.normalprint(vulnerables)
sys.exit(0)
else:
parser.print_help()
if args.output:
std.dumpjson(table_data, args.output)
std.stdout(f"Dumped result into {args.output}")
if __name__ == "__main__":
main()