Skip to content

Commit

Permalink
Feature v2.4.13 解决issue 64 65
Browse files Browse the repository at this point in the history
  • Loading branch information
panyi committed Mar 8, 2024
1 parent 393efdc commit 2a184a0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __pycache__/
*.so
/venv
*.json

favicon32.ico
debug.log
# Distribution / packaging
.Python
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG 代码变更记录

### 2.4.13
+ 新增icon文件和网址功能 [issue 64](https://github.com/Cl0udG0d/Fofa-hack/issues/64)
+ 修复BUG [issue 65](https://github.com/Cl0udG0d/Fofa-hack/issues/65)

### 2.4.12
+ 修复[issue 63](https://github.com/Cl0udG0d/Fofa-hack/issues/63)
+ 完善Authorization逻辑
Expand Down
43 changes: 32 additions & 11 deletions fofa.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
from tookit.unit import clipKeyWord, setProxy, outputLogo
import gettext
import locale
import mmh3
import requests
import base64

import codecs
config.ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
if getattr(sys, 'frozen', None):
dir = sys._MEIPASS
Expand All @@ -41,6 +43,8 @@ def main():
group.add_argument('--keyword', '-k', help=_('fofa搜索关键字'))
group.add_argument('--inputfile', '-i', help=_("指定文件,从文件中批量读取fofa语法"))
group.add_argument('--base', '-b', help=_("以base64的形式输入关键字 -b InRoaW5rcGhwIg=="))
group.add_argument('--iconurl', type=str, help="指定url的icon作为icon_hash关键字")
group.add_argument('--iconfile', type=str, help="指定icon_file作为icon_hash关键字")

parser.add_argument('--timesleep', '-t', help=_('爬取每一页等待秒数,防止IP被Ban,默认为3'), default=3)
parser.add_argument('--timeout', '-to', help=_('爬取每一页的超时时间,默认为180秒'), default=180)
Expand All @@ -52,6 +56,7 @@ def main():
parser.add_argument('--proxy', help=_("指定代理,代理格式 --proxy '127.0.0.1:7890'"))
parser.add_argument('--authorization', type=str, help="指定Authorization值")


# parser.add_argument('--type', type=str, choices=["common", "selenium"], default="common",
# help="运行类型,默认为普通方式")
args = parser.parse_args()
Expand All @@ -60,17 +65,33 @@ def main():
timeout = int(args.timeout)
if args.keyword:
search_key = clipKeyWord(args.keyword)
else:
base = args.base if args.base else None
if base:
try:
search_key = base64.b64decode(base).decode('utf-8')
except Exception as e:
print(e)
search_key = ""
pass
else:
elif args.base:
try:
search_key = base64.b64decode(args.base).decode('utf-8')
except Exception as e:
print(e)
search_key = ""
pass
elif args.iconurl:
if args.iconurl.endswith(".ico"):
icon_url = args.iconurl
else :
icon_url = args.iconurl + "favicon32.ico" if args.iconurl.endswith("/") else args.iconurl + "/favicon32.ico"
try:
_icon = mmh3.hash(
codecs.lookup('base64').encode(requests.get(icon_url).content)[0])
search_key = '''icon_hash="{}"'''.format(_icon)
except:
print("icon url " + icon_url + " 访问错误")
exit(0)
elif args.iconfile:
file_path = args.iconfile
if os.path.exists(file_path):
with open(file_path, 'rb') as f:
_icon = mmh3.hash(codecs.lookup('base64').encode(f.read())[0])
search_key = '''icon_hash="{}"'''.format(_icon)
else:
search_key = ""

endcount = int(args.endcount) if args.endcount else 100
level = args.level if args.level else "1"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ colorama==0.4.6
idna==3.4
importlib-metadata==7.0.1
lxml==4.9.2
mmh3==4.1.0
packaging==23.2
pefile==2023.2.7
pycryptodomex==3.19.0
Expand Down
24 changes: 16 additions & 8 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
from fofa_hack import fofa
from tookit import fofaUseragent

from tookit.sign import getUrl, getPage2Url

import requests,sys,mmh3,codecs

def main():
target_url = getPage2Url("ImhpIg==",10)
print(target_url)
html = requests.get(url=target_url,
headers=fofaUseragent.getFofaCookieHeaders(), timeout=5) \
.text
print(html)
# result_generator = fofa.api('body="亿邮邮件" && country="CN" && region!="HK" && region!="MO"', endcount=100)
# for data in result_generator:
# print(data)
import mmh3
import requests
import base64
# f = open("favicon32.ico","rb")
filename = "favicon32.ico"
# print(f.read())
with open(filename, 'rb') as f:
_icon = mmh3.hash(codecs.lookup('base64').encode(f.read())[0])
print('http.favicon.hash:' + str(_icon))


# response = requests.get('https://g.csdnimg.cn/static/logo/favicon32.ico')
# favicon = base64.b64encode(response.content)
# hash = mmh3.hash(favicon)


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion tookit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
# @File : config.py
# @Github: https://github.com/Cl0udG0d

VERSION_NUM = "2.4.12"
VERSION_NUM = "2.4.13"
ROOT_PATH=""
AUTHORIZATION = ""
11 changes: 9 additions & 2 deletions tookit/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def getSign(message):

def getUrl(qbase64):
ts = int(time.time() * 1000)
size = 10 if config.AUTHORIZATION else 50
size = 10 if config.AUTHORIZATION else 20
message = f'fullfalsepage1qbase64{qbase64}size{size}ts{ts}'
sign = urllib.parse.quote(getSign(message))
url = f'https://api.fofa.info/v1/search?qbase64={urllib.parse.quote(qbase64)}&full=false&page=1&size={size}&ts={ts}&sign={sign}&app_id=9e9fb94330d97833acfbc041ee1a76793f1bc691'
Expand All @@ -69,7 +69,14 @@ def getUrl(qbase64):
# url = f'https://api.fofa.info/v1/search?qbase64={urllib.parse.quote(qbase64)}&full=false&page={page}&size=10&ts={ts}&sign={sign}&app_id=9e9fb94330d97833acfbc041ee1a76793f1bc691'
# return url

def getUrlTest(qbase64):
ts = int(time.time() * 1000)
size = 10 if config.AUTHORIZATION else 20
message = f'fullfalsepage1qbase64{qbase64}size{size}ts{ts}'
sign = urllib.parse.quote(getSign(message))
url = f'https://api.fofa.info/v1/search?qbase64={urllib.parse.quote(qbase64)}&full=false&page=1&size={size}&ts={ts}&sign={sign}&app_id=9e9fb94330d97833acfbc041ee1a76793f1bc691'
return url


if __name__ == '__main__':
print(getUrl("InRoaW5rcGhwIg=="))
print(getUrlTest("aWNvbl9oYXNoPSIxMzMxOTQ0ODc3Ig=="))

0 comments on commit 2a184a0

Please sign in to comment.