# FOFA SDK 使用说明
## 简介
基于 [`FOFA API`](https://fofa.info/api) 编写的 `python` 版 `SDK`, 方便 `python` 开发者快速将 `FOFA` 集成到自己的项目中。
[Api Documentation](https://fofapro.github.io/fofa-py/index.html)
## FOFA 命令行工具
基于FOFA python SDK实现的简单命令行工具,用于简单的FOFA数据查询
## 安装
```shell
pip install fofa-py
```
## 用法
显示所有支持的命令
```shell
fofa
```
### 设置fofa api key
通过环境变量设置认证信息
| 环境变量Key | Value |
|--------------|:----------------------------------------------------------:|
| `FOFA_EMAIL` | 用户登陆 `FOFA` 使用的 `Email` |
| `FOFA_KEY` | 前往 [个人中心](https://fofa.info/userInfo) 查看 `API Key` |
### search
搜索子命令,从fofa搜索数据,
#### 搜索数据
搜索数据并展示结果
```shell
fofa search domain=bing.com --size 1000 -f ip,port,domain,title,certs_match,certs_expired
```
#### 统计搜索结果数量
```shell
fofa search domain=bing.com --count
382128
```
#### 查询聚合信息
```shell
fofa search domain=bing.com -f port,domain,protocol,title --stats --size 10
```
#### 保存结果数据
保存结果数据为csv或xls格式,示例:
```shell
# 保存数据为csv文件
fofa search domain=bing.com -f ip,port,domain,link,title,certs_match,certs_expired --size 50000 --save bing.csv
# 搜索证书匹配的数据
fofa search 'domain="bing.com" && cert.is_match=true' -f ip,port,domain,link,title,certs_match,certs_expired --size 50000 --save bing_cert_expired.xls
```
### host
查看一个域名或ip的host信息,示例
```shell
fofa host www.bing.com
{
"asn": 59067,
"category": [
"其他企业应用"
],
"consumed_fpoint": 0,
"country_code": "CN",
"country_name": "China",
"domain": [
"tuzhiji.com",
"61.129.255.240:8080"
],
"error": false,
"host": "www.bing.com",
"ip": "202.89.233.101",
"org": "Microsoft Mobile Alliance Internet Services Co., Ltd",
"port": [
443,
80,
8080
],
"product": [
"Microsoft-RSA-TLS-CA",
"Microsoft-RSA-TLS-CA-02"
],
"protocol": [
"https",
"http"
],
"required_fpoints": 0,
"update_time": "2023-06-27 08:00:00"
}
```
### 代码使用sdk
``` python
# -*- coding: utf-8 -*-
import fofa
if __name__ == "__main__":
email, key = ('test@test.com', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') # 输入email和key
client = fofa.Client(email, key) # 将email和key传入fofa.Client类进行初始化和验证,并得到一个fofa client对象
query_str = 'header="thinkphp" || header="think_template"'
for page in range(1, 51): # 从第1页查到第50页
fpoint = client.get_userinfo()["fofa_point"] # 查询F点剩余数量
if fpoint < 100:
break # 当F点小于100时,不再获取数据
data = client.search(query_str, size=100, page=page, fields="ip,city") # 查询第page页数据的ip和城市
for ip, city in data["results"]:
print "%s,%s" % (ip, city) # 打印出每条数据的ip和城市
```
## 协议
`FOFA SDK` 遵循 `MIT` 协议,查看 [协议文件](https://opensource.org/licenses/mit)
Raw data
{
"_id": null,
"home_page": "https://github.com/fofapro/fofa-py",
"name": "FOFA-py",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "fofa,security,network",
"author": "Fofa",
"author_email": "fofabot@baimaohui.net",
"download_url": "https://files.pythonhosted.org/packages/ab/5c/51476a7a116c2e54f5e3e26aabc3d295fd9eda757a49ba807569e778a12e/FOFA-py-2.0.3.tar.gz",
"platform": null,
"description": "# FOFA SDK \u4f7f\u7528\u8bf4\u660e\n\n## \u7b80\u4ecb\n \u57fa\u4e8e [`FOFA API`](https://fofa.info/api) \u7f16\u5199\u7684 `python` \u7248 `SDK`, \u65b9\u4fbf `python` \u5f00\u53d1\u8005\u5feb\u901f\u5c06 `FOFA` \u96c6\u6210\u5230\u81ea\u5df1\u7684\u9879\u76ee\u4e2d\u3002\n\n [Api Documentation](https://fofapro.github.io/fofa-py/index.html)\n\n## FOFA \u547d\u4ee4\u884c\u5de5\u5177\n \u57fa\u4e8eFOFA python SDK\u5b9e\u73b0\u7684\u7b80\u5355\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u7528\u4e8e\u7b80\u5355\u7684FOFA\u6570\u636e\u67e5\u8be2\n\n## \u5b89\u88c5\n```shell\npip install fofa-py\n```\n\n## \u7528\u6cd5\n\n \u663e\u793a\u6240\u6709\u652f\u6301\u7684\u547d\u4ee4\n```shell\nfofa\n```\n### \u8bbe\u7f6efofa api key\n \u901a\u8fc7\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u8ba4\u8bc1\u4fe1\u606f\n\n| \u73af\u5883\u53d8\u91cfKey | Value |\n|--------------|:----------------------------------------------------------:|\n| `FOFA_EMAIL` | \u7528\u6237\u767b\u9646 `FOFA` \u4f7f\u7528\u7684 `Email` |\n| `FOFA_KEY` | \u524d\u5f80 [\u4e2a\u4eba\u4e2d\u5fc3](https://fofa.info/userInfo) \u67e5\u770b `API Key` |\n\n\n### search\n\u641c\u7d22\u5b50\u547d\u4ee4\uff0c\u4ecefofa\u641c\u7d22\u6570\u636e\uff0c\n\n#### \u641c\u7d22\u6570\u636e\n\u641c\u7d22\u6570\u636e\u5e76\u5c55\u793a\u7ed3\u679c\n```shell\nfofa search domain=bing.com --size 1000 -f ip,port,domain,title,certs_match,certs_expired\n```\n\n#### \u7edf\u8ba1\u641c\u7d22\u7ed3\u679c\u6570\u91cf\n```shell\nfofa search domain=bing.com --count\n382128\n```\n\n#### \u67e5\u8be2\u805a\u5408\u4fe1\u606f\n```shell\nfofa search domain=bing.com -f port,domain,protocol,title --stats --size 10\n```\n\n#### \u4fdd\u5b58\u7ed3\u679c\u6570\u636e\n\u4fdd\u5b58\u7ed3\u679c\u6570\u636e\u4e3acsv\u6216xls\u683c\u5f0f\uff0c\u793a\u4f8b:\n\n```shell\n# \u4fdd\u5b58\u6570\u636e\u4e3acsv\u6587\u4ef6\nfofa search domain=bing.com -f ip,port,domain,link,title,certs_match,certs_expired --size 50000 --save bing.csv\n\n# \u641c\u7d22\u8bc1\u4e66\u5339\u914d\u7684\u6570\u636e\nfofa search 'domain=\"bing.com\" && cert.is_match=true' -f ip,port,domain,link,title,certs_match,certs_expired --size 50000 --save bing_cert_expired.xls\n```\n\n### host\n\u67e5\u770b\u4e00\u4e2a\u57df\u540d\u6216ip\u7684host\u4fe1\u606f\uff0c\u793a\u4f8b\n\n```shell\nfofa host www.bing.com\n{\n \"asn\": 59067,\n \"category\": [\n \"\u5176\u4ed6\u4f01\u4e1a\u5e94\u7528\"\n ],\n \"consumed_fpoint\": 0,\n \"country_code\": \"CN\",\n \"country_name\": \"China\",\n \"domain\": [\n \"tuzhiji.com\",\n \"61.129.255.240:8080\"\n ],\n \"error\": false,\n \"host\": \"www.bing.com\",\n \"ip\": \"202.89.233.101\",\n \"org\": \"Microsoft Mobile Alliance Internet Services Co., Ltd\",\n \"port\": [\n 443,\n 80,\n 8080\n ],\n \"product\": [\n \"Microsoft-RSA-TLS-CA\",\n \"Microsoft-RSA-TLS-CA-02\"\n ],\n \"protocol\": [\n \"https\",\n \"http\"\n ],\n \"required_fpoints\": 0,\n \"update_time\": \"2023-06-27 08:00:00\"\n}\n```\n\n### \u4ee3\u7801\u4f7f\u7528sdk\n\n``` python\n# -*- coding: utf-8 -*-\nimport fofa\n\nif __name__ == \"__main__\":\n email, key = ('test@test.com', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') # \u8f93\u5165email\u548ckey\n client = fofa.Client(email, key) # \u5c06email\u548ckey\u4f20\u5165fofa.Client\u7c7b\u8fdb\u884c\u521d\u59cb\u5316\u548c\u9a8c\u8bc1\uff0c\u5e76\u5f97\u5230\u4e00\u4e2afofa client\u5bf9\u8c61\n query_str = 'header=\"thinkphp\" || header=\"think_template\"'\n for page in range(1, 51): # \u4ece\u7b2c1\u9875\u67e5\u5230\u7b2c50\u9875\n fpoint = client.get_userinfo()[\"fofa_point\"] # \u67e5\u8be2F\u70b9\u5269\u4f59\u6570\u91cf\n if fpoint < 100:\n break # \u5f53F\u70b9\u5c0f\u4e8e100\u65f6\uff0c\u4e0d\u518d\u83b7\u53d6\u6570\u636e\n data = client.search(query_str, size=100, page=page, fields=\"ip,city\") # \u67e5\u8be2\u7b2cpage\u9875\u6570\u636e\u7684ip\u548c\u57ce\u5e02\n for ip, city in data[\"results\"]:\n print \"%s,%s\" % (ip, city) # \u6253\u5370\u51fa\u6bcf\u6761\u6570\u636e\u7684ip\u548c\u57ce\u5e02\n\n```\n\n\n## \u534f\u8bae\n`FOFA SDK` \u9075\u5faa `MIT` \u534f\u8bae\uff0c\u67e5\u770b [\u534f\u8bae\u6587\u4ef6](https://opensource.org/licenses/mit)\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python library for FOFA (https://fofa.info)",
"version": "2.0.3",
"project_urls": {
"Homepage": "https://github.com/fofapro/fofa-py"
},
"split_keywords": [
"fofa",
"security",
"network"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "80844d777f41376f6867fed74620d44a178b0a6bb8ed3e3e1711a02bc620dc20",
"md5": "4e2a4448c8b97aca72ab38d268469e9a",
"sha256": "2ac349b754b477cec25b79d6372e5f806465a8e961934078979c44a695eca4a6"
},
"downloads": -1,
"filename": "FOFA_py-2.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4e2a4448c8b97aca72ab38d268469e9a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 12177,
"upload_time": "2023-06-29T12:54:04",
"upload_time_iso_8601": "2023-06-29T12:54:04.190991Z",
"url": "https://files.pythonhosted.org/packages/80/84/4d777f41376f6867fed74620d44a178b0a6bb8ed3e3e1711a02bc620dc20/FOFA_py-2.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ab5c51476a7a116c2e54f5e3e26aabc3d295fd9eda757a49ba807569e778a12e",
"md5": "ef80e51667eaa07ad74ecb5961cb9c9e",
"sha256": "a7d7848ae291bd569d8e0f6f4126bade76212a21a5eb7d1133ef1f7ed9508210"
},
"downloads": -1,
"filename": "FOFA-py-2.0.3.tar.gz",
"has_sig": false,
"md5_digest": "ef80e51667eaa07ad74ecb5961cb9c9e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10387,
"upload_time": "2023-06-29T12:54:05",
"upload_time_iso_8601": "2023-06-29T12:54:05.503480Z",
"url": "https://files.pythonhosted.org/packages/ab/5c/51476a7a116c2e54f5e3e26aabc3d295fd9eda757a49ba807569e778a12e/FOFA-py-2.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-29 12:54:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "fofapro",
"github_project": "fofa-py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "fofa-py"
}