linux主机应急排查
linux应急响应
文件
ls -alt
查找72小时内新增的文件:
find / -ctime -2
文件日期、新增文件、可疑/异常文件、最近使用文件、浏览器下载文件
/var/run/utmp 有关当前登录用户的信息记录
/etc/passwd 用户列表
/tmp 临时目录
~/.ssh
/etc/ssh
ls -alt | head -n 10 查看文件
find ./ -mtime 0 -name "*.jsp" 查找24小时内被修改的JSP文件
ls -al /tmp | grep "Feb 27" 根据确定时间去反推变更的文件
find / *.jsp -perm 4777 查找777的权限的文件
隐藏文件.xxx
分析sshd 文件是否包括IP信息:
strings /usr/bin/.sshd | egrep '[1-9]{1,3}.[1-9]{1,3}.'
更改:
find /etc/ /usr/bin/ /usr/sbin/ /bin/ /usr/local/bin/ -type f -mtime 0
访问:
find /tmp -iname "*" -atime 1 -type f
命令目录:/usr/bin /usr/sbin
日志
/var/log/
/var/log/wtmp 登录进入,退出,数据交换、关机和重启纪录,即last
/var/log/lastlog 文件记录用户最后登录的信息,即lastlog
/var/log/secure 记录登入系统存取数据的文件,如 pop3/ssh/telnet/ftp
/var/log/cron 与定时任务相关的日志信息
/var/log/message 系统启动后的信息和错误日志
/var/log/apache2/access.log apache access log
/var/log/message 包括整体系统信息
/var/log/auth.log 包含系统授权信息,包括用户登录和使用的权限机制等
/var/log/userlog 记录所有等级用户信息的日志
/var/log/cron 记录crontab命令是否被正确的执行
/var/log/xferlog(vsftpd.log)记录Linux FTP日志
/var/log/lastlog 记录登录的用户,可以使用命令lastlog查看
/var/log/secure 记录大多数应用输入的账号与密码,登录成功与否
var/log/faillog 记录登录系统不成功的账号信息
history
查看爆破失败的IP:
grep 'Failed' /var/log/secure | awk '{print $11}' | sort | uniq -c | sort -nr
查看登录成功的IP:
grep 'Accepted' /var/log/secure | awk '{print $11}' | sort | uniq -c | sort -nr
more messages
定位有多少IP在爆破主机的root帐号:
grep "Failed password for root" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -nr | more
登录成功的IP:
grep "Accepted " /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -nr | more
监控最后400行日志文件的变化 等价与 tail -n 400 -f (-f参数是实时):
tail -400f demo.log
标记该行重复的数量,不重复值为1:
uniq -c demo.log
输出文件demo.log中查找所有包行ERROR的行的数量:
grep -c 'ERROR' demo.log
cat /var/log/secure |grep 'Accepted password‘
查看登录成功的日期、用户名及IP:
grep "Accepted " /var/log/secure* | awk '{print $1,$2,$3,$9,$11}'
查看试图爆破主机的IP:
开启iptables:grep "refused" /var/log/secure* | awk {'print $9'} | sort | uniq -c |sort -nr | more
未开启iptables:
grep "Failed password" /var/log/secure* | grep -E -o "(([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}))" | uniq -c
查看爆破主机的ROOT账号的IP:
grep "Failed password for root" /var/log/secure | awk '{print $11}' | sort
查看爆破用户名字典:
grep "Failed password" /var/log/secure | awk {'print $9'} | sort | uniq -c | sort -nr
grep -o "Failed password" /var/log/secure|uniq -c
grep "Accepted " /var/log/secure | awk '{print $1,$2,$3,$9,$11}
用户
last
/etc/shadow 密码登陆相关信息
uptime 查看用户登陆时间
/etc/sudoers sudo用户列表
/etc/passwd
查看UID为0的帐号:
awk -F: '{if($3==0)print $1}' /etc/passwd
查看能够登录的帐号:
cat /etc/passwd | grep -E "/bin/bash$"
awk '/$1|$6/{print $1}' /etc/shadow
lastlog 系统中所有用户最近一次登录信息
lastb 用户错误的登录列表
more /etc/sudoers | grep -v "^#|^$" | grep "ALL=(ALL)"
who 查询utmp文件并报告当前登录的每个用户
w 查询utmp文件并显示当前系统中每个用户和它所运行的进程信息
users 打印当前登录的用户,每个用户名对应一个登录会话。如果一个用户不止一个登录会话,其用户名显示相同次数
进程
lsof
ps aux | grep pid | grep –v grep
lsof -i:1677 查看指定端口对应的程序
lsof -p 1234 检查pid号为1234进程调用情况
strace -f -p 1234 跟踪分析pid号为1234的进程
lsof -g gid 找恶意文件关联的lib文件
ps -aux或ps -ef
pstree -a
获取进程pid后可cd到/proc/对应pid/fd
隐藏进程查看
ps -ef | awk '{print}' | sort -n | uniq >1ls /proc | sort -n |uniq >2diff 1 2
netstat -anptl
top
端口
netstat -anpt
自启动
~/.bashrc
rc.local
/etc/init.d
chkconfig
chkconfig --list | grep "3:on|5:on"
/etc/init.d/rc.local
/etc/rc.local
/etc/init.d/ 开机启动项
/etc/cron* 定时任务
计划任务
crontab -l
crontab /etc/cron*
crontab -u root -l
cat /etc/crontab
ls /etc/cron.*
/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/*
/var/log/cron*
misc
stat
echo $PATH
./rpm -Va > rpm.log
kill -9
chattr –i
rm
setfacl
getfacl
lsattr
ssh
chmod
find / -perm -004000 -type f
chattr +i
去执行权限:
chmod 000
查看预加载库:
echo $LD_PRELOAD
ssh后门快速判断:
strings /usr/bin/.sshd | egrep '[1-9]{1,3}.[1-9]{1,3}.'
检查SSH后门:
1)比对ssh的版本
ssh -V
2)查看ssh配置文件和/usr/sbin/sshd的时间:
stat /usr/sbin/sshd
3)strings检查/usr/sbin/sshd,是否有邮箱信息
4)通过strace监控sshd进程读写文件的操作
一般的sshd后门都会将账户密码记录到文件,可以通过strace进程跟踪到ssh登录密码文件。
ps axu | grep sshd | grep -v grep
root 65530 0.0 0.1 48428 1260 ? Ss 13:43 0:00 /usr/sbin/sshd
strace -o aa -ff -p 65530
grep open aa* | grep -v -e No -e null -e denied| grep WR
aa.102586:open("/tmp/ilog", O_WRONLY|O_CREAT|O_APPEND, 0666) = 4