Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Windows from sending RST packet when trying to connect to somebody via Pcap.net?

I'm trying to use Pcap.Net to open a tcp connection.

I'm sending following package:

SYN packet

The server is responding with:

SYN-ACK

After this, Windows on its own sends the reset packet:

RST

Why is this happening, and how do I block this behavior?

I'm doing this on Windows 7

like image 561
Arsen Zahray Avatar asked Oct 22 '12 09:10

Arsen Zahray


People also ask

Why does a server send an RST packet?

RST is sent by the side doing the active close because it is the side which sends the last ACK. So if it receives FIN from the side doing the passive close in a wrong state, it sends a RST packet which indicates other side that an error has occured.

What causes RST Wireshark?

What is a TCP Reset (RST)? When an unexpected TCP packet arrives at a host, that host usually responds by sending a reset packet back on the same connection. A reset packet is simply one with no payload and with the RST bit set in the TCP header flags.

Do firewalls send RST packets?

The Palo Alto Networks firewall sends a TCP Reset (RST) only when a threat is detected in the traffic flow. On all other cases the RST will not be sent by the firewall.

What is RST in TCP connection?

A TCP Reset (RST) packet is used by a TCP sender to indicate that it will neither accept nor receive more data. Out-of-path network management devices may generate and inject TCP Reset packets in order to terminate undesired connections.


2 Answers

As Mr Harris says, you can use WinDivert to do what you want. E.g. to just do the TCP handshake, you can write something like the following:

// TCP handshake using WinDivert:
HANDLE handle = DivertOpen("inbound && tcp.SrcPort == 80 && tcp.Syn && tcp.Ack", 0, 0, 0);
DivertSend(handle, synPacket, sizeof(synPacket), dstAddr, NULL);
...
DivertRecv(handle, synAckPacket, sizeof(synAckPacket), &srcAddr, &length);
...
DivertSend(handle, ackPacket, sizeof(ackPacket), dstAddr, NULL);
...

The DivertRecv() function redirects the server response into user space before it is handled by the Windows TCP/IP stack. So no pesky TCP RST will be generated. DivertSend() injects packets.

This is the main differences between WinDivert and WinPCAP. The latter is merely a packet sniffer, whereas the former can intercept/filter/block traffic.

WinDivert is written in C so you'd need to write your own .NET wrapper.

(usual disclosure: WinDivert is my project).

like image 133
Basil Avatar answered Sep 30 '22 21:09

Basil


Essentially, the problem is that scapy runs in user space, and the windows kernel will receive the SYN-ACK first. Your windows kernel will send a TCP RST because it won't have a socket open on the port number in question, before you have a chance to do anything with scapy.

The typical solution (in linux) is to firewall your kernel from receiving an RST packet on that TCP port (12456) while you are running the script... the problem is that I don't think Windows firewall allows you to be this granular (i.e. looking at TCP flags) for packet drops.

Perhaps the easiest solution is to do this under a linux VM and use iptables to implement the RST drops.

like image 25
Mike Pennington Avatar answered Sep 30 '22 20:09

Mike Pennington