@@ -16,6 +16,9 @@ def JSON_load(text):
1616 # 提取ip和port信息
1717 ip_port_list = [service [0 ] for service in data ["results" ]]
1818 # 打印提取的信息
19+ if ip_port_list == []:
20+ cprint ("[-] 没有搜索到任何资产,请确认你的语法是否正确" ,"yellow" )
21+ sys .exit ()
1922 for service in ip_port_list :
2023 if ("https" not in service ):
2124 service = "http://" + service
@@ -25,7 +28,7 @@ def JSON_load(text):
2528 f2 .close ()
2629 print (f"Service: { outurl } " )
2730
28- def Key_Dowload (key ,proxies ,choices ):
31+ def Key_Dowload (key ,proxies ,choices , searchs ):
2932 cprint ("======通过Fofa密钥进行API下载数据======" ,"green" )
3033 Headers = {
3134 "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" ,
@@ -40,13 +43,13 @@ def Key_Dowload(key,proxies,choices):
4043 i = 1
4144 while i <= pages :
4245 page_url = "&page=" + str (i )
43- keyurl = "https://fofa.info/api/v1/search/all?&key=" + key + "&qbase64=aWNvbl9oYXNoPSIxMTYzMjM4MjEifHxib2R5PSJXaGl0ZWxhYmVsIEVycm9yIFBhZ2Ui"
46+ keyurl = "https://fofa.info/api/v1/search/all?&key=" + key + "&qbase64=" + str ( searchs )
4447 dowloadurl = keyurl + page_url
4548 cprint ("[+] 正在尝试下载第 %d 页数据" % i , "red" )
4649 try :
4750 requests .packages .urllib3 .disable_warnings ()
4851 dowloadre = requests .get (url = dowloadurl , headers = Headers , timeout = 10 , verify = False , proxies = proxies )
49- if (dowloadre . status_code == 200 ) or (dowloadre .status_code == 201 ):
52+ if (" \" error \" :false" in str (dowloadre .text ) ):
5053 JSON_load (dowloadre .text )
5154 cprint ("-" * 45 , "red" )
5255 else :
@@ -62,7 +65,7 @@ def Key_Dowload(key,proxies,choices):
6265 f2 .close ()
6366 i = i + 1
6467
65- def Key_Test (key ,proxies ,choices ):
68+ def Key_Test (key ,proxies ,choices , searchs ):
6669 cprint ("======您的Fofa密钥进行API对接测试======" ,"green" )
6770 Headers = {
6871 "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" ,
@@ -83,7 +86,7 @@ def Key_Test(key,proxies,choices):
8386 cprint ("[+] 您的账号为VIP会员" , "red" )
8487 else :
8588 cprint ("[.] 您的账号不是VIP会员" , "yellow" )
86- Key_Dowload (key ,proxies ,choices )
89+ Key_Dowload (key ,proxies ,choices , searchs )
8790 else :
8891 apierror = data ["errmsg" ]
8992 cprint ("[-] 发生错误,API返回结果为 %s" % apierror ,"yellow" )
@@ -112,9 +115,15 @@ def FofaDowload(key,proxies):
112115 except Exception as e :
113116 print ("请不要输入无意义的字符串" )
114117 sys .exit ()
118+ search = input ("[.] 请输入要测绘的语句(默认icon_hash=\" 116323821\" ||body=\" Whitelabel Error Page\" ): " )
119+ if search == "" :
120+ searchs = str ("aWNvbl9oYXNoPSIxMTYzMjM4MjEifHxib2R5PSJXaGl0ZWxhYmVsIEVycm9yIFBhZ2Ui" )
121+ else :
122+ search = base64 .b64encode (search .encode ("utf-8" ))
123+ searchs = str (search .decode ('utf-8' ))
115124 f2 = open ("fofaout.txt" , "wb+" )
116125 f2 .close ()
117- Key_Test (key ,proxies ,choices )
126+ Key_Test (key ,proxies ,choices , searchs )
118127 count = len (open ("fofaout.txt" , 'r' ).readlines ())
119128 if count >= 1 :
120129 cprint ("[+][+][+] 已经将Fofa的资产结果导出至 fofaout.txt ,共%d行记录" % count ,"red" )
0 commit comments