Using Socket AF_PACKET / SOCK_RAW But Tell Kernel To Not Send RST
Solution 1:
The problem here is that you're asking for a way to tell the kernel in effect "do these 100 things for me, but leave this one particular detail out." Frankly, I think the iptables solution is the easiest and cleanest.
Another option, though, is to not ask the kernel to do all those other bits, and instead to take on more work yourself. Specifically, make up your own IP address, and start using it. The only downside is that you have to take over another important thing that the kernel has been doing for you: responding to ARPs (ARP is used to discover the MAC [Ethernet] address of the station that owns a given IP address). In brief, I'm suggesting you:
- Choose an unused IP address on your local subnet.
- Make up a MAC address for your use. (Not strictly necessary but will make it easier to distinguish "your" traffic.)
- Open a raw packet socket instead of raw IP socket (https://linux.die.net/man/7/packet).
- Compose and send an ARP request to discover the MAC address of the station you're sending to (if on local LAN, else the MAC of the next hop [router] IP address).
- Receive the ARP reply and record the other station's MAC.
- Construct and send your SYN packet from your own MAC address to the MAC of the destination station. (With your chosen source and dest IPs, ports, etc.)
- Listen for a return ARP for your IP and reply as needed.
- Receive the SYN+ACK response. Since the destination IP address (the one you made up) is not known to the kernel to belong to your system, the kernel will not respond to the SYN+ACK with RST (or anything else).
- Do whatever it is you want to do next...
You will of course have to be capturing promiscuously if you use a MAC address other than the one assigned to the interface. That is pretty typical with a raw packet socket. Also, you will be constructing Ethernet header, IP header, and TCP headers for all traffic (well, Ethernet + ARP for the ARP requests) so you will learn a lot.
Post a Comment for "Using Socket AF_PACKET / SOCK_RAW But Tell Kernel To Not Send RST"