user23352529
user23352529

Reputation: 21

Extra 0x00 at the start of TLS Client Hello packet, how to remove it?

I'm working on a Python proxy server that needs to receive TLS Client Hello data from a browser and forward it to the target server. However, I've noticed that the Client Hello packet sent by my proxy always has an extra 0x00 byte at the start, which shouldn't be there. The target server receives the data and then immediately closes the connection.

I've already checked a few things:

Before sending, I used print("Data to send:", data.hex()) in both the client and server to print the hexadecimal representation of the data. I've confirmed that the data itself doesn't have the 0x00, but as soon as it's sent to the target server, a 0x00 gets added.

I used Wireshark to analyze the packets and found that the data being sent is split into two TCP segments. The first segment only contains the 0x00, and the second one contains the full Client Hello data. Has anyone encountered this issue before? Any ideas on how to fix it?

def send_proxy_to_target(target_ip, target_port):
    key = (target_ip, target_port)
    task_queues = send_task_queues[key]

    target_socks = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    target_socks.connect((target_ip, int(target_port)))

    while True:
        if key not in send_task_queues:
            break
        token, datas, code = task_queues.get()
        if code == "102":
            break
        if code == "101":
            break

        recv_task_queues[key].put((target_socks, token, "100"))

        if send_heartbeat(target_socks):
            readable, writable, exceptional = select.select([], [target_socks], [], 0.1)
            if target_socks in writable:
                target_socks.sendall(datas)
                print(datas.hex())
            else:
                continue
        else:
            break

Upvotes: 0

Views: 44

Answers (0)

Related Questions