synchronizing/mitm

Deal with hanging connections and unknown protocols.

Closed this issue · 1 comments

As of right now mitm does not deal with hanging connections and unknown protocols very well. httpq will hang if the client never provide the correct bytes:

mitm/mitm/mitm.py

Lines 117 to 121 in 5b9ae63

# Read request from client until body.
req = httpq.Request()
while req.step_state() != httpq.state.BODY:
data = await reader.read(self.config.buffer_size)
req.feed(data)

Probable solution:

(a) Check if client.at_eof directly on the while loop, and
(b) Read up to n bytes. If we don't have a valid HTTP first line by then, the client is sending some other protocol.

Fixed this in 41f0cff via option (b).

mitm/mitm/protocol.py

Lines 104 to 107 in ec3adeb

try:
request = httpq.Request.parse(data)
except:
raise InvalidProtocol

We check if the protocol is HTTP (or any other custom protocol), and if it is not, the server disconnects with the client.