欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

基于 centos 7 Linux 创建隐藏进程和发现隐藏进程。

最编程 2024-04-04 16:36:54
...

一、隐藏进程

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

  1. 程序定义了一个变量 process_to_filter 来控制不显示哪个进程名
  2. 重写readdir,
    strcmp(process_name, process_to_filter) == 0)
    当发现当前进程名称与 process_to_filter 相同时,继续循环.
  1. 某些Linux中这个程序编译通不过

    解决方法

    删除最后两行中的一行

    DECLARE_READDIR(dirent64, readdir64);

    DECLARE_READDIR(dirent, readdir);

  2. 某些Linux中使用

    echo /usr/local/lib/libprocesshider.so >> /etc/ld.so.preload
    

    并不会生效
    此时我们需要配置环境变量

    bmfxgkpt-yhd:~# vi /etc/profile
    

    增加一行

    export LD_PRELOAD=/usr/local/lib/libprocesshider.so

二、如何发现隐藏进程

unhide 是一个小巧的网络取证工具,能够发现那些借助rootkit,LKM及其它技术隐藏的进程和TCP / UDP端口。这个工具在Linux,UNIX类,MS-Windows等操作系统下都可以工作。

安装

[root@kangcw ~]# yum install unhide
Loaded plugins: fastestmirror, langpacks, priorities
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * centos-sclo-rh: mirrors.aliyun.com
 * centos-sclo-sclo: mirrors.aliyun.com
 * remi-safe: mirror.innosol.asia
centos-sclo-rh                                                                                                                                                        | 3.0 kB  00:00:00     
centos-sclo-sclo                                                                                                                                                      | 2.9 kB  00:00:00     
epel                                                                                                                                                                  | 5.3 kB  00:00:00     
extras                                                                                                                                                                | 2.9 kB  00:00:00     
google-chrome                                                                                                                                                         | 1.3 kB  00:00:00     
mysql-connectors-community                                                                                                                                            | 2.5 kB  00:00:00     
mysql-tools-community                                                                                                                                                 | 2.5 kB  00:00:00     
mysql57-community                                                                                                                                                     | 2.5 kB  00:00:00     
os                                                                                                                                                                    | 3.6 kB  00:00:00     
remi-safe                                                                                                                                                             | 3.0 kB  00:00:00     
teamviewer                                                                                                                                                            | 2.5 kB  00:00:00     
updates                                                                                                                                                               | 2.9 kB  00:00:00     
remi-safe/primary_db                                                                                                                                                  | 1.7 MB  00:02:53     
Resolving Dependencies
--> Running transaction check
---> Package unhide.x86_64 0:20130526-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================
 Package                                     Arch                                        Version                                             Repository                                 Size
=============================================================================================================================================================================================
Installing:
 unhide                                      x86_64                                      20130526-1.el7                                      epel                                       63 k

Transaction Summary
=============================================================================================================================================================================================
Install  1 Package

Total download size: 63 k
Installed size: 146 k
Is this ok [y/d/N]: y
Downloading packages:
unhide-20130526-1.el7.x86_64.rpm                                                                                                                                      |  63 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : unhide-20130526-1.el7.x86_64                                                                                                                                              1/1 
  Verifying  : unhide-20130526-1.el7.x86_64                                                                                                                                              1/1 

Installed:
  unhide.x86_64 0:20130526-1.el7                                                                                                                                                             

Complete!

使用

使用unhide proc发现隐藏进程xianyu_cb,如下图所示:

 

推荐阅读