FTP协议的分析和扩展
脚本之家
| <------------------------------------------- 220 |
| AUTH TLS -------------------------------------------> |
| <------------------------------------------- 234 |
| TLSneg() <------------------------------------------> TLSneg() |
| PBSZ 0 -------------------------------------------> |
| <------------------------------------------- 200 |
| PROT P -------------------------------------------> |
| <------------------------------------------- 200 |
| USER elly -------------------------------------------> |
| <------------------------------------------- 331 |
| PASS **** -------------------------------------------> |
| <------------------------------------------- 230 |
| |
\====================================================================/
一个SSL FTP的连接过程实例:
/====================================================================\
| |
| WinSock 2.0 -- OpenSSL 0.9.7d 17 Mar 2004 |
| [R] Connecting to 192.168.21.3 -> IP=192.168.21.3 PORT=2121 |
| [R] Connected to 192.168.21.3 |
| [R] 220 Please enter your login name now. |
| [R] AUTH TLS (认证方法)|
| [R] 234 AUTH Command OK. Initializing SSL connection. |
| [R] Connected. Negotiating SSL/TLS session.. |
| [R] SSL/TLS negotiation successful... (协商关联)|
| [R] TLSv1/SSLv3 encrypted session using cipher AES256-SHA (256 bits)
| [R] PBSZ 0 (PBSZ设置)|
| [R] 200 PBSZ Command OK. Protection buffer size set to 0. |
| [R] USER elly (ftp传统认证)|
| [R] 331 Password required for elly . |
| [R] PASS (hidden) |
| [R] 230 User elly logged in. |
| [R] SYST |
| [R] 215 UNIX Type: L8 , CP:936 |
| [R] FEAT (扩展指令测试)|
| [R] 211-Extensions supported: |
| [R] SIZE |
| [R] MDTM |
| [R] MDTM YYYYMMDDHHMMSS filename |
| [R] LIST -laT |
| [R] STAT -laT |
| ... |
| [R] AUTH SSL |
| [R] AUTH TLS |
| [R] PROT |
| [R] PBSZ |
| [R] SSCN |
| [R] UTF8 |
| [R] 211 END |
| [R] CLNT FlashFXP 2.2.985 |
| [R] 213 client type set to FlashFXP 2.2.985. |
| [R] PWD (传统通讯过程)|
| [R] 257 "/" is current directory |
| [R] TYPE A |
| [R] 200 Type set to ASCII. |
| [R] PROT P (切换到保护模式)|
| [R] 200 PROT P accepted. |
| [R] PASV |
| [R] 227 Entering Passive Mode (192,168,21,3,5,122) |
| [R] Opening data connection IP: 192.168.21.3 PORT: 1402 |
| [R] LIST -al |
| [R] Connected. Negotiating SSL/TLS session.. (加密通讯过程)|
| [R] 150 Opening ASCII data connection for ls / using SSL/TLS. |
| [R] SSL/TLS negotiation successful... |
| [R] TLSv1/SSLv3 encrypted session using cipher AES256-SHA (256 bits)
| [R] 226-free disk space under this directory : 101 mb |
| [R] 226 Transfer finished successfully. Data connection closed . |
| [R] List Complete: 181 bytes in 0.14 seconds (1.26 KBps) |
| |
\====================================================================/
在ssl ftp中,有以下几个特殊点:
1, AUTH是可选指令,因为ssl ftp实现的方式不同而存在,详见下一节explicit SSL
与implicit SSL;
2, PBSZ和PROT是必须指令,用于切换到保护通道模式;
3, AUTH,PBSZ和PROT指令是实现SSL认证方式的必须方法,但可以与传统的User/Password
模式共存,或只取其一;
4, SSL认证方法的SSL认证过程(AUTH/PBSZ)和传统模式认证并无严格的先后顺序关联,可能在
用户名和密码之前,也可能在之后;但出于安全因素,最好在User/Password传输之前切换
到安全模式,可以确保User/Password的传输安全;
5, 在explicit SSL模式中,可以在任何时间切换到保护模式,如第四条所述;在implicit
SSL模式中,初始化连接将直接采用SSL Socket建立,不需要AUTH指令切换。
>>3.4 Explicit SSL和Implicit SSL
由于历史和软件兼容性因素,ssl FTP的实现有两种方式,分别是Explicit SSL和Implicit SSL,
上面的大部分数据都是以explicit SSL为范例。
Explicit SSL(外部SSL),又被称为AUTH SSL方式;Explicit SSL保持了与传统ftp服务的
良好兼容性,以一个ftp服务扩展指令的方式存在。初始化连接可以采用与传统ftp兼容的连
接模式,当需要传输加密信息时使用AUTH SSL指令切换到保护模式。使用Explicit SSL时
Server必须完整地实现AUTH/PBSZ/PROT等指令。
Implicit SSL(隐含SSL),是一个全新的ftp实现方式,在TCP三步握手完成之后就直接使用
SSL Socket进行协商和通讯,之后将全程采用SSL加密连接。在这种模式中一般ftp server
将监听在一个新的服务端口,IANA指定ftps:tcp:990为implicit SSL ftp的默认端口。因为在
连接初始阶段就自动由SSL实现完成了协商,因此implicit模式中AUTH指令是可选的。
在不考虑兼容性的因素下,在服务期端最好优先使用implicit SSL模式,可以获得更好的保密
特性。
比较两种ssl ftp实现模式区别如下:
/======================================================================\
| explicit implicit |
| client server client server |
|======================================================================|
| | |
| connect() ------> -+-明文 | sslConnect() ------> 加密 |
| <------ 220 | | <------ 220 -+ |
| AUTH SSL ------> | | USER *** ------> | |
| <------ 234 -+ | <------ 331 | |
| TLSneg() <-----> TLSneg() -+-加密 | PASS *** ------> | |
| <------ 200 | | <------ 230 | |
| USER *** ------> | | LIST <-----> ... | |
| <------ 331 | | RETR <-----> ... | |
| PASS *** ------> | | ... | |
| <------ 230 | | | |
| LIST/RETR <-----> ... | | sslClose() <-----> ... -+ |
| close() <-----> ... -+ | |
| | |
\======================================================================/
>>3.5 一些杂乱图示
在3.3种引用了一个Explicit SSL连接指令序列,这里是对应的Implicit SSL连接过程:
/======================================================================\
| WinSock 2.0 -- OpenSSL 0.9.7d 17 Mar 2004 |
| [R] Connecting to 192.168.21.3 -> IP=192.168.21.3 PORT=9909 |
| [R] Connected to 192.168.21.3 |
| [R] Connected. Negotiating SSL/TLS session.. |
| [R] SSL/TLS negotiation successful... |
| [R] TLSv1/SSLv3 encrypted session using cipher AES256-SHA (256 bits) |
| [R] 220 Please enter your login name now. |
| [R] PBSZ 0 |
| [R] 200 PBSZ Command OK. Protection buffer size set to 0. |
| [R] USER elly |
| [R] 331 Password required for elly . |
| [R] PASS (hidden) |
| [R] 230 User elly logged in. |
| [R] SYST |
| [R] 215 UNIX Type: L8 , CP:936 |
| [R] PROT P |
| [R] 200 PROT P accepted. |
| [R] PASV |
| [R] 227 Entering Passive Mode (192,168,21,3,5,122) |
| [R] Opening data connection IP: 192.168.21.