-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathz0scan.py
95 lines (78 loc) · 2.8 KB
/
z0scan.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
import inspect
import os
import sys
import threading
import requests
from colorama import deinit
from lib.controller.controller import start, task_push_from_name
from lib.core.enums import HTTPMETHOD
from datetime import datetime
from lib.parse.parse_request import FakeReq
from lib.parse.parse_responnse import FakeResp
from lib.proxy.baseproxy import AsyncMitmProxy
from lib.parse.cmdparse import cmd_line_parser
from lib.core.data import logger, conf, KB
from lib.core.option import init
def version_check():
if sys.version.split()[0][0] == "2":
logger.error(
"incompatible Python version detected ('{}'). To successfully run sqlmap you'll have to use version >= 3.6 (visit 'https://www.python.org/downloads/')".format(
sys.version.split()[0]))
sys.exit()
def modulePath():
"""
This will get us the program's directory, even if we are frozen
using py2exe
"""
try:
_ = sys.executable if hasattr(sys, "frozen") else __file__
except NameError:
_ = inspect.getsourcefile(modulePath)
return os.path.dirname(os.path.realpath(_))
def main():
version_check()
# init
root = modulePath()
cmdline = cmd_line_parser()
init(root, cmdline)
if conf.url or conf.url_file:
urls = []
if conf.url:
urls.append(conf.url)
if conf.url_file:
urlfile = conf.url_file
if not os.path.exists(urlfile):
logger.error("File:{} don't exists".format(urlfile))
sys.exit()
with open(urlfile) as f:
_urls = f.readlines()
_urls = [i.strip() for i in _urls]
urls.extend(_urls)
for domain in urls:
try:
req = requests.get(domain)
except Exception as e:
logger.error("request {} faild,{}".format(domain, str(e)))
continue
fake_req = FakeReq(domain, {}, HTTPMETHOD.GET, "")
fake_resp = FakeResp(req.status_code, req.content, req.headers)
task_push_from_name('loader', fake_req, fake_resp)
start()
elif conf.server_addr:
KB["continue"] = True
# 启动漏洞扫描器
scanner = threading.Thread(target=start)
scanner.daemon = True
scanner.start()
# 启动代理服务器
baseproxy = AsyncMitmProxy(server_addr=conf.server_addr, https=True)
try:
baseproxy.serve_forever()
except KeyboardInterrupt:
scanner.join(0.1)
threading.Thread(target=baseproxy.shutdown, daemon=True).start()
deinit()
print("\n[\033[1;34m%s\033[0m] [\033[33mWARNING\033[0m] User QUIT." %datetime.utcnow().strftime('%H:%M:%S'))
baseproxy.server_close()
if __name__ == '__main__':
main()