ter2w 发表于 2015-3-9 08:43:29

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

1.关闭匿名用户登录ftp支持匿名登录是不安全,所以要禁止匿名ftp登录
在/etc/vsftpd/vsftpd.conf修改以下三项
anonymous_enable=NO
#anon_upload_enable=YES
#anon_mkdir_write_enable=YES

# service vsftpd restart
关闭vsftpd:                                             [确定
为vsftpd启动vsftpd:                                     [确定
# 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
# useradd -s /sbin/nologin viong
建设一个不能登录系统用户. 只用来登录ftp服务 ,这里如果没设置用户目录。默认是在home下

# passwd viong
Changing password for user viong.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
# 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.cfginstall.loginstall.log.syslogpasswdviong.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即可

# ls /etc/vsftpd/ chroot_list
默认是不存在,需要我们手动建立
ftpusersuser_listvsftpd.confvsftpd_conf_migrate.sh

# touch /etc/vsftpd/chroot_list
# cut -d : -f1 /etc/passwd>>/etc/vsftpd/chroot_list
把本地用户都加入到chroot_list

cut命令是切去某一列,-d是每列的分隔符,-f 是切取第几列,然后重定向到chroot文件

# ll /etc/vsftpd/
总计 24
-rw-r--r-- 1 root root197 12-25 19:57 chroot_list
-rw--------1 root root 125 2007-12-13 ftpusers
ftpusers指的是阻止这个文件中的用户登陆
-rw------- 1 root root361 2007-12-13 user_list
-rw------- 1 root root 4396 12-25 19:19 vsftpd.conf
-rwxr--r-- 1 root root338 2007-12-13 vsftpd_conf_migrate.sh

(2)限制重要系统用户不能登录ftp权限
# 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

# echo viong >> /etc/vsftpd/ftpusers
把之前建的viong账号加进去测试

# 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

# service vsftpd restart
关闭vsftpd:                                             [确定
为vsftpd启动vsftpd:                                     [确定

# 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.
# echo viong >> /etc/vsftpd/user_list
把viong账号加入到 user_list

# 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:\Users\Administrator>ipconfig 查看本地ip

...................................

以太网适配器 VMware Network Adapter VMnet1:6

   连接特定的 DNS 后缀 . . . . . . . :
   IPv4 地址 . . . . . . . . . . . . : 192.168.184.1
   子网掩码. . . . . . . . . . . . : 255.255.255.0
   默认网关. . . . . . . . . . . . . :

只允许这个ip地址访问ftp ssh,可以写条iptable做限制.
如下:

# iptables -A INPUT -p tcp -s 192.168.184.1 --dport 22 -j ACCEPT允许192.168.184.1访问本地 22端口# iptables -A INPUT -p tcp -s 192.168.184.1 --dport 21 -j ACCEPT允许192.168.184.1访问本地 21端口# iptables -A INPUT -p tcp -s 192.168.184.1 --dport 65341:65351 -j ACCEPT允许192.168.184.1访问本地 PASV端口 # iptables -P INPUT DROP禁止任何输入的数据包# service iptables save 保存iptables设置将当前规则保存到 /etc/sysconfig/iptables:               [确定# service iptables status 检查iptables的设置表格:filterChain INPUT (policy DROP)numtarget   prot opt source               destination         1    RH-Firewall-1-INPUTall--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:214    ACCEPT    tcp -192.168.184.1      0.0.0.0/0      tcp dpts:65341:65351
页: [1]
查看完整版本: Vsftpd完全攻略(三)基于系统用户支持ftp上传 访问和vsftp安全设置