文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>用LKM更改Linux缺省安全等级

用LKM更改Linux缺省安全等级

时间:2006-06-19  来源:me09

用LKM更改Linux缺省安全等级

[ 作者:  加入时间:2005-11-30 14:03:09  来自: ]



 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位,使"黑客"不能轻易的修改它们.要抓他们就容易多了. 修改安全等级比较直接的办法是直接修改内核源码.将Linux/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,会连setuid ()都被禁止了,这样普通用户就不能登陆了.如果谁对2.2.x比较熟悉,请不吝赐教,共同提高嘛.

    在测试这些程序以前,请备份重要数据.本人不为运行此程序带来的任何损失负责.

     一旦securelevel=1,kernel将不允许装入modlue,所以你的kerneld可能不能正常工作,而且禁止你访问/dev/kmem, 所以有些用到svgalib的程序也不能正常工作,像zgv什么的。不过这本来就是安全隐患,所以不工作就不工作好了,呵呵。(关于chattr, lsaddr的问题请man chattr和man lsattr)。

/**************************** 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);

}

Linux联盟收集整理




<iframe name="google_ads_frame" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-3701573918329010&amp;dt=1150713995984&amp;lmt=1150603735&amp;prev_fmts=728x90_as%2C160x600_as&amp;format=468x60_as&amp;output=html&amp;url=http%3A%2F%2Fwww.xxlinux.com%2Flinux%2Farticle%2Fnetwork%2Fsecurity%2F20051130%2F279.html&amp;color_bg=F7F7F7&amp;color_text=333333&amp;color_link=333333&amp;color_url=333333&amp;color_border=F7F7F7&amp;ad_type=text_image&amp;ref=http%3A%2F%2Fwww.xxlinux.com%2Flinux%2Farticle%2Fnetwork%2Fsecurity%2F&amp;cc=17&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_his=1&amp;u_java=true&amp;u_nplug=14&amp;u_nmime=51" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" height="60" scrolling="no" width="468"></iframe>
<iframe name="google_ads_frame" src="http://pagead2.googlesyndication.com/cpa/ads?client=ca-pub-3701573918329010&amp;cpa_choice=CAAQ3L2U_AEaCMoXius7bYsJKMD29IMB&amp;oe=GB2312&amp;dt=1150713996015&amp;lmt=1150603735&amp;prev_fmts=120x60_as_rimg&amp;format=180x60_as_rimg&amp;output=html&amp;url=http%3A%2F%2Fwww.xxlinux.com%2Flinux%2Farticle%2Fnetwork%2Fsecurity%2F20051130%2F279.html&amp;region=_google_cpa_region_&amp;ref=http%3A%2F%2Fwww.xxlinux.com%2Flinux%2Farticle%2Fnetwork%2Fsecurity%2F&amp;cc=16&amp;u_h=768&amp;u_w=1024&amp;u_ah=738&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_his=1&amp;u_java=true&amp;u_nplug=14&amp;u_nmime=51" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" frameborder="0" height="60" scrolling="no" width="180"></iframe>
相关阅读 更多 +
排行榜 更多 +
球我归位手机版

球我归位手机版

休闲益智 下载
进击小巨人最新版

进击小巨人最新版

冒险解谜 下载
吞就完了手机版

吞就完了手机版

冒险解谜 下载