我已将 proftpd 设置为使用 ssl/tls。尝试连接时收到“非法端口命令”
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)
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
通过普通 ftp 连接工作正常...
我正在使用 WS_FTP 和 ftp-authssl//xxx.nl/.... 我尝试了其他几个连接选项、端口等。但都给出了相同的错误。尽管似乎有时会显示第一个目录列表(但这可能是 WS_FTP 的缓存)
首先请注意,最后两个命令 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 允许连接到这些端口。
我也在 SuperUser 上发布了这个问题并在那里得到了答案:我已将以下内容添加到 proftpd.conf 中:
PassivePorts 49152 65534
TLSOptions NoSessionReuseRequired
Run Code Online (Sandbox Code Playgroud)
对于 PassivePorts,请参阅http://proftpd.org/docs/directives/linked/config_ref_PassivePorts.html
对于 TLSOptions,请参阅http://www.proftpd.org/docs/howto/TLS.html(基于 WS_FTP 的一些日志消息,我发现 NoSessionReuseRequired 应该有所帮助)。
| 归档时间: |
|
| 查看次数: |
24169 次 |
| 最近记录: |