File Transfer Protocol FTP
1、File Transfer Protocol 早期的三个应用级协议之一 2、基于C/S结构 3、双通道协议: 数据和命令连接 数据连接则是从命令决定传输数据开始到数据传输结束,这个连接则关闭了 客户端发起请求服务端响应、双方正式建立连接。而结束,这是命令连接的正常工作逻辑 数据连接是临时根据命令需求建立的、根本目的是为了客户端上传数据给服务端 数据连接谁给打开 数据连接如果是为服务器端主动去连接客户端的称为主动模式 由客户端发请求、服务端响应、称为被动模式 FTP多数都是工作在被动模式下,由客户端发请求来连接服务器 4、数据传输格式: 二进制(默认)和文本 5、两种模式:服务器角度 主动(PORT style):服务器主动连接 命令(控制):客户端:随机port --- 服务器:tcp21 数据:客户端:随机port ---服务器:tcp20 被动(PASV style):客户端主动连接 命令(控制):客户端:随机port --- 服务器:tcp21 数据:客户端:随机port --- 服务器:随机port 6、服务器被动模式数据端口示例: 227 Entering Passive Mode (172,16,0,1,224,59) 服务器数据端口为:224*256+59
Introduction to FTP Software:
FTP服务器: Wu-ftpd,Proftpd,Pureftpd,ServU,IIS vsftpd:Very Secure FTP Daemon,CentOS默认FTP服务器 高速,稳定,下载速度是WU-FTP的两倍 ftp.redhat.com数据:单机最多可支持15000个并发客户端软件: ftp,lftp,lftpget,wget,curl ftp -A ftpserver port -A主动模式 –p 被动模式 lftp –u username ftpserver lftp [email protected] lftpget ftp://ftpserver/pub/file gftp:GUI centos5 最新版2.0.19 (11/30/2008) filezilla,CuteFtp,FlashFXP,LeapFtp IE ftp://username:[email protected]
FTP Service
状态码: 1XX: 信息 125:数据连接打开 2XX: 成功类状态 200:命令OK 230:登录成功 3XX: 补充类 331:用户名OK 4XX: 客户端错误 425:不能打开数据连接 5XX: 服务器错误 530:不能登录用户认证: 匿名用户:ftp,anonymous,对应Linux用户ftp 系统用户:Linux用户,用户/etc/passwd,密码/etc/shadow 虚拟用户:特定服务的专用用户,独立的用户/密码文件 nsswitch:network service switch名称解析框架 pam:pluggable authentication module 用户认证 /lib64/security /etc/pam.d/ /etc/pam.conf
VSFTPD Service
1, provided by VSFTPD Package 2, no longer managed by xinetd 3, user authentication profile:/ETC/PAM.D/VSFTPD4, Service script:/usr/lib/systemd/system/vsftpd.service /ETC/RC.D/INIT.D/VSFTPD5, configuration file:/etc/vsftpd/vsftpd.conf man 5 vsftpd.conf format: option=value Note: = No spaces 6, anonymous users (mapped to System user FTP) shared file location:/VAR/FTP7, System User shared file location: User home directory 8, Virtual user shared file location: The home directory of the system user for which the mapping is 9, the command port LISTEN_PORT=2110, Active mode port connect_from_port_20=yes active mode Port ftp_data_port=20 (default) specify Active mode port 11, passive mode port range Linux clients use passive mode by default Windows clients default to active mode pasv_min_port=6000 0 to randomly assign pasv_max_port=601012, use local time Use_localtime=yes use local time (default is no, GMT is used) 13, anonymous user anonymous_enable=yes support anonymous user No_anon_passwor D=yes (default no) anonymous user skipped password check anon_world_readable_only (default YES) can only download all read files Anon_upload_enable=yes Anonymous upload, Note: File system permissions anon_mkdir_write_enable=yes anonymous build directory anon_umask=0333 Specifies the umask of the anonymous upload file, the default077 Anon_other_write_enable=yes can delete and modify the uploaded file Chown_uploads=yes (default no) specifies the default owner and rights of the uploaded file Limited to Chown_username=wang chown_upload_mode=064414, Linux system user Local_enable=yes whether to allow Linux users to log in Write_enable=yes allows Linux users to upload files local_umask=022 Specify default permissions for system users to upload files Guest_enable=yes All system users are mapped to guest user guest_username=ftp with the above option to take effect, specify Guest user Local_root=/ftproot GUE St User Login Directory 15, imprison all system users in the home directory Chroot_local_user=yes (default no, not imprisoned) imprison the system users 16, imprison or not imprison specific system users in the home directory, and the above set the function opposite Chroot_list_ Enable=yes chroot_list_file=/etc/vsftpd/chroot_list when Chroot_local_user=yes, the user in Chroot_list is not imprisoned when Chroo T_local_user=no, the user is imprisoned in the Chroot_list 17, wu-ftp log: Enabled by default Xferlog_enable=yes (default) Enable record upload download log xferlog _std_format=yes (default) uses WU-FTP log format xferlog_file=/var/log/xferlog (default) to automatically generate VSFTPD logs: not enabled by default Dual_log_enable=yes using VSFTPD log format, default is not enabled Vsftpd_log_file=/var/log/vsftpd.log (default) can automatically generate 18, login prompt information ftpd_banner= "Welcome to mage FTP SE RVer "Banner_file=/etc/vsftpd/ftpbanner.txt Precedence above entry effective directory Access prompt Dirmessage_enable=yes (default) Message_fi Le=.message (default) information is stored in the specified directory. MESSAGE19, using Pam (pluggable authentication Modules) to complete user authentication pam_service_name=vsftpd Pam Profile:/etc/pam.d/vsftpd/etc/vsftpd/ftpusers default file user denied login normally, when any file is accessed through a network service, he should be controlled by two dimension 1, controlled by the software itself defined access control rules 2, controlled by the file system
VSFTPD Anonymous User Configuration Example
Simple example: As soon as you install the service, you can use FTP1, install vsftpd software [[email protected] ~] #yum-y install VSFTPD2, start the VSFTPD service [[Email pro Tected] ~] #systemctl start VSFTPD3, access by client to do a simple test [[email protected] ~] #lftp 192.168.137.56 lftp 192.168.137.56 :~> ls drwxr-xr-x 2 0 0 6 Geneva Pub lftp 192.168.137.56:/> CD Pub Lftp 192.168.137.56:/pub> ls lftp 192.168.137.56:/pub> ls-rw-r--r--1 0 0 Oct 2 2 12:26 issue lftp 192.168.137.56:/pub> lcd/tmp lcd OK, local cwd=/tmp lftp 192.168.137.56:/pub> mget issu E bytes Transferred lftp 192.168.137.56:/pub> bye [[email protected] ~] #ls/tmp/issue4, file rights shared by server Limit change to 600[[email protected]/var/ftp/pub] #chmod issue [[email protected]/var/ftp/pub] #lltotal 4- RW-------1 root root 20:26 issue5, connect again via client and download this file [[email protected] ~] #lftp 192.168.137.56 lftp 19 2.168.137.56:/> CD PUB/LFTP 192.168.137.56:/pub> ls-rw-------1 0 0 Oct 12:26 issue lftp 192.168.137.56:/pub> m Get issue mget:access failed:550 failed to open file. (issue) lftp 192.168.137.56:/pub> Configure anonymous user upload, download, and other functions: Modify the configuration file, open Allow anonymous user upload function [[email protected]/etc/vsftpd ] #vim vsftpd.conf #anon_upload_enable =yes anon_upload_enable=yes through client authentication [[Email pro Tected] ~] #lftp 192.168.137.56 lftp 192.168.137.56:~> lcd/etc/lcd OK, local cwd=/etc lftp 192.16 8.137.56:~> put fstab put:access failed:553 Could not create file. (fstab) Lftp 192.168.137.56:/> Normally, the FTP user anonymous is mapped to an FTP user, and the default shared pub directory belongs to the default root group, and the FTP user is mapped to other users without write permission, so Cause Unable to upload, it is recommended not to modify the permissions of the pub, it is best to create a new directory to upload the solution: In the pub peer directory to create a new directory dedicated to upload, modify the directory of the owning group and owner permissions for FTP [[email protected]/var/ftp]# mkdir upload [[email protected]/var/ftp] #ls pub upload [[email protected]/var/ftp] #ll ToTal 0 Drwxr-xr-x 2 root root Oct 20:26 pub drwxr-xr-x 2 root root 6 Oct 20:52 upload [[Emai L protected]/var/ftp] #chown-R ftp.ftp upload/[[email protected]/var/ftp] #ll-ld upload/drwxr -xr-x 2 FTP FTP 6 Oct 20:52 upload/Verify client again [[email protected] ~] #lftp 192.168.137.56/upload cd o K, cwd=/upload lftp 192.168.137.56:/upload> lcd/etc lcd OK, local cwd=/etc lftp 192.168.137.56:/u pload> put fstab 595 bytes transferred lftp 192.168.137.56:/upload> switch to view files on the server [[Email&nbs P;protected]/var/ftp] #cd upload/[[email protected]/var/ftp] #ls-l upload/total 4-rw------- 1 FTP FTP 595 Oct 20:55 fstab Change the uploaded file owner to another user, and modify the file permissions: Edit configuration file [[email protected]/etc/vsftpd] #vim VSFTPD.C onf #chown_uploads =yes #chown_username =whoever change to Chown_uploads=yes Chown_username=cobbler Chown_upload_mode=0644 Create Cobbler user [[[email protected]/etc/vsftpd] #useradd Cobbler restart VSFTPD service [[Email protec Ted]/etc/vsftpd] #systemctl Restart VSFTPD Verify the success of this setting through the client [[email protected] ~] #lftp 192.168.137.56/upload cd OK, cwd=/upload lftp 192.168.137.56:/upload> lcd/etc lcd OK, local cwd=/etc lftp 192.1 68.137.56:/upload> put passwd 1199 bytes transferred lftp 192.168.137.56:/upload> ls view file properties from the server side [[email protected]/var/ftp] #cd upload/[[email protected]/var/ftp/upload] #ll Total 8 -RW-------1 FTP FTP 595 Oct 20:55 fstab-rw-r--r--1 Cobbler FTP 1199 Oct 21:04 passwd on client connection to server attempt Can I create a directory lftp 192.168.137.56:/upload> mkdir test mkdir:access failed:550 Permission denied. (test) lftp 192.168.137.56:/upload> rm fstab rm:access failed:550 Permission denied. (fstab) lftp 192.168.137.56:/upload> RM PASSWD rm:access failed:550 Permission denied. (passwd) Lftp 192.168.137.56:/upload> need to allow anonymous users to create delete files or directories need to be in the server configuration file to open the following two items [[email protected]/ ETC/VSFTPD] #vim vsftpd.conf anon_mkdir_write_enable=yes anon_other_write_enable=yes Restart service after modification [[[email protected]/etc/vsftpd] #systemctl Restart VSFTPD authentication on the client [[email protected] ~] #lftp 192.1 68.137.56/upload cd OK, cwd=/upload lftp 192.168.137.56:/upload> mkdir test mkdir OK, ' test ' creat Ed lftp 192.168.137.56:/upload> ls-rw-------1 595 Oct 12:55 fstab- rw-r--r--1 1199 Oct 13:04 passwd drwx------2 6 Oct 22 13: Ten test lftp 192.168.137.56:/upload> RM fstab rm OK, ' fstab ' removed lftp 192.168.137.56:/upload& Gt RM passwd rm OK, ' passwd ' removed lftp 192.168.137.56:/upload> rmdir tesT rmdir OK, ' test ' removed lftp 192.168.137.56:/upload> ls lftp 192.168.137.56:/upload>
VSFTPD Anonymous User Configuration Example
Create a system user and modify the password [[email protected]/etc/vsftpd] #useradd ilinux [[email protected]/etc/vsftpd] #echo 123456| passwd--stdin ilinux changing password for user ilinux. Passwd:all authentication tokens updated successfully. The client is logged on to the system user that was created on the server side, and the name of the system user is displayed after logging on, and the anonymous user does not have [[email Protected] ~] #lftp-u ilinux 192.168.137.56 password:lftp [email protected]:~> ls lftp [email&nb Sp;protected]:~> lcd/etc/lcd OK, local cwd=/etc lftp [email protected]:~> put issue at bytes Transfe rred lftp [email protected]:~> ls-rw-r--r--1 1001 1001 Oct 13:19 issue lftp [em Ail protected]:~> in the server-side Ilinux home directory to view files uploaded from the client each user accesses the user's home directory after logging in to ftp Why anonymous users are accessing the/VAR/FTP directory, Anonymous user access is also home directory, is the home directory of FTP [[email protected]/var/ftp/upload] #grep "^ftp"/etc/passwd ftp:x:14:50:ftp user:/var/ftp :/sbin/nologin [[email protected]/var/ftp/upload] #ls/home/ilinux/issue system users and anonymous users are not controlled in the same way, even if anonymousUser upload and download, the system users are not affected, normal can upload and download
Mapping system users to Guest account guest
Create a directory of guest users and guests, and then you need to remove the Write permission from the directory you created, or you can report an error by client-side validation [[email protected]/var/ftp/upload] #useradd-D/data/ftproot Vsguest [[email protected]/var/ftp/upload] #chmod-W/data/ftproot/[[email protected]/var/ftp/upload] #ls -ld/data/ftproot/dr-x------2 vsguest vsguest Oct 21:56/data/ftproot/[[email protected]/var/ftp/upl Oad] #chmod +rx!$ chmod +rx/data/ftproot/[[email protected]/var/ftp/upload] #ls-ld/data/ftproot/dr-x R-xr-x 2 vsguest vsguest Oct 21:56/data/ftproot/[[email protected]/var/ftp/upload] #编辑配置文件增加两项选项 [[Emai L protected]/etc/vsftpd] #vim vsftpd.conf #guest user guest_enable=yes guest_username=vsguest Restart service [[Emai L protected]/etc/vsftpd] #systemctl Restart VSFTPD Copy the test file to the guest directory, can be distinguished from under this directory [[email protected]/etc/vsftpd ] #cp/etc/vsftpd/vsftpd.conf/data/ftproot/is tested on the client: it says to remove the guest directory Write permission, otherwise it will prompt 500 error prompt [[email protected] ~]# Lftp-u ilinux 192.168.137.56 Password: Lftp [email protected]:~> pwd ftp://[email protected] lftp [email protected]:~> ls Ls:login failed:500 OOPS:vsftpd:refusing to run with writable root inside Chroot () lftp [EMAIL PROTECTED]:~&G T LS ls:login failed:500 OOPS:vsftpd:refusing to run with writable root inside Chroot () lftp [email protected ]:~> ls lftp [email protected]:/> ls-rw-------1 0 0 5129 Oct vsftpd.conf Lftp [email protected]:/> The two items that were mapped to the Guest account on the server and then passed the client test to see if it was back in its own home directory [[email protected]/etc/vs FTPD] #vim vsftpd.conf #guest_enable =yes #guest_username =vsguest Restart service [[email protected]/etc/vsftpd] #systemctl Restart vsftpd then in the home under the Ilinux directory to view the files inside, and then through the client to see if the inside and see here is the same file [[email protected]/var/ftp/ Upload] #ls/home/ilinux/issue test client: [[email protected] ~] #lftp-u ilinux 192.168.137.56 password:lftp [email protected]:~>ls-rw-r--r--1 1001 1001 Oct 13:19 Issue lftp [email protected]:~> lftp [ Email protected]:~> cd/etc/Once the system user is allowed to log in after a tragic problem, it can wander around the entire system, not only their home directory, if the server has sensitive information, so that users can directly download after logging in Information disclosure, it is recommended that the best user login to stay in their home directory, other directories do not let it switch freely
Example of imprisoning system users at home directory:
To imprison which user to ensure that the user's home directory does not have write permissions, or will be error, not to use but imprisoned users do not often modify the parameters inside the configuration file [[email protected]/etc/vsftpd] #vim vsftpd.conf chroot _list_enable=yes chroot_list_file=/etc/vsftpd/chroot_list Create a new user [[email protected]/etc/vsftpd] #useradd ik8s [[email protected]/etc/vsftpd] #echo 123456|passwd--stdin ik8s changing password for user ik8s. Passwd:all authentication tokens updated successfully. Remove the Write permission from the user's home directory [[email protected]/etc/vsftpd] #chmod-w// /ik8s/Create a list of users to be imprisoned [[email protected]/etc/vsftpd] #vim/etc/vsftpd/chroot_list ik8s Restart service [[email protected ]/ETC/VSFTPD] #systemctl restart VSFTPD client test: [[email protected] ~] #lftp-u ilinux,123456 192.168.137.56 lftp [ email protected]:~> cd/etc/lftp [email protected]:/etc> exit [[email  ;p rotected] ~] #lftp-u ik8s,123456 192.168.137.56 lftp [email protected]:~> cd/etc cd:access failed:550 F ailed to change directory. (/etc) LFTP [email protected]:/> ls lftp [email protected]:/>
Network file sharing service-vsftp