近期服務(wù)器頻繁有被入侵的,大致分析了一下入侵行為,整理了需要做的安全策略:
管理機(jī)端設(shè)置:
1.跳板機(jī)權(quán)限只開放運(yùn)維人?
a.運(yùn)維人員密碼必須重新設(shè)置,密碼長(zhǎng)度不小于8位
b.密碼設(shè)置必須要有大小寫,數(shù)字,特殊字符組合。
c.強(qiáng)制90天更改密碼
d.設(shè)置密碼避免重復(fù)使用
e.個(gè)人賬戶設(shè)定登錄失敗次數(shù)為6次,一旦超過(guò)6次,將會(huì)鎖定賬號(hào)。
2.跳板機(jī)禁止root登錄,每周update
3.禁止在跳板機(jī)上保存登錄密碼,ip列表等信息,將history記錄默認(rèn)設(shè)置為500條。
4.修改PPTP vpn?務(wù)器賬戶密碼,定期更新補(bǔ)丁。
服務(wù)端設(shè)置:
a.登錄段配置同之前配置。
b.定期修改密碼。
c.服務(wù)器端每周update補(bǔ)丁。
d.禁用root直接登錄,創(chuàng)建運(yùn)維人員單獨(dú)賬號(hào)。必要時(shí)使用sudo成為root進(jìn)行管理
e.服務(wù)器禁止ping操作,增加安全性。
d.隱藏系統(tǒng)版本號(hào),防止版本信息泄露
d.優(yōu)化sysct.conf預(yù)防DDoS攻擊
e.定時(shí)檢查主要配置文件,系統(tǒng)主要目錄是否有異常,可通過(guò)MD5校驗(yàn)如發(fā)現(xiàn)有變動(dòng)重新分發(fā)一份。如/etc/passwd /etc/shadow /etc/group /etc/sysctl.conf, /bin /sbin等。
具體細(xì)節(jié)如下:
#設(shè)定用戶90天修改密碼,提前7天提醒
UserList=$(ls /home/|awk '{print $NF}'|grep -v lost+found)
for user in $UserList
do
chage -M 90 -W 7 $user
done
#禁ping
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
#設(shè)定用戶過(guò)期時(shí)間90默認(rèn)密碼長(zhǎng)度8位
cp /etc/login.defs /etc/login.defs.bak
sed -i '/PASS_MIN_LEN/s/[0-9]{1,6}/90/' /etc/login.defs
sed -i '/PASS_MIN_LEN/s/[0-9]{1,3}/8/' /etc/login.defs
#設(shè)定用戶登錄,普通用戶登錄識(shí)別超過(guò)6次鎖定300s.
echo "account required pam_tally.so deny=100 no_magic_root reset" >>/etc/pam.d/system-auth
echo "auth required pam_tally.so onerr=fail deny=6 unlock_time=300" >>/etc/pam.d/system-auth
#隱藏系統(tǒng)版本號(hào)
mv /etc/issue /etc/isseu
mv /etc/issue.net /etc/isseu.net
mv /etc/redhat-release /etc/rehdat-release
#優(yōu)化內(nèi)核參數(shù)
echo '
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536
# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536
# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736
# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296
# ------------- Kernel Optimization -------------
net.ipv4.tcp_max_tw_buckets = 60000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.ip_conntrack_max = 655360
net.ipv4.netfilter.ip_conntrack_max =655360
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 180 ' >>/etc/sysctl.conf
#生效
sysctl -p
#記錄histtory日志
echo '
#history
export HISTTIMEFORMAT="%F %T `whoami` "
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
HISTDIR=/usr/local/bin/.history
if [ -z $USER_IP ]
then
USER_IP=`hostname`
fi
if [ ! -d $HISTDIR ]
then
mkdir -p $HISTDIR
chmod 777 $HISTDIR
fi
if [ ! -d $HISTDIR/${LOGNAME} ]
then
mkdir -p $HISTDIR/${LOGNAME}
chmod 300 $HISTDIR/${LOGNAME}
fi
export HISTSIZE=4000
DT=`date +%Y%m%d_%H%M%S`
export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.history.$DT"
chmod 600 $HISTDIR/${LOGNAME}/*.history* 2>/dev/null '>>/etc/profile
#安全登錄
/etc/hosts.allow
#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
sshd:192.168.1.101
/etc/hosts.deny
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
sshd:all
#檢查防火墻配置(開放指定用戶地址登錄|服務(wù)地址開放用戶地址段)
iptables-save
#創(chuàng)建普通用戶
useradd mdf
echo -e 'pwd123456'|passwd mdf --stdin
#禁止root登錄權(quán)限
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
#優(yōu)化ssh鏈接慢問(wèn)題
sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i '/#UseDNS yes/aUseDNS no' /etc/ssh/sshd_config
/etc/init.d/sshd restart