gpt4 book ai didi

c# - 在 C# 中使用原始套接字

转载 作者:可可西里 更新时间:2023-11-01 02:30:04 27 4
gpt4 key购买 nike

我想用 C# 编写一个端口扫描器,但我不能使用 SocketType.Raw,因为原始套接字已从桌面版本的 Windows 中取出。我不能使用 SharpPcap 或 Winpcap 的其他包装器,因为我使用 PPPoE 进行互联网连接,而 Winpcap 不支持 PPP 设备。

我需要使用一个实现原始套接字且不依赖于 winpcap 的库。

有什么想法吗?基本上我需要发送 SYN,接收 SYN/ACK 或 RST 但不要发回 ACK。

编辑:

对于不相信 RAW 套接字已从桌面版 Windows 消失的人,请参见此处:http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548(v=vs.85).aspx

On Windows 7, Windows Vista, Windows XP with Service Pack 2 (SP2), and Windows XP with Service Pack 3 (SP3), the ability to send traffic over raw sockets has been restricted in several ways:

  • TCP data cannot be sent over raw sockets.
  • UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address).
  • A call to the bind function with a raw socket for the IPPROTO_TCP protocol is not allowed.
    Note The bind function with a raw socket is allowed for other protocols (IPPROTO_IP, IPPROTO_UDP, or IPPROTO_SCTP, for example).

最佳答案

注意 nmap 是如何做到这一点的,现在我相信您的选择是在以太网框架上进入较低级别。

“Nmap 仅支持以太网接口(interface)(包括大多数 802.11 无线网卡和许多 VPN 客户端)进行原始数据包扫描。除非使用 -sT -Pn 选项,否则不支持 RAS 连接(例如 PPP 拨号)和某些 VPN 客户端. 当 Microsoft 在 Windows XP SP2 中删除原始 TCP/IP 套接字支持时,此支持被删除。现在 Nmap 必须发送较低级别的以太网帧。”

所以 - 这将我们带到:

http://www.codeproject.com/KB/IP/sendrawpacket.aspx

关于c# - 在 C# 中使用原始套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7533205/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com