A-002.Oblivion.《末日时在做什么?有没有空?可以来拯救吗?》.20210827.389276c2.7z

This script is used to decrypt and extract files from a remote location. It uses the AESGCM algorithm to decrypt the data and the sha3_256 and sha3_512 hash functions to verify the integrity of the data. The script uses the requests library to make HTTP requests to a remote server and the os library to handle file operations. The script expects the seed file to be in a specific format, and uses the information in this seed file to download and decrypt the other files. The script also includes a debug flag which, when set to true, will print debug information instead of saving the files to disk.

import os
from base64 import urlsafe_b64decode
from hashlib import sha3_256, sha3_512
from json import loads

from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from requests.models import Response
from requests.sessions import Session

filename: str = r"A-002.Oblivion.《末日时在做什么?有没有空?可以来拯救吗?》.20210827.389276c2.7z"
debug: bool = False


class Seed:
    key: bytes = urlsafe_b64decode(
        b"ZF9AfpoffXhT4lLcAqNT2FCY0pXKFP_FUjm0oumPCOlYGHQZ52rQiV9oSd9byyP98kFjtINVT1pSnXtBfseVDA=="
    )
    ar: str = "oDly2YPAnYdZz4PnJci2lqNHVDjpKYCqmq0yQHrn4fc"
    checksum: str = "71YBBLUg936_xaULTykfE28HkUykmsq6lQsmVn3S8Q0="


class KeyDerivation:
    def __init__(self, iv: bytes, next: bytes) -> None:
        assert len(iv) == 256, "iv must be 2048 bits"
        assert len(next) == 64, "next must be 512 bits"
        self.__generator__ = sha3_512(iv)
        self.__next__ = next

    def __call__(self) -> bytes:
        self.__generator__.update(self.__generator__.digest())
        self.__generator__.update(self.__next__)
        return self.__generator__.digest()


def decrypt(data: bytes, key: bytes) -> bytes:
    assert len(key) == 64, "key must be 512 bits"
    return AESGCM(key=key[:32]).decrypt(
        nonce=key[-12:], data=data, associated_data=key[32:-12]
    )


session = Session()


def get(ar: str) -> Response:
    print("ar", ar)
    while True:
        try:
            resp = session.get(f"https://arweave.net/{ar}/d")
            resp.raise_for_status()
            return resp
        except Exception as err:
            print("error", err)


def extract(key: bytes, ar: str, checksum: str) -> bytes:
    checksum = urlsafe_b64decode(checksum)
    checked = False
    while not checked:
        data = get(ar).content[12:]
        checked = checksum == (sha3_256(data).digest())
    return decrypt(data=data, key=key)


if __name__ == "__main__":
    seed = loads(extract(key=Seed.key, ar=Seed.ar, checksum=Seed.checksum))
    keyDerivation = KeyDerivation(
        iv=urlsafe_b64decode(seed["crypto"]["iv"]),
        next=urlsafe_b64decode(seed["crypto"]["next"]),
    )

    print("debug", debug)
    if debug:
        for obj in seed["store"]:
            key = keyDerivation()
            extract(key=key, ar=obj["ar"], checksum=obj["checksum"])
    else:
        import sys

        if getattr(sys, "frozen", False):
            current = os.path.dirname(sys.executable)
        else:
            current = os.path.dirname(os.path.abspath(__file__))

        with open(os.path.join(current, filename), "wb") as fout:
            for obj in seed["store"]:
                key = keyDerivation()
                fout.write(extract(key=key, ar=obj["ar"], checksum=obj["checksum"]))