拥有VPS之-发现入侵

上周末才买入一台VPS,由于急着把blog迁移过来,所以装完系统后,就只顾着blog的事了,VPS安全方面的事情,本来打算在本周末来收拾一番的。没想到啊,没想到,万恶的资本主义国家,黑客也这么多,哥刚把blog搭好,你又来给哥捣乱了。

上午,正在彻erlang代码,zhoux在gtalk上和我说,他的账号不能通过ssh登录。于是乎,做为VPS的首席维护官,我立马试着去登录。提示输入密码后,很快就看到了$提示符,然后手指不由自主地做了个终端爱好者的习惯性动作-’ls’,可是’ls’并没有像往常一样显示我当前目录的内容,而是提示”/bin/ls: no such directory”,哥当时就震惊了。第一反应还以为是环境变量被人改了,’env’看了下,没有发现异常。然后想用’ps aux’查看到进程列表,结果哥再次震惊了,屏幕上提示”/bin/ps: no such directory”,再试’top’,还是”/usr/bin/top: no such directory”,我靠,你都把路径给提示出来了,却还告诉我没有这个路径,存心逗哥玩么。以前刚开始用linux时,还带着windows cmd的习惯,查看目录内容会用’dir’,结果发现也有效,然后哥又试着用了下’dir’,这下还好,能够看到目录内容了。

这下哥就深思了,三大常用命令不能用,可是’cd’竟然还能用,啥原因呢?既然提示”/bin/ls”不存在,那就去看看倒底有没有。”cd /bin”后”dir -l”一看,’ls’还在的啊,只不过,文件属性与其它文件不一致。’/bin’目录下其它正常文件的属性都是像这样子的:

-rwxr-xr-x 1 root root 934336 2010-04-19 10:16 bash
-rwxr-xr-x 3 root root 31176 2010-02-08 19:06 bunzip2

可是’ls’, ‘ps’的属性却是这样的

-rwxr-xr-x 1 122 avahi 114032 2010-03-05 11:41 ls
-rwxr-xr-x 1 122 avahi 101232 2009-12-17 03:34 ps

看到这里,哥一阵心寒,这十有八九是被入侵了,MD,他是从哪来的啊?于是哥又跑到’/var/log’下看了一番,’syslog’的内容太杂乱,什么程序都喜欢往里扔log,仔细翻了翻,发现在我登出服务器后的日志里,发现这么一段:

Jun 3 02:32:43 vps syslogd 1.5.0#5ubuntu4: restart.
Jun 3 02:32:43 vps xinetd[1519]: Starting reconfiguration
Jun 3 02:32:43 vps xinetd[1519]: attribute: disable should not be in default section [file=/etc/xinetd.conf] [line=12]
Jun 3 02:32:43 vps xinetd[1519]: Reading included configuration file: /etc/xinetd.d/chargen [file=/etc/xinetd.conf] [line=15]
Jun 3 02:32:43 vps xinetd[1519]: Reading included configuration file: /etc/xinetd.d/daytime [file=/etc/xinetd.d/daytime] [line=28]
Jun 3 02:32:43 vps xinetd[1519]: Reading included configuration file: /etc/xinetd.d/discard [file=/etc/xinetd.d/discard] [line=26]
Jun 3 02:32:43 vps xinetd[1519]: Reading included configuration file: /etc/xinetd.d/echo [file=/etc/xinetd.d/echo] [line=25]
Jun 3 02:32:43 vps xinetd[1519]: Reading included configuration file: /etc/xinetd.d/time [file=/etc/xinetd.d/time] [line=26]
Jun 3 02:32:43 vps xinetd[1519]: removing chargen
Jun 3 02:32:43 vps xinetd[1519]: removing chargen
Jun 3 02:32:43 vps xinetd[1519]: removing daytime
Jun 3 02:32:43 vps xinetd[1519]: removing daytime
Jun 3 02:32:43 vps xinetd[1519]: removing discard
Jun 3 02:32:43 vps xinetd[1519]: removing discard
Jun 3 02:32:43 vps xinetd[1519]: removing echo
Jun 3 02:32:43 vps xinetd[1519]: removing echo
Jun 3 02:32:43 vps xinetd[1519]: removing time
Jun 3 02:32:43 vps xinetd[1519]: removing time
Jun 3 02:32:43 vps xinetd[1519]: Swapping defaults
Jun 3 02:32:43 vps xinetd[1519]: Reconfigured: new=0 old=0 dropped=0 (services)

这个时候,没人去操作的话,syslog怎么会突然重启?见鬼了,进而想到用’stat’来查看’/bin/ls’的文件状态,发现:

File: `/bin/ls’
Size: 96423 Blocks: 224 IO Block: 4096 regular file
Device: 807h/2055d Inode: 1355 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 122/ avahi) Gid: ( 122/ avahi)
Access: 2010-06-03 01:02:30.448318679 +0800
Modify: 2010-05-30 11:41:16.000000000 +0800
Change: 2010-06-03 02:32:43.654213635 +0800

修改时间是”2010-06-03 02:32:43″,与syslog重启时间一致!,这让我越发肯定系统是被入侵了。
这些不能用的程序,文件属主都是avahi,经google一番,发现avahi只是个正常的系统服务,详见wikipedia。不放心,遂”su”到root,然后在’/’下执行”find / -group avahi”,执行结果如下:

./var/run/avahi-daemon
./var/run/avahi-daemon/pid
./var/run/avahi-daemon/socket
./usr/bin/find
./usr/bin/md5sum
./usr/bin/pstree
./usr/bin/top
./usr/lib/libsh/hide
./usr/lib/libsh/.sniff/shsniff
./usr/lib/libsh/.sniff/shp
./usr/lib/libsh/shsb
./usr/lib/libsh/.bashrc
./proc/24136
./proc/24136/task
./proc/24136/task/24136
./proc/24138
./proc/24138/task
./proc/24138/task/24138
./sbin/ttyload
./sbin/ttymon
./sbin/ifconfig
./bin/ls
./bin/netstat
./bin/ps
./lib/libsh.so/shrs
./lib/libsh.so/shhk
./lib/libsh.so/shhk.pub
./lib/libsh.so/shdcf

事实证明,这次搜索,是这次发现入侵过程中的重大突破。一举发现被替换的系统程序以及潜伏在系统中的木马路径。’/usr/lib/libsh’和’/lib/libsh.so’就是入侵者安放木马的地方!再次使用google搜索”libsh”,发现这木马早在05年前就有了。哥的ubuntu 9.10 server edition居然中了05年前的木马,真是杯具。
虽然人肉发现了木马所在,可还是不太放心,指不定在哪个犄角旮旯还窝着一群木马呢。于是乎,使用”aptitude install chkrootkit rkhunter”安装了两个linux下号称检查木马的神器。先用”chkrootkit”检查了一番,结果如下:

……
Searching for t0rn’s v8 defaults… Possible t0rn v8 (or variation) rootkit installed

Searching for Showtee… Warning: Possible Showtee Rootkit installed

Searching for Romanian rootkit… /usr/include/file.h /usr/include/proc.h
……

也就是说,’chkrootkit’检测出了3个疑似木马,前两个光靠个名字,哥实在无从找起,只好看第三个带路径的了,打开这两个文件,发现内容如下:

/usr/include/file.h:
h.conf
libsh
.sh
system
shsb
libsh.so
shp
shsniff
srd0

/usr/include/proc.h:
3 burim
3 mirkforce
3 synscan
3 ttyload
3 shsniff
3 ttymon
3 shsb
3 shp
3 hide
4 ttyload

隐藏得真TMD好,粗一看,还真以为是C库的头文件,不过linux C库的头文件是肯定没有’file.h’了,文件相关的函数都在’fcntl.h’里。这两个文本文件看起来和用’find’找到的文件有共同点,只不过不清楚它们是干啥的。然后接着用”rkhunter –check”再检查了一番,这次的结果和用’chkrootkit’有些不一样。btw,’rkhunter’的输出不仅显示在屏幕上,还可以在’/var/log/rkhunter.log’中看到:

[12:30:08] /usr/sbin/unhide [ Warning ]
[12:30:08] Warning: The file ‘/usr/sbin/unhide’ exists on the system, but it is not present in the rkhunter.dat file.
[12:30:08] /usr/sbin/unhide-linux26 [ Warning ]
[12:30:08] Warning: The file ‘/usr/sbin/unhide-linux26’ exists on the system, but it is not present in the rkhunter.dat file.
[12:30:28] Warning: SHV4 Rootkit [ Warning ]
[12:30:28] File ‘/lib/lidps1.so’ found
[12:30:28]
[12:30:28] Checking for SHV5 Rootkit…
[12:30:28] Checking for file ‘/etc/sh.conf’ [ Found ]
[12:30:28] Checking for directory ‘/usr/lib/libsh’ [ Found ]
[12:30:28] Warning: SHV5 Rootkit [ Warning ]
[12:30:28] File ‘/etc/sh.conf’ found
[12:30:28] Directory ‘/usr/lib/libsh’ found
[12:30:43] Checking loaded kernel modules [ Warning ]
[12:30:43] Warning: No output found from the lsmod command or the /proc/modules file:
[12:30:43] /proc/modules output:
[12:30:43] lsmod output:
[12:31:05] Checking if SSH root access is allowed [ Warning ]
[12:31:05] Warning: The SSH and rkhunter configuration options should be the same:
[12:31:05] SSH configuration option ‘PermitRootLogin’: yes
[12:31:05] Rkhunter configuration option ‘ALLOW_SSH_ROOT_USER’: no

这下又发现四个异常文件,’/usr/sbin/unhide’、’/usr/sbin/unhide-linux26’,’/lib/lidps1.so’和’/etc/sh.conf’,还有之前哥人肉发现的’/usr/lib/libsh’目录。倒数第二个warning其实是因为这台机器是基于openvz的vps, 所有的modules都是在真实的系统中,在vps里是看不到的,所以该warning是正常,忽略不计。最后一个warning是我工作没到位啊,贫图方便,就允许root登录ssh了。

到此,发现入侵的过程就告一段落,一共发现了8个被替换掉的系统程序,两种木马SHV4和SHV5(chkrootkit检查到的另两种,哥实在没能找出来)以及若干黑客入侵时留下的文件。后续将会带来对这些文件的分析,以及清除方法,可不是简单的’rm’操作哦!

PS: 写完后发现,时间已经过了0点,今天是全国论坛维护日,个人网站留言板检修日。身处海外VPS的刻薄狐狸,感到既庆幸,又伤感。庆幸我不用去备案,不用做任何维护操作,同时又伤感21年前那些为了祖国命运而英勇牺牲的前辈。纸是包不住火的,历史越掩盖,越明朗。天朝这些年的所做所为,无异于掩耳盗铃,终究将成为历史的笑话,而我不知能否有这一天看到被还原的历史真相。谨以此后记,纪念在那场动乱中献身的英雄。

《拥有VPS之-发现入侵》有2个想法

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注