HelloZeroNet / Documentation

ZeroNet Documentation
https://zeronet.readthedocs.org/
GNU General Public License v2.0
74 stars 107 forks source link

How to properly handle request IDs? #71

Closed MuxZeroNet closed 6 years ago

MuxZeroNet commented 6 years ago

A request packet has its unique request ID. A ZeroNet implementation interprets a response packet with the help of the request ID. If an attacker spoofs the request ID in a malicious response packet, then the implementation cannot properly interpret the response, and may incorrectly abort the previous request. This attack works even when the attacker does not run the Internet infrastructure. Consider the following example.

When sequential request ID works:

A --> B
<getFile, req_id=0>

B --> A
<response, to_req_id=0, file_content=bytes>

A: I got a response for request 0. It has file payload in it.

When sequential request ID does not work:

A --> B
<getFile, req_id=0>

C --> A
<response, to_req_id=0, error>

B --> A
<response, to_req_id=0, file_content=bytes>

A: I got a response for request 0. I can decode this response properly. It says there is
   an error on the other side.
A: I got a response for request 0. I handled request 0 a second ago, dropping this
   response.

There are algorithms that handle request IDs more safely.

Which algorithm does ZeroNet use?

HelloZeroNet commented 6 years ago

The request-id is per-connection. I not sure how could anyone inject a fake response packet to a TCP (and encrypted) stream. And if someone could, then I think the random id does not helps as the attacker could also record the request id sent to remote client.