1.vsftpd服务程序

  vsftpd 作为更加安全的文件传输的服务程序,允许用户以三种认证模式登录到FTP 服务器上。

  匿名开放模式:是一种最不安全的认证模式,任何人都可以无需密码验证而直接登录到FTP 服务器。

  本地用户模式:是通过Linux 系统本地的账户密码信息进行认证的模式,相较于匿名开放模式更安全,而且配置起来也很简单。但是如果被黑客破解了账户的信息,就可以畅通无阻地登录FTP 服务器,从而完全控制整台服务器。

  虚拟用户模式:是这三种模式中最安全的一种认证模式,它需要为FTP 服务单独建立用户数据库文件,虚拟出用来进行口令验证的账户信息,而这些账户信息在服务器系统中实际上是不存在的,仅供FTP 服务程序进行认证使用。

  这样,即使黑客破解了账户信息也无法登录服务器,从而有效降低了破坏范围和影响。

  ftp 是Linux 系统中以命令行界面的方式来管理FTP 传输服务的客户端工具。安装:  

[root@localhost ~]# yum install ftp
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
... ...
Running transaction
  Installing : ftp-0.17-67.el7.x86_64                                                               1/1 
  Verifying  : ftp-0.17-67.el7.x86_64                                                               1/1 

Installed:
  ftp.x86_64 0:0.17-67.el7                                                                              

Complete!

  卸载:

[root@localhost ~]# rpm -qa | grep vsftpd
vsftpd-3.0.2-27.el7.x86_64
[root@localhost ~]# systemctl stop vsftpd.service 
[root@localhost ~]# rpm -e vsftpd-3.0.2-27.el7.x86_64
warning: /etc/vsftpd/vsftpd.conf saved as /etc/vsftpd/vsftpd.conf.rpmsave

2.匿名开放模式

  匿名开放模式一般用来访问不重要的公开文件(在生产环境中尽量不要存放重要文件)。

  vsftpd 服务程序默认开启了匿名开放模式,我们需要做的就是开放匿名用户的上传、下载文件的权限,以及让匿名用户创建、删除、更名文件的权限。

  可以向匿名用户开放的权限参数以及作用

    

[root@linuxprobe ~]# vim /etc/vsftpd/vsftpd.conf
1 anonymous_enable=YES
2 anon_umask=022
3 anon_upload_enable=YES
4 anon_mkdir_write_enable=YES
5 anon_other_write_enable=YES
6 local_enable=YES
7 write_enable=YES
8 local_umask=022
9 dirmessage_enable=YES
10 xferlog_enable=YES

  在 vsftpd 服务程序的主配置文件中正确填写参数,然后保存并退出。还需要重启vsftpd服务程序,让新的配置参数生效。一定要把配置过的服务程序加入到开机启动项中,以保证服务器在重启后依然能够正常提供传输服务:  

[root@localhost ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

  现在就可以在客户端使用软件连接到远程的FTP 服务器了。在vsftpd 服务程序的匿名开放认证模式下,其账户统一为anonymous,密码为空。而且在连接到FTP 服务器后,默认访问的是/目录。

   

   执行ftp 命令  

[C:\~]$ ftp 10.10.64.109


Connecting to 10.10.64.109:21...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
220 (vsFTPd 3.0.2)
Name (10.10.64.109:Hen): anonymous
331 Please specify the password.
Password:    //直接回车
230 Login successful.
ftp:/> 

ftp:/> cd pub
250 Directory successfully changed.
ftp:/pub> mkdir files
550 Create directory operation failed.

  系统显示拒绝创建目录!我们明明在前面清空了iptables 防火墙策略,而且也在vsftpd服务程序的主配置文件中添加了允许匿名用户创建目录和写入文件的权限啊。  

  在vsftpd 服务程序的匿名开放认证模式下,默认访问的是/var/ftp 目录。查看该目录的权限得知,只有root 管理员才有写入权限。

  下面将目录的所有者身份改成系统账户ftp 即可(该账户在系统中已经存在)  

[root@localhost ~]# ls -ld /var/ftp/pub/
drwxr-xr-x. 2 root root 6 Apr  1 12:55 /var/ftp/pub/
[root@localhost ~]# chown -Rf ftp /var/ftp/pub/
[root@localhost ~]# ls -ld /var/ftp/pub/
drwxr-xr-x. 2 ftp root 6 Apr  1 12:55 /var/ftp/pub/
[root@localhost ~]# ftp 10.10.64.109
Connected to 10.10.64.109 (10.10.64.109).
220 (vsFTPd 3.0.2)
Name (10.10.64.109:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> mkdir files
550 Create directory operation failed.

  系统再次报错!尽管我们在使用ftp 命令登入FTP 服务器后,再创建目录时系统依然提示操作失败,但是报错信息却发生了变化。在没有写入权限时,系统提示“权限拒绝”(Permission denied)。下面修改selinux。

  使用 getsebool 命令查看与FTP 相关的SELinux 域策略都有哪些:  

[root@localhost ~]# getsebool -a | grep ftp
ftpd_anon_write --> off
ftpd_connect_all_unreserved --> off
ftpd_connect_db --> off
ftpd_full_access --> off
ftpd_use_cifs --> off
ftpd_use_fusefs --> off
ftpd_use_nfs --> off
ftpd_use_passive_mode --> off
httpd_can_connect_ftp --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off
tftp_home_dir --> off

  可以根据经验(需要长期培养,别无它法)和策略的名称判断出是ftpd_full_access--> off策略规则导致了操作失败。接下来修改该策略规则,并且在设置时使用-P 参数让修改过的策略永久生效,确保在服务器重启后依然能够顺利写入文件。  

[root@localhost ~]# setsebool -P ftpd_full_access=on

  现在便可以顺利执行文件创建、修改及删除等操作了。  

[root@localhost ~]# ftp 10.10.64.109
Connected to 10.10.64.109 (10.10.64.109).
220 (vsFTPd 3.0.2)
Name (10.10.64.109:root): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> mkdir files
257 "/pub/files" created
ftp> rename files database
350 Ready for RNTO.
250 Rename successful.
ftp> rmdir database
250 Remove directory operation successful.
ftp> exit
221 Goodbye.

 

posted on 2020-09-24 20:57  星痕1216  阅读(403)  评论(0编辑  收藏  举报