-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_scanner.py
executable file
·207 lines (170 loc) · 6.68 KB
/
basic_scanner.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
#!/usr/bin/env python3
import warnings
warnings.simplefilter("ignore", UserWarning)
import argparse
import os
import requests
from Wappalyzer import Wappalyzer, WebPage
import re
import subprocess
import shlex
import threading
import sys
subdirectories = []
parser = argparse.ArgumentParser(description='Basic Scanner for CTF')
parser.add_argument('host', help='directory to start')
parser.add_argument('--rec','-r', help='recursive gobuster scan', action='store_true')
parser.add_argument('--subdomains','-s', help='scan subdomains', action='store_true')
args = parser.parse_args()
ip = args.host
rec = args.rec
sub = args.subdomains
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
END = '\033[0m'
def menu_decorator(color_args):
def function_wrapper(func):
def draw_outlines(*args):
print_colored_line(color_args['color'])
print_colored_string(color_args['color'], f"\t{color_args['text']}")
print_colored_line(color_args['color'])
print(color_args['color'], end='')
func(*args)
print_colored_line(color_args['color'])
print('\033[0m')
return draw_outlines
return function_wrapper
def main():
global ip
print_colored_line(GREEN)
print_colored_string(GREEN, f"Scanning {ip}...")
nmap_scan(ip)
gobuster_scan(ip)
if sub:
wfuzz_scan(ip)
comment_scan(ip)
wappalyzer_scan(ip)
# nmap scan
@menu_decorator({"color": CYAN, "text": "Aggressiv NMAP SCAN" })
def nmap_scan(ip):
print(subprocess.getoutput(f"nmap -A {ip}"))
# gobuster scan
@menu_decorator({"color": YELLOW, "text": "Gobuster Scan" })
def gobuster_scan(ip):
global rec
def scan_recursive(route='/'):
if not route == '/':
print(route)
global subdirectories
subdirectories.append(route)
# output = subprocess.run(shlex.split(f"gobuster dir -u http://{ip}{route} -w /usr/share/wordlists/dirb/common.txt -t 100 --timeout 20s"), stdout=subprocess.PIPE).stdout.decode('utf-8')
output = subprocess.run(shlex.split(f"gobuster dir -u http://{ip}{route} -w common.txt -t 100 --timeout 20s"), stdout=subprocess.PIPE).stdout.decode('utf-8')
delete_line()
output = output.split('\n')
if rec:
thread_list = []
for name in get_dirnames(output):
def scan_rec(route,name):
if route == '/':
scan_serial(f'{route}{name}')
else:
scan_serial(f'{route}/{name}')
thread = threading.Thread(target=scan_rec, args=(route,name))
thread_list.append(thread)
thread.start()
for thread in thread_list:
thread.join()
else:
for name in get_dirnames(output):
print(f'{route}{name}')
scan_recursive()
def scan_serial(route):
print(route)
global subdirectories
subdirectories.append(route)
output = subprocess.run(shlex.split(f"gobuster dir -u http://{ip}{route} -w /usr/share/wordlists/dirb/common.txt -t 100 --timeout 20s"), stdout=subprocess.PIPE).stdout.decode('utf-8')
# output = subprocess.run(shlex.split(f"gobuster dir -u http://{ip}{route} -w common.txt -t 100 --timeout 20s"), stdout=subprocess.PIPE).stdout.decode('utf-8')
delete_line()
output = output.split('\n')
for name in get_dirnames(output):
if len(name.split('.')) == 2:
if name.split('.')[0] and name.split('.')[1]:
if not name == 'index.html':
print(f'{route}/{name}')
continue
if route == '/':
scan_serial(f'{route}{name}')
else:
scan_serial(f'{route}/{name}')
def get_dirnames(output):
dirs = []
for line in output:
line = line.strip()
if line.startswith('/'):
line = line.split()[0].replace('/', '') # dirname without anything
dirs.append(line)
return dirs
def delete_line():
sys.stdout.write('\033[F') #back to previous line
sys.stdout.write('\033[K') #clear line
@menu_decorator({"color": BLUE, "text": "Subdomain Scan" })
def wfuzz_scan(ip):
command = f'wfuzz -c -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -u "http://{ip}" -H "Host: FUZZ.{ip}"'
print('Exclude Words --hw x (for example 290, check results)')
print(command)
print(subprocess.getoutput(command))
# comment scan
@menu_decorator({"color": GREEN, "text": "Comments Scan" })
def comment_scan(ip):
def get_comments(ip,subdirectory):
url = f"http://{ip}{subdirectory}"
if not subdirectory:
url = f"http://{ip}/"
response = requests.get(url)
html_comments = re.findall(r'\<\!\-\-(?:.|\n|\r)*?-->', response.text)
css_js_comments = re.findall(r'(\/\*[\w\'\s\r\n\*]*\*\/)|(\/\/[\w\s\']*)|(\<![\-\-\s\w\>\/]*\>)', response.text)
user_passwd = re.findall(r'[a-zA-Z][a-zA-Z0-9]+:[^: \&\.\~]*[a-zA-Z0-9]+[^:\&\.\~]+', response.text)
def filter_comments(comments):
if type(comments[0]) == tuple:
return list(set([comment for tuplee in comments for comment in tuplee if comment]))
else:
return list(set(comments))
print(f"\nComments for {url}")
if html_comments:
for comment in filter_comments(html_comments):
print(comment)
if css_js_comments:
for comment in filter_comments(css_js_comments):
print(comment)
if user_passwd:
for entry in user_passwd:
print(entry)
global subdirectories
get_comments(ip, None)
for subdirectory in subdirectories:
get_comments(ip, subdirectory)
# wappalyzer scan
@menu_decorator({"color": PURPLE, "text": "Wappalyzer Scan" })
def wappalyzer_scan(ip):
webpage = WebPage.new_from_url(f"http://{ip}/")
wappalyzer = Wappalyzer.latest()
parse_wappalyzer_result(wappalyzer.analyze_with_versions_and_categories(webpage))
def parse_wappalyzer_result(result):
print(f"{'Name':<20} {'Category':<20} {'Name':20}")
print()
for key,inner_dict in result.items():
key = str(key)
versions = str(inner_dict['versions'])
categories = str(inner_dict['categories'])
print(f"{key:<20} {versions:<20} {categories:20}")
def print_colored_line(color):
print(color + "---------------------------------------------------------------------------------" + '\033[0m')
def print_colored_string(color, string):
print(color + string + '\033[0m')
if __name__ == '__main__':
main()