FTP 非法 PORT 命令

FTP 非法 PORT 命令

我已经将 proftpd 设置为使用 ssl/tls。尝试连接时,我收到“非法 PORT 命令”

Finding Host xxx.nl ...
Connecting to xxx.xxx.xxx.xxx:21
Connected to xxx.xxx.xxx.xxx:21 in 0.018001 seconds, Waiting for Server 
Response
Initializing SSL Session ...
220 FTP Server ready.
AUTH TLS
234 AUTH TLS successful
SSL session NOT set for reuse
SSL Session Started.
Host type (1): AUTO
USER xxx
331 Password required for xxx
PASS (hidden)
230 User xxx logged in
SYST
215 UNIX Type: L8
Host type (2): Unix (Standard)
PBSZ 0
200 PBSZ 0 successful
PROT P
200 Protection set to Private
PWD
257 "/" is the current directory
CWD /var/www/html/
250 CWD command successful
PWD257 "/var/www/html/" is the current directory
TYPE A
200 Type set to A
PORT 192,168,192,14,211,181
500 Illegal PORT command
Port failed 500 Illegal PORT command
PASV
227 Entering Passive Mode (xxx,xxx,xxx,xxx,160,151).
connecting data channel to xxx.xxx.xxx.xxx:160,151(41111)
Failed to connect data channel to xxx.xxx.xxx.xxx:160,151(41111)

iptables:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     icmp --  anywhere             anywhere            /* 000 accept all icmp */
ACCEPT     all  --  anywhere             anywhere            /* 001 accept all to lo interface */
REJECT     all  --  anywhere             loopback/8          /* 002 reject local traffic not on loopback interface */ reject-with icmp-port-unreachable
ACCEPT     all  --  anywhere             anywhere            /* 003 accept all to eth1 interface */
ACCEPT     all  --  anywhere             anywhere            /* 004 accept related established rules */ state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            multiport ports ftp /* 021 allow ftp. */
ACCEPT     tcp  --  anywhere             anywhere            multiport ports ssh /* 022 allow ssh. */
ACCEPT     tcp  --  anywhere             anywhere            multiport ports smtp /* 025 allow smtp. */
ACCEPT     tcp  --  anywhere             anywhere            multiport ports pharos /* 051 allow rundeck. */
ACCEPT     tcp  --  anywhere             anywhere            multiport ports 8140 /* 814 allow puppetserver. */
ACCEPT     tcp  --  anywhere             anywhere            multiport ports http /* 080 allow http. */
ACCEPT     tcp  --  anywhere             anywhere            multiport ports https /* 443 allow https. */
DROP       all  --  anywhere             anywhere            /* 999 drop all */

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

通过普通 ftp 连接就可以了......

我正在使用 WS_FTP 和 ftp-authssl//xxx.nl/.... 我尝试了其他几个连接选项、端口等。但都给出了相同的错误。虽然有时似乎会显示第一个目录列表(但这可能是 WS_FTP 的缓存)

答案1

首先请注意,最后两个命令 PORT 和 PASV 彼此无关。它们是两个独立的连接尝试(一次用于主动 FTP,一次用于被动 FTP)。


因此,您的 PORT 失败是可以预料的。

这种方式PORT(“主动 FTP”模式)的工作方式是让客户端将自己的地址发送到服务器 - 服务器连接回用于数据传输。

根据日志,您的客户端计算机位于 NAT 后面,并且拥有一个“私有”IP 地址。这是它唯一知道的地址,因此它使用 PORT 命令发送该地址。

通常情况下,你的路由器会识别 FTP 连接,并偷偷地编辑PORT 命令,将您的私有地址替换为路由器自己的公共地址。(或者,如果您运气不好,它会将其替换为垃圾。)

但是,由于你的控制连接现在使用 TLS 加密,因此路由器不能执行此修复(它看到的只是加密数据),服务器收到的正是您的客户端发送的内容:您的私人地址。

由于服务器位于另一个网络上,因此它不可能访问私有地址(这就是 NAT 的全部意义所在)。尽管它甚至懒得尝试,但出于安全原因,大多数服务器会立即拒绝任何与控制连接来源不完全匹配的地址。

tl;dr 将 FTP 客户端切换到被动模式。是的,您的日志也显示被动模式 (PASV) 已损坏。但至少它是有些如果您的服务器具有专用的公共 IP 地址,则可以修复,而主动模式则不能。


那 PASV 呢?嗯,问题类似。

通常,服务器的防火墙会监听 FTP 控制连接,从“进入被动模式 (x,y,z…)”回复中提取临时端口,并将其标记为属于“相关”连接。然后您的规则 #004 会允许它。

但是,iptables 无法看透 TLS(它看到的都是加密数据),无法再将您的 FTP 数据连接识别为相关连接。因此,您的连接只会触及规则 #999 并被丢弃。

要使 PASV 正常工作,您需要配置 ProFTPd 以使用特定的无源端口范围(具体范围是什么并不重要),并告诉 iptables 允许连接到这些端口。

答案2

PORT 192,168,192,14,211,181

此命令表示客户端正在 IP 地址 192.168.192.14 端口 54197 上监听来自服务器的数据连接。192.168.*.* 是私有 IP 地址,无法通过互联网路由。这意味着互联网上的服务器无法访问此 IP 地址。这就是服务器认为 PORT 命令无效的原因。

答案3

我也在 SuperUser 上发布了这个问题并在那里得到了答案:我在 proftpd.conf 中添加了以下内容:

PassivePorts 49152 65534
TLSOptions NoSessionReuseRequired

对于 PassivePorts,请参阅http://proftpd.org/docs/directives/linked/config_ref_PassivePorts.html

有关 TLSOptions,请参阅http://www.proftpd.org/docs/howto/TLS.html(根据来自 WS_FTP 的一些日志消息,我发现 NoSessionReuseRequired 应该有所帮助)。

答案4

这对我有用:您需要将以下几行添加到vsftpd.conf。我花了几天时间试图找到这个答案

listen=YES
#listen_ipv6=YES

以下是 vsftpd.conf 中所有未注释的项目

listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
pasv_enable=YES
pasv_min_port=1024
pasv_max_port=1048
port_enable=YES
pasv_address=PUT YOUR PUBLIC IP ADDRESS HERE (e.g. 18.236.105.3)

相关内容