mystery
mystery

Reputation: 19513

CGI script does not receive parameters if they contain equals sign

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");
}

Upvotes: 2

Views: 1979

Answers (1)

Greg Hewgill
Greg Hewgill

Reputation: 992985

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 called QUERY_STRING.

It would probably be worthwhile for you to review the CGI specification.

Upvotes: 6

Related Questions