Skip to content

Commit 2e686f9

Browse files
authored
Add files via upload
1 parent d0ef564 commit 2e686f9

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

inc/zoom.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
################
4+
# AabyssZG #
5+
################
6+
7+
import requests, sys, json, re, random, base64
8+
from termcolor import cprint
9+
from time import sleep
10+
import urllib3
11+
urllib3.disable_warnings()
12+
13+
def JSON_load(text):
14+
json_str = text
15+
data = json.loads(json_str)
16+
# 提取ip和port信息
17+
ip_port_list = [(match["portinfo"]["hostname"], match["portinfo"]["service"], match["ip"], match["portinfo"]["port"]) for match in data["matches"]]
18+
# 打印提取的信息
19+
for hostname, service, ip, port in ip_port_list:
20+
if ("https" in service):
21+
service = "https://"
22+
else:
23+
service = "http://"
24+
if (hostname):
25+
outurl = str(service) + str(hostname) + ":" + str(port)
26+
else:
27+
outurl = str(service) + str(ip) + ":" + str(port)
28+
f2 = open("zoomout.txt", "a")
29+
f2.write(str(outurl) + '\n')
30+
f2.close()
31+
print(f"Service: {outurl}")
32+
33+
def Key_Dowload(key,proxies,choices):
34+
cprint("======通过ZoomEye密钥进行API下载数据======","green")
35+
Headers = {
36+
"API-KEY": key,
37+
"Content-Type": "application/x-www-form-urlencoded"
38+
}
39+
pages = (choices//20) + 1
40+
i = 1
41+
f2 = open("zoomout.txt", "wb+")
42+
f2.close()
43+
while i <= pages:
44+
page_url = "&page=" + str(i)
45+
keyurl = "https://api.zoomeye.org/host/search?query=app:\"Spring Framework\"&t=web"
46+
dowloadurl = keyurl + page_url
47+
cprint("[+] 正在尝试下载第 %d 页数据" % i, "red")
48+
try:
49+
requests.packages.urllib3.disable_warnings()
50+
dowloadre = requests.get(url=dowloadurl, headers=Headers, timeout=6, verify=False, proxies=proxies)
51+
if (dowloadre.status_code == 200) or (testre.status_code == 201):
52+
JSON_load(dowloadre.text)
53+
cprint("-" * 45, "red")
54+
else:
55+
cprint("[-] API返回状态码为 %d" % testre.status_code,"yellow")
56+
cprint("[-] 请根据返回的状态码,参考官方手册:https://www.zoomeye.org/doc","yellow")
57+
except KeyboardInterrupt:
58+
print("Ctrl + C 手动终止了进程")
59+
sys.exit()
60+
except Exception as e:
61+
print("[-] 发生错误,已记入日志error.log\n")
62+
f2 = open("error.log", "a")
63+
f2.write(str(e) + '\n')
64+
f2.close()
65+
i = i + 1
66+
67+
def Key_Test(key,proxies,choices):
68+
cprint("======您的ZoomEye密钥进行API对接测试======","green")
69+
Headers = {
70+
"API-KEY": key,
71+
"Content-Type": "application/x-www-form-urlencoded"
72+
}
73+
keytesturl = "https://api.zoomeye.org/host/search?query=app:\"Spring Framework\"&page=1"
74+
try:
75+
requests.packages.urllib3.disable_warnings()
76+
testre = requests.get(url=keytesturl, headers=Headers, timeout=6, verify=False, proxies=proxies)
77+
if (testre.status_code == 200) or (testre.status_code == 201):
78+
cprint("[+] 您的key有效,测试成功!", "red")
79+
Key_Dowload(key,proxies,choices)
80+
else:
81+
cprint("[-] API返回状态码为 %d" % testre.status_code,"yellow")
82+
cprint("[-] 请根据返回的状态码,参考官方手册:https://www.zoomeye.org/doc","yellow")
83+
except KeyboardInterrupt:
84+
print("Ctrl + C 手动终止了进程")
85+
sys.exit()
86+
except Exception as e:
87+
print("[-] 发生错误,已记入日志error.log\n")
88+
f2 = open("error.log", "a")
89+
f2.write(str(e) + '\n')
90+
f2.close()
91+
92+
def ZoomDowload(key,proxies):
93+
cprint("======开始对接ZoomEye接口进行Spring资产测绘======","green")
94+
cprint('[+] 您的ZoomEye密钥为:' + key ,"green")
95+
try:
96+
choices = input("\n请输入要测绘的资产数量(默认100条): ")
97+
if choices == '':
98+
choices = "100"
99+
elif int(choices) <= 0:
100+
print("请不要输入负数")
101+
sys.exit()
102+
choices = int(choices)
103+
except Exception as e:
104+
print("请不要输入无意义的字符串")
105+
sys.exit()
106+
Key_Test(key,proxies,choices)
107+
count = len(open("zoomout.txt", 'r').readlines())
108+
if count >= 1:
109+
cprint("[+][+][+] 已经将ZoomEye的资产结果导出至 zoomout.txt ,共%d行记录" % count,"red")
110+
sys.exit()

0 commit comments

Comments
 (0)