Last active
July 27, 2021 12:58
-
-
Save hanshou101/c181d32c64c46875590fd3711f1964cb to your computer and use it in GitHub Desktop.
Shodan查询
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
参考资料: | |
1. [Python2写法](https://www.cnblogs.com/miaodaren/p/9177379.html) | |
2. [Python3改写](https://www.cnblogs.com/miaodaren/p/9177379.html) | |
以上两个办法,都是错误的!!! | |
3. [正确写法](https://gist.github.com/yehgdotnet/b9dfc618108d2f05845c4d8e28c5fc6a) | |
""" | |
import base64 | |
import codecs | |
from urllib.request import urlopen | |
import mmh3 | |
import requests | |
# 存在问题!!! | |
def trans_to_shodan(bs: bytes): | |
favicon = base64.b64encode(bs) | |
print(favicon) | |
hash = mmh3.hash(favicon) | |
print(hash) | |
def method1_wrong(url: str): | |
response = requests.get(url, verify=False) | |
trans_to_shodan(response.content) | |
def method2_wrong(url: str): | |
bs = urlopen(url).read() | |
trans_to_shodan(bs) | |
# 使用成功 | |
def method3_correct(url: str): | |
response = requests.get(url, verify=False) | |
favicon = codecs.encode(response.content, "base64") | |
hash = mmh3.hash(favicon) | |
print(hash) | |
# ico_url = "https://42.194.241.239/favicon.ico" | |
# ico_url = "https://www.google.com/favicon.ico" | |
ico_url = "http://common.cnblogs.com/favicon.ico" | |
# ico_url = "https://common.cnblogs.com/favicon.svg" | |
# ico_url = "https://www.shodan.io/static/img/favicon.png" | |
# method1_wrong(ico_url) | |
# method2_wrong(ico_url) | |
method3_correct(ico_url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment