• Vsftpd完全攻略(三)基于系统用户支持ftp上传 访问和vsftp安全设置


    原文链接:http://viong.blog.51cto.com/844766/261342

    1.关闭匿名用户登录

    ftp支持匿名登录是不安全,所以要禁止匿名ftp登录
    /etc/vsftpd/vsftpd.conf修改以下三项
    anonymous_enable=NO
    #anon_upload_enable=YES
    #anon_mkdir_write_enable=YES
     
    [root@red-hat-5 ~]# service vsftpd restart
    关闭vsftpd                                             [确定]
    vsftpd启动vsftpd                                     [确定]
    [root@red-hat-5 ~]# ftp 127.0.0.1
    Connected to 127.0.0.1.
    220 (vsFTPd 2.0.5)
    530 Please login with USER and PASS.
    530 Please login with USER and PASS.
    KERBEROS_V4 rejected as an authentication type
    Name (127.0.0.1:root): anonymous
    331 Please specify the password. ------>提示登录失败,说明已经禁
                                    用匿名登录
    Password:
    530 Login incorrect.
    Login failed.
     

    2.创建一个系统用户来登录ftp

     
    [root@red-hat-5 ~]# useradd -s /sbin/nologin viong
    建设一个不能登录系统用户. 只用来登录ftp服务 ,这里如果没设置用户目录。默认是在home
     
    [root@red-hat-5 ~]# passwd viong
    Changing password for user viong.
    New UNIX password:
    Retype new UNIX password:
    passwd: all authentication tokens updated successfully.
    [root@red-hat-5 ~]# ftp 127.0.0.1
    Connected to 127.0.0.1.
    220 (vsFTPd 2.0.5)
    530 Please login with USER and PASS.
    530 Please login with USER and PASS.
    KERBEROS_V4 rejected as an authentication type
    Name (127.0.0.1:root): viong
    331 Please specify the password. ------>提示登录成功
    Password:
    230 Login successful.
    Remote system type is UNIX.
    Using binary mode to transfer files.
     
    接下来测试权限
     
    ftp> put viong.txt 上传viong.txt文件成功
    local: viong.txt remote: viong.txt
    227 Entering Passive Mode (127,0,0,1,98,115)
    150 Ok to send data.
    226 File receive OK.
    ftp> mkdir hong 创建hong目录文件成功
    257 "/home/viong/hong" created
    ftp> rmdir hong 删除hong目录文件成功
    250 Remove directory operation successful.
    ftp> pwd  显示家目录
    257 "/home/viong"
    ftp> cd /etc 切换/etc成功
    250 Directory successfully changed.
    ftp> mget passwd 下载passwd
    mget passwd?
    227 Entering Passive Mode (127,0,0,1,220,77)
    150 Opening BINARY mode data connection for passwd (1429 bytes).
    226 File send OK.
    1429 bytes received in 5.9e-05 seconds (2.4e+04 Kbytes/s)
    ftp> !ls 显示下载passwd成功
    anaconda-ks.cfg  install.log  install.log.syslog  passwd  viong.txt
     

    3.加强vsftp安全设置

    从以上可以看出ftp家目录存在安全漏洞,所以要修改以下设置:

    (1)限制系统用户锁定在家目录

     
    Vi /etc/vsftpd/vsftpd.conf
     
    去掉前面#
    chroot_list_enable=YES
    chroot_list_file=/etc/vsftpd/chroot_list 限制更多系统用户
     
    然后把所有用户加入/etc/vsftpd/chroot_list即可
     
    [root@red-hat-5 ~]# ls /etc/vsftpd/ chroot_list
    默认是不存在,需要我们手动建立
    ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh
     
    [root@red-hat-5 ~]# touch /etc/vsftpd/chroot_list
    [root@red-hat-5 ~]# cut -d : -f  1 /etc/passwd>>/etc/vsftpd/chroot_list
    把本地用户都加入到chroot_list
     
    cut命令是切去某一列-d是每列的分隔符-f 是切取第几列然后重定向到chroot文件
     
    [root@red-hat-5 ~]# ll /etc/vsftpd/
    总计 24
    -rw-r--r-- 1 root root  197 12-25 19:57 chroot_list
    -rw--------1 root root 125 2007-12-13 ftpusers
     ftpusers指的是阻止这个文件中的用户登陆
    -rw------- 1 root root  361 2007-12-13 user_list
    -rw------- 1 root root 4396 12-25 19:19 vsftpd.conf
    -rwxr--r-- 1 root root  338 2007-12-13 vsftpd_conf_migrate.sh
     

    (2)限制重要系统用户不能登录ftp权限

     
    [root@red-hat-5 ~]# cat /etc/vsftpd/ftpusers
    默认会加入一些比较重要系统用户
    # Users that are not allowed to login via ftp
    root
    bin
    daemon
    adm
    lp
    sync
    shutdown
    halt
    mail
    news
    uucp
    operator
    games
    nobody
     
     [root@red-hat-5 ~]# echo viong >> /etc/vsftpd/ftpusers
     把之前建的viong账号加进去测试
     
    [root@red-hat-5 ~]# ftp 127.0.0.1
    Connected to 127.0.0.1.
    220 (vsFTPd 2.0.5)
    530 Please login with USER and PASS.
    530 Please login with USER and PASS.
    KERBEROS_V4 rejected as an authentication type
    Name (127.0.0.1:root): viong
    331 Please specify the password.  ----->提示登录失败,说明生效了
    Password:
    530 Login incorrect.
    Login failed.
     

    (3)利用ftp用户策略允许登录ftp的系统用户

     
    系统添加一个用户也默认有ftp的登陆权限,是不安全,要一个个设置,有点繁琐。利用ftp用户策略解决这个问题,user_list文件设置,只有user_list中存在的用户才能登录系统
     
    修改配置文件:vi  /etc/vsftpd/vsftpd.conf
     
    userlist_enable=YES文件后面添加
    userlist_deny=NO
    userlist_file=/etc/vsftpd/user_list
     
    [root@red-hat-5 ~]# service vsftpd restart
    关闭vsftpd                                             [确定]
    vsftpd启动vsftpd                                     [确定]
     
    [root@red-hat-5 ~]# ftp 127.0.0.1
    Connected to 127.0.0.1.
    220 (vsFTPd 2.0.5)
    530 Please login with USER and PASS.
    530 Please login with USER and PASS.
    KERBEROS_V4 rejected as an authentication type
    Name (127.0.0.1:root): viong
    530 Permission denied.   ------------->提示登录失败
    Login failed.
    [root@red-hat-5 ~]# echo viong >> /etc/vsftpd/user_list
    viong账号加入到 user_list
     
    [root@red-hat-5 ~]# ftp 127.0.0.1
    Connected to 127.0.0.1.
    220 (vsFTPd 2.0.5)
    530 Please login with USER and PASS.
    530 Please login with USER and PASS.
    KERBEROS_V4 rejected as an authentication type
    Name (127.0.0.1:root): viong
    331 Please specify the password.  ------------->提示登录成功
    Password:
    230 Login successful.
    Remote system type is UNIX.
    Using binary mode to transfer files.
     

    (4)设置登录ftp目标ip地址

     
    为了让ftp更安全,我们设置ftp目标ip地址访问
     
    C:UsersAdministrator>ipconfig 查看本地ip
     
    ...................................
     
    以太网适配器 VMware Network Adapter VMnet1:6
     
       连接特定的 DNS 后缀 . . . . . . . :
       IPv4 地址 . . . . . . . . . . . . : 192.168.184.1
       子网掩码  . . . . . . . . . . . . : 255.255.255.0
       默认网关. . . . . . . . . . . . . :
     
    只允许这个ip地址访问ftp ssh,可以写条iptable做限制.
    如下:
     
    [root@red-hat-5 ~]# iptables -A INPUT -p tcp -s 192.168.184.1 --dport 22 -j ACCEPT
    允许192.168.184.1访问本地 22端口
    [root@red-hat-5 ~]# iptables -A INPUT -p tcp -s 192.168.184.1 --dport 21 -j ACCEPT
    允许192.168.184.1访问本地 21端口
    [root@red-hat-5 ~]# iptables -A INPUT -p tcp -s 192.168.184.1 --dport 65341:65351 -j ACCEPT
    允许192.168.184.1访问本地 PASV端口
     
    [root@red-hat-5 ~]# iptables -P INPUT DROP  禁止任何输入的数据包
    [root@red-hat-5 ~]# service iptables save 保存iptables设置
    将当前规则保存到 /etc/sysconfig/iptables:                 [确定]
    [root@red-hat-5 ~]# service iptables status 检查iptables的设置
    表格:filter
    Chain INPUT (policy DROP)
    num  target     prot opt source               destination        
    1    RH-Firewall-1-INPUT  all  --  0.0.0.0/0            0.0.0.0/0          
    2    ACCEPT     tcp  --  192.168.184.1        0.0.0.0/0           tcp dpt:22
    3    ACCEPT     tcp  --  192.168.184.1        0.0.0.0/0           tcp dpt:21

    4    ACCEPT    tcp -192.168.184.1        0.0.0.0/0      tcp dpts:65341:65351

  • 相关阅读:
    006开源O/R映射框架内容回顾
    005---query接口初步
    004---持久对象的生命周期介绍
    C++中计算矩阵的行列式
    异面直线判定
    华夏万家不投资最佳激活顺序
    飞行目标定位测量相关文献记录
    程序运行缺少MSVCR110.dll
    C++中的return返回值:return0 or return -1?
    办宽带
  • 原文地址:https://www.cnblogs.com/hubery/p/3647384.html
Copyright © 2020-2023  润新知