Skip to content

Commit

Permalink
Feature v2.5.0 添加fofa-py SDK代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Cl0udG0d committed Aug 4, 2024
1 parent 272b966 commit f01e2e6
Show file tree
Hide file tree
Showing 7 changed files with 945 additions and 3 deletions.
11 changes: 9 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
altgraph==0.17.4
backports.tarfile==1.2.0
certifi==2023.7.22
cffi==1.16.0
charset-normalizer==2.0.12
colorama==0.4.6
cryptography==43.0.0
decorator==5.1.1
docutils==0.20.1
idna==3.4
importlib-metadata==7.0.1
importlib_resources==6.4.0
jaraco.classes==3.4.0
jaraco.context==5.3.0
jaraco.functools==4.0.2
jaraco.functools==4.0.1
jeepney==0.8.0
keyring==25.2.1
lxml==4.9.2
markdown-it-py==3.0.0
Expand All @@ -20,17 +24,20 @@ nh3==0.2.18
packaging==23.2
pefile==2023.2.7
pkginfo==1.10.0
py==1.11.0
pycparser==2.22
pycryptodomex==3.19.0
Pygments==2.18.0
pyinstaller==6.4.0
pyinstaller-hooks-contrib==2024.1
PySocks==1.7.1
pywin32-ctypes==0.2.2
readme_renderer==43.0
requests==2.27.1
requests-toolbelt==1.0.0
retry==0.9.2
rfc3986==2.0.0
rich==13.7.1
SecretStorage==3.3.3
twine==5.1.1
typing_extensions==4.12.2
urllib3==1.26.19
Expand Down
104 changes: 103 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
@@ -1 +1,103 @@
# edit test py 1
# -*- coding: utf-8 -*-
from tookit.fofa_client import Client

def get_base_results(key,search_key,size=10000,page=1):
client = Client(key)
data = client.search(search_key, size=size, page=page,fields="link,port,protocol,country,region,city,as_number,as_organization,host,domain,os,"
"server,product")
return data["results"]


def add_city_to_region(result_pool,current_country, current_region, current_city):
"""
添加城市信息 包含 country region city
@param result_pool:
@param current_country:
@param current_region:
@param current_city:
"""
# 检查 current_country 是否存在于 result_pool["country"]
if current_country not in result_pool["country"]:
# 如果不存在,则创建它,并初始化为一个空字典
result_pool["country"][current_country] = {}

# 检查 current_region 是否存在于 current_country 对应的字典中
if current_region not in result_pool["country"][current_country]:
# 如果不存在,则创建它,并初始化为一个空集合
result_pool["country"][current_country][current_region] = set()

# 现在可以安全地向 current_region 的集合中添加 current_city
result_pool["country"][current_country][current_region].add(current_city)


def init_result_pool(results):
result_pool = {
"country":{},
"port":set(),
"product":set(),
}
for result in results:
current_country = result[3]
current_region = result[4]
current_city = result[5]
add_city_to_region(result_pool,current_country,current_region,current_city)
result_pool["port"].add(result[1])
products = result[12].split(",")
for product in products:
result_pool["product"].add(product)

# result_pool["country"][current_country][current_region].add(current_city)
print(result_pool)
return result_pool

def get_new_search_key_list(source_key,result_pool):
search_key_result = []

# 真

## 城市
country_result = []
for country_code, country_data in result_pool['country'].items():

for region_code, region_data in country_data.items():
for city in region_data:
country_result.append(f'({source_key}) && country="{country_code}" && region="{region_code}" && city="{city}"')

## 产品
product_result = []
for search_key in country_result:
for product in result_pool['product']:
product_result.append(f'{search_key} && product="{product}"')


## 端口
port_result = []
for search_key in product_result:
for port in result_pool["port"]:
port_result.append(f'{search_key} && port="{port}"')


# false_port_key = ""
# for port in result_pool["port"]:
# false_port_key += f" && port != {port}"
#
# for search_key in country_result:
# port_result.append(f"{search_key} {false_port_key}")

for result in port_result:
print(result)


return

if __name__ == "__main__":
key = '' # 输入key
source_key = 'header="thinkphp" || header="think_template"'
result = get_base_results(key,source_key,100)
print(result)
result_pool = init_result_pool(result)
get_new_search_key_list(source_key,result_pool)
# print(result)
# print(len(result))


2 changes: 2 additions & 0 deletions tookit/fofa_client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .client import Client
from .exception import FofaError
Loading

0 comments on commit f01e2e6

Please sign in to comment.