主要命令:
1 | awk、sort、uniq、find、lsattr |
文件排查
近期修改/创建文件排查
1 | #查看24小时内被修改的文件,0不是24小时 1表示48小时。单位为天 |
检查Root用户的.bash_history 文件
1 | cat /root/.bash_history |
检查普通用户的.bash_history 文件
1 | cat /home/[user]/.bash_history |
i属性:
1 | #查看文件是否有 |
webshell查找:
1 | find /var/www/ -name "*.php" |xargs egrep 'assert|phpspy|c99sh|milw0rm|eval|\(gunerpress|\(base64_decoolcode|spider_bc|shell_exec|passthru|\(\$\_\POST\[|eval \(str_rot13|\.chr\(|\$\{\"\_P|eval\(\$\_R|file_put_contents\(\.\*\$\_|base64_decode' |
查找指定时间内修改过的文件
1 | touch -t 202006171150 t_start //新建一个2015-06-17 11:50 时间点的文件 |
或者
1 | find / -name '*' -newermt '2020-10-14 08:00:00' ! -newermt '2020-10-16 00:00:00' |
指定日期内产生的文件
1 | ls --full-time /home/ | sed -n '/2019-09-03/p' |
网络排查
进程端口
异常连接:
1 | netstat -pantlu |
通过进程ID查看对应程序:
1 | Ls -alt /proc/<pid>/exe |
查看历史命令:
1 | history |
查看资源占用情况:
1 | top |
恶意通讯
监控与目标IP通信的进程(有些时候可能会是域名,无法访问的时候可能会自动切换IP,这时候可以将域名在hosts里修改固定IP)
1 | while true;do netstat -antp | grep 211.94.114.12; done |
枚举系统文件夹的文件,按修改事件排序查看7天内被修改过的文件:
1 | find /usr/bin/ /usr/sbin/ /bin/ /usr/local/bin/ -type f -mtime +7 | xargs ls -la |
监控守护进程的行为:
1 | lsof -p [pid] |
永恒之蓝流量
对于MS17010的流量,通过网络侧抓包分析,永恒之蓝的攻击载荷一般都会发送NT Trans Request的载荷,里面含有大量的nop指令,发送完NT Trans Request载荷后会发送几个Trans2 Secondary Request载荷相关的Trans2 Secondary Request,在发送载荷后,在Trans2 Respone内的返回Multiplex ID:82则为攻击成功。
系统排查
历史命令
1 | history |
登陆日志
Rootkit
账户排查
查看UID为0的帐号:
1 | awk -F: '{if($3==0)print $1}' /etc/passwd |
查看能够登录的帐号:
1 | cat /etc/passwd | grep -E "/bin/bash$" |
进程排查
通过进程ID查看对应程序:
1 | Ls -alt /proc/<pid>/exe |
查看占用进程:
1 | top |
隐藏进程查看
1 | ps -ef | awk '{print}' | sort -n | uniq >1 |
隐藏项进程排查
1 | ps -ef |awk '{print}'|sort -n | uniq >1 |
启动项
1 | ls -alt /etc/init.d/ |
一 通过(init.d)服务的方式自启动
1.在/etc/init.d 下建立相关程序的启动脚本
ln -s /etc/init.d/服务名 /etc/rc.d/rc3.d/S100服务名 //S:开机自启动 100:启动顺序
2.chkconfig –add 服务名
3.chkconfig 服务名 on 开机自启动
chkconfig 服务名 off 关闭自启动
4.service 服务名 start 手动启动服务
5.service 服务名 stop 手动关闭服务
6.chkconfig –list查看开启启动项
3,5为关注启动
二 通过systemctl 服务的方式自启动
1.cd /usr/lib/systemd/system/
2.vi 服务名.service
1 | # Systemd unit file for default tomcat |
3.systemctl enable 服务名.service //设置自启动服务
4.systemctl start 服务名.service //启动服务
5.systemctl stop 服务名.service //停止服务
6.service 服务名 start //启动服务
7.service 服务名 stop //停止服务
三 自定义开机程序
1.vi /etc/rc.d/rc.local
2.末尾添加启动命令
3 /usr/src/tomcat/bin/startup.sh /*自动启动tomcat*/
四 定时启动脚本
最好是-e进去看,因为有些直接-l是无法看到的
- /root下写好启动的shell文件
- crontab -e
- 设置好定时时间
- 设置为每分钟检查一次 // */1 * * * * 脚本目录
other
1 | # 显示logged in表示用户还在登录 |
1 | crontab -l |
日志分析
应用日志
1 | cat access.log | cut -f 1 -d ' '|sort |uniq -c | sort -k 1 -n -r 查看攻击数量最多的IP |
跟这个等价:
1 | cat access.log | awk '{print $7}' | uniq -c | sort -nr | head -10 |
IP统计到IP.txt
1 | awk '{print $1}' access.log >ip.txt |
计算IP出现次数
1 | sort ip.txt |uniq -c |
查找文件
1 | find ./ -name "*.log" |xargs grep -rn "/data/admin.html" |
主机日志
查询log主机登陆日志:
1 | grep "Accepted " /var/log/secure* | awk '{print $1,$2,$3,$9,$11}' |
定位有爆破的源IP:
1 | 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 |
爆破日志的用户名密码:
1 | grep "Failed password" /var/log/secure|perl -e 'while($_=<>){ /for(.*?) from/; print "$1\n";}'|uniq -c|sort -nr |
登录成功
1 | grep 'Accepted' /var/log/secure | awk '{print $11}' | sort | uniq -c | sort -nr |
或者last命令,它会读取位于/var/log/wtmp的文件
1 | lastb #列出登入系统失败的用户相关信息 |
把该文件记录的登录系统的用户名单,全部显示出来。
登录失败:
1 | grep 'Failed' /var/log/secure | awk '{print $11}' | sort | uniq -c | sort -nr |
查询可以远程登录的帐号信息:
1 | awk '/\$1|\$6/{print $1}' /etc/shadow |
查询特权用户特权用户(uid 为0):
1 | awk -F: '$3==0{print $1}' /etc/passwd |
针对幽灵模式(last不会留存日志),可以通过ss -nt命令找到144.21.14.13
1 | root@VM-0-7-ubuntu:~# ss -nt#可以看到 |