├── requirement.txt ├── tests.jpg ├── README.md ├── config.py └── fofa-Cscan.py /requirement.txt: -------------------------------------------------------------------------------- 1 | requests 2 | openpyxl 3 | ipaddress 4 | tableprint 5 | -------------------------------------------------------------------------------- /tests.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wudicainiao/Fofa-Cscan/HEAD/tests.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fofa-Cscan 2 | a Simple tool.Based on fofa.so 3 | 4 | # **Usage : python3 fofa-Cscan.py** 5 | 6 | **Support CIDR** 7 | 8 | **screenshot:** 9 | 10 | ![avatar](/tests.jpg) 11 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import time 3 | 4 | class define: 5 | GREEN = "\033[32m" 6 | RED = "\033[0;31m" 7 | BLUE = "\033[94m" 8 | ORANGE = "\033[33m" 9 | Timeout = 500 10 | filename = 'out\\%s.xlsx' % time.strftime("%Y-%m-%d-%H-%M", time.localtime(time.time())) 11 | 12 | FOFA_EMAIL = 'FOFA_EMAIL' # 使用时替换此处FOFA_EMAIL 13 | Apikey = 'Apikey' # 使用时替换此处Apikey 14 | 15 | banner = ''' 16 | 17 | __..--.._ 18 | ..... .--~ ..... `. 19 | .": "`-.. . .' ..-'" :". ` 20 | ` `._ ` _.'`"( `-"'`._ ' _.' ' 21 | ~~~ `. ~~~ 22 | .' 23 | / 24 | ( 25 | ^---' 26 | 27 | [*] Author:dacAIniao@重明安全 28 | ''' 29 | 30 | usage = ''' 31 | Usage: 32 | Supporting CIDR format! 33 | 34 | python3 fofa.py [options] 35 | 36 | Options: 37 | -i ip eg : 8.8.8.8 8.8.8.0/24 8.8.8.8/16 38 | -f ip_file eg : 8.8.8.8 8.8.8.0/24 8.8.8.8/16 39 | ''' 40 | 41 | -------------------------------------------------------------------------------- /fofa-Cscan.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | import os 3 | import sys 4 | import json 5 | import base64 6 | import requests 7 | import ipaddress 8 | import tableprint 9 | from config import * 10 | import openpyxl as ws 11 | from requests.packages.urllib3.exceptions import InsecureRequestWarning 12 | requests.packages.urllib3.disable_warnings(InsecureRequestWarning) 13 | 14 | 15 | def http(url): 16 | try: 17 | r = requests.get(url=url,verify=False,headers={'Connection':'close'}) 18 | return r.text 19 | except Exception as e: 20 | raise e 21 | 22 | def ip(ip): 23 | qbase = base64.b64encode(str("ip=%s"%ip).encode('utf-8')) 24 | res = http('https://fofa.so/api/v1/search/all?email=%s&key=%s&qbase64=%s&size=100&page=1&fields=ip,host,title,port,protocol'%(define.FOFA_EMAIL,define.Apikey,str(qbase,'utf-8'))) 25 | [write_xlsx(i) for i in json.loads(res)["results"]] 26 | 27 | def creat_txt(): 28 | if os.path.exists(define.filename) == False: 29 | if os.path.exists('out\\') == False: 30 | os.mkdir('out') 31 | with open(define.filename,'a+',encoding='utf-8') as a: 32 | print(define.BLUE+"[*]创建文件成功 %s"%define.filename) 33 | else: 34 | print(define.RED+"[*]文件已存在 文件为:%s"%define.filename) 35 | 36 | def write_xlsx(res): 37 | print(define.GREEN+"[*]内容正在写入 :%s"%res) 38 | wb = ws.load_workbook(define.filename) 39 | sheet1 = wb['Sheet'] 40 | num = sheet1.max_row 41 | sheet1.cell(row = num+1,column = 1,value = res[0]) 42 | sheet1.cell(row = num+1,column = 2,value = res[1]) 43 | sheet1.cell(row = num+1,column = 3,value = res[2]) 44 | sheet1.cell(row = num+1,column = 4,value = res[3]) 45 | sheet1.cell(row = num+1,column = 5,value = res[4]) 46 | wb.save(define.filename) 47 | wb.close() 48 | 49 | def creat_xlsx(): 50 | if os.path.exists(define.filename) == False: 51 | s = 0 52 | wb = ws.Workbook() 53 | ws1 = wb.active 54 | if os.path.exists('out\\') == False: 55 | os.mkdir('out') 56 | word=['ip','host','title','port','protocol'] 57 | for i in word: 58 | s = s + 1 59 | ws1.cell(row =1,column = s,value = i) 60 | wb.save(define.filename) 61 | print(define.RED+"[*]创建文件成功 %s"%define.filename) 62 | else: 63 | print(define.RED+"[*]文件已存在 文件为:%s"%define.filename) 64 | 65 | if __name__ == '__main__': 66 | print(define.ORANGE+define.banner) 67 | 68 | if len(sys.argv) < 2: 69 | print(define.ORANGE+define.usage) 70 | 71 | elif sys.argv[1] == '-i': 72 | print(define.BLUE+"[*]开始抓取") 73 | creat_xlsx() 74 | [ip(s) for s in ipaddress.ip_network(str(sys.argv[2]),False)] 75 | print(define.BLUE+"[*]抓取完毕") 76 | 77 | elif sys.argv[1] == '-f': 78 | print(define.BLUE+"[*]开始抓取") 79 | creat_xlsx() 80 | [ip(s) for x in open(sys.argv[2]) for s in ipaddress.ip_network(x.strip(),False)] 81 | print(define.BLUE+"[*]抓取完毕") 82 | 83 | else: 84 | print(define.ORANGE+define.usage) 85 | --------------------------------------------------------------------------------