FTP 主动模式和被动模式测试
FTP协议的命令 与 返回码 详解(2009-03-19 09:46:07)标签:ftp 协议命令 返回码 教育 分类:软件开发
FTP命令
命令 描述
ABOR 中断数据连接程序
ACCT <account> 系统特权帐号
ALLO <bytes> 为服务器上的文件存储器分配字节
APPE <filename> 添加文件到服务器同名文件
CDUP <dir path> 改变服务器上的父目录
CWD <dir path> 改变服务器上的工作目录
DELE <filename> 删除服务器上的指定文件
HELP <command> 返回指定命令信息
LIST <name> 如果是文件名列出文件信息,如果是目录则列出文件列表
MODE <mode> 传输模式(S=流模式,B=块模式,C=压缩模式)
MKD <directory> 在服务器上建立指定目录
NLST <directory> 列出指定目录内容
NOOP 无动作,除了来自服务器上的承认
PASS <password> 系统登录密码
PASV 请求服务器等待数据连接
PORT <address> IP 地址和两字节的端口 ID
PWD 显示当前工作目录
QUIT 从 FTP 服务器上退出登录
REIN 重新初始化登录状态连接
REST <offset> 由特定偏移量重启文件传递
RETR <filename> 从服务器上找回(复制)文件
RMD <directory> 在服务器上删除指定目录
RNFR <old path> 对旧路径重命名
RNTO <new path> 对新路径重命名
SITE <params> 由服务器提供的站点特殊参数
SMNT <pathname> 挂载指定文件结构
STAT <directory> 在当前程序或目录上返回信息
STOR <filename> 储存(复制)文件到服务器上
STOU <filename> 储存文件到服务器名称上
STRU <type> 数据结构(F=文件,R=记录,P=页面)
SYST 返回服务器使用的操作系统
TYPE <data type> 数据类型(A=ASCII,E=EBCDIC,I=binary)
USER <username>> 系统登录的用户名
FTP响应码
响应代码 解释说明
110 新文件指示器上的重启标记
120 服务器准备就绪的时间(分钟数)
125 打开数据连接,开始传输
150 打开连接
200 成功
202 命令没有执行
211 系统状态回复
212 目录状态回复
213 文件状态回复
214 帮助信息回复
215 系统类型回复
220 服务就绪
221 退出网络
225 打开数据连接
226 结束数据连接
227 进入被动模式(IP 地址、ID 端口)
230 登录因特网
250 文件行为完成
257 路径名建立
331 要求密码
332 要求帐号
350 文件行为暂停
421 服务关闭
425 无法打开数据连接
426 结束连接
450 文件不可用
451 遇到本地错误
452 磁盘空间不足
500 无效命令
501 错误参数
502 命令没有执行
503 错误指令序列
504 无效命令参数
530 未登录网络
532 存储文件需要帐号
550 文件不可用
551 不知道的页类型
552 超过存储分配
553 文件名不允许
lftp -d 192.168.0.253
pasv 被动模式
port 主动模式 由客户端决定
nc 192.168.0.253 21 //连接端口
1.是扫描器 扫描端口
2.是连接端口的工具。相当于 telnet 85X256+205段口号
nc -l(监听) 192.168.0.253 12345(端口) -k(不因为外界断开连接而服务器断开)
2回3次握手2回 4次挥手
[root@whl ~]# telnet 192.168.0.129 21
Trying 192.168.0.129...
Connected to www.uplooking.com (192.168.0.129).
Escape character is '^]'.
220 (vsFTPd 2.0.5)
USER ftp
331 Please specify the password.
PASS 123
230 Login successful.
PWD
257 "/"
STAT
211-FTP server status:
Connected to 192.168.0.110
Logged in as ftp
TYPE: ASCII
No session bandwidth limit
Session timeout in seconds is 300
Control connection is plain text
Data connections will be plain text
At session startup, client count was 5
vsFTPd 2.0.5 - secure, fast, stable
211 End of status
FTP的主被动模式:
192。168。0。110 client
192.168.0.129 SERVER
[root@mercury ~]# ssh 192.168.0.110
root@192.168.0.110's password:
Last login: Fri Oct 22 16:44:15 2010 from www.uplooking.com
[root@whl ~]#
被动模式:
[root@whl ~]# telnet 192.168.0.129 21
Trying 192.168.0.129...
Connected to www.uplooking.com (192.168.0.129).
Escape character is '^]'.
220 (vsFTPd 2.0.5)
USER ftp
331 Please specify the password.
PASS 123
230 Login successful.
PASV
227 Entering Passive Mode (192,168,0,129,170,218)
LIST
150 Here comes the directory listing.
226 Directory send OK.
[root@whl ~]# echo $[170*256+218]
43738
[root@whl ~]# nc 192.168.0.129 43738
-rwxrwxrwx 1 0 0 4520 Oct 15 04:46 iptab.txt
drwxr-xr-x 11 0 0 4096 Oct 22 10:34 pub
-rwxrwxrwx 1 0 0 3111600128 Oct 14 03:26 rhel5u5.iso
-rw-r--r-- 1 0 0 1280 Oct 15 06:37 trustdb.gpg
-rw-r--r-- 1 0 0 4303 Oct 15 04:37 新建 文本文档 (2).txt~
-rw-r--r-- 1 0 0 1782 Oct 22 05:05 新文件 3
+++++++++++++++++++++++++++++++++======
主动模式
1、clinet 开启11111端口的监听
nc -l 192.168.0.27 11111 -k
echo $[11111/256] = 43
echo $[11111%256] = 103
2、telnet 192.168.0.254 21
USER ftp
PASS 123123
PORT 192,168,0,27,43,103
LIST 回车可以看到OK的字样。你需要去nc -l 192.168.0.27 11111 -k 这个接口下看结果
150 Here comes the directory listing.
226 Directory send OK.
在server端可以通过此脚本 ,看到server确实打开了20端口主动连接客户端的11111端口
while : ;do netstat -na | grep :20 | grep -v 20433 >> /tmp/ftpdata.txt;done
或者 抓包看tcpdump -i eth0 -vnn port 20
[root@ftpserver ~]# tcpdump -i eth1 -vnn port 20tcpdump: listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes
14:51:29.833966 IP (tos 0x0, ttl 64, id 34602, offset 0, flags [DF], proto: TCP (6), length: 60) 192.168.0.254.20 > 192.168.0.27.11111: S, cksum 0x92d9 (correct), 4177100919:4177100919(0) win 5792 <mss 1460,sackOK,timestamp 2951005 18706057,nop,wscale 7>
14:51:29.834159 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto: TCP (6), length: 60) 192.168.0.27.11111 > 192.168.0.254.20: S, cksum 0x4782 (correct), 688182270:688182270(0) ack 4177100920 win 5792 <mss 1460,sackOK,timestamp 18726092 2951005,nop,wscale 7>
14:51:29.834192 IP (tos 0x0, ttl 64, id 34603, offset 0, flags [DF], proto: TCP (6), length: 52) 192.168.0.254.20 > 192.168.0.27.11111: ., cksum 0x8cbf (correct), ack 1 win 46 <nop,nop,timestamp 2951006 18726092>
14:51:29.834740 IP (tos 0x8, ttl 64, id 34604, offset 0, flags [DF], proto: TCP (6), length: 731) 192.168.0.254.20 > 192.168.0.27.11111: P 1:680(679) ack 1 win 46 <nop,nop,timestamp 2951006 18726092>
14:51:29.834779 IP (tos 0x8, ttl 64, id 34605, offset 0, flags [DF], proto: TCP (6), length: 52) 192.168.0.254.20 > 192.168.0.27.11111: F, cksum 0x8a17 (correct), 680:680(0) ack 1 win 46 <nop,nop,timestamp 2951006 18726092>
14:51:29.835038 IP (tos 0x0, ttl 64, id 28467, offset 0, flags [DF], proto: TCP (6), length: 52) 192.168.0.27.11111 > 192.168.0.254.20: ., cksum 0x8a0d (correct), ack 680 win 56 <nop,nop,timestamp 18726093 2951006>
14:51:29.835319 IP (tos 0x0, ttl 64, id 28468, offset 0, flags [DF], proto: TCP (6), length: 52) 192.168.0.27.11111 > 192.168.0.254.20: F, cksum 0x8a0b (correct), 1:1(0) ack 681 win 56 <nop,nop,timestamp 18726093 2951006>
14:51:29.835344 IP (tos 0x8, ttl 64, id 34606, offset 0, flags [DF], proto: TCP (6), length: 52) 192.168.0.254.20 > 192.168.0.27.11111: ., cksum 0x8a14 (correct), ack 2 win 46 <nop,nop,timestamp 2951007 18726093>
被动模式:
1 client 连接服务器端
telnet 192.168.0.254 21
USER ftp
PASS 12312
PASV
227 Entering Passive Mode (192,168,0,254,244,51)
LIST
150 Here comes the directory listing.
226 Directory send OK.
得知服务器端开了 $[244*256+51] 也就是这个端口62515
[root@localhost ~]# telnet 192.168.0.254 62515
在此接口看传回的数据
1 nc 是扫描器,用于扫描端口
2 nc是连接端口的工具,相当于telnet ip port
3 nc 可以让你指定监听的端口

浙公网安备 33010602011771号