如果参数包含等号,CGI 脚本不会接收参数
我有一个 CGI 脚本(编译的 C 程序),它输出其命令行参数(argv[0]、argv[1] 等)。
如果我尝试 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");
}
I have a CGI script (compiled C program) that outputs its command line arguments (argv[0], argv[1] etc.).
If I try http://ajf.me/c/?abc I get "abc" as the second parameter.
However, if I try http://ajf.me/c/?a=bc I do not get any second parameter.
Why does using =
stop the parameters from being passed to the program?
If it matters here is the C code:
#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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在命令行上向 CGI 程序传递参数一定是 Web 服务器的异常情况。通常,
?
之后的部分可在名为QUERY_STRING
的环境变量中使用。您可能值得查看 CGI 规范。
Passing parameters to a CGI program on its command line must be an anomaly of your web server. Normally the part after the
?
is available in an environment variable calledQUERY_STRING
.It would probably be worthwhile for you to review the CGI specification.