UNIX应急响应攻略( 二 )


[root@ay4z3ro foo]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.1 0.2 1356 496 ? S 19:07 0:04 init
root 2 0.0 0.0 0 0 ? SW 19:07 0:00 [keventd]
root 3 0.0 0.0 0 0 ? SWN 19:07 0:00 [ksoftirqd_CPU0]
root 4 0.0 0.0 0 0 ? SW 19:07 0:00 [kswapd]
root 5 0.0 0.0 0 0 ? SW 19:07 0:00 [bdflush]
root 6 0.0 0.0 0 0 ? SW 19:07 0:00 [kupdated]
root 7 0.0 0.0 0 0 ? SW< 19:07 0:00 [mdrecoveryd]
root 11 0.0 0.0 0 0 ? SW 19:07 0:00 [kjournald]
root 114 0.0 0.5 2108 1304 ? S 19:07 0:00 devfsd /dev
root 209 0.0 0.0 0 0 ? SW 19:07 0:00 [khubd]
root 338 0.0 0.0 0 0 ? SW 19:07 0:00 [kjournald]
rpc 620 0.0 0.2 1496 520 ? S 19:07 0:00 [portmap]
root 636 0.0 0.2 1452 624 ? S 19:07 0:00 syslogd -m 0
…………………(以下省略)
Ps命令输出中的START字段显示了程序开始运行的时间 , 对于查出攻击时间很有帮助 。有时仅通过时间就能识别可疑进程 。
Linux下还可以通过strings –f /proc/[0-9]*/cmdline来查看系统中运行进程的完整命令行参数 , 但是这个并不完全可信 。
因为攻击者甚至不需要插入内核模块 , 而只在应用层的编码中加入语句就能欺骗我们 。
===============
检测LKM Rootkit
===============
内核模块后门,还有什么比这个更臭屁的呢?Solaris,Linux和几乎所有的Unix都支持LKM(Loadable Kernel Modules),
用普通的方法无法检测其存在 , 这给应急响应带来了极大的挑战性 。对于我们来说 , 解决的办法是找到那些lkm rootkit ,
并熟悉 , 解剖他们 。有时lkm rootkit虽然被成功装载 , 但在系统的某些细节上会出现“异常 , 甚至可能使系统在运行一段时间后彻底崩溃 。
还有 , lkm虽然活动在ring0核心态 , 但是攻击者往往会在系统的某处留下痕迹 , 比如攻击者为了让系统每次关闭或重启后能自动装入他安置的
内核后门 , 可能会改写/etc/modules.conf或/etc/rc.local.
kstat/ksec是检测lkm非常方便的工具,前者用于Linux , 后者用于*BSD.
[root@ay4z3ro kstat]# ./kstat
Usage: ./kstat [-i iff] [-P] [-p pid] [-M] [-m addr] [-s]
-i iff may be specifIEd as 'all' or as name (e.g. eth0)
displays info about the queried interface
-P displays all processes
-p pid is the process id of the queried task
-M displays the kernel's LKMs' linked list
-m addr is the hex address of the queried module
displays info about the module to be found at addr
-s displays info about the system calls' table
其中-s参数最有用 , 它显示了系统调用入口的信息 , 能检测市面上最流行的knark和adore这两个内核后门 ,
但理论上他并不能检测出所有的lkm rootkit.
Kstat/ksec站点:http://www.s0ftpj.org
其实熟悉内核攻击的人都知道Kstat单纯检查sys_call_table[]的方式如今已经
被攻击的一方完全超越 , e4gle很早也写过这类文章 。
有兴趣可以看看2002焦点峰会jbtzhm的《内核后门实现及其检测》
现在Linuxforum安全版版主madsys在Phrack61上有篇文章:
Finding hidden kernel modules (the extrem way)--链接:
http://www.linuxforum.net/forum/gshowflat.php?Cat=&Board=security&Number=434871&page=0&vIEw=collapsed&sb=5&o=all&fpart=
======================
检测开放端口和关联进程
======================
[root@ay4z3ro foo]# netstat –anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 620/
tcp 0 0 0.0.0.0:6000 0.0.0.0:* LISTEN 908/X
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 880/sshd
udp 0 0 0.0.0.0:111 0.0.0.0:* 620/
Active Unix domain sockets (servers and established)

推荐阅读