歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 提高Linux安全等級

提高Linux安全等級

日期:2017/2/27 9:40:49   编辑:更多Linux
  Linux缺省的安全等級是0,如果將其升到1,就可以一定程度上提高系統的安全性.安全等級 為1的時候,它會禁止修改ex2fs系統中文件的immutable和append-only位,同時禁止裝入 /移除module.所以我們可以先用chattr +i <file>將大部分的可執行文件,動態連接庫, 一些重要的系統文件(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) [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 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't 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); }




Copyright © Linux教程網 All Rights Reserved