-
Notifications
You must be signed in to change notification settings - Fork 5
/
scscanner.py
180 lines (167 loc) · 6.88 KB
/
scscanner.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
#! /usr/bin/env python3
from concurrent.futures import ThreadPoolExecutor, as_completed
import requests
from requests import RequestException
import urllib3
import sys
import argparse
import datetime as dt
import codecs
import os
urllib3.disable_warnings()
class color:
purple = '\033[95m'
cyan = '\033[96m'
darkcyan = '\033[36m'
blue = '\033[94m'
green = '\033[92m'
yellow = '\033[93m'
red = '\033[91m'
bold = '\033[1m'
underline = '\033[4m'
reset = '\033[0m'
magenta = "\033[35m"
parser = argparse.ArgumentParser()
parser.add_argument('-T', metavar='list.txt', type=str, help='File contain lists of domain')
parser.add_argument('-w', '--workers', metavar='15', nargs='?', default=4, type=int, help='Thread value. Default value is 4')
parser.add_argument("-t", "--target", metavar='google.com', type=str, help='Single domain check')
parser.add_argument("-f", "--filter", metavar='200', type=int, help='Status code filter')
parser.add_argument("-s", "--silent", default=False, action="store_true", help="Silent mode option. Don't print status code output")
parser.add_argument("-o", "--output", metavar='result.txt', type=str, help='Save the results to file')
args = parser.parse_args()
domainlist = args.T
worker = args.workers
singledomain = args.target
statuscodefilter = args.filter
silentopts = args.silent
output_file = args.output
today = dt.datetime.now()
dateonly = today.date()
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
path = os.getcwd()
dir_name = ("scscanner", str(dateonly))
created_dirname = "-".join(dir_name)
def argscheck():
if len(sys.argv)==1:
parser.print_help(sys.stderr)
sys.exit(1)
elif domainlist == None and singledomain == None:
parser.print_help(sys.stderr)
print()
print(f"{color.red}{color.bold}Error: Domain list or target is mandatory{color.reset}{color.reset}")
sys.exit(1)
elif domainlist is not None and singledomain is not None:
parser.print_help(sys.stderr)
print()
print(f"{color.red}{color.bold}Error: Please chose either single target or bulk target.{color.reset}{color.reset}")
sys.exit(1)
elif silentopts and statuscodefilter is None:
parser.print_help(sys.stderr)
print()
print(f"{color.red}{color.bold}Error: -s only work if -f is supplied.{color.reset}{color.reset}")
sys.exit(1)
elif domainlist is not None:
try:
codecs.open(domainlist, encoding="utf-8", errors="strict").readlines()
except Exception as err:
print(f"{color.red}{color.bold}Error: {type(err).__name__} was raised. Please provide valid domain list{color.reset}{color.reset}")
sys.exit(1)
def banner():
print("""
___ ___ ___ ___ __ _ _ __ _ __ ___ _ __
/ __|/ __/ __|/ __/ _` | '_ \| '_ \ / _ \ '__|
\__ \ (__\__ \ (_| (_| | | | | | | | __/ |
|___/\___|___/\___\__,_|_| |_|_| |_|\___|_|
scscanner - Massive HTTP Status Code Scanner
""")
if not silentopts:
banner()
else:
pass
def domaincheck(probed):
if not probed.startswith("http://") and not probed.startswith("https://"):
probed = 'http://' + probed
else:
probed = probed
return requests.get(probed, headers=headers, allow_redirects=False, verify=False, timeout=7)
def savedresult(httpcode, domain):
try:
if output_file:
file_name = (httpcode, output_file)
created_filename = "-".join(file_name)
final_dir = os.path.join(path, created_dirname, created_filename)
os.makedirs(os.path.dirname(final_dir), exist_ok=True)
with open(final_dir, "a") as f:
f.write(domain + '\n')
f.close()
except Exception as err:
return (f"{type(err).__name__} was raised: {err}")
class scscanner:
def statuscode(probed):
try:
req = domaincheck(probed)
if not statuscodefilter:
savedresult(str(req.status_code), probed)
if statuscodefilter:
if req.status_code == statuscodefilter:
savedresult(str(req.status_code), probed)
if silentopts:
return(probed)
if (statuscodefilter == 301) or (statuscodefilter == 302):
return(f"[{color.bold}{req.status_code}{color.reset}] - {probed} --> {req.headers['Location']}")
return(f"[{color.bold}{req.status_code}{color.reset}] - {probed}")
else:
pass
else:
if req.status_code == 200:
return(f"[{color.green}{req.status_code}{color.reset}] - {probed}")
elif (req.status_code == 301) or (req.status_code == 302):
return(f"[{color.yellow}{req.status_code}{color.reset}] - {probed} --> {color.yellow}{req.headers['Location']}{color.reset}")
else:
return(f"[{color.red}{req.status_code}{color.reset}] - {probed}")
except RequestException as err:
if statuscodefilter:
pass
else:
savedresult(str("000"), probed)
return(f"[000] - {probed} [{color.bold}{color.red}{type(err).__name__}{color.reset}]")
def singlescan():
probed = singledomain
statusresult = scscanner.statuscode(probed)
if statusresult is not None:
print(statusresult)
else:
print(f"{color.bold}Domain status code and status code filter is not match{color.reset}")
def masscan():
with ThreadPoolExecutor(max_workers=worker) as executor:
with codecs.open(domainlist, encoding="utf-8", errors="strict") as tglist:
domainname = tglist.read().splitlines()
loopcheck = [executor.submit(scscanner.statuscode, probed) for probed in domainname]
try:
for future in as_completed(loopcheck):
if future.result():
print(future.result())
else:
pass
except KeyboardInterrupt as err:
tglist.close()
print(f"{type(err).__name__}")
os._exit(1)
finally:
executor.shutdown()
if __name__ == '__main__':
argscheck()
try:
if output_file and not silentopts:
print(f"{color.bold}Your result will be saved at: {color.green}{os.path.join(path, created_dirname)}{color.reset}\n")
for _ in [0]:
if singledomain:
scscanner.singlescan()
else:
scscanner.masscan()
except Exception as err:
print(f"{type(err).__name__} was raised: {err}")
finally:
sys.exit()