2022-03-22 18:03:05 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# _*_ coding:utf-8 _*_
|
|
|
|
|
|
|
|
|
|
import base64
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
from Config.config_decorators import Save_Csv
|
|
|
|
|
from Config.config_api import FOFA_EAMIL, FOFA_API_KEY
|
2022-04-14 10:27:03 +08:00
|
|
|
from Tools.SaveHosts import gethosts
|
2022-03-22 18:03:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def fofaapi(keyword,num):
|
|
|
|
|
reslist=[]
|
|
|
|
|
bkeyword = bytes(keyword, encoding="utf8")
|
|
|
|
|
bs64 = base64.b64encode(bkeyword)
|
|
|
|
|
bs64 = bs64.decode()
|
|
|
|
|
res = requests.get('https://fofa.info/api/v1/search/all?email={}&key={}&qbase64={}&fields=host,ip,port,country,city,server,title&size={}'.format(FOFA_EAMIL,FOFA_API_KEY,bs64,str(num)))
|
|
|
|
|
result = res.json()['results']
|
2022-04-14 10:27:03 +08:00
|
|
|
hosts=[]
|
2022-03-22 18:03:05 +08:00
|
|
|
for i in result:
|
|
|
|
|
dic={}
|
|
|
|
|
dic['host'] = i[0]
|
|
|
|
|
dic['ip'] = i[1]
|
|
|
|
|
dic['port'] = i[2]
|
|
|
|
|
dic['country'] = i[3]
|
|
|
|
|
dic['city'] = i[4]
|
|
|
|
|
dic['server'] = i[5]
|
|
|
|
|
dic['title'] = i[6]
|
|
|
|
|
reslist.append(dic)
|
2022-04-15 11:16:07 +08:00
|
|
|
hosts.append(i[0])
|
2022-03-22 18:03:05 +08:00
|
|
|
print(dic)
|
2022-04-14 10:27:03 +08:00
|
|
|
gethosts(hosts)
|
2022-03-22 18:03:05 +08:00
|
|
|
return reslist
|
|
|
|
|
|
|
|
|
|
@Save_Csv
|
|
|
|
|
def run(keyword,num):
|
|
|
|
|
return fofaapi(keyword,num)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
fofaapi('app="test"',3)
|