Last active
June 1, 2023 01:31
-
-
Save GreeeenApple/90fcfb21816a1c5ed0801174055bacd8 to your computer and use it in GitHub Desktop.
python 3.10 flask app pin generator
This file contains 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 hashlib | |
from itertools import chain | |
probably_public_bits = [ | |
"user", # exec username | |
"flask.app", # default | |
"wsgi_app", # <= uvicorn, default "Flask" | |
"/venv/lib/python3.10/site-packages/flask/app.py" # app.py or app.pyc | |
] | |
private_bits = [ | |
'4883362083', # /proc/net/arp, /sys/class/net/eth0/address, => 0x123123123 => 4883362083 | |
'XXXXXXXXXXXXXXhoge.hoge' # /etc/machine-id + (. /proc/self/cgroup or blank) | |
] | |
h = hashlib.sha1() # old h = hashlib.md5() | |
for bit in chain(probably_public_bits, private_bits): | |
if not bit: | |
continue | |
if isinstance(bit, str): | |
bit = bit.encode("utf-8") | |
h.update(bit) | |
h.update(b"cookiesalt") # or h.update(b'shittysalt') | |
cookie_name = f"__wzd{h.hexdigest()[:20]}" | |
h.update(b"pinsalt") | |
num = f"{int(h.hexdigest(), 16):09d}"[:9] | |
for group_size in 5, 4, 3: | |
if len(num) % group_size == 0: | |
rv = "-".join( | |
num[x : x + group_size].rjust(group_size, "0") | |
for x in range(0, len(num), group_size) | |
) | |
break | |
else: | |
rv = num | |
print(rv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment