linux-等保三级脚本(2)
该脚本主要是针对 CentOS Linux 7 合规基线加固的一些配置操作,包括创建用户、安全审计配置、入侵防范配置、访问控制配置、身份鉴别策略配置等。如果您需要在脚本中添加公司网址,您可以在适当的位置添加相应的内容。不过请注意,在实际生产环境中,建议谨慎进行脚本修改和执行,以免造成意外的影响。
#!/bin/bash
# CentOS Linux 7基线标准系统-等保三级-CentOS Linux 7合规基线加固
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
#定义脚本执行时间日志
bash_run(){
mkdir /etc/funi_bash -p
echo date +"%Y-%m-%d %H:%M:%S" > /etc/funi_bash/safe_date.log
}
bash_run
#判断是否执行加固脚本
check_bash(){
if [ -e /etc/funi_bash/safe_date.log ]; then
message=`cat /etc/funi_bash/safe_date.log`
echo 该服务器已于$message执行加固脚本,请确认是否继续执行
elsecreateuser
dengbao_bash
fi}
#运维管理员:GGB
#安全管理员:GGB
#审计管理员:GGB#新建管理员funi用户
createuser(){
useradd funi
if [ -z "$1" ]; then
echo "未传入密码,使用默认密码创建用户funi成功"
echo 'Funi_2021rjy' | passwd --stdin funi
echo "funi ALL=(ALL) ALL" >> /etc/sudoers
else
echo "使用自定义密码创建用户funi成功"
echo '$1' | passwd --stdin funi
echo "funi ALL=(ALL) ALL" >> /etc/sudoers
fi
}
createuser#新建安全审计safeuser用户
createsafeuser(){
useradd safeuser
if [ -z "$2" ]; then
echo "未传入密码,使用默认密码创建用户funi成功"
echo 'Funi_2021rjy' | passwd --stdin funi
echo "funi ALL=(ALL) ALL" >> /etc/sudoers
else
echo "使用自定义密码创建用户funi成功"
echo '$1' | passwd --stdin funi
echo "funi ALL=(ALL) ALL" >> /etc/sudoers
fi
}
createsafeuser#新建安全审计audituser用户
createaudituser(){
useradd audituser
if [ -z "$3" ]; then
echo "未传入密码,使用默认密码创建用户funi成功"
echo 'Funi_2021rjy' | passwd --stdin funi
echo "audituser ALL=(ALL) ALL" >> /etc/sudoers
else
echo "使用自定义密码创建用户funi成功"
echo '$1' | passwd --stdin funi
echo "audituser ALL=(ALL) ALL" >> /etc/sudoers
fi
}
createaudituser#1
# 修改密码最大有效期为180天
passwdtime(){
echo "#01修改密码最大有效期为180天"
cp /etc/login.defs /etc/login.defs-${time}
sed -i.bak 's/^\(PASS_MAX_DAYS\).*/\1 180/' /etc/login.defs
if [ "$?" == 0 ]
then
action "sed -i.bak 's/^\(PASS_MAX_DAYS\).*/\1 180/' /etc/login.defs" /bin/true
else
action "sed -i.bak 's/^\(PASS_MAX_DAYS\).*/\1 180/' /etc/login.defs" /bin/false
fi
chage --maxdays 180 root
if [ "$?" == 0 ]
then
action "chage --maxdays 180 root" /bin/true
else
action "chage --maxdays 180 root" /bin/false
fi
}
passwdtime#2
# 修改密码必须包含四种字符
mimaguifan(){
echo "#02修改密码必须包含四种字符"
sed -i 's/# minclass = 0/minclass = 3/g' /etc/security/pwquality.conf
if [ "$?" == 0 ]
then
action "sed -i 's/# minclass = 0/minclass = 3/g' /etc/security/pwquality.conf" /bin/true
else
action "sed -i 's/# minclass = 0/minclass = 3/g' /etc/security/pwquality.conf" /bin/false
fi
}
mimaguifan#3
# 修改两次修改密码的最小间隔时间为7天
passwdjiange(){
echo "#03修改两次修改密码的最小间隔时间为7天"
sed -i.bak 's/^\(PASS_MIN_DAYS\).*/\1 7/' /etc/login.defs
if [ "$?" == 0 ]
then
action "sed -i.bak 's/^\(PASS_MIN_DAYS\).*/\1 7/' /etc/login.defs" /bin/true
else
action "sed -i.bak 's/^\(PASS_MIN_DAYS\).*/\1 7/' /etc/login.defs" /bin/false
fi
chage --mindays 7 root
if [ "$?" == 0 ]
then
action "chage --mindays 7 root" /bin/true
else
action "chage --mindays 7 root" /bin/false
fi
}
passwdjiange#4
# 修改密码必须包含四种字符
passwdnandu(){
echo "#04修改密码必须包含四种字符"
cp /etc/security/pwquality.conf /etc/security/pwquality.conf-${time}
sed -i 's/# minclass = 0/minclass = 3/g' /etc/security/pwquality.conf
if [ "$?" == 0 ]
then
action "sed -i 's/# minclass = 0/minclass = 3/g' /etc/security/pwquality.conf" /bin/true
else
action "sed -i 's/# minclass = 0/minclass = 3/g' /etc/security/pwquality.conf" /bin/false
fi
}
passwdnandu#5,6,7,8
# 修改密码最短为9位
mimaweishu(){
echo "#05,06,07,08修改密码最短为9位"
sed -i 's/# minlen = 9/minlen = 9/g' /etc/security/pwquality.conf
if [ "$?" == 0 ]
then
action "sed -i 's/# minlen = 9/minlen = 9/g' /etc/security/pwquality.conf " /bin/true
else
action "sed -i 's/# minlen = 9/minlen = 9/g' /etc/security/pwquality.conf " /bin/false
fi
}
mimaweishu#9
# 密码设置及登陆控制文件/etc/pam.d/password-auth 禁止使用最近用过的5个密码 remember=5
password_auth(){
echo "#09密码设置及登陆控制文件/etc/pam.d/password-auth,禁止使用最近用过的5个密码"
cp /etc/pam.d/password-auth /etc/pam.d/password-auth-${time}
sed -i 's/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=5/g' /etc/pam.d/password-auth
if [ "$?" == 0 ]
then
action "sed -i 's/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=5/g' /etc/pam.d/password-auth" /bin/true
else
action "sed -i 's/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=5/g' /etc/pam.d/password-auth" /bin/false
fi
}
password_auth# 密码设置及登陆控制文件/etc/pam.d/system-auth 禁止使用最近用过的5个密码 remember=5
system_auth(){
echo "#密码设置及登陆控制文件/etc/pam.d/system-auth 禁止使用最近用过的5个密码 remember=5"
cp /etc/pam.d/system-auth /etc/pam.d/system-auth-${time}
sed -i 's/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=5/g' /etc/pam.d/system-auth
if [ "$?" == 0 ]
then
action "sed -i 's/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=5/g' /etc/pam.d/system-auth" /bin/true
else
action "sed -i 's/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok/password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=5/g' /etc/pam.d/system-auth" /bin/false
fi
}
system_auth#10
#密码过期时间告警
logindefs(){
echo "#10密码过期时间告警"
cp /etc/login.defs /etc/login.defs-${time}
echo 'PASS_WARN_AGE 30 ' >> /etc/login.defs
if [ "$?" == 0 ]
then
action "echo 'PASS_WARN_AGE 30 ' >> /etc/login.defs" /bin/true
else
action "echo 'PASS_WARN_AGE 30 ' >> /etc/login.defs" /bin/false
fi
}
logindefs# ssh服务端每900秒向客户端发送一次消息,以保持长连接
sshchanglianjie(){
echo "#ssh服务端每900秒向客户端发送一次消息,以保持长连接"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config-${time}
sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 900/g' /etc/ssh/sshd_config
if [ "$?" == 0 ]
then
action "sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 900/g' /etc/ssh/sshd_config" /bin/true
else
action "sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 900/g' /etc/ssh/sshd_config" /bin/false
fi
}
sshchanglianjie# 客户端3次超时即断开客户端
sshdunakai(){
echo "#客户端3次超时即断开客户端"
sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 3/g' /etc/ssh/sshd_config
if [ "$?" == 0 ]
then
action "sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 3/g' /etc/ssh/sshd_config" /bin/true
else
action "sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 3/g' /etc/ssh/sshd_config" /bin/false
fi
}
sshdunakai#11
#检查是否存在空口令用户账号,如果有则锁定用户
kongkoulin(){
echo "#11检查是否存在空口令用户账号,如果有则锁定用户"
if [ `awk -F: 'NR==FNR && $3 >= 1000 && $3 < 65534 {users[$1]}; NR!=FNR && ($2 == "" || $2 == "!!") && ($1 in users) {print $1}' /etc/passwd /etc/shadow | wc -l` != 0 ]; thenfor i in `awk -F: 'NR==FNR && $3 >= 1000 && $3 < 65534 {users[$1]}; NR!=FNR && ($2 == "" || $2 == "!!") && ($1 in users) {print $1}' /etc/passwd /etc/shadow`;dousermod -L $iaction "当前${i}用户没有密码,已锁定,如需要使用执行 usermod -U username 解锁" /bin/falseecho "当前${i}用户没有密码,已锁定" >> /etc/funi_bash/safe_date.logdone
elseaction "当前无空口令用户" /bin/true
fi
}
kongkoulin#12
# 用户重新尝试输入密码的次数设为4
sshcghangsi(){
echo "#12用户重新尝试输入密码的次数设为4"
sed -i 's/#MaxAuthTries 6/MaxAuthTries 4/g' /etc/ssh/sshd_config
if [ "$?" == 0 ]
then
action "sed -i 's/#MaxAuthTries 6/MaxAuthTries 4/g' /etc/ssh/sshd_config" /bin/true
else
action "sed -i 's/#MaxAuthTries 6/MaxAuthTries 4/g' /etc/ssh/sshd_config" /bin/false
fi
echo 'Protocol 2' >> /etc/ssh/sshd_config
if [ "$?" == 0 ]
then
action "echo 'Protocol 2' >> /etc/ssh/sshd_config" /bin/true
else
action "echo 'Protocol 2' >> /etc/ssh/sshd_config" /bin/false
fi
}
sshcghangsi# 13 SSH 日志级别设置为INFO,记录登录和注销活动
sshlog(){
echo "#13 SSH 日志级别设置为INFO,记录登录和注销活动"
sed -i 's/#LogLevel INFO/LogLevel INFO/g' /etc/ssh/sshd_config
if [ "$?" == 0 ]
then
action "sed -i 's/#LogLevel INFO/LogLevel INFO/g' /etc/ssh/sshd_config" /bin/true
else
action "sed -i 's/#LogLevel INFO/LogLevel INFO/g' /etc/ssh/sshd_config" /bin/false
fi
service sshd restart
if [ "$?" == 0 ]
then
action "service sshd restart" /bin/true
else
action "service sshd restart" /bin/false
fised -i '/# User/a\auth required pam_tally2.so onerr=fail audit silent deny=5 unlock_time=900' /etc/pam.d/password-auth
if [ "$?" == 0 ]
then
action "sed -i '/# User/a\auth required pam_tally2.so onerr=fail audit silent deny=5 unlock_time=900' /etc/pam.d/password-auth" /bin/true
else
action "sed -i '/# User/a\auth required pam_tally2.so onerr=fail audit silent deny=5 unlock_time=900' /etc/pam.d/password-auth" /bin/false
fised -i '/# User/a\auth required pam_tally2.so onerr=fail audit silent deny=5 unlock_time=900' /etc/pam.d/system-auth
if [ "$?" == 0 ]
then
action "sed -i '/# User/a\auth required pam_tally2.so onerr=fail audit silent deny=5 unlock_time=900' /etc/pam.d/system-auth" /bin/true
else
action "sed -i '/# User/a\auth required pam_tally2.so onerr=fail audit silent deny=5 unlock_time=900' /etc/pam.d/system-auth" /bin/false
fi
echo 'TMOUT=900' >> /etc/profile
if [ "$?" == 0 ]
then
action "echo 'TMOUT=900' >> /etc/profile" /bin/true
else
action "echo 'TMOUT=900' >> /etc/profile" /bin/false
fi
}
sshlog#22
# 禁止root登录
PermitRootLogin(){
echo "#22禁止root登录"
sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
if [ "$?" == 0 ]
then
action "sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config" /bin/true
else
action "sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config" /bin/false
fi
service sshd restart
if [ "$?" == 0 ]
then
action "service sshd restart" /bin/true
else
action "service sshd restart" /bin/false
fi
}
PermitRootLogin#24
#检查使用IP协议远程维护的设备是否配置SSH协议,禁用telnet协议
telnet(){
echo "24检查使用IP协议远程维护的设备是否配置SSH协议,禁用telnet协议"
rpm -qa |grep telnet*
if [ $? == 0 ];
thenecho "disable = yes" >> /etc/xinetd.d/telnetservice xinetd restartaction "禁用telnet协议" /bin/true
elseaction "禁用telnet协议" /bin/false
fi}
telnet#25
#禁止匿名VSFTP用户登录
vsftpuser(){
echo "25禁止匿名VSFTP用户登录"
if [ -f /etc/vsftpd.conf ] || [ -f /etc/vsftpd/vsftpd.conf ];
thenecho "anonymous_enable=NO" >> /etc/vsftpd.conf 2>/dev/null || echo "anonymous_enable=NO" >> /etc/vsftpd/vsftpd.confaction "禁止匿名VSFTP用户登录" /bin/true
fi
}#26
#删除ftp用户
delftp(){
echo "26 删除ftp用户"
userdel -f ftp
if [ $? == 0 ]
thenaction "userdel -f ftp" /bin/true
elseaction "userdel -f ftp" /bin/false
fi
}
delftp#29
#检查配置文件/etc/snmp/snmpd.conf是否存在。
snmpd_file(){
echo "#29检查配置文件/etc/snmp/snmpd.conf是否存在。"
if [ -f /etc/snmp/snmpd.conf ];
then action "文件/etc/snmp/snmpd.conf存在" /bin/true
elsemkdir -p /etc/snmp && touch /etc/snmp/snmpd.conf action "创建/etc/snmp/snmpd.conf成功" /bin/true
fi
}
snmpd_file#33,34
#禁止系统账号进行交互式登录
userdenlu(){
echo "33,34禁止系统账号进行交互式登录"
for i in `echo 'bin sys nuucp adm lp mail uucp operator games gopher ftp nobody nobody4 noaccess listen webservd rpm dbus avahi mailnull smmsp nscd vcsa rpc rpcuser nfs sshd pcap ntp haldaemon distcache apache webalizer squid xfs gdm sabayon named'`;dopasswd -l $i > /dev/nullaction "${i}用户已锁定" /bin/true
done
}
userdenlu#37
#检查是否使用PAM认证模块禁止wheel组之外的用户su为root
sufile(){
echo "#37检查是否使用PAM认证模块禁止wheel组之外的用户su为root"
if [ -f /etc/pam.d/su ]
thensed -i '2i\auth sufficient pam_rootok.so' /etc/pam.d/sused -i '2i\auth required pam_wheel.so group=wheel' /etc/pam.d/suaction "/etc/pam.d/su文件" /bin/true
elseaction "/etc/pam.d/su文件" /bin/false
fi
}#38
#禁止root登录VSFTP
rootvsftp(){
echo "#38禁止匿名VSFTP用户登录"
if [ -f /etc/ftpusers ] || [ -f /etc/vsftpd/ftpusers ]
thenecho "root" >> /etc/ftpusers || echo "root" >> /etc/vsftpd/ftpusersaction "#禁止root登录VSFTP" /bin/true
elseaction "#禁止root登录VSFTP" /bin/false
fi
}
rootvsftp#39
#禁止root登录WU-FTP
rootwuftp(){
echo "#39禁止root登录WU-FTP"
if [ -f /etc/ftpusers ]
then echo "root" >> /etc/ftpusersaction "禁止root登录WU-FTP" /bin/true
elseaction "禁止root登录WU-FTP" /bin/false
fi
}
rootwuftp#40检查重要文件是否存在suid和sgid权限
suidfile(){
echo "#40检查重要文件是否存在suid和sgid权限"
find /usr/bin/chage /usr/bin/gpasswd /usr/bin/wall /usr/bin/chfn /usr/bin/chsh /usr/bin/newgrp /usr/bin/write /usr/sbin/usernetctl /usr/sbin/traceroute /bin/mount /bin/umount /bin/ping /sbin/netreport -type f -perm +6000 2>/dev/nul
if [ $? == 0 ]
then for i in `echo '/usr/bin/chage /usr/bin/gpasswd /usr/bin/wall /usr/bin/chfn /usr/bin/chsh /usr/bin/newgrp /usr/bin/write /usr/sbin/usernetctl /usr/sbin/traceroute /bin/mount /bin/umount /bin/ping /sbin/netreport '`do chmod a-s $idoneaction "#40检查重要文件是否存在suid和sgid权限" /bin/true
elseaction "#40检查重要文件是否存在suid和sgid权限" /bin/false
fi
}
suidfile#41检查是否存在除root之外UID为0的用户
root_uid(){
echo "#41检查是否存在除root之外UID为0的用户"
if [ `awk -F: '$3 == 0 && $1 != "root"{print $1}' /etc/passwd | wc -l` >=1 ]
thenaction 当前UID为零的用户有`echo ` awk -F: '$3 == 0 && $1 != "root"{print $1}' /etc/passwd`` /bin/true
elseaction "#41不存在除root之外UID为0的用户" /bin/true
fi
}
root_uid#42检查是否限制FTP用户登录后能访问的目录
ftp_file(){
echo "#42检查是否限制FTP用户登录后能访问的目录"
if [ -f /etc/vsftpd.conf ]
thenecho " chroot_local_user=YES" >> /etc/vsftpd.conf /etc/init.d/vsftpd restart action "修改/etc/vsftpd.conf" /bin/true
elseaction "修改/etc/vsftpd.conf" /bin/false
fi
if [ -f /etc/pure-ftpd/pure-ftpd.conf ]
thenecho " ChrootEveryone yes AllowUserFXP no AllowAnonymousFXP no" >> /etc/pure-ftpd/pure-ftpd.conf /etc/init.d/pure-ftpd restartaction "修改/etc/pure-ftpd/pure-ftpd.conf" /bin/true
elseaction "修改/etc/pure-ftpd/pure-ftpd.conf" /bin/false
fi}
ftp_file#44检查/usr/bin/目录下的可执行文件的拥有者属性,当可执行文件设置s属性时,执行时可以获取其拥有者的权限。
binfile_s(){
if [ -d /usr/bin/ ]
thenecho "含有“s”属性的文件如下,可使用 chmod a-s filename 取消权限"find /usr/bin -type f \( -perm -04000 -o -perm -02000 \) -exec ls -lg {} \;
elseaction "/usr/bin/目录下的可执行文件已无含s权限" /bin/true
fi
}
binfile_s#45/etc/rc2.d文件权限是否符合规范
file_rc2(){
echo "#45/etc/rc2.d文件权限是否符合规范"
if [ -e /etc/rc2.d ]
then chmod 750 /etc/rc2.d/action "/etc/rc2.d文件权限符合规范" /bin/true
elseaction "/etc/rc2.d文件不存在" /bin/false
fi
}
file_rc2#46/etc/rc4.d文件权限是否符合规范
file_rc4(){
echo "#46/etc/rc4.d文件权限是否符合规范"
if [ -e /etc/rc4.d ]
then chmod 750 /etc/rc4.d/action "#45/etc/rc4.d文件权限符合规范" /bin/true
elseaction "/etc/rc4.d文件不存在" /bin/false
fi
}
file_rc4#47/etc/passwd文件权限是否符合规范
passwd_file(){
echo "#47/etc/passwd文件权限是否符合规范"
if [ -e /etc/passwd ]
then chmod 750 /etc/passwdaction "/etc/passwd文件权限符合规范" /bin/true
elseaction "/etc/passwd文件不存在" /bin/false
fi
}
passwd_file#48检查系统引导器配置文件权限
chmod_file(){
echo "#48检查系统引导器配置文件权限"
for i in `echo "/etc/grub.conf boot/grub/grub.conf /etc/lilo.conf /etc/grub2.cfg /boot/grub2/grub.cfg"`
doif [ -e $i ];thenchmod 600 $i action "${i}文件已修改600权限" /bin/truefi
done
}
chmod_file#49/etc/xinetd.conf文件权限是否符合规范
xinetd_file(){
echo "#49/etc/xinetd.conf文件权限是否符合规范"
if [ -e /etc/xinetd.conf ]
then chmod 750 /etc/passwdaction "/etc/xinetd.conf文件权限符合规范" /bin/true
elseaction "/etc/xinetd.conf文件不存在" /bin/false
fi
}
xinetd_file#50/etc/group文件权限是否符合规范
group_file(){
echo "#50/etc/group文件权限是否符合规范"
if [ -e /etc/group ]
then chmod 644 /etc/groupaction "/etc/group文件权限符合规范" /bin/true
elseaction "/etc/group文件不存在" /bin/false
fi
}
group_file#51/tmp文件权限是否符合规范
tmp_file(){
echo "#51/tmp文件权限是否符合规范"
if [ -e /tmp ]
then chmod 750 /tmpaction "/tmp文件权限符合规范" /bin/true
elseaction "/tmp文件不存在" /bin/false
fi
}
tmp_file#52/etc/shadow文件权限是否符合规范
shadow_file(){
echo "#52/etc/shadow文件权限是否符合规范"
if [ -e /etc/shadow ]
then chmod 750 /etc/shadowaction "/etc/shadow文件权限符合规范" /bin/true
elseaction "/etc/shadow文件不存在" /bin/false
fi
}
shadow_file#53/etc/rc.d/init.d/文件权限是否符合规范
rc_d_file(){
echo "#53/etc/rc.d/init.d/文件权限是否符合规范"
if [ -e /etc/rc.d/init.d/ ]
then chmod 750 /etc/rc.d/init.d/action "/etc/rc.d/init.d/ 文件权限符合规范" /bin/true
elseaction "/etc/rc.d/init.d/ 文件不存在" /bin/false
fi
}
rc_d_file#54/etc/rc0.d文件权限是否符合规范
rc_file(){
echo "#54/etc/rc0.d文件权限是否符合规范"
if [ -e /etc/rc0.d ]
then chmod 750 /etc/rc0.daction "/etc/rc0.d 文件权限符合规范" /bin/true
elseaction "/etc/rc0.d文件不存在" /bin/false
fi
}
rc_file#55/etc/services文件权限是否符合规范
services_file(){
echo "#55/etc/services文件权限是否符合规范"
if [ -e /etc/services ]
then chmod 644 /etc/servicesaction "/etc/services 文件权限符合规范" /bin/true
elseaction "/etc/services 文件不存在" /bin/false
fi
}
services_file#56/etc/rc3.d文件权限是否符合规范
rc3_file(){
echo "#56/etc/rc3.d文件权限是否符合规范"
if [ -e /etc/rc3.d ]
then chmod 750 /etc/rc3.daction "/etc/rc3.d 文件权限符合规范" /bin/true
elseaction "/etc/rc3.d 文件不存在" /bin/false
fi
}
rc3_file#57/etc/rc6.d文件权限是否符合规范
rc6_file(){
echo "#57/etc/rc6.d文件权限是否符合规范"
if [ -e /etc/rc6.d ]
then chmod 750 /etc/rc6.daction "/etc/rc6.d 文件权限符合规范" /bin/true
elseaction "/etc/rc6.d 文件不存在" /bin/false
fi
}
rc6_file#58/etc/rc5.d文件权限是否符合规范
rc5_file(){
echo "#58/etc/rc5.d文件权限是否符合规范"
if [ -e /etc/rc5.d ]
then chmod 750 /etc/rc5.daction "/etc/rc5.d 文件权限符合规范" /bin/true
elseaction "/etc/rc5.d 文件不存在" /bin/false
fi
}
rc5_file#59/etc/rc1.d/文件权限是否符合规范
rc1_file(){
echo "#59/etc/rc1.d/文件权限是否符合规范"
if [ -e /etc/rc1.d ]
then chmod 750 /etc/rc1.daction "/etc/rc1.d 文件权限符合规范" /bin/true
elseaction "/etc/rc1.d 文件不存在" /bin/false
fi
}
rc1_file#60/etc/security目录权限是否符合规范
security_file(){
echo "#60/etc/security目录权限是否符合规范"
if [ -e /etc/security ]
then chmod 600 /etc/securityaction "/etc/security 文件权限符合规范" /bin/true
elseaction "/etc/security 文件不存在" /bin/false
fi
}
security_file#61,62,63,64检查文件属性
file_shadow(){
echo "#61,62,63,64检查文件属性"
for i in ` echo '/etc/shadow /etc/group /etc/passwd /etc/gshadow' `
doif [ -e $i ]thenchattr +i $iaction "${i}文件属性已不可修改" /bin/trueelseaction "${i}文件不存在" /bin/falsefi
done}
file_shadow#65检查用户目录缺省访问权限设置
login_file(){
echo "#65检查用户目录缺省访问权限设置"
if [ -e /etc/login.defs ]
thensed -i 's/^UMASK.*/UMASK 027/g' /etc/login.defsaction " sed -i 's/^UMASK.*/UMASK 027/g' /etc/login.defs" /bin/true
elseaction "/etc/login.defs文件不存" /bin/false
fi
}#66~73检查日志文件是否非全局可写
log_file(){
echo "#66~73检查日志文件是否非全局可写"
for i in `echo ' /var/log/maillog /var/log/mail /var/log/secure /var/log/messages /var/log/localmessages /var/log/spooler /var/log/boot.log /var/log/cron '`
doif [ -e $i ];thenchmod 775 $iaction "${i}文件权限已修改" /bin/trueelseaction "${i}文件不存在" /bin/falsefi
done
}
log_file#74,75检查是否配置用户所需最小权限
file_chmod(){
echo "#66~73检查日志文件是否非全局可写"
for i in `echo '/etc/passwd /etc/group'`
doif [ -e $i ];thenchmod 775 $iaction "${i}文件权限已修改" /bin/trueelseaction "${i}文件不存在" /bin/falsefi
done
}
file_chmod#78限制FTP用户登录后上传文件的属性
FTP_file(){
echo "#78限制FTP用户登录后上传文件的属性"
if [ -e /etc/vsftpd.conf ];then # 检查文件是否存在并且未注释if ! grep -q "^write_enable=YES" /etc/vsftpd.conf; thenecho "write_enable=YES" >> /etc/vsftpd.conffiif ! grep -q "^ls_recurse_enable=YES" /etc/vsftpd.conf; thenecho "ls_recurse_enable=YES" >> /etc/vsftpd.conffiif ! grep -q "^local_umask=022" /etc/vsftpd.conf; thenecho "local_umask=022" >> /etc/vsftpd.conffiif ! grep -q "^anon_umask=022" /etc/vsftpd.conf; thenecho "anon_umask=022" >> /etc/vsftpd.conffi/etc/init.d/vsftpd restart# 检查文件是否存在并且未注释if ! grep -q "^Umask 177:077" /etc/pure-ftpd/pure-ftpd.conf; thenecho "Umask 177:077" >> /etc/pure-ftpd/pure-ftpd.conffi# 重启ftp服务/etc/init.d/pure-ftpd restartaction "限制FTP用户登录后上传文件的属性设置已完成" /bin/true
elseaction "/etc/vsftpd.conf文件不存在" /bin/false
fi
}
FTP_file#79检查是否禁用不必要的系统服务#83如果没有必要,需要停止NFS服务
nfs_sys(){
echo "#83如果没有必要,需要停止NFS服务"
if [ `rpm -qa | grep nfs | wc -l` != 0 ];thensystemctl stop nfsaction "nfs服务已完成停止" /bin/true
elseaction "为安装nfs服务" /bin/false
fi
}
nfs_sys#84设置 主机允许策略文件/etc/hosts.allow 的属组和属主为root
host_allow(){
echo "#设置主机允许策略文件/etc/hosts.allow 的属组和属主为root"
chown root:root /etc/hosts.allow
if [ "$?" == 0 ]
then
echo
action "chown root:root /etc/hosts.allow" /bin/true
else
action "chown root:root /etc/hosts.allow" /bin/false
fi
}
host_allow#85 检查是否关闭ident服务
check_ident() {echo "#85检查是否关闭ident服务"ident_status=$(systemctl is-active ident)if [ "$ident_status" = "active" ]thensystemctl disable identaction "已禁用ident服务" /bin/falseelseaction "ident服务已关闭" /bin/truefi
}
check_ident#86 检查是否关闭time服务
check_time() {echo "#86检查是否关闭time服务"time_status=$(systemctl is-active time)if [ "$time_status" = "active" ]thensystemctl disable timeaction "已禁用time服务" /bin/falseelseaction "time服务已关闭" /bin/truefi
}
check_time#87 检查是否关闭nfs服务
check_nfs() {echo "#87检查是否关闭nfs服务"nfs_status=$(systemctl is-active nfs)if [ "$nfs_status" = "active" ]thensystemctl disable nfsaction "已禁用nfs服务" /bin/falseelseaction "nfs服务已关闭" /bin/truefi
}
check_nfs#88 检查是否关闭chargen服务
check_chargen() {echo "#88检查是否关闭chargen服务"chargen_status=$(systemctl is-active chargen)if [ "$chargen_status" = "active" ]thensystemctl disable chargenaction "已禁用chargen服务" /bin/falseelseaction "chargen服务已关闭" /bin/truefi
}
check_chargen#89 检查是否关闭klogin服务
check_klogin() {echo "#89检查是否关闭klogin服务"klogin_status=$(systemctl is-active klogin)if [ "$klogin_status" = "active" ]thensystemctl disable kloginaction "已禁用klogin服务" /bin/falseelseaction "klogin服务已关闭" /bin/truefi
}
check_klogin#90 检查是否关闭ypbind服务
check_ypbind() {echo "#90检查是否关闭ypbind服务"ypbind_status=$(systemctl is-active ypbind)if [ "$ypbind_status" = "active" ]thensystemctl disable ypbindaction "已禁用ypbind服务" /bin/falseelseaction "ypbind服务已关闭" /bin/truefi
}
check_ypbind#91 检查是否关闭tftp服务
check_tftp() {echo "#91检查是否关闭tftp服务"tftp_status=$(systemctl is-active tftp)if [ "$tftp_status" = "active" ]thensystemctl disable tftpaction "已禁用tftp服务" /bin/falseelseaction "tftp服务已关闭" /bin/truefi
}
check_tftp#92 检查是否关闭nfslock服务
check_nfslock() {echo "#92检查是否关闭nfslock服务"nfslock_status=$(systemctl is-active nfslock)if [ "$nfslock_status" = "active" ]thensystemctl disable nfslockaction "已禁用nfslock服务" /bin/falseelseaction "nfslock服务已关闭" /bin/truefi
}
check_nfslock#93 检查是否关闭lpd服务
check_lpd() {echo "#93检查是否关闭lpd服务"lpd_status=$(systemctl is-active lpd)if [ "$lpd_status" = "active" ]thensystemctl disable lpdaction "已禁用lpd服务" /bin/falseelseaction "lpd服务已关闭" /bin/truefi
}
check_lpd#94 检查是否关闭discard服务
check_discard() {echo "#94检查是否关闭discard服务"discard_status=$(systemctl is-active discard)if [ "$discard_status" = "active" ]thensystemctl disable discardaction "已禁用discard服务" /bin/falseelseaction "discard服务已关闭" /bin/truefi
}
check_discard#95 检查是否关闭kshell服务
check_kshell() {echo "#95检查是否关闭kshell服务"kshell_status=$(systemctl is-active kshell)if [ "$kshell_status" = "active" ]thensystemctl disable kshellaction "已禁用kshell服务" /bin/falseelseaction "kshell服务已关闭" /bin/truefi
}
check_kshell#96 检查是否关闭daytime服务
check_daytime() {echo "#96检查是否关闭daytime服务"daytime_status=$(systemctl is-active daytime)if [ "$daytime_status" = "active" ]thensystemctl disable daytimeaction "已禁用daytime服务" /bin/falseelseaction "daytime服务已关闭" /bin/truefi
}
check_daytime#97 检查是否关闭echo服务
check_echo() {echo "#97检查是否关闭echo服务"echo_status=$(systemctl is-active echo)if [ "$echo_status" = "active" ]thensystemctl disable echoaction "已禁用echo服务" /bin/falseelseaction "echo服务已关闭" /bin/truefi
}
check_echo#98 检查是否关闭sendmail服务
check_sendmail() {echo "#98检查是否关闭sendmail服务"sendmail_status=$(systemctl is-active sendmail)if [ "$sendmail_status" = "active" ]thensystemctl disable sendmailaction "已禁用sendmail服务" /bin/falseelseaction "sendmail服务已关闭" /bin/truefi
}
check_sendmail#99 检查是否关闭ntalk服务
check_ntalk() {echo "#99检查是否关闭ntalk服务"ntalk_status=$(systemctl is-active ntalk)if [ "$ntalk_status" = "active" ]thensystemctl disable ntalkaction "已禁用ntalk服务" /bin/falseelseaction "ntalk服务已关闭" /bin/truefi
}
check_ntalk#100 检查是否关闭printer服务
check_printer() {echo "#100检查是否关闭printer服务"printer_status=$(systemctl is-active printer)if [ "$printer_status" = "active" ]thensystemctl disable printeraction "已禁用printer服务" /bin/falseelseaction "printer服务已关闭" /bin/truefi
}
check_printer#101 检查是否关闭bootps服务
check_bootps() {echo "#101检查是否关闭bootps服务"bootps_status=$(systemctl is-active bootps)if [ "$bootps_status" = "active" ]thensystemctl disable bootpsaction "已禁用bootps服务" /bin/falseelseaction "bootps服务已关闭" /bin/truefi
}
check_bootps##102 设置允许访问的IP地址并重启SSH服务
#check_allow() {
# allowed_ip="192.168.4.44"
#
# #102 检查是否限制了远程登录的IP范围
# if grep -q "$allowed_ip" /etc/hosts.allow; then
# action "远程登录IP范围已经限制" /bin/true
# else
# action "远程登录IP范围未限制" /bin/false
# # 编辑 /etc/hosts.allow 文件,增加允许访问的IP
# if ! grep -q "sshd:$allowed_ip:allow" /etc/hosts.allow; then
# echo "sshd:$allowed_ip:allow" >> /etc/hosts.allow
# fi
# fi
#
# # 重启SSH服务
# if systemctl status sshd >/dev/null; then
# systemctl restart sshd
# fi
#}
#
#
##103 编辑 /etc/hosts.deny 文件,增加一行 all:all
#check_deny() {
# if ! grep -q "all:all" /etc/hosts.deny; then
# echo "all:all" >> /etc/hosts.deny
# systemctl restart xinetd
# action "/etc/hosts.deny未配置正确" /bin/false
# else
# action "/etc/hosts.deny配置正确" /bin/true
# fi
#}#104检查保留历史命令的条数
histsize(){
echo "#104 保留历史命令条数"
file="/etc/profile"
neiron="HISTSIZE=.*"
neirong="HISTSIZE=3000"
cp "$file" "$file".bak
sed -i 's/^"$neiron"/"$neirong"' "$file"
source "$file"
action "内容已经替换并加载文件" /bin/true
}
histsize#105检查保留历史命令的记录文件大小
histfilesize(){
echo "#105 历史命令文件大小"
file="/etc/profile"
neirong="HISTFILESIZE=500"
grep "$neirong" "$file"
if [ $? -eq 0 ]; thenaction "配置内容存在" /bin/true
elsecp "$file" "$file".backupecho "$neirong" >> "$file"source "$file"action "已添加内容到文件并加载" /bin/true
fi
}
histfilesize#106检查是否安装OS补丁
os(){
echo "#106 检查是否安装OS补丁"
if command -v apt &>/dev/null; thenupdate_command="apt update && apt upgrade -y >> /dev/null"
elif command -v yum &>/dev/null; thenupdate_command="yum check-update >> /dev/null && yum update -y >> /dev/null"
elif command -v zypper &>/dev/null; thenupdate_command="zypper refresh && zypper update -y >> /dev/null"
elseaction "无法确定系统类型或找不到适用的包管理工具" /bin/falseexit 1
fi
eval "$update_command"
if [ $? -eq 0 ]; thenaction "系统更新完成" /bin/ture
elseaction "系统更新失败,请检查错误信息" /bin/false
fi
}
os#107是否设置ssh登录前警告Banner
ssh_banner_ner(){
echo "#107 ssh_banner登录前设置"
banner_file="/etc/ssh_banner"
banner_content="Authorized only. All activity will be monitored and reported"
sshd_config_file="/etc/ssh/sshd_config"
banner_config="Banner /etc/ssh_banner"
if [ -f "$banner_file" ]; thenaction "文件 $banner_file 已存在" /bin/true
elsetouch "$banner_file"chown bin:bin "$banner_file"chmod 644 "$banner_file"echo "$banner_content" > "$banner_file"action "已创建 $banner_file 文件并写入内容" /bin/true
fi
if grep -q "$banner_config" "$sshd_config_file"; thenaction "sshd_config 文件中已存在 Banner 配置" /bin/false
elseecho "$banner_config" >> "$sshd_config_file"action "已添加 Banner 配置到 sshd_config 文件" /bin/true
fiif command -v systemctl >/dev/null; thensystemctl restart sshdaction"已重启 sshd 服务" /bin/trueelif command -v service >/dev/null; thenservice sshd restartaction "已重启 sshd 服务" /bin/trueelseaction "无法确定系统使用的服务管理工具,请手动重启 sshd 服务" /bin/falsefi
}
ssh_banner_ner#108 ssh_banner登录后设置
ssh_banner(){
echo "#108 ssh_banner登录后设置"
motd_file="/etc/motd"
motd_content="Login success. All activity will be monitored and reported"
if [ -f "$motd_file" ]; thenecho "$motd_content" > "$motd_file"action "motd文件存在已修改" /bin/true
elseecho "$motd_content" >"$motd_file"action "motd文件已创建并写入" /bin/true
fi
}
ssh_banner#109检查是否更改默认的telnet登录警告Banner
telnet(){
echo "#109 telnet警告 设置"
banner_file="/etc/ssh_banner"
banner_content=" Authorized only. All activity will be monitored and reported "
sshd_config_file="/etc/ssh/sshd_config"
banner_config="Banner /etc/ssh_banner"
touch "$banner_file"
chown bin:bin "$banner_file"
chmod 644 "$banner_file"
echo "$banner_content" >> "$banner_file"
if grep -q "$banner_config" "$sshd_config_file"; thenaction "sshd_config 文件中已存在 Banner 配置" /bin/false
elseecho "$banner_config" >> "$sshd_config_file"action "已添加 Banner 配置到 sshd_config 文件" /bin/true
fi
if command -v systemctl >/dev/null; thensystemctl restart sshdaction "已重启 sshd 服务" /bin/true
elif command -v service >/dev/null; thenservice sshd restartaction "已重启 sshd 服务" /bin/true
elseaction "无法确定系统使用的服务管理工具,请手动重启 sshd 服务" /bin/false
fi
}
telnet#110
#111#112rsyslog是否启用记录cron行为日志功能
rsyslog_cron() {
echo "#112 rsyslog是否启用记录cron行为日志功能"
filelog="/etc/rsyslog.conf"
file="var/log/cron"
neirong="cron.*"$file""
if [ -f "$filelog" ]; thencp "$filelog" ${filelog}.${time}bakecho "$neirong" >> "$filelog"if [ ! -f "$file" ]; thentouch "$file"chmod 755 "$file"action "cron 文件已创建" /bin/trueelseaction "cron 文件已存在" /bin/falsefi
elseaction "rsyslog.conf配置 文件不存在" /bin/false
fi
}
rsyslog_cron#113syslog是否启用记录cron行为日志功能
syslog_cron() {
echo "#113 syslog_cron"
filelog="/etc/syslog.conf"
file="var/log/cron"
neirong="cron.*"$file""
if [ -f "$filelog" ]; thenecho "$neirong" >> "$filelog"if [ ! -f "$file" ]; thentouch "$file"chmod 755 "$file"action "cron 文件已创建" /bin/trueelseaction "cron 文件已存在" /bin/falsefi
elseaction "syslog.conf配置 文件不存在" /bin/false
fi
}
syslog_cron#114syslog-ng是否启用记录cron行为日志功能
syslog_ng_cron(){
echo "#114 cron 日志功能"
filelog="/etc/syslog-ng/syslog-ng.conf"
file="/var/log/cron"
neirong=" filter f_cron { facility(cron); }; destination cron { file("$file"); }; log { source(src); filter(f_cron); destination(cron); };"
if [ -f "$filelog" ]; thencp "$filelog" "$filelog".backupecho "$neirong" >> "$filelog"if [ ! -f "$file" ]; thentouch "$file"chmod 755 "$file"action "cron 文件已创建" /bin/trueelseaction "cron 文件已存在" /bin/falsefi
elseaction "syslog-ng.conf配置 文件不存在" /bin/false
fi
}
syslog_ng_cron#115检查是否记录成功登陆日志
login(){
echo "#115 登录情况日志"
day=$(date +"%a %b %e")
last | grep "$day" >/dev/null
if [ $? -eq 0 ]; thenaction "成功记录登录记录" /bin/true
elseaction "未成功记录登录记录" /bin/false
fi
}
login
#116
#117#118检查syslog-ng是否配置安全事件日志
syslog_ng_anquan(){
echo "#118 syslog安全日志"
filelog="/etc/syslog-ng/syslog-ng.conf"
file="/var/adm/msgs"
neirong=" filter f_msgs { level(err) or facility(kern) and level(debug) or facility(daemon) and level(notice); }; destination msgs { file("$file"); }; log { source(src); filter(f_msgs); destination(msgs); }; "
if [ -f "$filelog" ]; thencp "$filelog" ${filelog}-${time}.bakgrep "$file" "$filelog" >/dev/nullif [ $? -ne 0 ]; then echo "$neirong" >> "$filelog"if [ ! -f "$file" ]; thentouch "$file"chmod 666 "$file"action "创建日志文件" /bin/trueelse service syslog restartaction "syslog-ng服务重启" /bin/truefielseaction "rslog-ng配置文件内容已经存在" /bin/falsefi
elseaction "rslog-ng配置文件不存在" /bin/false
fi
}
syslog_ng_anquan#117,119检查rsyslog是否配置安全事件日志
rsyslog_anquan(){
echo "#117,119 rsyslog安全日志"
filelog="/etc/rsyslog.conf"
file="/var/adm/messages"
neirong="*.err;kern.debug;daemon.notice /var/adm/messages"
if [ -f "$filelog" ]; thencp "$filelog" "$filelog".backupangrep "$file" "$filelog" >/dev/nullif [ $? -ne 0 ];thensed -i "75i$neirong" "$filelog"if [ ! -f "$file" ];thentouch "$file" chmod 666 "$file"action "创建日志文件" /bin/trueelseservice rsyslog restartaction "rsyslog服务重启" /bin/true fielse action "rsyslog配置文件内容已经存在" /bin/truefi
elseaction "rsyslog配置文件不存在" /bin/false
fi
}
rsyslog_anquan#120检查是否配置su命令使用情况记录
su(){
echo "#120 su 命令使用情况"
if grep -q "Red Hat Enterprise Linux Server 5" /etc/redhat-release; thenecho "编辑 /etc/syslog.conf 文件"sed -i 's/^authpriv\.\*.*$/authpriv.* \/var\/log\/secure/' /etc/syslog.conf
fi
if [[ -f /etc/rsyslog.conf || -f /etc/syslog-ng/syslog-ng.conf ]]; thenif grep -q "Red Hat Enterprise Linux Server 6" /etc/redhat-release || \grep -q "openSUSE release 11" /etc/SuSE-release; thenecho "编辑 /etc/rsyslog.conf 文件"sed -i 's/^authpriv\.\*.*$/authpriv.* \/var\/log\/secure/' /etc/rsyslog.confelif grep -q "SuSE Linux Enterprise Server 9" /etc/SuSE-release; thenecho "编辑 /etc/syslog.conf 文件"sed -i 's/^authpriv\.\*.*$/authpriv.* \/var\/log\/secure/' /etc/syslog.confelif grep -q "SUSE Linux Enterprise Server 10" /etc/SuSE-release || \grep -q "SUSE Linux Enterprise Server 11" /etc/SuSE-release; thenecho "编辑 /etc/syslog-ng/syslog-ng.conf 文件"sed -i '/filter f_secure {/a\ facility(authpriv);' /etc/syslog-ng/syslog-ng.confsed -i '/destination priverr {/a\ file("/var/log/secure");' /etc/syslog-ng/syslog-ng.confsed -i '/log {/a\ source(src); filter(f_secure); destination(priverr);' /etc/syslog-ng/syslog-ng.conffi
fi
touch /var/log/secure
if command -v systemctl &>/dev/null; thensystemctl restart rsyslog.service
elif command -v service &>/dev/null; thenservice syslog restart
elseaction "无法确定系统类型或找不到适用的服务管理工具" /bin/falseexit 1
fi
action "syslog 配置已修改并服务已重启" /bin/true
}
su#121
#122#123 rsyslog 远程日志功能
rsyslog(){
echo "#123 rsyslog 远程日志功能"
ip="192.168.0.1"
mail="*.*"
file="/etc/rsyslog.conf"
if [ -f "$file" ]; thencp "$file" "$file".backupecho "$mial" @"$ip" >> "$file"systemctl restart rsyslogaction "rsyslog 已经重启" /bin/true
elseaction "rsyslog.conf 文件" /bin/false
fi
}
rsyslog#124 syslog_ng远程日志功能
syslog_ng_conf(){
echo "#124 syslog_ng远程日志功能"
file="/etc/syslog-ng.conf"
ip="192.168.0.1"
shu="514"
if [ -f "$file" ]; thencp "$file" "$file".backupecho "destination logserver { udp("$ip" port("$shu"));};log {source(src);destination(logserver);};" >> "$file"systemctl restart syslog-ngaction "syslog-ng 已经重启" /bin/true
elseaction "syslog-ng文件" /bin/false
fi
}
syslog_ng_conf#125 syslog远程日志功能
syslog(){
echo "#125 syslog远程日志功能"
mail="*.*"
ip="192.168.0.1"
file=/etc/syslog.conf
if [ -f "$file" ]; thencp "$file" "$file".backupecho "$mail @$ip" >> "$file"service syslog restartaction "syslog 已经重启" /bin/true
elseaction "syslog.conf文件" /bin/false
fi
}
syslog # 设置 主机拒绝策略文件/etc/hosts.deny 的属组和属主为root
host_deny(){
echo "#设置主机拒绝策略文件/etc/hosts.deny 的属组和属主为root"
chown root:root /etc/hosts.deny
if [ "$?" == 0 ]
then
action "chown root:root /etc/hosts.deny" /bin/true
else
action "chown root:root /etc/hosts.deny" /bin/false
fi
}
host_deny# 设置 主机允许策略文件/etc/hosts.allow的权限为644
host_all(){
echo "#设置 主机允许策略文件/etc/hosts.allow的权限为644"
chmod 644 /etc/hosts.allow
if [ "$?" == 0 ]
then
action "chmod 644 /etc/hosts.allow" /bin/true
else
action "chmod 644 /etc/hosts.allow" /bin/false
fi
}
host_all# 设置 主机拒绝策略文件/etc/hosts.deny的权限为644
host_de(){
echo "#设置主机拒绝策略文件/etc/hosts.deny的权限为644"
chmod 644 /etc/hosts.deny
if [ "$?" == 0 ]
then
action "" /bin/true
else
action "" /bin/false
fi
}
host_de# 设置用户/组 的用户和密码文件属主属组为root
userpass(){
echo "#设置用户/组 的用户和密码文件属主属组为root"
chown root:root /etc/passwd /etc/shadow /etc/group /etc/gshadow
if [ "$?" == 0 ]
then
action "chown root:root /etc/passwd /etc/shadow /etc/group /etc/gshadow" /bin/true
else
action "chown root:root /etc/passwd /etc/shadow /etc/group /etc/gshadow" /bin/false
fi
}
userpass# 设置组文件 的权限为0644
group(){
echo "#设置组文件 的权限为0644"
chmod 0644 /etc/group
if [ "$?" == 0 ]
then
action "chmod 0644 /etc/group" /bin/true
else
action "chmod 0644 /etc/group" /bin/false
fi
}
group# 设置用户文件 的权限为644
passwdfile(){
echo "#设置用户文件 的权限为644"
chmod 0644 /etc/passwd
if [ "$?" == 0 ]
then
action "chmod 0644 /etc/passwd" /bin/true
else
action "chmod 0644 /etc/passwd" /bin/false
fi
}# 设置用户的密码文件为0400只读,禁止修改用户密码
shadow_file(){
echo "#设置用户的密码文件为0400只读,禁止修改用户密码"
chmod 0400 /etc/shadow
if [ "$?" == 0 ]
then
action "chmod 0400 /etc/shadow" /bin/true
else
action "chmod 0400 /etc/shadow" /bin/false
fi
}
shadow_file# 设置组密码文件为0400制度, 禁止修改组密码
gshadow_file(){
echo "#设置组密码文件为0400制度, 禁止修改组密码"
chmod 0400 /etc/gshadow
if [ "$?" == 0 ]
then
action "chmod 0400 /etc/gshadow" /bin/true
else
action "chmod 0400 /etc/gshadow" /bin/false
fi
}
gshadow_file# 设置sshd主配置文件属主属组为root
sshd_root(){
echo "#设置sshd主配置文件属主属组为root"
chown root:root /etc/ssh/sshd_config
if [ "$?" == 0 ]
then
action "chown root:root /etc/ssh/sshd_config" /bin/true
else
action "chown root:root /etc/ssh/sshd_config" /bin/false
fi
}
sshd_root# 设置sshd主配置文件权限为0600
sshd_limits(){
echo "#设置sshd主配置文件权限为0600"
chmod 600 /etc/ssh/sshd_config
if [ "$?" == 0 ]
then
action "chmod 600 /etc/ssh/sshd_config" /bin/true
else
action "chmod 600 /etc/ssh/sshd_config" /bin/false
fi
}
sshd_root# 设置/etc/profile文件属主属组为root
fprfile_env(){
echo "#设置/etc/profile文件属主属组为root"
chown root:root /etc/profile
if [ "$?" == 0 ]
then
action "chown root:root /etc/profile" /bin/true
else
action "chown root:root /etc/profile" /bin/false
fi
}
fprfile_env# 设置/etc/profile文件权限为644
profile_limits(){
echo "#设置/etc/profile文件权限为644"
chmod 644 /etc/profile
if [ "$?" == 0 ]
then
action "chmod 644 /etc/profile" /bin/true
else
action "chmod 644 /etc/profile" /bin/false
fi
}
profile_limits# 开机自启安全审计服务并现在启动
audit_enable(){
echo "#开机自启安全审计服务并现在启动"
systemctl enable --now auditd
if [ "$?" == 0 ]
then
action "systemctl enable --now auditd" /bin/true
else
action "systemctl enable --now auditd" /bin/false
fi
}
audit_enable# 开机自启日志服务并现在启动
rsyslog_log(){
echo "#开机自启日志服务并现在启动"
systemctl enable --now rsyslog
if [ "$?" == 0 ]
then
action "systemctl enable --now rsyslog" /bin/true
else
action "systemctl enable --now rsyslog" /bin/false
fi
}
rsyslog_log# 定义安全审计规则
anquanshengji(){
cp /etc/audit/rules.d/audit.rules /etc/audit/rules.d/audit.rules-${time}
echo "#定义安全审计规则"
echo '-a always,exit -F arch=b64 -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=4294967295 -k delete -a always,exit -F arch=b32 -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=4294967295 -k delete' >> /etc/audit/rules.d/audit.rules
if [ "$?" == 0 ]
then
action "/etc/audit/rules.d/audit.rules" /bin/true
else
action "/etc/audit/rules.d/audit.rules" /bin/false
fi
}
anquanshengji# 定义安全设计规则
anquansheji(){
cp /etc/audit/audit.rules /etc/audit/audit.rules-${time}
echo "#定义安全设计规则"
echo '-a always,exit -F arch=b64 -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=4294967295 -k delete -a always,exit -F arch=b32 -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=4294967295 -k delete' >> /etc/audit/audit.rules
if [ "$?" == 0 ]
then
action "/etc/audit/audit.rules " /bin/true
else
action "/etc/audit/audit.rules " /bin/false
fi
}
anquansheji# 定义安全审计规则
anquansheji_rulesd(){
echo "#定义安全审计规则"
echo ' -w /etc/group -p wa -k identity -w /etc/passwd -p wa -k identity -w /etc/gshadow -p wa -k identity -w /etc/shadow -p wa -k identity -w /etc/security/opasswd -p wa -k identity' >> /etc/audit/rules.d/audit.rules
if [ "$?" == 0 ]
then
action "/etc/audit/rules.d/audit.rules" /bin/true
else
action "/etc/audit/rules.d/audit.rules" /bin/false
fi
}
anquansheji_rulesd# 定义安全审计规则
anquansheji_audit(){
echo ' -w /etc/group -p wa -k identity -w /etc/passwd -p wa -k identity -w /etc/gshadow -p wa -k identity -w /etc/shadow -p wa -k identity -w /etc/security/opasswd -p wa -k identity' >> /etc/audit/audit.rules
if [ "$?" == 0 ]
then
action "/etc/audit/audit.rules" /bin/true
else
action "/etc/audit/audit.rules" /bin/false
fi
}
anquansheji_audit# 定义安全审计规则
anquansheji_rulesd_file(){
echo ' -w /etc/sudoers -p wa -k scope -w /etc/sudoers.d/ -p wa -k scope' >> /etc/audit/rules.d/audit.rules
if [ "$?" == 0 ]
then
action "/etc/audit/rules.d/audit.rules" /bin/true
else
action "/etc/audit/rules.d/audit.rules" /bin/false
fi
}
anquansheji_rulesd_file# 定义安全审计规则
anquansheji_audit_file(){
echo ' -w /etc/sudoers -p wa -k scope -w /etc/sudoers.d/ -p wa -k scope' >> /etc/audit/audit.rules
if [ "$?" == 0 ]
then
action "/etc/audit/audit.rules" /bin/true
else
action "/etc/audit/audit.rules" /bin/false
fi
}
anquansheji_audit_file# 暂停rpcbind服务--nfs需要依赖rpcbind服务来实现客户端和服务器的路由请求
systemctl disable --now rpcbind &>/dev/null
systemctl disable --now rpcbind.socket &>/dev/null#执行日志写入
bash_run
# systemctl stop rpcbind &>/dev/null
# systemctl stop rpcbind.socket &>/dev/null
# systemctl disable rpcbind.socket &>/dev/null
# systemctl disable rpcbind.socket &>/dev/null
action "CentOS Linux 7基线标准系统-等保三级-基线加固已完成!!" /bin/true
相关文章:
linux-等保三级脚本(2)
该脚本主要是针对 CentOS Linux 7 合规基线加固的一些配置操作,包括创建用户、安全审计配置、入侵防范配置、访问控制配置、身份鉴别策略配置等。如果您需要在脚本中添加公司网址,您可以在适当的位置添加相应的内容。不过请注意,在实际生产环…...

【论文阅读】Consistency Models
文章目录 IntroductionDiffusion ModelsConsistency ModelsDefinitionParameterizationSampling Training Consistency Models via DistillationTraining Consistency Models in IsolationExperiment Introduction 相比于单步生成的模型(例如 GANs, VAEs, normalizi…...

Ceph应用管理
目录 资源池 Pool 管理 创建 CephFS 文件系统 MDS 接口 服务端操作 客户端操作 创建 Ceph 块存储系统 RBD 接口 创建 Ceph 对象存储系统 RGW 接口 OSD 故障模拟与恢复 资源池 Pool 管理 我们如何向 Ceph 中存储数据呢?首先我们需要在 Ceph 中定义一个 Pool…...

大师学SwiftUI第6章 - 声明式用户界面 Part 3
安全域视图 SwiftUI还内置了创建安全文本框的视图。这一视图会把用户输入的字符替换成点以及隐藏敏感信息,比如密码。 SecureField(String, text: Binding):该初始化方法创建一个安全输入框。第一个参数定义占位文本,text参数为存储…...

使用AI自动生成PPT提高制作效率
使用AI自动生成PPT提高制作效率 在制作PPT方面,很多制作者都会轻易跳进一个怪圈:“我要制作一个关于关爱老人的PPT,该怎么做呢,有模板没有?”这个会涉及很多逻辑需要经过不断的思考,制作PPT要通过很多素材、使用技巧、…...

Servlet中访问网页常遇到的问题
网页出现404 出现这一种情况是浏览器访问的资源不存在 第一种情况通常是路径出错请检查你的路径是否一致 第二种情况确认你的webapp是否被正确加载 smart tomcat由于只加载一个webapp 如果加载失败 就会直接启动失败 拷贝war方式到Tomcat要加载多个webapp如果失败只有日志 查…...

Vue加载序列帧动图
解读方法 使用<img :src"currentFrame" alt"加载中" /> 加载图片动态更改src的值使用 requestAnimationFrame 定时更新在需要的页面调用封装的组件 <LoadToast v-if"showLoading" /> 封装组件 <template><div class"…...

k8s的配置资源管理
1、configmap*:1.2加入新的特征(重点) 2、secret:保存密码,token,保存敏感的k8s资源(保存加密的信息) (1)敏感的k8s资源,这类数据可以直接存放在…...

vue 指定区域可拖拽的限定拖拽区域的div(如仅弹窗标题可拖拽的弹窗)
<template><div class"container" ref"container"><div class"drag-box" v-drag><div class"win_head">弹窗标题</div><div class"win_content">弹窗内容</div></div><…...

【idea】idea插件编写教程,博主原创idea插件已上架idea插件市场 欢迎下载
前言:经常使用Objects.equals(a,b)方法的同学 应该或多或少都会因为粗心而传错参, 例如日常开发中 我们使用Objects.equals去比较 status(入参),statusEnum(枚举), 很容易忘记statusEnum.getCode() 或 statusEnum.getVaule() ,再比…...

探索Python数据结构与算法:解锁编程的无限可能
文章目录 一、引言1.1 数据结构与算法对于编程的重要性1.2 Python作为实现数据结构与算法的强大工具 二、列表和元组2.1 列表:创建列表、索引、切片和常用操作2.2 元组:不可变序列的特性和使用场景 三、字符串操作和正则表达式3.1 字符串的常见操作和方法…...
责任链模式介绍及演示
责任链模介绍 责任链模式(Chain of Responsibility Pattern)是一种行为设计模式,其主要目的是将请求的发送者和接收者解耦。在这个模式中,多个对象有机会处理一个请求,形成一条“责任链”。每个对象在链中检查该请求并…...
智能小程序小部件(Widget)表单组件属性说明+代码明细
在 Tuya MiniApp Tools 中,新建项目并选择小部件(Widget)对应模板即可自动创建小部件(Widget)项目。 button 按钮,用于强调操作并引导用户去点击。 属性说明 属性名类型默认值必填说明sizestringdefault否按钮的大小typestringdefault否按钮的样式类…...

自学Python笔记总结(更新中……)
自学Python笔记总结 网址数据类型类型查看类型,使用type内置类标识符 输出输入语句format函数的语法及用法数据类型的转换运算符算数运算符赋值运算符的特殊场景拆包 比较运算符逻辑运算符 与 短路位运算符运算符优先级 程序流程控制分支语句pass 占位 循环语句 whi…...

十四.变量、异常处理
变量、异常处理 1.变量1.1系统变量1.1.1系统变量分类1.1.2查看系统变量 1.2用户变量1.2.1用户变量分类1.2.2会话用户变量1.2.3局部变量1.2.4对比会话用户变量与局部变量 补充:MySQL 8.0的新特性—全局变量的持久化 2.定义条件与处理程序2.1案例分析2.2定义条件2.3定义处理程序2…...

import { ArrowRight } from “@element-plus/icons-vue“;
今天下午快被这个问题折磨疯了 虽然知道这个问题怎么产生的 但项目里那个碍眼的红线就是去不掉 后来才发现 这是插件的锅 我的心情 你知道我想要说什么的 想必能看到这篇文章的 也知道这个问题是怎么产生的 vue3ts使用的时候 默认是需要带上文件名的 但是引入el组件时 …...
Kubernetes 面试宝典
创建 Pod的主要流程? 客户端提交 Pod 的配置信息(可以是 yaml 文件定义的信息)到 kube-apiserver. Apiserver 收到指令后,通知 controllr-manager 创建一个资源对象 controller-manager 通过 apiserver 将 pod 的配置信息存储到 ETCD 数据中薪心中 kube-scheduler 检查到 p…...

c语言二维数组
系列文章目录 c语言二维数组 c语言二维数组 系列文章目录一、二维数组的定义一、二维数组的内存模型 一、二维数组的定义 int main() {//二维数组的定义int arr[3][4];arr[0][0]; arr[0][1]; arr[0][2]; arr[0][3]; arr[0][4];arr[1][0]; arr[1][1]; arr[1][2]; arr[1][3]; ar…...

ArcGIS Pro 拓扑编辑和常见一些拓扑错误处理
7.4 拓扑编辑 拓扑编辑也叫共享编辑,多个数据修改时,一块修改,如使用数据:chp7\拓扑检查.gdb,数据集DS下JZX、JZD和DK,加载地图框中,在“地图”选项卡下选择“地图拓扑”或“ds_Topology(地理数据库)”&…...

前端踩坑之——antDesignVue的upload组件
本地启动时控制台会报404,放到服务器上控制台会报405(多发一个请求) 原因:upLoad有默认的上传事件 解决:阻止默认事件即可 beforeUpload Hook function which will be executed before uploading. Uploading will be stopped with false or …...
[2025CVPR]DeepVideo-R1:基于难度感知回归GRPO的视频强化微调框架详解
突破视频大语言模型推理瓶颈,在多个视频基准上实现SOTA性能 一、核心问题与创新亮点 1.1 GRPO在视频任务中的两大挑战 安全措施依赖问题 GRPO使用min和clip函数限制策略更新幅度,导致: 梯度抑制:当新旧策略差异过大时梯度消失收敛困难:策略无法充分优化# 传统GRPO的梯…...

shell脚本--常见案例
1、自动备份文件或目录 2、批量重命名文件 3、查找并删除指定名称的文件: 4、批量删除文件 5、查找并替换文件内容 6、批量创建文件 7、创建文件夹并移动文件 8、在文件夹中查找文件...

全球首个30米分辨率湿地数据集(2000—2022)
数据简介 今天我们分享的数据是全球30米分辨率湿地数据集,包含8种湿地亚类,该数据以0.5X0.5的瓦片存储,我们整理了所有属于中国的瓦片名称与其对应省份,方便大家研究使用。 该数据集作为全球首个30米分辨率、覆盖2000–2022年时间…...

cf2117E
原题链接:https://codeforces.com/contest/2117/problem/E 题目背景: 给定两个数组a,b,可以执行多次以下操作:选择 i (1 < i < n - 1),并设置 或,也可以在执行上述操作前执行一次删除任意 和 。求…...

ElasticSearch搜索引擎之倒排索引及其底层算法
文章目录 一、搜索引擎1、什么是搜索引擎?2、搜索引擎的分类3、常用的搜索引擎4、搜索引擎的特点二、倒排索引1、简介2、为什么倒排索引不用B+树1.创建时间长,文件大。2.其次,树深,IO次数可怕。3.索引可能会失效。4.精准度差。三. 倒排索引四、算法1、Term Index的算法2、 …...
MySQL用户和授权
开放MySQL白名单 可以通过iptables-save命令确认对应客户端ip是否可以访问MySQL服务: test: # iptables-save | grep 3306 -A mp_srv_whitelist -s 172.16.14.102/32 -p tcp -m tcp --dport 3306 -j ACCEPT -A mp_srv_whitelist -s 172.16.4.16/32 -p tcp -m tcp -…...
laravel8+vue3.0+element-plus搭建方法
创建 laravel8 项目 composer create-project --prefer-dist laravel/laravel laravel8 8.* 安装 laravel/ui composer require laravel/ui 修改 package.json 文件 "devDependencies": {"vue/compiler-sfc": "^3.0.7","axios": …...
Mysql8 忘记密码重置,以及问题解决
1.使用免密登录 找到配置MySQL文件,我的文件路径是/etc/mysql/my.cnf,有的人的是/etc/mysql/mysql.cnf 在里最后加入 skip-grant-tables重启MySQL服务 service mysql restartShutting down MySQL… SUCCESS! Starting MySQL… SUCCESS! 重启成功 2.登…...
JS手写代码篇----使用Promise封装AJAX请求
15、使用Promise封装AJAX请求 promise就有reject和resolve了,就不必写成功和失败的回调函数了 const BASEURL ./手写ajax/test.jsonfunction promiseAjax() {return new Promise((resolve, reject) > {const xhr new XMLHttpRequest();xhr.open("get&quo…...

破解路内监管盲区:免布线低位视频桩重塑停车管理新标准
城市路内停车管理常因行道树遮挡、高位设备盲区等问题,导致车牌识别率低、逃费率高,传统模式在复杂路段束手无策。免布线低位视频桩凭借超低视角部署与智能算法,正成为破局关键。该设备安装于车位侧方0.5-0.7米高度,直接规避树枝遮…...