Skip to content

Commit b4ad384

Browse files
authored
Update hunter.py
1 parent 153666f commit b4ad384

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

inc/hunter.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
def JSON_load(text):
1414
json_str = text
1515
data = json.loads(json_str)
16-
# 提取ip和port信息
17-
ip_port_list = [(match["url"]) for match in data["data"]["arr"]]
16+
if data["data"]["arr"]:
17+
# 提取ip和port信息
18+
ip_port_list = [(match["url"]) for match in data["data"]["arr"]]
19+
else:
20+
cprint("[-] 没有搜索到任何资产,请确认你的语法是否正确","yellow")
21+
sys.exit()
1822
# 打印提取的信息
1923
for service in ip_port_list:
2024
outurl = str(service)
@@ -23,7 +27,7 @@ def JSON_load(text):
2327
f2.close()
2428
print(f"Service: {outurl}")
2529

26-
def Key_Dowload(key,proxies,choices):
30+
def Key_Dowload(key,proxies,choices,searchs):
2731
cprint("======通过Hunter密钥进行API下载数据======","green")
2832
Headers = {
2933
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
@@ -38,13 +42,13 @@ def Key_Dowload(key,proxies,choices):
3842
i = 1
3943
while i <= pages:
4044
page_url = "&page=" + str(i)
41-
keyurl = "https://hunter.qianxin.com/openApi/search?api-key=" + key + "&search=YXBwLm5hbWU9IlNwcmluZyBXaGl0ZWxhYmVsIEVycm9yIg==&page_size=20&is_web=1"
42-
dowloadurl = keyurl + page_url
45+
keyurl = "https://hunter.qianxin.com/openApi/search?api-key=" + str(key) + "&search=" + str(searchs) + "&page_size=20&is_web=1"
46+
dowloadurl = str(keyurl + page_url)
4347
cprint("[+] 正在尝试下载第 %d 页数据" % i, "red")
4448
try:
4549
requests.packages.urllib3.disable_warnings()
4650
dowloadre = requests.get(url=dowloadurl, headers=Headers, timeout=10, verify=False, proxies=proxies)
47-
if (dowloadre.status_code == 200) or (dowloadre.status_code == 201):
51+
if ("\"code\":200" in str(dowloadre.text)):
4852
JSON_load(dowloadre.text)
4953
cprint("-" * 45, "red")
5054
sleep(2)
@@ -55,13 +59,14 @@ def Key_Dowload(key,proxies,choices):
5559
print("Ctrl + C 手动终止了进程")
5660
sys.exit()
5761
except Exception as e:
62+
print(e)
5863
print("[-] 发生错误,已记入日志error.log\n")
5964
f2 = open("error.log", "a")
6065
f2.write(str(e) + '\n')
6166
f2.close()
6267
i = i + 1
6368

64-
def Key_Test(key,proxies,choices):
69+
def Key_Test(key,proxies,choices,searchs):
6570
cprint("======您的Hunter密钥进行API对接测试======","green")
6671
Headers = {
6772
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
@@ -70,15 +75,16 @@ def Key_Test(key,proxies,choices):
7075
keytesturl = "https://hunter.qianxin.com/openApi/search?api-key=" + key + "&search=dGl0bGU9IuWMl-S6rCI=&page=1&page_size=10&is_web=1"
7176
try:
7277
requests.packages.urllib3.disable_warnings()
73-
testre = requests.get(url=keytesturl, headers=Headers, timeout=6, verify=False, proxies=proxies)
78+
testre = requests.get(url=keytesturl, headers=Headers, timeout=10, verify=False, proxies=proxies)
7479
json_str = testre.text
7580
data = json.loads(json_str)
7681
recode = data["code"]
7782
if str(recode) == "200":
7883
cprint("[+] 您的key有效,测试成功!", "red")
7984
rest_quota = data["data"]["rest_quota"]
8085
cprint("[+] %s" % rest_quota, "red")
81-
Key_Dowload(key,proxies,choices)
86+
sleep(2)
87+
Key_Dowload(key,proxies,choices,searchs)
8288
else:
8389
cprint("[-] API返回状态码为 %d" % recode,"yellow")
8490
cprint("[-] 请根据返回的状态码,参考官方手册:https://hunter.qianxin.com/home/helpCenter?r=5-1-1","yellow")
@@ -96,7 +102,7 @@ def HunterDowload(key,proxies):
96102
cprint("======开始对接鹰图接口进行Spring资产测绘======","green")
97103
cprint('[+] 您的Hunter密钥为:' + key ,"green")
98104
try:
99-
choices = input("\n请输入要测绘的资产数量(默认100条): ")
105+
choices = input("\n[.] 请输入要测绘的资产数量(默认100条): ")
100106
if choices == '':
101107
choices = "100"
102108
elif int(choices) <= 0:
@@ -106,9 +112,15 @@ def HunterDowload(key,proxies):
106112
except Exception as e:
107113
print("请不要输入无意义的字符串")
108114
sys.exit()
115+
search = input("[.] 请输入要测绘的语句(默认app.name=\"Spring Whitelabel Error\"): ")
116+
if search == "":
117+
searchs = str("YXBwLm5hbWU9IlNwcmluZyBXaGl0ZWxhYmVsIEVycm9yIg==")
118+
else:
119+
search = base64.urlsafe_b64encode(search.encode("utf-8"))
120+
searchs = str(search.decode('utf-8'))
109121
f2 = open("hunterout.txt", "wb+")
110122
f2.close()
111-
Key_Test(key,proxies,choices)
123+
Key_Test(key,proxies,choices,searchs)
112124
count = len(open("hunterout.txt", 'r').readlines())
113125
if count >= 1:
114126
cprint("[+][+][+] 已经将Hunter的资产结果导出至 hunterout.txt ,共%d行记录" % count,"red")

0 commit comments

Comments
 (0)