漏洞描述:
request.c中request_check_hostname函数处理HTTP请求头中的主机名时,对IPV6格式的主机名检查不够严格,可能导致路径回溯访问的漏洞。
41 /* IPv6 adress */
42 if (host->ptr[0] == '[') { //使用‘[’激活IPV6地址检查
43 char *c = host->ptr + 1;
44 int colon_cnt = 0;
45
46 /* check portnumber */
47 for (; *c && *c != ']'; c++) {//检查IPV6地址中是否包含非法字符
48 if (*c == ':') {
49 if (++colon_cnt > 7) {
50 return -1;
51 }
52 } else if (!light_isxdigit(*c) && '.' != *c) {
53 return -1;
54 }
55 }
56
57 /* missing ] */
58 if (!*c) {
59 return -1;
60 }
61
62 /* check port */
63 if (*(c+1) == ':') {//如果‘]’后不为':8080'这种标示访问端口的写法,直接返回0,表示主机名检查无误。
64 for (c += 2; *c; c++) {
65 if (!light_isdigit(*c)) {
66 return -1;
67 }
68 }
69 }
70 return 0;
71 }
漏洞重现: