#Manually crafted TCP SYN packet yields no response

15 messages · Page 1 of 1 (latest)

solar creek
#

I have this code where I'm manually crafting TCP SYN packets in C by setting all IP and TCP header fields myself, including the TCP flags and checksum. When I send these SYN packets to an open port on a remote host (or even localhost), I expect to receive a SYN-ACK response. However, I don't receive any response at all; all I see in my wireshark live capture is the handcrafted SYN packet I just sent out.

I have no idea what the problem is, but my best guess could be the checksum function? If the calculated checksum is wrong, then it would be standard behavior to drop the packet. That said, I've reviewed the checksum function a LOT of times, but I still can't see whats wrong.

Here's the code (I've replaced irrelevant parts with ..., and removed error checking for brevity)

jolly sleetBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

carmine burrow
#

Just opening the port is not enough, there needs to be an application listening on that port.

solar creek
#

Anyhow, even if there is no port listening, the remote host should reply with RST-ACK

solar creek
# solar creek

This is when I use netcat, more specifically: nc localhost 1244 (I am not listening on port 1244)

#

Using my C program, no response at all ¯_(ツ)_/¯

drowsy juniper
#

your pseudo_header contains padding, those will be calculated as well (and a) its UB to read them. their value is indeterminate b) depending on the way you're sending the header - might affect the actual correctness of your checksum). i have no idea what tcph looks like - but it might present the same problem.
misread the definition of it. ignore that. if tcph has no padding you can ignore that as well

as for your checksum function itself - i have no idea if its correct or not but wireshark will be able to tell you that.
https://www.wireshark.org/docs/wsug_html_chunked/ChAdvChecksums.html 7.10.1

Wireshark will validate the checksums of many protocols, e.g., IP, TCP, UDP, etc.

It will do the same calculation as a “normal receiver” would do, and shows the checksum fields in the packet details with a comment, e.g., [correct] or [invalid, must be 0x12345678].

solar creek
#

The docs tell me the checksum validation can be incorrect due to this thing called checksum offloading.

solar creek
#

Alright epic, so the problem really is in the checksum calculation.

#

I turned of checksum offloading for the loopback interface (silly me), which doesn't work. I did it for my NIC, and now it is evident that the checksum calculation is wrong.