网上搜索了一下, 发现此代码主要原理是通过搜索 int 0x80的中断服务程序中的sys_call_table来实现.
在linux中所有的syscall都是调用int 0x80, int 0x80的中断服务程序为system_call(arch/x86/kernel/traps_32.c:set_system_gate(SYSCALL_VECTOR,&system_call). system_call (arch/x86/entry_32.S)最终call *sys_call_table(,%eax,4)来完成一个syscall调用.
即int 0x80 -> system_call -> sys_call_table, 这样我们只要首先获取int 0x80的中断服务地址system_call地址, 然后在system_call代码中直接搜索call指令即可找到sys_call_table地址了!
另一种方法就是直接修改
通过cat /boot/System.map-`uname -r` |grep sys_call_table 查看当前sys_call_table地址,并与通过以上方法取得的地址做比较!
内核版本: ubuntu 2.6.24-19-server
/*
* Standard in kernel modules
*/
#include <linux/kernel.h> /* We're doing kernel work */
#include <linux/module.h> /* Specifically, a module, */
#include <linux/moduleparam.h> /* which will have params */
#include <linux/unistd.h> /* The list of system calls */
/*
* For the current (process) structure, we need
* this to know who the current user is.
*/
#include <linux/sched.h>
#include <asm/uaccess.h>
unsigned long *sys_call_table = 0;
//EXPORT_SYMBOL ( sys_call_table );
struct {
unsigned short limit;
unsigned int base;
} __attribute__ ( ( packed ) ) idtr;
struct {
unsigned short offset_low;
unsigned short segment_select;
unsigned char reserved, flags;
unsigned short offset_high;
} __attribute__ ( ( packed ) ) * idt;
unsigned long* find_sys_call_table(void)
{
unsigned long system_call = 0; // x80中断处理程序system_call 地址
char *call_hex = "\xff\x14\x85"; // call 指令
char *code_ptr = NULL;
char *p = NULL;
unsigned long sct = 0x0;
int i = 0;
// 获取中断描述符表寄存器的地址
__asm__ ( "sidt %0": "=m" ( idtr ) );
// 获取0x80中断处理程序的地址
idt = ( void * ) ( idtr.base + 8 * 0x80 );
system_call = ( idt->offset_high << 16 ) | idt->offset_low;
// 搜索system_call代码
code_ptr = (char *)system_call;
for(i = 0;i < ( 100 - 2 ); i++) {
//// 查找call指令
if(code_ptr[i] == call_hex[0]
&& code_ptr[i+1] == call_hex[1]
&& code_ptr[i+2] == call_hex[2] ) {
//
p = &code_ptr[i] + 3;
break;
}
}
if ( p ){
sct = *(unsigned long*)p;
}
return (unsigned long*)sct;
}
int init_module ( void ) {
if ( ( sys_call_table = find_sys_call_table() ) ) {
printk( "sys_call_table = %p\n", sys_call_table );
}
return 0;
}
void cleanup_module ( void ) {
}
Makefile文件:
obj-m = get_sct.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean
分享到:
相关推荐
MySQL-client-5.5.45-1.linux2.6.x86_64.rpm
MySQL-server-5.5.10-1.linux2.6.x86_64 Linux 安装包
MySQL-client-5.5.39-2.linux2.6.x86_64.rpm MySQL-client客户端
MySQL-client-5.5.52-1.linux2.6.x86_64.rpm MySQL-client-5.5.52-1.linux2.6.x86_64.rpm
MySQL-server-5.5.52-1.linux2.6.x86_64.rpm MySQL-server-5.5.52-1.linux2.6.x86_64.rpm
qcc3040、3046 TWS集成开发环境, 配合本人发布的ADK265源代码使用
MySQL-shared-compat-5.5.27-1.linux2.6.x86_64.rpm
linux环境下mysql的tar安装包--MySQL-5.5.40-1.linux2.6.x86_64.rpm-bundle.tar
MySQL-client-5.5.34-1.linux2.6.x86_64.rpm
寻找资料不容易,每个资料都是测试过的,希望能对大家有所帮助。
MySQL-client-5.5.44-1.linux2.6.x86_64.rpm
linux 2.6.23.4
MySQL-server-5.5.45-1.linux2.6.x86_64.rpm
MySQL-server-5.5.47-1.linux2.6.x86_64
MySQL-server-5.5.44-1.linux2.6.x86_64.rpm
fckeditor_2.6.5.0fckeditor_2.6.5.0fckeditor_2.6.5.0fckeditor_2.6.5.0
MySQL-devel-5.5.28-1.linux2.6.x86_64.rpm安装包,包含了开发mysql的头文件和库
mysql数据库MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品。MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS (Relational Database ...
linux-2.6.8.1.tar.bz2linux-2.6.8.1.tar.bz2linux-2.6.8.1.tar.bz2linux-2.6.8.1.tar.bz2linux-2.6.8.1.tar.bz2linux-2.6.8.1.tar.bz2linux-2.6.8.1.tar.bz2linux-2.6.8.1.tar.bz2linux-2.6.8.1.tar.bz2linux-2.6....
MySQL-5.5.48-1.linux2.6.x86_64.rpm-bundle.tar Centos 6.5安装此mysql5.5版本方法http://blog.csdn.net/sq347216161/article/details/79457412