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

前端 未结 3 768
盖世英雄少女心
盖世英雄少女心 2021-01-05 12:06

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

I\'m sending following package:

\"SYN

3条回答
  •  时光取名叫无心
    2021-01-05 12:46

    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).

提交回复
热议问题