精易论坛

标题: 求易语言例子或者转易语言 [打印本页]

作者: suming99    时间: 2025-5-13 20:02
标题: 求易语言例子或者转易语言
请求大佬们,下面这个代码在易语言怎么实现,AI翻译有问题或者无法使用



    # mix with FNV prime & mask
    client_rand_mix = (0x1000193 * client_rand)
    client_rand_mask = client_rand_mix & 0x8000003f
    print(f"{client_rand_mix=}")
    print(f"{client_rand_mask=}")

    client_xor_server = client_rand_mask ^ server_rand
    client_xor_server_mod = client_xor_server % 60
    print(f"{client_xor_server=}")
    print(f"{client_xor_server_mod=}")

    index = client_xor_server_mod
    print(f"{index=}")

    aes_key = map(lambda x: (x ^ 0xA5) & 0xFF, KEY_POOL[index:index + 24])
    aes_key = bytes(aes_key)
    print(f"aes_key={aes_key.hex()}")

    aes = AES.new(aes_key, AES.MODE_ECB)

    print(f"local_mac={LOCAL_MAC.hex()}")

    payload_arr = create_payload_array(server_mac, LOCAL_MAC, index)
    if not verify_do_check_client(payload_arr, LOCAL_MAC, index, server_mac):
        print("we are sad :(")

    payload = f"SendInfo.gch?info={len(payload_arr)}|{b''.join(map(lambda x: x.to_bytes(4, 'little'), payload_arr)).decode('utf-8')}"

    url = "/webFacEntry"
    print(f'--> POST {url} "{payload}"')

    res = s.post(
        ROOT + url,
        data=aes.encrypt(
            pad(payload.encode(), 16)
        )
    )
    print(f'<-- {res.status_code} {len(res.content)} bytes')
    if res.status_code != 200:
        raise Exception(f"expected 200. got {res.status_code}")








def evaluate_alphabet(alphabet: str, exponent: int, modulus: int, value_map = lambda x: x):
    """
    Determine if a proposed alphabet of payload bytes is still able to encode all values that
    a payload with no restrictions could represent.

    value_map can be used to to make the search faster by limiting the search space.

    Returns a mapping of desired inputs and the inputs that produce them (we're just
    going to brute force this because of the alphabet constraints)
    """
    unrestricted_possible_values = set()
    for i in range(modulus):
        unrestricted_possible_values.add(value_map(pow(i, exponent, modulus)))

    possible_values = dict()
    for num in int_alphabet_generator(alphabet, 4):
        result = value_map(pow(num, exponent, modulus))
        if result not in possible_values:
            possible_values[result] = num
            if len(possible_values) == len(unrestricted_possible_values):
                return possible_values

    assert False, f"Not all possible values found within modulus {len(possible_values)} / {len(unrestricted_possible_values)}"

# some subset of chars it should be safe to use in the urlparam
alphabet = "lmaoztebcdfghijknpqrsuvwxy"

# used for the first 4 entries in client_data, before a new exponent and
# modulus are derived. figure out all representable values so we can use
# this when we craft the first 4 integers of payload which let us control
# the derived values used for the rest of the decoding
header_encoding_map = evaluate_alphabet(alphabet, 0x1687, 0x7561)

# since it turns out we have absolute control over the exponent and modulus,
# can just precalculate. we also only care about the lower byte of the encoded
# values, as do_check_client truncates the modular exponentation result when
# calculating mac address bytes. so once we have all possible lower bytes, we're
# done.
mac_encoding_map = evaluate_alphabet(alphabet, 0x1, 0x1687, lambda x: x & 0xff)

def verify_do_check_client(client_data: list[int], server_mac: bytes,
                           calculated_idx: int, LOCAL_MAC: bytes) -> int:
    processed_word0 = pow(client_data[0], 0x1687, 0x7561)
    processed_word1 = pow(client_data[1], 0x1687, 0x7561)
    processed_word2 = pow(client_data[2], 0x1687, 0x7561)
    processed_word3 = pow(client_data[3], 0x1687, 0x7561)

    derived_exponent = (processed_word0 * calculated_idx) + processed_word1
    derived_modulus = (processed_word2 * calculated_idx) + processed_word3

    client_data = client_data[4:]
    remaining_word_len = len(client_data)
    work_buffer = [0] * len(client_data)

    if remaining_word_len < 6:
        print(f"Warning: Remaining client_data words are less than 6")
        return 0

    for i in range(6):
        work_buffer[i] = pow(client_data[i], derived_exponent, derived_modulus) & 0xff

    calculated_LOCAL_MAC = bytes(work_buffer[:6])
    if calculated_LOCAL_MAC != LOCAL_MAC:
        print(f"local mismatch {calculated_LOCAL_MAC} != {LOCAL_MAC}")
        return 0

    for i in range(6, remaining_word_len):
        work_buffer[i] = pow(client_data[i], derived_exponent, derived_modulus) & 0xff

        if i >= 6 and (i + 1) % 6 == 0:
            calculated_server_mac = bytes(work_buffer[ i-5 : i+1 ])
            if calculated_server_mac != server_mac:
                print(f"local mismatch {calculated_server_mac} != {server_mac}")
                continue
            return 1

    return 0

def create_payload_array(LOCAL_MAC, server_mac, _calculated_idx: int):
    payload = []

    # new exponent/modulus will be derived based on our input and this
    # index which is selected randomly and given to us. we have to work
    # with a exponent of the form:
    #
    # new_exponent = (pow(input1, 0x1687, 0x7561) * calculated_idx) + pow(input2, 0x1687, 0x7561)
    # new_modulus = (pow(input3, 0x1687, 0x7561) * calculated_idx) + pow(input4, 0x1687, 0x7561)
    #
    # we're going to take advantage of the multiply, and pick input1 and input3 such that
    # calculated_idx is multiplied by 0, making it irrelevant to payload generation.

    # exponent
    payload.append(header_encoding_map[0])      # input1; cancels out calculated_idx
    payload.append(header_encoding_map[1])      # input2; selected exponent

    # modulus
    payload.append(header_encoding_map[0])      # input3; cancels out calculated_idx
    payload.append(header_encoding_map[0x1687]) # input4; selected modulus

    # since we've now gotten control of the exponent and modulus, we just staple the
    # local and remote mac addresses to the payload.
    payload.extend(map(mac_encoding_map.__getitem__, LOCAL_MAC + server_mac + server_mac))

    return payload






补充内容 (2025-5-13 20:19):
主要是加密部分,该如何用易语言写




欢迎光临 精易论坛 (https://125.confly.eu.org/) Powered by Discuz! X3.4