编程语言
首页 > 编程语言> > 使用Python实现fofa调用api搜索资产

使用Python实现fofa调用api搜索资产

作者:互联网

0x01 获取email和api_key
在这里插入图片描述在个人主页的个人资料中,查看个人的email和api_key
0x02 脚本实现
在脚本实现过程中需要使用三个Python库,requests、base64、sys。

import requests
import base64
import sys

API的请求地址:

api = api = r'https://fofa.so/api/v1/search/all?email={}&key={}&qbase64={}&size=10000'

email参数填个人资料中的联系邮箱。
key参数填个人资料中的API KEY。
qbase64是搜索资产的关键字,需要使用base64编码后才可成功发送请求。
size参数为搜索结果的最大值,默认为100条,上限为10000条。
完整代码:

import requests
import base64
import sys


email = r'你的email'
api_key = r'你的API KEY'
api = r'https://fofa.so/api/v1/search/all?email={}&key={}&qbase64={}&size=10000'
arg = sys.argv[1]
print(arg)
flag = base64.b64encode(arg.encode()).decode()
response = requests.get(api.format(email,api_key,flag))
results = response.json()["results"]
print("共搜索到{}条记录!".format(len(results)))
file_name = r"{}.txt".format(arg)
f = open(file_name,"a")
for addr in results:
	f.write(addr[0]+'\n')
f.close()

脚本使用format函数对字符串进行拼接,qbase64在执行脚本时传入参数,最终搜索到的资产结果写入以关键字命名的txt文档,并保存在脚本当前目录下。
0x03 执行脚本
在这里插入图片描述
在这里插入图片描述PS:这是对fofa的API接口调用初尝试,后续如有新的成功尝试,会继续更新。

标签:fofa,Python,base64,results,api,key,import,email
来源: https://blog.csdn.net/weixin_43137410/article/details/117718184