简体   繁体   中英

CGI program run in debug mode

We have a C++ CGI application which serves some web request. I am trying to run the same in debug mode for analysis purpose. The approach I have taken is invoking it with gdb:

As per first step - I rename my actual CGI application and place my own program with the same name

In that program I am trying to invoke the actual CCGI application in debug mode using GDB:

const char* argv[] = ["gdb -p <pid> -batch -ex bt 2>/dev/null", NULL];

execve("./myprog", (char**)argv, NULL);

The issue is that since myrog is a CGI application it takes input from STDIN.

How can I capture the input in my program and pass the same to the actual CGI application?

I did this: in cgi main i added code to look for an existing file, like /var/tmp/flag. While existing, i run in a loop. Time enough to attach to cgi process via gdb. After then i delete /var/tmp/flag and from now I can debug my cgi code.

bool file_exists(const char *filename)
{
   ifstream ifile(filename);
   return ifile;
}

int cgiMain()
{

 while (file_exists ("/var/tmp/flag"))
     sleep (1);
 ...
 your code 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM