Boa Web Server缺陷报告及其修正方法

发表于:2015-1-16 10:25

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:qq361301276    来源:51Testing软件测试网采编

分享:
  修正方法
  CGI 应答头包括多行, 我们必须对其进行逐行分析, 并作出正确的应答.
  下面是修改好的源程序, 即将原来的 82-136 (即相当下文#else, #endif内部分) 替换成如下代码:
#if 1
while(1) {
int         len;
char *        pnext = NULL;
char *         ptmp = NULL;
/* not find HTTP header tailer */
if (NULL == (pnext=strchr(buf, '\n')))        /* has no '\n' */
break;
/* the length of this line,
* include '\n'
*/
len = pnext - buf + 1;
if (!strncasecmp(buf, "Location: ", 10)) {        /* got a location header */
/* not the first one
* exchange this line to the first line
*/
if (buf != req->header_line)
{
if (NULL == (ptmp=(char *)malloc(len)))
{
log_error_time();
perror("malloc");
send_r_error(req);
return 0;
}
/* move Status: to line header */
memcpy(ptmp, buf, len);
memmove(req->header_line+len, req->header_line, buf-req->header_line);
memcpy(req->header_line, ptmp, len);
free(ptmp);
}
/* force pointer header */
buf = req->header_line;
#ifdef FASCIST_LOGGING
log_error_time();
fprintf(stderr, "%s:%d - found Location header \"%s\"\n",
__FILE__, __LINE__, buf + 10);
#endif
if (buf[10] == '/') {   /* virtual path */
log_error_time();
fprintf(stderr,
"server does not support internal redirection: " \
"\"%s\"\n", buf + 10);
send_r_bad_request(req);
/*
* We (I, Jon) have declined to support absolute-path parsing
* because I see it as a major security hole.
* Location: /etc/passwd or Location: /etc/shadow is not funny.
*
* Also, the below code is borked.
* request_uri could contain /cgi-bin/bob/extra_path
*/
/*
strcpy(req->request_uri, buf + 10);
return internal_redirect(req);
*/
} else {                /* URL */
char *c2;
c2 = strchr(buf + 10, '\n');
/* c2 cannot ever equal NULL here because we already have found one */
--c2;
while (*c2 == '\r')
--c2;
++c2;
/* c2 now points to a '\r' or the '\n' */
*c2++ = '\0';       /* end header */
/* first next header, or is at req->header_end */
while ((*c2 == '\n' || *c2 == '\r') && c2 < req->header_end)
++c2;
if (c2 == req->header_end)
send_r_moved_temp(req, buf + 10, "");
else
send_r_moved_temp(req, buf + 10, c2);
}
req->status = DONE;
return 1;
}  else if (!strncasecmp(buf, "Status: ", 8)) {
/* not the first one
* exchange this line to the first line
*/
if (buf != req->header_line)
{
if (NULL == (ptmp=(char *)malloc(len)))
{
log_error_time();
perror("malloc");
send_r_error(req);
return 0;
}
/* move Status: to line header */
memcpy(ptmp, buf, len);
memmove(req->header_line+len, req->header_line, buf-req->header_line);
memcpy(req->header_line, ptmp, len);
free(ptmp);
}
req->header_line--;
memcpy(req->header_line, "HTTP/1.0 ", 9);
return 1;
}
/* pointer to next line */
buf = pnext + 1;
/* reach the end of HTTP header */
if ('\0' == buf[0] || '\n' == buf[0] || '\r' == buf[0])
break;
}
if (1) {        /* always done */
#else
if (!strncasecmp(buf, "Status: ", 8)) {
req->header_line--;
memcpy(req->header_line, "HTTP/1.0 ", 9);
} else if (!strncasecmp(buf, "Location: ", 10)) { /* got a location header */
#ifdef FASCIST_LOGGING
log_error_time();
fprintf(stderr, "%s:%d - found Location header \"%s\"\n",
__FILE__, __LINE__, buf + 10);
#endif
if (buf[10] == '/') {   /* virtual path */
log_error_time();
fprintf(stderr,
"server does not support internal redirection: " \
"\"%s\"\n", buf + 10);
send_r_bad_request(req);
/*
* We (I, Jon) have declined to support absolute-path parsing
* because I see it as a major security hole.
* Location: /etc/passwd or Location: /etc/shadow is not funny.
*
* Also, the below code is borked.
* request_uri could contain /cgi-bin/bob/extra_path
*/
/*
strcpy(req->request_uri, buf + 10);
return internal_redirect(req);
*/
} else {                /* URL */
char *c2;
c2 = strchr(buf + 10, '\n');
/* c2 cannot ever equal NULL here because we already have found one */
--c2;
while (*c2 == '\r')
--c2;
++c2;
/* c2 now points to a '\r' or the '\n' */
*c2++ = '\0';       /* end header */
/* first next header, or is at req->header_end */
while ((*c2 == '\n' || *c2 == '\r') && c2 < req->header_end)
++c2;
if (c2 == req->header_end)
send_r_moved_temp(req, buf + 10, "");
else
send_r_moved_temp(req, buf + 10, c2);
}
req->status = DONE;
return 1;
} else {                    /* not location and not status */
#endif
22/2<12
2023测试行业从业人员调查问卷已开启,千元大奖正在等你~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号