【linux系统加固之】shell加固

来源:互联网 发布:传奇扫号器账号数据库 编辑:程序博客网 时间:2024/05/01 21:16

一.采用最新版本的bash版本:

最新版本bash可从其官方网站下载:https://www.gnu.org/software/bash/


二.最小化裁剪和配置:

去掉readline编辑和history功能;

去掉job控制功能;

去掉其他一些高级的功能;

        ../configure --host=$(MACHINE)-linux \

  --enable-minimal-config \
--disable-alias \
--disable-bang-history \
--disable-debugger \
--disable-directory-stack \
--disable-help-builtin \
--disable-history \
--disable-job-control \
--disable-net-redirections \
--disable-readline \
--enable-restricted \
--disable-separate-helpfiles \
--disable-single-help-strings \
--enable-strict-posix-default \
--enable-mem-scramble \
--disable-profiling \


三.去掉交互功能

只能用于解释脚本和执行单条命令,影响bash状态的方式有:

1.根据argv[0]可知当前bash的启动状态

以“-”开头表示login_shell,“sh”表示act_like_sh, “su”表示su_shell,具体的可以参看源代码set_shell_name (argv0)函数;

2.命令行选项

长选项parse_long_options(),可以屏蔽掉部分长选项的支持:

static const struct {
  const char *name;
  int type;
  int *int_value;
  char **char_value;
} long_args[] ;

短选项parse_shell_options(),可以屏蔽掉部分长选项的支持:

const struct {
  char *name;
  int letter;
  int *variable;
  setopt_set_func_t *set_func;
  setopt_get_func_t *get_func;
} o_options[]
;


3.set内置命令

去掉内置的set命令部分支持set_builtin (list)

const struct flags_alist shell_flags[]


四.编译选项

编译选项加上: -fstack-protector-all 堆栈保护

   -fPIE 位置无关代码

链接选项加上:-lssp 堆栈保护库支持

  -Wl,-z,relro,-z,now 支持链接时GOT放在可读写数据区之前,防止溢出修改到GOT

支持动态连接器启动时bind所有符号然后才执行应用程序,这样可使GOT remap为只读,可通过.dynamic分区判断可执行文件是否编译为了bind now

-pie 产生位置无关可执行应用,通过file命令可检查是否编译为位置无关。


五.打上已知漏洞的patch

https://nvd.nist.gov 查找当前使用内核版本之后暴露的一些high level的漏洞,并打上相应patch

0 0