专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Linux » linux更改权限:用LKM更改linux缺省安全等级 »正文

linux更改权限:用LKM更改linux缺省安全等级

来源: 发布时间:星期四, 2009年2月12日 浏览:50次 评论:0



  Linux缺省等级是0,如果将其升到1,就可以定程度上提高系统性.安全等级
  为1时候,它会禁止修改ex2fs系统中文件immutable和append-only位,同时禁止装入
  /移除module.所以我们可以先用chattr +i 将大部分可执行文件,动态连接库,
  些重要系统文件(inetd.conf,securetty,hosts.allow,hosts.deny,rc.d下
  动script...)加上immutable位,这样"黑客"就很难在你机器上放置木马和留后门了.
  (即便他已经得到了root权限,当然通过直接硬盘读写仍然可以修改,但比较麻烦而且危险
  ).
  
  "黑客"们旦进入系统获得root,首先会清除系统记录文件.你可以给些系统记录文件
  (wtmp,messages,syslog...)增加append-only位,使"黑客"不能轻易修改它们.要抓
  他们就容易多了.:-)
  
  修改安全等级比较直接办法是直接修改内核源码.将/kernel/sched.c中
  securelevel设成1即可.不过如果要改变安全等级话需要重新编译内核,我太懒,不想那
  么麻烦.:-)
  
  为什么不用module呢?我写了个很简单lkm和个client来完成安全等级切换.
  
  思路方法: insmod lkm; clt -h;
  
  注意:普通用户也可以执行clt来切换安全等级,所以最好是在clt和lkm中加段密码检查,
  如果密码不对就不允许执行.:-)
  
  这两个在Redhat 5.2(2.0.36)下编译运行通过.对于2.2.x内核,securelevel
  变成了securebits,简单将它改到1,会连uid都被禁止了,这样普通用户就不能
  登陆了.如果谁对2.2.x比较熟悉,请不吝赐教,共同提高嘛.:)
  
  <在测试这些以前,请备份重要数据.本人不为运行此带来任何损失负责.>
  
  (旦securelevel=1,kernel将不允许装入modlue,所以你kerneld可能不能正
  常工作而且禁止你访问/dev/kmem,所以有些用到svgalib也不能正常工作
  象zgv什么不过这本来就是安全隐患所以不工作就不工作好了呵呵)
  (有关chattr,lsaddr请man chattr和man lsattr)
  
  [email protected]
  
  /**************************** 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 modied you want to run it in 2.2.x kernel).
  * It is really very simple,but we just for educational purposes.:-)
  *
  * [email protected]
  */
  
  # MODULE
  # __KERNEL__
  
  #
  #
  #
  #
  #
  #
  # .h>
  #
  #
  #
  #
  #
  #
  #
  # .h>
  
  # __NR_secureswitch 250
  
  extern void *sys_call_table;
  
   sys_secureswitch( secure)
  {
  (secure0) securelevel=0;
  (secure1) securelevel=1;
   securelevel;
  }
  
   init_module(void)
  {
  sys_call_table[__NR_secureswitch] = (void *)sys_secureswitch;
   0;
  }
  void cleanup_module(void)
  {
  sys_call_table[__NR_secureswitch] = NULL;
  ;
  }
  /************************ 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]
  */
  #
  #
  #
  # __NR_secureswitch 250
   inline _syscall1(, secureswitch, , command);
   ( argc,char **argv)
  
  {
   ret,level = 0;
   (argc < 2)
  
  {
  fprf(stderr,"Usage: %s [-h/-l]n",argv[0]);
  exit(-1);
  }
   (argv[1][1] h) level;
   (argv[1][1] != l)
  {
  fprf(stderr,"Usage: %s [-h/-l]n",argv[0]);
  exit(-1);
  }
  ret = secureswitch(level);
   (ret < 0)
  prf("Hmmm...It seemed that our lkm hasnt been loaded.;-)n");
   {
   (ret 0) {
  puts("Now the secure level is changed to 0!n");
  } {
  puts("Now the secure level is chagned to 1!n");
  }
  }
  (1);
  }
  
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: