/ nmap Public
Add support for TCP Fast Open to prevent false negatives #1204
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge.
Nmap currently discards SYN-ACK packets having the TCP Fast Open option (RFC 7413) set. Thus leading to false negative results.
This patch implements the support of this option, fixing the false negative.
I tested successfully this patch in the field, of course.
During an internal pentest, I discovered a false negative on a TCP port that I knew for sure was open. SYN scans did not see it, whereas connect scans were good.
Running nmap with
-dddI saw that the SYN ACK packet was discarded:
Rejecting TCP packet because of bad TCP header
In Wireshark, I saw that the TCP Fast Open option was enabled.
Its kind is "34" which is not currently handled in the code. Therefore the code reads the next byte, which is the length of the option and incorrectly interprets it as a kind. According to the RFC, the length is a range from 6 to 18. In my case it was 8, so the code assumed it was a timestamp header and it was then incorrect.
I know that TCP Fast Open option should not appear in SYN-ACKs if the option was not present in the prior SYN. However, this is what I observed on my client's network...
This is also related to this message in the mailing list.
You can test it against the following scapy code, after preventing the default behavior of the kernel with
iptables -A OUTPUT -p tcp --tcp-flags RST RST --sport 8000 -j DROP
With the current nmap, you get:
And with the patch: