Created
July 11, 2023 19:26
-
-
Save kmsec-uk/470c0ee74d29dcb338450595da3a4632 to your computer and use it in GitHub Desktop.
Generate a Shodan favicon hash (32-bit signed MMH3 hash) from file
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
import base64 | |
import re | |
import mmh3 | |
with open('favicon.ico', 'rb') as favicon: | |
# 1. To base64 | |
b64 = base64.b64encode(favicon.read()) | |
# 2. To string | |
utf8_b64 = b64.decode('utf-8') | |
# 3. !Required to match Shodan! Insert newlines (\n) every 76 characters, and also at the end | |
with_newlines = re.sub("(.{76}|$)", "\\1\n", utf8_b64, 0, re.DOTALL) | |
# 4. MMH3 hash | |
hash = mmh3.hash(with_newlines) | |
print(hash) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment