TCP 与 UDP。在关闭的端口上发送数据

TCP 与 UDP。在关闭的端口上发送数据

我尝试了解 TCP 和 UDP 数据包在错误检查方面的差异。我知道 UDP 数据包是无连接的,并且不关心数据包是否安全到达目的地。而 TCP 数据包与 UDP 相反。

我的问题是,如果将数据包发送到远程主机的关闭端口,UDP 和 TCP 数据包会发生什么操作?

UDP 数据包 - 使用 ICMP(代码 3)进行响应?TCP 数据包 - 使用 RST 数据包进行响应?

答案1

根据RFC 793重置生成规则:

As a general rule, reset (RST) must be sent whenever a segment arrives
which apparently is not intended for the current connection.  A reset
must not be sent if it is not clear that this is the case.

There are three groups of states:

 1.  If the connection does not exist (CLOSED) then a reset is sent
 in response to any incoming segment except another reset.  In
 particular, SYNs addressed to a non-existent connection are rejected
 by this means.

由于端口已关闭(不监听或通信),因此没有连接,因此 TCP 应该使用 RST 包进行回复。

RFC 768对于 UDP,没有指定对关闭端口的任何操作,但是ICMP RFC 792指定可以发送的消息类型 3 代码 3,目标不可达:目标端口不可达。

然而,只有未经过滤的端口才会真正做到这一点。已过滤连接根本不回复,只是丢弃数据包。任何名副其实的防火墙通常都会进行过滤,因为它通过提供较少的信息使攻击者的工作变得更加困难。

答案2

使用 UDP 你可能会在 Wireshark 中看到:

52081 14:12:05.897100 37.xxx.xxx.xxx 5060 port-xxxx.xxxnet.de ICMP 406 47445 目的地不可达 (端口不可达)

这里的端口是47445。37.xxx.xxx.xxx是你的IP,端口--xxxx.xxxnet.de是尝试的服务器。

答案3

值得一提的是,即使服务器 udp 端口​​关闭,您仍然可以观察从客户端发送到该关闭端口的 udp 数据包。

尝试:

服务器:

sudo tcpdump -n -i eth0 udp and dst port 8080 -X

替换eth0为您自己的网卡接口和8080服务器端关闭的端口。

客户:

echo "send from client, udp protocol" | nc -u [server ip] 8080

相关内容