浅谈FTP ALG

来源:互联网 发布:华为云计算部门怎么样 编辑:程序博客网 时间:2024/05/17 09:19




浅谈FTP ALG

分享

分类: 网络技术2009-03-09 17:50
最近遇到了FTP的问题,牵扯到了ALG,在这里写一下,为了以后的学习参考.
先来认识一下ALG的概念,
It allows customized NAT traversal filters to be plugged into the gateway to support address andport translation for certain application layer "control/data" protocols such as FTP, BitTorrent, SIP,RTSP, file transfer in IM applications etc.
对于那种控制和数据会话的应用,比如FTP,BT,SIP,NAT处理的时候就会有问题,因为它们会把ip address 和port放在payload里面,这个时候就需要ALG来做处理,现在一般的网关(router)在默认情况下都会打开FTP ALG.
如果你的FTP 客户端在一个NAT router后面 ,客户端会和FTP服务器端首先建立一个控制连接,对于控制连接,一般服务器端的端口21,但是传递文件的时候,要先通过控制连接协商出一个数据连接来,也就是协商出一个ip address 和port,通过这个IP address和port,对方才可以连接过来做数据传输.
但是问题在于协商的ip address和port在payload里面,经过NAT router 的时候,不会改变,因为NAT router 只会改IP 层的,不会动TCP/UDP里面的数据,服务器最后得到的payload里面的是私有IP地址,这样就无法建立数据会话.
所以在应用ALG,ALG就是在发现IP报文头做了NAT,在这个时候出现port request,就需要同时改变PORT命令,我做试验抓包发现有的时候port不一定会变.

因为FTP是一个TCP的连接,如果更改payload,那么就涉及到整个TCP连接的一些参数的更改,比如sequence number,ack number,TCP报文的checksum等等。
这里有必有来说一下TCP checksum的计算,tcp checksum需要下列值,pseudo header,TCP header,data(payload) 
对于pseudo header,解释如下,在这里,就需要你对TCP/IP比较了解了,TCP/IP是基础,一定要精通.
The pseudo header conceptually prefixed to the UDP header contains the source address, the destination address, the protocol, and the UDP length. This information gives protection against misrouted datagrams.

我贴了两张抓包的截图,
topo,pc(192.168.10.33)---NAT router(wan:172.25.27.78)---FTP server(172.25.5.8)
before ALG



after ALG



从两幅截图就可以看出,payload的ip地址变了,并且ip address 大小比之前小(192.168.10.33-->172.25.27.78),这样的话会导致next sequence number也会变化,带不管怎么样tcp checksum都会重新计算,因为payload变了.
在这样的TOPO里面(client在lan,server在wan),这种问题只会出现在PORT mode里面,在pass mode里面就没有问题,即使把FTP ALG关掉都没问题。
具体原因,去看一下port mode和pass mode的定义就能懂了.
具体如下,In active mode, the FTP client opens a dynamic port, sends the FTP server the dynamic port number on which it is listening over the control stream and waits for a connection from the FTP server. When the FTP server initiates the data connection to the FTP client it binds the source port to port 20 on the FTP server.

In passive mode, the FTP server opens a dynamic port, sends the FTP client the server's IP address to connect to and the port on which it is listening (a 16-bit value broken into a high and low byte, as explained above) over the control stream and waits for a connection from the FTP client. In this case, the FTP client binds the source port of the connection to a dynamic port.


对于FTP ALG的概念吧,下一段粘自RFC 2623 ,解释的很好,可以参考下,
   "PORT" command and "PASV" response in FTP control session payload   identify the IP address and TCP port that must be used for the data   session it supports. The arguments to the PORT command and PASV   response are an IP address and a TCP port in ASCII. An FTP ALG is   required to monitor and update the FTP control session payload so   that information contained in the payload is relevant to end nodes.   The ALG must also update NAT with appropriate data session tuples and   session orientation so that NAT could set up state information for   the FTP data sessions.   Because the address and TCP port are encoded in ASCII, this may   result in a change in the size of packet.  For instance,   10,18,177,42,64,87 is 18 ASCII characters, whereas   193,45,228,137,64,87 is 20 ASCII characters. If the new size is same   as the previous, only the TCP checksum needs adjustment as a result   of change of data. If the new size is less than or greater than the   previous, TCP sequence numbers must also be changed to reflect the   change in length of FTP control data portion.  A special table may be   used by the ALG to correct the TCP sequence and acknowledge numbers.   The sequence number and acknowledgement correction will need to be   performed on all future packet of the connection.虽然这只是个ALG的应用,但还是牵扯到很多理论,同样,对于SIP ALG,H323 ALG,RTSP,道理也是一样,只不过是TCP和UDP的区别了。呵呵.
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 人工喂养七天的小羊拉希怎么办 仔兔出生3天吃过奶就尿怎么办 小兔子买回来两天不拉屎怎么办 大狗生了小狗把小狗咬死了怎么办 狗妈妈一直咬小狗的脐带怎么办 狗狗体内驱虫驱不干净怎么办 打老鼠脚被老鼠咬了怎么办 天正画的cad打开显示空白怎么办 苹果手机信息被拉进群聊怎么办 空调的控制线的报验资料怎么办 窗窗户罩子护栏上的瓦楞板怎么办 酸洗好的带钢容易返锈怎么办 化肥撤到小树苗上现在变黑了怎么办 尿素液烧的太慢了怎么办 天堂鸟肥料施多了黄叶了怎么办 死水塘养的鱼每天在死怎么办 北京的阿姆斯肥把苗都烧死了怎么办 纱窗被老鼠咬了个洞 怎么办 低电量模式下动态墙纸不能用怎么办 吃的包装袋执行标准错了怎么办 退换东西的时候外包装坏了怎么办 闲鱼买家以与描述不符退货怎么办 闲鱼买家申请退款又签收了怎么办 店铺买的手机是拆开过的怎么办 卖家以包装破损拒收快递怎么办 车辆迁出落户信封被自己拆开怎么办 快递签收了发现物品坏了怎么办 快递签收后发现货坏了怎么办 闲鱼退货有破损卖家要求赔偿怎么办 邮政快递收货后发现快递破损怎么办 中通把包裹发到别的省份去了怎么办 寄快递没拿单子但东西破损了怎么办 快递签收以后发现东西少了怎么办 淘宝时收到的货破损我该怎么办 淘宝买的冰箱七天无理由退货怎么办 截图放进ai中变得很模糊怎么办 买房子的贷款合同丢了怎么办 索尼9000e挂墙后面借口怎么办 想把木头锯成小块的怎么办 第一天上班交接完工作想辞职怎么办 POS机刷卡成功没打出单子怎么办