##Description: Security detection script
echo "##########################################################################"
echo "# Epoint health check script #"
echo "#警告:本脚本只是一个检查的操作,未对服务器做任何修改,管理员可以根据此报告 #"
echo "##########################################################################"
#read -p "=====================Are You Ready,Please press enter=================="
echo "##########################################################################"
echo "##########################################################################"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>系统基本信息<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
system=$(cat /etc/os-release | grep "^NAME" | awk -F\" '{print $2}')
version=$(cat /etc/redhat-release | awk '{print $4$5}')
address=$(ip addr | grep inet | grep -v "inet6" | grep -v "127.0.0.1" | awk '{ print $2; }' | tr '\n' '\t' )
cpumodel=$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq)
cpu=$(cat /proc/cpuinfo | grep 'processor' | sort | uniq | wc -l)
machinemodel=$(dmidecode | grep "Product Name" | sed 's/^[ \t]*//g' | tr '\n' '\t' )
echo "机器型号: $machinemodel"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>资源使用情况<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
summemory=$(free -h |grep "Mem:" | awk '{print $2}')
freememory=$(free -h |grep "Mem:" | awk '{print $4}')
usagememory=$(free -h |grep "Mem:" | awk '{print $3}')
uptime=$(uptime | awk '{print $2" "$3" "$4" "$5}' | sed 's/,$//g')
loadavg=$(uptime | awk '{print $9" "$10" "$11" "$12" "$13}')
echo "已使用内存大小: $usagememory"
echo "可使用内存大小: $freememory"
echo "=============================dividing line================================"
echo "=============================dividing line================================"
ps -ef | grep zombie | grep -v grep
echo ">>>有僵尸进程------[需调整]"
echo "=============================dividing line================================"
ps auxf |sort -nr -k 3 |head -5
echo "=============================dividing line================================"
ps auxf |sort -nr -k 4 |head -5
echo "=============================dividing line================================"
echo "=============================dividing line================================"
echo "=============================dividing line================================"
echo "=============================dividing line================================"
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
echo "=============================dividing line================================"
systemctl list-unit-files | grep enabled
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>系统用户情况<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
echo "=============================dividing line================================"
cut -d: -f1,2,3,4 /etc/passwd
echo "=============================dividing line================================"
cut -d: -f1,2,3 /etc/group
echo "=============================dividing line================================"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>身份鉴别安全<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
grep -i "^password.*requisite.*pam_cracklib.so" /etc/pam.d/system-auth > /dev/null
grep -i "pam_pwquality\.so" /etc/pam.d/system-auth > /dev/null
echo ">>>密码复杂度:未设置,请加固密码--------[需调整]"
echo "=============================dividing line================================"
awk -F":" '{if($2!~/^!|^*/){print ">>>("$1")" " 是一个未被锁定的账户,请管理员检查是否是可疑账户--------[需调整]"}}' /etc/shadow
echo "=============================dividing line================================"
more /etc/login.defs | grep -E "PASS_MAX_DAYS" | grep -v "#" |awk -F' ' '{if($2!=90){print ">>>密码过期天数是"$2"天,请管理员改成90天------[需调整]"}}'
echo "=============================dividing line================================"
grep -i "^auth.*required.*pam_tally2.so.*$" /etc/pam.d/sshd > /dev/null
echo ">>>登入失败处理:未开启,请加固登入失败锁定功能----------[需调整]"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>访问控制安全<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
more /etc/passwd |awk -F ":" '{if($3>500){print ">>>/etc/passwd里面的"$1 "的UID为"$3",该账户非系统默认账户,请管理员确认是否为可疑账户--------[需调整]"}}'
echo "=============================dividing line================================"
awk -F: '$3==0 {print $1}' /etc/passwd
echo "=============================dividing line================================"
awk -F: '($2=="!!") {print $1"该账户为空口令账户,请管理员确认是否为新增账户,如果为新建账户,请配置密码-------[需调整]"}' /etc/shadow
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>安全审计<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
echo "正常情况下登录到本机30天内的所有用户的历史记录:"
echo "=============================dividing line================================"
echo "查看syslog日志审计服务是否开启:"
if service rsyslog status | egrep " active \(running";then
echo ">>>经分析,syslog服务已开启"
echo ">>>经分析,syslog服务未开启,建议通过service rsyslog start开启日志审计功能---------[需调整]"
echo "=============================dividing line================================"
if more /etc/rsyslog.conf | egrep "@...\.|@..\.|@.\.|\*.\* @...\.|\*\.\* @..\.|\*\.\* @.\.";then
echo ">>>经分析,客户端syslog日志已开启外发--------[需调整]"
echo ">>>经分析,客户端syslog日志未开启外发---------[无需调整]"
echo "=============================dividing line================================"
more /etc/rsyslog.conf | grep -v "^[$|#]" | grep -v "^$"
echo "=============================dividing line================================"
ls -ltr /bin/ls /bin/login /etc/passwd /bin/ps /etc/shadow|awk '{print ">>>文件名:"$9" ""最后修改时间:"$6" "$7" "$8}'
###############################################################################################
# ls文件:是存储ls命令的功能函数,被删除以后,就无法执行ls命令 #
# login文件:login是控制用户登录的文件,一旦被篡改或删除,系统将无法切换用户或登陆用户 #
# /etc/passwd是一个文件,主要是保存用户信息 #
# /bin/ps 进程查看命令功能支持文件,文件损坏或被更改后,无法正常使用ps命令 #
# /etc/shadow是/etc/passwd的影子文件,密码存放在该文件当中,并且只有root用户可读 #
###############################################################################################"
echo "=============================dividing line================================"
log_secure=/var/log/secure
log_messages=/var/log/messages
log_boot=/var/log/boot.log
if [ -e "$log_secure" ]; then
echo ">>>/var/log/secure日志文件存在"
echo ">>>/var/log/secure日志文件不存在------[需调整]"
if [ -e "$log_messages" ]; then
echo ">>>/var/log/messages日志文件存在"
echo ">>>/var/log/messages日志文件不存在------[需调整]"
if [ -e "$log_cron" ]; then
echo ">>>/var/log/cron日志文件存在"
echo ">>>/var/log/cron日志文件不存在--------[需调整]"
if [ -e "$log_boot" ]; then
echo ">>>/var/log/boot.log日志文件存在"
echo ">>>/var/log/boot.log日志文件不存在--------[需调整]"
if [ -e "$log_dmesg" ]; then
echo ">>>/var/log/dmesg日志文件存在"
echo ">>>/var/log/dmesg日志文件不存在--------[需调整]"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>剩余信息保护<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
echo "如果磁盘空间利用率过高,请及时调整---------[需调整]"
echo "=============================dividing line================================"
echo "=============================dividing line================================"
more /etc/fstab | grep -v "^#" | grep -v "^$"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>入侵防范安全<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
more /var/log/secure |grep refused
echo "有入侵行为,请分析处理--------[需调整]"
echo "=============================dividing line================================"
echo ">>>用户错误登入--------[需调整]"
echo "=============================dividing line================================"
more /var/log/secure | grep "Failed" > /dev/null
more /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print ">>>登入失败的IP和尝试次数: "$2"="$1"次---------[需调整]";}'
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>恶意代码防范<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
crontab -l | grep clamscan.sh > /dev/null
crontab -l | grep freshclam.sh > /dev/null
echo ">>>未安装ClamAV杀毒软件,请部署杀毒软件加固主机防护--------[无需调整]"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>资源控制安全<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
if ps -elf |grep xinet |grep -v "grep xinet";then
echo ">>>xinetd服务正在运行,请检查是否可以把xinetd服务关闭--------[无需调整]"
echo ">>>xinetd服务未开启-------[无需调整]"
echo "=============================dividing line================================"
if service sshd status | grep -E "listening on|active \(running\)"; then
echo ">>>SSH服务未开启--------[需调整]"
echo "=============================dividing line================================"
echo "查看是否开启了Telnet-Server服务:"
if more /etc/xinetd.d/telnetd 2>&1|grep -E "disable=no"; then
echo ">>>Telnet-Server服务已开启"
echo ">>>Telnet-Server服务未开启--------[无需调整]"
echo "=============================dividing line================================"
ps axu | grep iptables | grep -v grep || ps axu | grep firewalld | grep -v grep
iptables -nvL --line-numbers
echo ">>>防火墙未启用--------[需调整]"
echo "=============================dividing line================================"
echo "查看系统SSH远程访问设置策略(host.deny拒绝列表):"
if more /etc/hosts.deny | grep -E "sshd"; then
echo ">>>远程访问策略已设置--------[需调整]"
echo ">>>远程访问策略未设置--------[无需调整]"
echo "=============================dividing line================================"
echo "查看系统SSH远程访问设置策略(hosts.allow允许列表):"
if more /etc/hosts.allow | grep -E "sshd"; then
echo ">>>远程访问策略已设置--------[需调整]"
echo ">>>远程访问策略未设置--------[无需调整]"
echo "=============================dividing line================================"
echo "当hosts.allow和host.deny相冲突时,以hosts.allow设置为准"
echo "=============================dividing line================================"
grep -i "TMOUT" /etc/profile /etc/bashrc
echo ">>>未设置登入超时限制,请设置,设置方法:在/etc/profile或者/etc/bashrc里面添加参数TMOUT=600 --------[需调整]"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>end<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"