Skip to main content

FOFA SDK 使用说明

简介

基于 FOFA API 编写的 python 版 SDK, 方便 python 开发者快速将 FOFA 集成到自己的项目中。

Api Documentation

FOFA 命令行工具

基于FOFA python SDK实现的简单命令行工具,用于简单的FOFA数据查询

安装

pip install fofa-py

用法

显示所有支持的命令

fofa

设置fofa api key

通过环境变量设置认证信息

环境变量Key Value
FOFA_EMAIL 用户登陆 FOFA 使用的 Email
FOFA_KEY 前往 个人中心 查看 API Key

搜索子命令,从fofa搜索数据,

搜索数据

搜索数据并展示结果

fofa search domain=bing.com --size 1000 -f ip,port,domain,title,certs_match,certs_expired

统计搜索结果数量

fofa search domain=bing.com --count
382128

查询聚合信息

fofa search domain=bing.com -f port,domain,protocol,title --stats --size 10

保存结果数据

保存结果数据为csv或xls格式,示例:

# 保存数据为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信息,示例

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

# -*- 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 协议,查看 协议文件

Metadata

Release files for FOFA-py 2.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for FOFA-py 2.0.3
File Size Uploaded Provenance
FOFA-py-2.0.3.tar.gz 10.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for FOFA-py 2.0.3
File Interpreter ABI Platform
FOFA_py-2.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 22.6 kB

Release files / FOFA-py-2.0.3.tar.gz

Download URL FOFA-py-2.0.3.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a7d7848ae291bd569d8e0f6f4126bade76212a21a5eb7d1133ef1f7ed9508210
BLAKE2b-256 checksum
How to use checksums
ab5c51476a7a116c2e54f5e3e26aabc3d295fd9eda757a49ba807569e778a12e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

Release files / FOFA_py-2.0.3-py3-none-any.whl

Download URL FOFA_py-2.0.3-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ac349b754b477cec25b79d6372e5f806465a8e961934078979c44a695eca4a6
BLAKE2b-256 checksum
How to use checksums
80844d777f41376f6867fed74620d44a178b0a6bb8ed3e3e1711a02bc620dc20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

Security for FOFA-py 2.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page