vsftpd禁用匿名用戶
修改vasftpd服務(wù)的配置文件/etc/vsftpd.conf(或/etc/vsftpd/vsftpd.conf)
anonymous_enable=NO
#Options Indexes FollowSymLinks #刪掉Indexes
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
將Options Indexes FollowSymLinks中的Indexes去掉,就可以禁止 Apache 顯示該目錄結(jié)構(gòu)。
Indexes的作用就是當(dāng)該目錄下沒有 index.html 文件時(shí),自動顯示目錄結(jié)構(gòu)
使用open_basedir選項(xiàng)能夠控制 PHP 腳本只能訪問指定的目錄,這樣能夠避免 PHP 腳本訪問不應(yīng)該訪問的文件,一定程度下降低了 phpshell 的危害。一般情況下,可以設(shè)置為只能訪問網(wǎng)站目錄:
open_basedir = /var/www/html/files
設(shè)置不允許通過root賬戶進(jìn)行ssh登錄系統(tǒng)
# vi /etc/ssh/sshd_config
在文件中找到下面一行文字:
#PermitRootLogin no
去掉該行前面的#號,使其成為下面這樣:
PermitRootLogin no
接下來,在shell中輸入以下命令來重啟ssh服務(wù)
# service sshd restart
MYSQL關(guān)閉TCP/IP遠(yuǎn)程連接
/etc/my.cnf 配置文件中進(jìn)行
–skip-networking
開啟SYN Cookie內(nèi)核參數(shù)
sysctl -w net.ipv4.tcp_syncookies=1
數(shù)據(jù)庫安全加固
一般情況下我們要想辦法登錄自己的數(shù)據(jù)庫靶機(jī)進(jìn)行加固
在終端中輸入
mysql -u root -p root
登錄數(shù)據(jù)庫
查看數(shù)據(jù)庫版本號:select version();
查看數(shù)據(jù)庫列表:show databases;
查看任意用戶:
使用命令use mysql;選擇MySQL庫
然后使用命令show tables;查看數(shù)據(jù)庫中的表
使用命令select user,host from user where host=’%’;
找到用戶test
刪除任意用戶::
使用命令drop user ‘test’@’%’;
修改默認(rèn)管理員用戶名:
使用命令update user set user=’admin’ where user=’root’;
Linux安全加固:
linux安全限制
vi /etc/profile 新加入:TMOUT=600? //600秒無操作,自動退出文章來源:http://www.zghlxwxcb.cn/news/detail-498639.html
?[root@station90 桌面]# awk -F : '($2=="") {print $1}' /etc/shadow //檢查空口令帳號
zhang3
[root@station90 桌面]# tail -n 1 /etc/shadow | head -n 1 //-F :是以冒號作為分隔符,($2==""表示第1個(gè)和第2個(gè)冒號之間是空的,即空口令帳號,{print $1}打印出用戶名
zhang3::15071:0:99999:7:::
檢查帳號
[root@station90 桌面]# pwck
用戶 adm:目錄 /var/adm 不存在
用戶 news:目錄 /etc/news 不存在
用戶 uucp:目錄 /var/spool/uucp 不存在
用戶 gopher:目錄 /var/gopher 不存在
用戶 pcap:目錄 /var/arpwatch 不存在
用戶 avahi-autoipd:目錄 /var/lib/avahi-autoipd 不存在
用戶 oprofile:目錄 /home/oprofile 不存在
pwck:無改變
口令復(fù)雜度及登錄失敗策略
應(yīng)啟用登錄失敗處理功能,可采取結(jié)束會話,限制非法登錄次數(shù)和自動退出措施,口令應(yīng)有復(fù)雜度要求并定期更換
要求強(qiáng)制記住3個(gè)密碼歷史
口令至少包含1個(gè)數(shù)字,字母和其他特殊字符(如:#,@,!,$等);
5次遠(yuǎn)程登錄失敗自動結(jié)束會話
[root@station90 桌面]# cat /etc/login.defs | grep PASS | grep -v ^#
PASS_MAX_DAYS 90 //口令最大使用日期90天
PASS_MIN_DAYS 0 //若設(shè)置為2,則設(shè)置密碼2天后才可以再次更改密碼,即密碼至少要保留的天數(shù)
PASS_MIN_LEN 8 //口令最小長度8位
PASS_WARN_AGE 7 //口令過期前7天警告
[root@station90 pam.d]# cat /etc/pam.d/system-auth | tail -n 2 && grep ^#password /etc/pam.d/system-auth
password required pam_cracklib.so difok=3 minlen=8 dcredit=-1,lcredit=-1 ocredit=-1 maxrepeat=3
password required pam_unix.so use_authtok nullok md5
#password requisite pam_cracklib.so try_first_pass retry=3 //注釋這一行后,無法修改密碼
[root@station90 pam.d]# passwd
Changing password for user root.
passwd: Authentication information cannot be recovered
修改登錄失敗策略
[root@station90 ssh]# cat /etc/ssh/sshd_config | grep MaxAuth
MaxAuthTries 1 //遠(yuǎn)程用戶通過ssh連接登錄2次失敗后自動結(jié)束會話
[root@station90 ssh]# ssh 192.168.0.90
root@192.168.0.90's password:
Permission denied, please try again.
root@192.168.0.90's password:
Received disconnect from 192.168.0.90: 2: Too many authentication failures for root
關(guān)閉telnet服務(wù),redhat默認(rèn)是關(guān)閉telnet服務(wù)的
[root@station90 ssh]# netstat -tnlp | grep :23
[root@station90 ssh]# cd /etc/xinetd.d/
[root@station90 xinetd.d]# ls telnet*
ls: telnet*: 沒有那個(gè)文件或目錄
如果有telnet服務(wù),則把該目錄下的telnet文件改為disable=yes
[root@station90 xinetd.d]# tail -n 2 /etc/xinetd.d/krb5-telnet | head -n 1
disable = yes
[root@station90 xinetd.d]# service xinetd restart
停止 xinetd: [確定]
啟動 xinetd: [確定]
[root@station90 xinetd.d]# chkconfig xinetd on
openssh應(yīng)該禁止使用協(xié)議1,禁止root直接登錄
/etc/ssh/sshd_config
Protocol 2
MaxAuthTries 1
PermitRootLogin no //不允許root用戶使用ssh登錄
StrictModes yes
PermitEmptyPasswords no //不允許使用空密碼登錄
PrintLastLog yes
[root@station60 init.d]# pwd
/etc/rc.d/init.d
[root@station60 init.d]# chmod -R 750 ./ 也可以直接chmod -R /etc/init.d/*
[root@station60 init.d]# ll | head -n 2
total 644
-rwxr-x--- 1 root root 1566 Jun 8 2009 acpid
umask至少為027,最好是077
[root@station60 ~]# grep umask /etc/bashrc
umask 077
umask 077
[root@station60 ~]# . /etc/bashrc
[root@station60 ~]# umask
0077
[root@station60 ~]# touch 3.txt
[root@station60 ~]# ll 3.txt
-rw------- 1 root root 0 Apr 8 00:11 3.txt
檢查系統(tǒng)是否最小化安裝,啟動的運(yùn)行級別為3
查看/etc/pam.d/su是否包含以下兩行
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth required pam_wheel.so use_uid //上面的注釋已經(jīng)說的很清楚了,沒有注釋下面這一行,那么要su到別的用戶就必須在wheel組中
[root@station60 pam.d]# gpasswd -a oracle wheel
Adding user oracle to group wheel
[root@station60 pam.d]# id oracle
uid=500(oracle) gid=500(oracle) groups=500(oracle),0(root),10(wheel) context=system_u:system_r:unconfined_t
[root@station60 pam.d]# id zhang3
uid=501(zhang3) gid=501(zhang3) groups=501(zhang3) context=system_u:system_r:unconfined_t
[root@station60 pam.d]# su - zhang3
[zhang3@station60 ~]$ su - root //以下密碼輸入都是正確的
Password:
su: incorrect password
[zhang3@station60 ~]$ su - oracle
Password:
su: incorrect password
[zhang3@station60 ~]$ su - oracle
Password:
su: incorrect password
[zhang3@station60 ~]$ su - oracle
Password:
su: incorrect password
[zhang3@station60 ~]$
[oracle@station60 ~]$ su - oracle
Password:
[oracle@station60 ~]$ su - root
Password:
[root@station60 ~]#
操作指南 1.本地登錄用戶參考配置操作
#cd /etc/profile.d
執(zhí)行
#vi autologout.sh
加入如下內(nèi)容:
TMOUT=600
readonly TMOUT
export TMOUT
保存退出,系統(tǒng)將在用戶閑置10分鐘后自動注銷。
2.遠(yuǎn)程登錄用戶參考配置操作
#vi /etc/ssh/sshd_config
將以下內(nèi)容設(shè)置為:
ClientAliveInterval 600
ClientAliveCountMax 0
以上表示10分鐘閑置后,自動注銷并結(jié)束會話。
檢測方法 1、判定條件
查看帳號超時(shí)是否自動注銷;
2、檢測操作
cat /etc/ssh/sshd_config
檢查其中兩個(gè)參數(shù)設(shè)置:
ClientAliveInterval 600
ClientAliveCountMax 0
(2)執(zhí)行:awk -F: '($3 == 0) { print $1 }' /etc/passwd
返回值包括“root”以外的條目,說明有其他超級用戶,低于安全要求。
2、檢測操作
執(zhí)行:awk -F: '($3 == 0) { print $1 }' /etc/passwd
返回值包括“root”以外的條目,說明有其他超級用戶;
/etc/securetty 文件設(shè)置root登陸的tty和vc(虛擬控制臺)設(shè)備。/etc/securetty 文件被login程序讀 (通常 /bin/login)。它的格式是允許的tty和vc列表,注釋掉或不出現(xiàn)的設(shè)備,不允許root登陸。
vc/1
#vc/2
#vc/3
#vc/4
#vc/5
#vc/6
#vc/7
#vc/8
#vc/9
#vc/10
#vc/11
tty1
#tty2
#tty3
#tty4
#tty5
#tty6
#tty7
#tty8
#tty9
#tty10
#tty11
root只能從tty1和vc登陸。建議僅允許root從一個(gè)tty或vc登陸,如果需要更多設(shè)備登陸,使用su命令轉(zhuǎn)換為root。
#!/bin/sh
#
export file=/root/Desktop/Look_Here
echo "These username have null code" >> $file
awk -F : '($2 =="") {print $1}' /etc/shadow >> $file
#change system code policy
#1 login /etc/login.defs
perl -i -pe 's,99999,90,g' /etc/login.defs
sed -i.bak '18s/5/8/' /etc/login.defs
echo "PASS_MIN_LEN 8">> /etc/login.defs
#2 pam /etc/pam.d/system-auth
echo "password required pam_cracklib.so difok=3 minlen=8 dcredit=-1 lcredit=-1 ocredit=-1 maxrepeat=3" >>/etc/pam.d/system-auth
echo "password required pam_unix.so use_authtok nullok md5 " >> /etc/pam.d/system-auth
sed -i.bak '13s/password/#password/' /etc/pam.d/system-auth
#perl -i -pe 's/password requisite pam_cracklib.so try_first_pass retry=3/#password requisite pam_cracklib.so try_first_pass retry=3'/g /etc/pam.d/system-auth
#3 ssh /etc/ssh/sshd_config
perl -i -pe 's/#MaxAuthTries 6/MaxAuthTries 5/g' /etc/ssh/sshd_config
#4 telnet /etc/xinetd.d/telnet
(chkconfig telnet off 2>&1) > /dev/null
#5 ssh /etc/ssh/sshd_config
perl -i -pe 's/#StrictModes/StrictModes/' /etc/ssh/sshd_config
perl -i -pe 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
perl -i -pe 's/#PermitEmptyPasswords/PermitEmptyPasswords/' /etc/ssh/sshd_config
#6 umask /etc/bashrc
perl -i -pe 's/umask 002/umask 077/' /etc/bashrc
perl -i -pe 's/umask 022/umask 077/' /etc/bashrc
source /etc/bashrc
#7 runlevel 3 /etc/inittab
perl -i -pe 's/id:5/id:3/' /etc/inittab
#8 /etc/pam.d/su
sed -i.bak '6s/#auth/auth/' /etc/pam.d/su
#9 securetty /etc/securetty
perl -i -pe 's/^/#/g' /etc/securetty
echo "vc/1" >> /etc/securetty
echo "tty1" >> /etc/securetty
#10 uid=0
echo "These username's uid is 0" >> $file
awk -F : '($3==0) {print $1}' /etc/passwd > $file
#11 auto logout /etc/profile.d/
echo "TMOUT=600" >/etc/profile.d/autologout.sh
echo "readonly TMOUT">>/etc/profile.d/autologout.sh
echo "export TMOUT" >>/etc/profile.d/autologout.sh
chmod +x /etc/profile.d/autologout.sh
#12 ssh ClientAliveInterval
perl -i -pe 's/#ClientAlive/ClientAlive/g' /etc/ssh/sshd_config
sed -i.bak '106s/0/600/g' /etc/ssh/sshd_config
sed -i.bak '107s/3/0/g' /etc/ssh/sshd_config
#13 chmod chattr
chmod 400 /etc/shadow /etc/gshadow
chmod 600 /boot/grub/grub.conf /etc/securetty
chattr +a /var/log/messages
chattr +i /var/log/messages
chattr +i /etc/passwd
chattr +i /etc/shadow
chattr +i /etc/gshadow
chattr +i /etc/group
chattr +i /etc/services
chattr +i /etc/securetty
(service sshd restart;chkconfig sshd on) > /dev/null文章來源地址http://www.zghlxwxcb.cn/news/detail-498639.html
到了這里,關(guān)于網(wǎng)絡(luò)安全運(yùn)維-安全加固篇的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!