RedHat有一个解决Shellshock漏洞的方法,该漏洞涉及预加载库。变通方法源代码的URL可在bash_ld_preload.c上找到。
但解决方法的步骤现在似乎已经不见了。这是一个糟糕的解决方案还是没有解决方案?
代码:
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
static void __attribute__ ((constructor)) strip_env(void);
extern char **environ;
static void strip_env()
{
char *p,*c;
int i = 0;
for (p = environ[i]; p!=NULL;i++ ) {
c = strstr(p,"=() {");
if (c != NULL) {
*(c+2) = ' ';
}
p = environ[i];
}
}
给定的代码从环境中完全删除了所有导出的函数(或者,更确切地说,使其内容为空字符串)。
这确实有您想要的副作用,使与解析和处理导出函数相关的漏洞变得毫无意义。