-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchafofa.py
59 lines (50 loc) · 1.9 KB
/
chafofa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: UTF-8 -*-
# @Time: 11:40
# @Author: 浪飒
# @File: chafofa.py
# @Software: PyCharm
import base64
import json
import time
import click
import requests
import xlwt
def Welcome():
print('''
查fofa命令行工具 author:浪飒
________ _____ __________ _________
/ ____/ / / / | / ____/ __ \/ ____/ |
/ / / /_/ / /| | / /_ / / / / /_ / /| |
/ /___/ __ / ___ | / __/ / /_/ / __/ / ___ |
\____/_/ /_/_/ |_| /_/ \____/_/ /_/ |_|
Options:
-f TEXT 请输入fofa查询语法
-s INTEGER 请输入所要查询的条数,默认100条
--help Show this message and exit.
''')
def jm_base64(string):
return base64.b64encode(string.encode('utf-8'))
@click.command()
@click.option("-f", help="请输入fofa查询语法", prompt="请输入fofa查询语法")
@click.option("-s", default=100, help="请输入所要查询的条数,默认100条")
def chafofa(f, s):
qbase64 = str(jm_base64(f), 'UTF-8')
req = f"https://fofa.info/api/v1/search/all?email=3540005812@qq.com&key=e07547984526bca8f6716578e68e5f5d&qbase64={qbase64}&size={s}&fields=ip,host,port,protocol,title,server"
res = requests.get(req).content.decode("utf-8")
dict_data = json.loads(res) # json转成python字典
results = dict_data.get('results')
book = xlwt.Workbook(encoding='utf-8', style_compression=0)
sheet = book.add_sheet(f'fofa查询结果', cell_overwrite_ok=True)
col = ('IP', 'host', '端口', '协议', '网站标题', '网站server')
for i in range(0, 6):
sheet.write(0, i, col[i])
for i in range(len(results)):
data=results[i]
for j in range(0, 6):
sheet.write(i+1, j, data[j])
path=f'{str(time.time().__hash__())}_fofa查询结果.xls'
book.save(path)
print(f"表格已保存为{path}")
if __name__ == '__main__':
Welcome()
chafofa()