EONRaider / blackhat-python3

Source code for the book "Black Hat Python" by Justin Seitz. The code has been fully converted to Python 3, reformatted to comply with PEP8 standards and refactored to eliminate dependency issues involving the implementation of deprecated libraries.
2.02k stars 414 forks source link

Broken pipe error in chapter02/bhnet.py client_sender #10

Closed dy5function closed 3 years ago

dy5function commented 3 years ago

https://github.com/EONRaider/blackhat-python3/blob/86d067db54b37d12ec2cf4204e7458fc5b6c0fb0/chapter02/bhnet.py#L148

Description

An exception occurs in chapter02/bhnet.py in the function client_sender on the second call to client.send() in the sender while-loop. The exception due to a broken pipe.

Reproduction Steps

The bug was found by running chapter02/tcp-server.py and connecting to it with chapter02/bhnet.py:

$ python3 ./bhpnet.py -t 127.0.0.1 -p 9999
Hallo [Ctrl-D]
ACK! Test1
 Test2
[*] Exception! Exiting.
[*] Caught exception socket.error: [Errno 32] Broken pipe

On the server side:

$ python3 ./tcp-server.py 
[*] Listening on 0.0.0.0:9999
[*] Accepted connection from: 127.0.0.1:50890
[*] Received: b'Hallo\n'
('127.0.0.1', 50890)

Note that the outer while-loop (line 128 - 148) is run through twice after the initial successful sending of the buffer to the server but without ever sending data again. The expected behavior is that "Test1" would be sent to the server at the end of one loop cycle and "Test2" would be sent at the end of the next loop cycle. However, the server never receives even "Test1".

dy5function commented 3 years ago

I think I found the problem already by myself: The tcp-server.py script closes the connection after receiving the first message from bhnet.py which is intended behavior I guess... I am sorry for raising this issue prematurely...

I am fine with closing this issue, sorry again!