/**************************** lkm.c ********************************/ /* Simple lkm to secure Linux. * This module can be used to change the securelevel of Linux. * Running the client will switch the securelevel. * * gcc -O3 -Wall -c lkm.c * insmod lkm * * It is tested in RedHat 5.2 (2.0.36). * (It should be modified if you want to run it in 2.2.x kernel). * It is really very simple,but we just for educational purposes.:-) * * [email protected] */ #define MODULE #define __KERNEL__ #include <linux/config.h> #include <linux/module.h> #include <linux/version.h> #include <linux/errno.h> #include <linux/types.h> #include <linux/fs.h> #include <linux/string.h> #include <linux/mm.h> #include <linux/proc_fs.h> #include <asm/segment.h> #include <asm/unistd.h> #include <linux/dirent.h> #include <asm/unistd.h> #include <linux/sockios.h> #include <linux/if.h> #define __NR_secureswitch 250 extern void *sys_call_table[]; int sys_secureswitch(int secure) { if(secure==0) securelevel=0; if(secure==1) securelevel=1; return securelevel; } int init_module(void) { sys_call_table[__NR_secureswitch] = (void *)sys_secureswitch; return 0; } void cleanup_module(void) { sys_call_table[__NR_secureswitch] = NULL; return; } /************************ clt.c **************************/ /* * This client can switch the secure level of Linux. * * gcc -O3 -Wall -o clt clt.c * Usage: clt -h/-l * -h switch to the high secure level. * -l switch to the low secure level. * * Most of codes are ripped from [email protected],thanks smiler.:) * [email protected] */ #include <asm/unistd.h> #include <stdio.h> #include <errno.h> #define __NR_secureswitch 250 static inline _syscall1(int, secureswitch, int, command); int main(int argc,char **argv) { int ret,level = 0; if (argc < 2) { fprintf(stderr,"Usage: %s [-h/-l]n",argv[0]); exit(-1); } if (argv[1][1] == h) level++; else if (argv[1][1] != l) { fprintf(stderr,"Usage: %s [-h/-l]n",argv[0]); exit(-1); } ret = secureswitch(level); if (ret < 0) printf("Hmmm...It seemed that our lkm hasn been loaded.;-)n"); else { if (ret == 0) { puts("Now the secure level is changed to 0!n"); } else { puts("Now the secure level is chagned to 1!n"); } } return(1); }
本文地址:http://com.8s8s.com/it/it32607.htm