Last active
September 27, 2024 15:42
-
-
Save DavidBuchanan314/b6c9102c327f2ba42a3ed374e6ede90f to your computer and use it in GitHub Desktop.
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 base64 | |
import time | |
from cryptography.hazmat.primitives import serialization | |
from cryptography.hazmat.primitives import hashes | |
from cryptography.hazmat.primitives.asymmetric import padding | |
import ctypes | |
libc = ctypes.CDLL("libc.so.6") # glibc needed | |
OS_VERSION = "rabbit_OS_v0.8.99_20240606175556" | |
HEALTH_PUBKEY = b"""-----BEGIN RSA PUBLIC KEY----- | |
MIIBigKCAYEAqLNRPcujKw1elkNJc+10o37YVbb7OjYa4Cv2pG2BzfSV3Ev7LMva | |
A2w0PAy25DhQU2NI7RU2a51OvTz0DsXM69oakuN0oSrKa9Eit2GPnX89H702MXGX | |
iRDZWEufAx67AaxK9d80Bajh2Abn06Bwaz9Z4D8vMxUOGsYkVKMW0LrmnW4984XI | |
UqT3+lOiEijBamodU/mORTeuxc5cdan00fq8qTOYuGFuKlPJSI3EExFHP3ONHD6z | |
44+PxXmhw532uAiNnT74yKXBoVYU19b8AAWLiSKyjf1eeus7dTobPKcpMemlJgxH | |
tVHtaSgnUugQ0a3XvmTVQpSeytPw8bL+/3c5KXfjGxPchoEZi7d71wv/AufDiSXr | |
gaew1KfJZBsr8Somr03b8xsHRJruPT61iPceh9bTWscwnK3WmDpAxnjdPQiflt/m | |
KkPEETtKGx0X5kUImHnr1jhUdYKmEOHfwkXBKVc66hpn85WGJ7MPVyixIOpzScAY | |
nKjVsP4ma6iFAgMBAAE= | |
-----END RSA PUBLIC KEY-----""" | |
pubkey = serialization.load_pem_public_key(HEALTH_PUBKEY) | |
RSA_PKCS1_OAEP_PADDING = padding.OAEP( | |
mgf=padding.MGF1(algorithm=hashes.SHA1()), | |
algorithm=hashes.SHA1(), | |
label=None | |
) | |
def getHealthRand(seed=None): | |
libc.srand(seed if seed is not None else libc.time(0)) | |
while True: | |
x = libc.rand() % 100 # rand() is always positive so we don't need to worry about % operator discrepancies | |
if x >= 10: | |
return x &~1 # round down to nearest even int, for some reason | |
def getHealth(): | |
now = time.time() | |
gmt = time.gmtime(now) | |
millis = int((now * 1_000_000) // 1000) % 1000 | |
timestamp = f"{gmt.tm_year:04d}{gmt.tm_mon:02d}{gmt.tm_mday:02d}{gmt.tm_hour:02d}{gmt.tm_min:02d}{gmt.tm_sec:02d}{millis:03d}" | |
msg = f"{OS_VERSION},{timestamp},{getHealthRand(int(now))}" | |
print("Device-Health:", msg) | |
ciphertext = pubkey.encrypt(msg.encode(), RSA_PKCS1_OAEP_PADDING) | |
return base64.b64encode(ciphertext).decode() | |
if __name__ == "__main__": | |
print(getHealth()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pure-python glibc rand reimpl: