Liunx应急上机排查脚本

应急排查
建议先清除计划任务、启动项、守护进程,再清除恶意进程,防止卷土重来,清理不干净。
应急排查收集常见信息脚本

#!/bin/bash 
#Liunx 应急响应上机信息收集
#应急清理:建议先清除计划任务、启动项、守护进程,再清除恶意进程。
# busybox 安装
#yum -y install wget make gcc perl glibc-static ncurses-devel libgcrypt-devel
#wget http://busybox.net/downloads/busybox-1.33.0.tar.bz2
#tar -jxvf busybox-1.33.0.tar.bz2
#cd busybox-1.33.0 && make && make install
echo -e '\e[31;43m 应急排查信息收集\e[0m'
echo -e '\e[31;43m 应急建议先清除计划任务、启动项、守护进程,再清除恶意进程。\e[0m' 

uptime
#账号安全
echo -e '\e[31;43m 账号安全\e[0m'
#当前登陆用户(pts|tty)
echo -e '\e[34;47m w命令 \e[0m'
#剔除某用户pkill -9 -t pts/0
w

#查看特权用户
echo -e '\e[34;47m 特权用户 \e[0m'
awk -F: '$3==0{print $1}' /etc/passwd
echo -e '\e[34;47m sudo的权限的用户 \e[0m'
cat /etc/sudoers | grep -v "^#\|^$" | grep "ALL=(ALL)"
#查看公钥配置
echo -e '\e[34;47m 免密登陆公钥 \e[0m'
cat ~/.ssh/authorized_keys

#查看可以远程登陆的用户
echo -e '\e[34;47m 可以远程登陆的用户 \e[0m'
awk '/\$1|\$6/{print $1}' /etc/shadow

#成功登陆的用户和时间
echo -e '\e[34;47m 成功登陆用户和时间 \e[0m'
grep "Accepted " /var/log/secure | awk '{print $1,$2,$3,$9,$11}'
#爆破的IP
echo -e '\e[34;47m 存在爆破的IP \e[0m'
 grep "Failed password" /var/log/secure|grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"|sort |uniq  -c
#爆破字典
echo -e '\e[34;47m 爆破的字典 \e[0m'
grep "Failed password" /var/log/secure|perl -e 'while($_=<>){ /for(.*?) from/; print "$1\n";}'|sort -nr|uniq -c

#查看网络链接
echo -e '\e[31;43m 网络情况IP \e[0m'
echo -e '\e[34;47m 查看网络链接 \e[0m'
netstat -antlp 

echo -e '\e[34;47m 主机防火墙配置 \e[0m'
iptables -nL


#查看用户空间的进程
echo -e '\e[31;43m 进程 \e[0m'
echo -e '\e[34;47m ps 命令 \e[0m'
ps -aux | grep -v '\['
#查看开机启动
echo -e '\e[31;43m 启动项 \e[0m'
echo -e '\e[34;47m 查看启动项文件\e[0m'
runlevel
ls -l /etc/rc.d/rc3.d/ 
chkconfig --list

echo -e '\e[34;47m 定时任务 \e[0m'
# 查看定时任务
crontab -l

#其他启动任务
echo -e '\e[34;47m 其他启动任务文件 \e[0m'
crontfile=("/var/spool/cron/" "/etc/crontab" "/etc/cron.d/" "/etc/cron.daily/" "/etc/cron.hourly/" "/etc/cron.monthly/" "/etc/cron.weekly/" "/etc/anacrontab" "/var/spool/anacron/")
for f in ${crontfile[@]};
do
echo '=======定时启动文件目录:'$f
ls $f
done

echo -e '\e[34;47m 最进修改的文件 \e[0m'
# 查看/etc/下最近两天的修改的文件
find /etc -ctime -2 
#lsof -c $file  查看是否存在有可疑文件的相关进程信息


echo -e '\e[31;43m 加载恶意链接库 \e[0m'
echo -e '\e[34;47m 是否存在预加载 \e[0m'
# 查看是否有预加载的so库文件
cat /etc/ld.so.preload
echo $LD_PRELOAD

#发现可以进程后查看:
#1)ls -l /proc/$PID/exe
#2)

#校验rpm文件是否有变化
echo -e '\e[31;43m RPM file \e[0m'
echo -e '\e[34;47m 检查RPM file是否被改 \e[0m'

rpm -Va 

执行结果eg:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/u013908944/article/details/118275314