【问题标题】:CGI script does not receive parameters if they contain equals sign如果参数包含等号,CGI 脚本不接收参数
【发布时间】:2011-07-17 19:48:13
【问题描述】:

我有一个输出其命令行参数(argv[0]、argv[1] 等)的 CGI 脚本(编译的 C 程序)。

如果我尝试http://ajf.me/c/?abc,我会得到“abc”作为第二个参数。

但是,如果我尝试http://ajf.me/c/?a=bc,我不会得到任何第二个参数。

为什么使用= 会阻止参数传递给程序?

如果这里重要的是 C 代码:

#include <stdio.h>

int main (int argc, char *argv[]) {
    int i;
    printf("Content-Type: text/html;charset=utf-8\n\n");
    printf("<!DOCTYPE html>\n");
    printf("<html>\n");
    printf("<head>\n");
    printf("<title>ajf.me powered by ANSI C!</title>\n");
    printf("</head>\n");
    printf("<body>\n");
    printf("<h2>Supplied Arguments</h2>\n");
    printf("argc: %d\n", argc);
    printf("<ol>\n");
    for (i = 0; i < argc; ++i) {
        printf("<li>%s</li>\n", argv[i]);
    }
    printf("</ol>\n");
    printf("<em>Yes, this is vulnerable to null-byte injection. For instance, <a href=\"?Injected%%00Null\" style=\"font-family: monospace; color: green;\">?Injected\\0Null</a>.</em>\n");
    printf("</body>\n");
    printf("</html>\n");
}

【问题讨论】:

  • 天哪,为什么不依赖文字字符串连接而不是执行所有那些 printf 调用?

标签: c apache cgi cgi-bin


【解决方案1】:

在命令行上向 CGI 程序传递参数一定是您的 Web 服务器的异常情况。通常? 之后的部分在名为QUERY_STRING 的环境变量中可用。

您可能值得回顾一下CGI specification

【讨论】:

猜你喜欢
  • 2013-02-06
  • 1970-01-01
  • 2021-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-06
  • 2017-02-10
  • 1970-01-01
相关资源
最近更新 更多