// 密碼複雜度: 字母/數字/特殊符號,不小於8位; 用戶密碼 5 次不能重複;
vim /etc/pam.d/system-auth
auth required pam_tally2.so onerr=fail deny=3 unlock_time=1200 even_deny_root root_unlock_time=1200
auth sufficient pam_unix.so nullok try_first_pass remember=5
password requisite pam_cracklib.so retry=3 difork=3 minlen=8 lcredit=-1 dcredit=-1 ocredit=-1
// 設置按期修改密碼時間
vim /etc/login.defs
PASS_MAX_DAYS 90
PASS_MIN_DAYS 0
PASS_MIN_LEN 8
PASS_WARN_AGE 7
// 設置錯誤密碼登陸不超過3次, 超過鎖定20分鐘
find /lib* -iname "pam_tally2.so"
/lib64/security/pam_tally2.so
vim /etc/pam.d/sshd
auth required pam_tally2.so deny=3 unlock_time=12000
// 啓用auditd審計功能, 審計覆蓋到服務器及用戶
/etc/init.d/auditd start
// 記錄用戶的登陸與操做(操做日誌記錄 /tmp/dbasky/root/192.168.10.108\)
vim /etc/profile
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
if [ ! -d /tmp/dbasky ]
then
mkdir /tmp/dbasky
chmod 755 /tmp/dbasky
fi
if [ ! -d /tmp/dbasky/${LOGNAME} ]
then
mkdir /tmp/dbasky/${LOGNAME}
chmod 300 /tmp/dbasky/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date "+%Y-%m-%d_%H-%M-%S"`
export HISTFILE="/tmp/dbasky/${LOGNAME}/${USER_IP}-dbasky.$DT"
export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S]"
chmod 600 /tmp/dbasky/${LOGNAME}/*dbasky* 2>/dev/null
// 審計重要文件
auditctl -w /etc/passwd -p war ausearch -f /etc/passwd -x rm/vim.... // 查詢
vim /etc/audit/audit.rules ... ... // 添加(-w 路徑; -p 權限; -k 關鍵字 ;r 讀; w 寫; x 執行; a 修改文件屬性;)
-a exit,always -F arch=b64 -S umask -S chown -S chmod -a exit,always -F arch=b64 -S unlink -S rmdir -a exit,always -F arch=b64 -S setrlimit -a exit,always -F arch=b64 -S setuid -S setreuid -a exit,always -F arch=b64 -S setgid -S setregid -a exit,always -F arch=b64 -S sethostname -S setdomainname -a exit,always -F arch=b64 -S adjtimex -S settimeofday -a exit,always -F arch=b64 -S mount -S _sysctl -w /etc/group -p wa -w /etc/passwd -p wa -w /etc/shadow -p wa -w /etc/sudoers -p wa -w /etc/ssh/sshd_config -w /etc/bashrc -p wa -w /etc/profile -p wa -w /etc/profile.d/ -w /etc/aliases -p wa -w /etc/sysctl.conf -p wa -w /var/log/lastlog
// 審計工具
aureport // 生成審計活動概述;
* -au // 查看受權失敗的詳細信息;
* -m // 全部帳戶修改的相關事件;
// 建立審計用戶audit
useradd audit passwd audit 12tianrong. mkdir /tmp/dbasky chown -R audit.audit /var/log/audit/ chmod 750 /var/log/audit/ chmod 600 /var/log/audit/audit.log chown -R audit.audit /tmp/dbasky/ vim /etc/sudoers audit node2.hkrt.cn.com=/bin/ls,/bin/cat,/usr/bin/tail,/usr/bin/sz Defaults logfile=/var/log/sudo %wheel node2.hkrt.cn.com=/sbin/*,/usr/bin/*,/usr/sbin/*,!/sbin/reboot,!/sbin/init,!/sbin/poweroff,!/sbin/shutdown
// 保護審計進程,避免受到未預期的中斷
[root@localhost script]# vim audit_up.sh #!/bin/sh while true do ps -ef | grep " auditd" | grep -v "grep" if [ "$?" -eq 1 ] then /etc/init.d/auditd start echo "process has been restarted!" else echo "process already started!" fi sleep 10 done chmod +x audit_up.sh sh audit_up.sh >/dev/null &
// 審計記錄保留半年以上
// 定時任務每週將日誌內容切割分離
crontab -e 00 00 * * 1 /bin/mv /var/log/audit/audit.log /data/auditback/audit.log.$(date -d '1 days ago' +%d) mkdir -p /data/auditback
// 文件完整性
tar xf tripwire-2.4.2.2-src.tar.bz2 -C /usr/src/ cd /usr/src/tripwire-2.4.1.2-src/ ./configure --prefix=/usr/local/tripwire make && make install vim /usr/local/tripwire/etc/twcfg 9 LOOSEDIRECTORYCHECKING =true // 不監測所屬目錄的完整性
12 REPORTLEVEL =4 // 改變監測結果報告等級
// 創建加密格式
cd /usr/local/tripwire/etc/ /usr/local/tripwire/sbin/twadmin --create-cfgfile -S site.key twcfg.txt
/usr/local/tripwire/sbin/tripwire --init // 初始化數據庫
/usr/local/tripwire/sbin/tripwire --init /usr/local/tripwire/sbin/tripwire --check --interactive find / -type f -name *.twr // 生成的檢測文件
/usr/local/tripwire//sbin/twprint --print-report --twrfile /usr/local/tripwire/lib/tripwire/report/node2.hkrt.cn.com-20180318-002054.twr # 查看檢查記錄;
// 防惡意代碼軟件
tar xf maldetect-current.tar.gz -C /usr/src/ cd /usr/src/maldetect-1.6.2/ ./install.sh maldet --scan-all / // 檢測
// 存儲路徑
/usr/local/maldetect/sess/session.180316-0921.16896 /usr/local/maldetect/sess/session.hits.180316-0921.16896
// 單個用戶系統資源(CPU、內存、硬盤)的使用限度進行限制
// 之後每一個一分鐘就會檢查一次,調整佔用50%以上CPU或25%內存的進程的nice值,從而使這樣的進程優先級變低,被調度的機會減小,同時會向root發郵件提示該進程被調整過。
cd /script vim cpu.sh #!/bin/sh PIDS=`top -bn 1 | grep "^ *[1-9]" | awk '{ if($9 > 50 || $10 > 25 && id -u $2 > 500) print $1}'` for PID in $PIDS do renice +10 $PID echo "renice +10 $PID" done chmod +x /script/cpu.sh crontab -e * * * * * /scripts/cpu.sh >/dev/null
// 系統的最大併發會話鏈接數進行限制(注意新建Xshell,嘗試是否能鏈接)
ulimit -n 8192 /etc/sysctl.conf中加入ip_conntrack_max=8192 /usr/include/bits/types.h 文件,改變__FD_SETSIZE 的值: #define _ _FD_SETSIZE 8192 echo 8192 > /proc/sys/fs/file-max ulimit -Hn 8192
執行sysctl -p 生效..
/bin/bash: Too many open files in system 報錯
修改 /proc/sys/fs/file-max 執行上述命令生效