CentOS6系列加固指南V12.docx
《CentOS6系列加固指南V12.docx》由会员分享,可在线阅读,更多相关《CentOS6系列加固指南V12.docx(14页珍藏版)》请在冰豆网上搜索。
CentOS6系列加固指南V12
CentOS6系列加固指南
CentOS6加固指南
目的:
本文档可作为CentOS6加固的基本操作指导
历史记录:
作者:
描述:
生成日期:
备注
David
v1.2
2014-11-11
创建
内容:
目录
安装部分4
1.启用防火墙4
2.建立初始账户和组4
加固部分5
1.SSH加固5
2.使用PAM仅允许SYS组用户可以使用su到root5
3.帐号策略加固5
4.最小服务原则6
5.命令限制7
6.禁用CTRL-ALT-DELETE重启(检查)7
7.历史命令条数限制7
8.日志记录服务开启8
9.用户执行命令记录到syslog8
10.时钟同步8
11.删除无用帐号和组9
12.配置账户超时自动注销9
13.防止IP地址欺骗(可选)9
14.重要配置文件保护标记9
15.ROOT用户创建文件初始权限提升10
16.系统启动级别设置(检查)10
17.系统未屏蔽登录提示信息10
18.指定允许root登陆的TTY设备10
19.限制/etc/rc.d/init.d/目录下脚本文件的权限11
20.加固部分带临时权限的程序(“s”位权限的程序)11
21.更新防火墙规则11
22.额外安全脚本14
安装部分(需补充)
1.启用防火墙
启用防火墙,开放ssh端口
2.建立初始账户和组
1、建立SYS(系统组)用户组;
2、给所有SYS成员分配帐号,并都属于SYS组;
加固部分
1.SSH加固
sshd_config配置:
修改前
修改后
#Authentication:
#LoginGraceTime2m
#PermitRootLoginyes
#StrictModesyes
#MaxAuthTries6
……
#UseDNSyes
#Authentication:
LoginGraceTime30s
PermitRootLoginno#禁止root直接远程登录
StrictModesyes
MaxAuthTries3
……
UseDNSno
chattr+i/etc/ssh/sshd_config
2.使用PAM仅允许SYS组用户可以使用su到root
编辑su文件(vi/etc/pam.d/su),在开头添加下面两行:
authsufficient/lib/security/pam_rootok.so
authrequired/lib/security/pam_wheel.sogroup=SYS这表明只有SYS组的成员可以使用su命令成为root用户。
你可以把用户添加到SYS组,以使它可以使用su命令成为root用户。
添加方法为:
#usermod-a-GSYSusername#添加用户到组SYS
#usermod-GSYSusername#更改用户到组SYS
#usermod-gSYSusername#强制更改用户到组SYS
3.帐号策略加固
Vim/etc/login.defs
#Passwordagingcontrols:
#PASS_MAX_DAYSMaximumnumberofdaysapasswordmaybeused.
#PASS_MIN_DAYSMinimumnumberofdaysallowedbetweenpasswordchanges.
#PASS_MIN_LENMinimumacceptablepasswordlength.
#PASS_WARN_AGENumberofdayswarninggivenbeforeapasswordexpires.
PASS_MAX_DAYS90
PASS_MIN_DAYS0
PASS_MIN_LEN8
PASS_WARN_AGE15
4.最小服务原则
禁用netfs服务(非挂载需求时)
servicenetfsstop
chkconfig--level12345netfsoff
禁用acpid服务
serviceacpidstop
chkconfig--level12345acpidoff
禁用haldaemon服务
servicehaldaemonstop
chkconfig--level12345haldaemonoff
禁用rpcgssd服务(除非你需要或使用NFSv4,否则关闭它。
)
servicerpcgssdstop
chkconfig--level12345rpcgssdoff
禁用nfs服务(可选)
servicenfsstop
chkconfig--level12345nfsoff
禁用nfslock服务
servicenfslockstop
chkconfig--level12345nfslockoff
禁用autofs服务
serviceautofsstop
chkconfig--level12345autofsoff
禁用cups服务
servicecupsstop
chkconfig--level12345cupsoff
禁用sendmail服务(可选)
servicesendmailstop
chkconfig--level12345sendmailoff
禁用ip6tables服务
serviceip6tablesstop
chkconfig--level12345ip6tablesoff
5.命令限制
chmod700/usr/bin/finger
chmod700/usr/bin/who
chmod700/usr/bin/w
chmod700/usr/bin/whereis
chmod700/sbin/ifconfig
chmod700/usr/bin/which
chmod700/usr/bin/gcc
chmod700/usr/bin/make
chmod700/bin/rpm
6.禁用CTRL-ALT-DELETE重启(检查)
修改/etc/inittab文件,注释下面行
ca:
:
ctrlaltdel:
/sbin/shutdown-t3-rnow
7.历史命令条数限制
修改/etc/profile文件中
HISTSIZE=1000该为HISTSIZE=20
若存在HISTFILESIZE=1000,应改为HISTFILESIZE=20
在“~/.bash_logout”文件中添加下面这行“rm-f$HOME/.bash_history”。
这样,当用户每次注销时,.bash_history文件都会被删除。
编辑.bash_logout文件(vi~/.bash_logout),添加下面这行:
rm-f$HOME/.bash_history
8.日志记录服务开启
syslog.conf文件中添加日志外发syslog服务器地址,并重启syslog服务。
vi/etc/syslog.conf
结尾添加如下两行:
*.*@xxx.xxx.xxx.xxx
kern.warning/var/log/iptables#用于记录iptablesDROP
#志
servicesyslogrestart
9.用户执行命令记录到syslog
如下脚本实现,
if!
egrep-q"local5\.\*\*\/var\/log\/history.log"/etc/rsyslog.conf;then
echo'local5.*/var/log/history.log'>>/etc/rsyslog.conf
else
echo"commandhistoryloggingwithin/etc/rsyslog.confalreadydone."
fi
if!
egrep-q"functionhistory_to_syslog"/etc/profile;then
cat>>/etc/profile<<\EOF
functionhistory_to_syslog
{
declarecmd
cmd=$(echo`history|tail-n1|cut-c7-`|sed-lne's/-/_/g')
logger-plocal5.notice[$$:
$USER]-$cmd
}
traphistory_to_syslogDEBUG
EOF
10.时钟同步
为了便于分析log,每台服务器需要进行时钟同步(ntp)
11.删除无用帐号和组
userdellp
userdelgames
userdeladm
userdelshutdown
userdeluucp
userdeloperator
userdelgopher
userdelftp
groupdellp
groupdelgames
groupdeladm
groupdeluucp
groupdeldip
12.配置账户超时自动注销
#vi/etc/profile
在“HISTFILESIZE=”后面加入下面这行:
TMOUT=1800#登录的账户半小时内没动作自动注销
13.防止IP地址欺骗(可选)
在/etc/hosts文件中增加如下行:
nospoofon
“nospoof on”可以使系统通过逆向解析的方式防止IP欺骗。
14.重要配置文件保护标记
chattr+i/etc/login.defs
chattr+i/etc/ssh/sshd_config
15.ROOT用户创建文件初始权限提升
umask027
执行该命令并添加到/etc/bashrc文件末尾。
16.系统启动级别设置(检查)
#vi/etc/inittab
将下面一行
id:
5:
initdefault:
改为
id:
3:
initdefault:
3表示系统启动后进入多用户模式,5表示系统启动后进入Xwindows模式。
17.系统未屏蔽登录提示信息
A、更改本机登录提示信息
追加/etc目录下的/etc/issue文件
ALERT!
Youareenteringasecuredarea!
YourIPandlogininformation
havebeenrecorded.Systemadministrationhasbeennotified.
Thissystemisrestrictedtoauthorizedaccessonly.Allactivitieson
thissystemarerecordedandlogged.Unauthorizedaccesswillbefully
investigatedandreportedtotheappropriatelawenforcementagencies.
B、更改远程登录提示信息
修改/etc目录下的/etc/文件
ALERT!
Youareenteringasecuredarea!
YourIPandlogininformation
havebeenrecorded.Systemadministrationhasbeennotified.
Thissystemisrestrictedtoauthorizedaccessonly.Allactivitieson
thissystemarerecordedandlogged.Unauthorizedaccesswillbefully
investigatedandreportedtotheappropriatelawenforcementagencies.
18.指定允许root登陆的TTY设备
vi/etc/securetty
只保留2个连接,其它行注释掉
tty1
tty2
19.限制/etc/rc.d/init.d/目录下脚本文件的权限
chmod–R700/etc/rc.d/init.d/*
20.加固部分带临时权限的程序(“s”位权限的程序)
chmoda-s/usr/bin/chage
chmoda-s/usr/bin/gpasswd
chmoda-s/usr/bin/wall
chmoda-s/usr/bin/chfn
chmoda-s/usr/bin/chsh
chmoda-s/usr/bin/newgrp
chmoda-s/usr/bin/write
chmoda-s/usr/sbin/usernetctl
chmoda-s/bin/traceroute
chmoda-s/bin/mount
chmoda-s/bin/umount
chmoda-s/sbin/netreport
21.更新防火墙规则
此项已做入脚本中。
#########################################################################
#Version:
1.0
#Date:
2014-11-11
###ENDINITINFO
#########################################################################
serviceiptablesstop
IPTABLES=/sbin/iptables
#startbyflushingtherules
$IPTABLES-PINPUTDROP
$IPTABLES-PFORWARDACCEPT
$IPTABLES-POUTPUTACCEPT
$IPTABLES-tnat-PPREROUTINGACCEPT
$IPTABLES-tnat-PPOSTROUTINGACCEPT
$IPTABLES-tnat-POUTPUTACCEPT
$IPTABLES-tmangle-PPREROUTINGACCEPT
$IPTABLES-tmangle-POUTPUTACCEPT
$IPTABLES-F
$IPTABLES-X
$IPTABLES-Z
$IPTABLES-tnat-F
$IPTABLES-tmangle-F
$IPTABLES-tnat-X
$IPTABLES-tmangle-X
$IPTABLES-tnat-Z
##allowpacketscomingfromthemachine
$IPTABLES-AINPUT-ilo-jACCEPT
$IPTABLES-AOUTPUT-olo-jACCEPT
#allowoutgoingtraffic
$IPTABLES-AOUTPUT-oeth0-jACCEPT
#blockspoofing
$IPTABLES-AINPUT-s127.0.0.0/8-i!
lo-jDROP
$IPTABLES-AINPUT-mstate--stateRELATED,ESTABLISHED-jACCEPT
$IPTABLES-AINPUT-picmp-jACCEPT
#stopbadpackets
$IPTABLES-AINPUT-mstate--stateINVALID-jDROP
#stoppingfloodattack
$IPTABLES-NPING
$IPTABLES-APING-picmp--icmp-typeecho-request-mlimit--limit1/second-jRETURN
#$IPTABLES-APING-picmp-jREJECT
$IPTABLES-IINPUT-picmp--icmp-typeecho-request-mstate--stateNEW-jPING
#################################
##allowaccesspolice
#################################
#tcpports
#smtp
$IPTABLES-AINPUT-ptcp-mtcp--dport25-jACCEPT
#http
$IPTABLES-AINPUT-ptcp-mtcp--dport80-jACCEPT
#pop3
$IPTABLES-AINPUT-ptcp-mtcp--dport110-jACCEPT
#imap
$IPTABLES-AINPUT-ptcp-mtcp--dport143-jACCEPT
#snmp
$IPTABLES-AINPUT-ptcp-mtcp--dport161-jACCEPT
#ldap
$IPTABLES-AINPUT-ptcp-mtcp--dport389-jACCEPT
#https
$IPTABLES-AINPUT-ptcp-mtcp--dport443-jACCEPT
#smtpoverSSL
$IPTABLES-AINPUT-ptcp-mtcp--dport465-jACCEPT
#lineprinterspooler
$IPTABLES-AINPUT-ptcp-mtcp--dport515-jACCEPT
#cups
$IPTABLES-AINPUT-ptcp-mtcp--dport631-jACCEPT
#oracle
$IPTABLES-AINPUT-ptcp-mtcp--dport1530-jACCEPT
#mysql
$IPTABLES-AINPUT-ptcp-mtcp--dport3306-jACCEPT
#vnc
$IPTABLES-AINPUT-ptcp-mtcp--dport5901-jACCEPT
#tomcat
$IPTABLES-AINPUT-ptcp-mtcp--dport8080-jACCEPT
#puppet
$IPTABLES-AINPUT-ptcp-mtcp--dport8140-jACCEPT
#nrpe
$IPTABLES-AINPUT-ptcp-mtcp--dport15666-jACCEPT
#oracle
$IPTABLES-AINPUT-ptcp-mtcp--dport1433-jACCEPT
#mcafeenwa
$IPTABLES-AINPUT-ptcp-mtcp--dport65443-jACCEPT
#SSH
$IPTABLES-AINPUT-ptcp-mtcp--dport22-jACCEPT
#samba(netbios)
$IPTABLES-AINPUT-ptcp-mtcp--dport137:
139-jACCEPT
$IPTABLES-AINPUT-ptcp-mtcp--dport137:
139-jACCEPT
#udpports
#DNS
$IPTABLES-AINPUT-pudp-mudp--dport53-jACCEPT
#DHCP
$IPTABLES-AINPUT-pudp-mudp--dport67:
68-jACCEPT
#NTP
$IPTABLES-AINPUT-pudp-mudp--dport123-jACCEPT
#SNMP
$IPTABLES-AINPUT-pudp-mudp--dport161:
162-jACCEPT
#Iptablesdroplogging
$IPTABLES-AINPUT-jLOG--log-prefix"[IPTABLESDROPLOGS]:
"--log-level4
#finally-droptherest
$IPTABLES-AINPUT-pall-jDROP
serviceiptablessave
serviceiptablesstart