1 <html> 2 <body> 3 <form id="form" name="form" method="post" action="../cgi-bin/run.cgi"> 4 <p></p> 5 <input type="text" name="cmd1" id="user" > 6 <p></p> 7 <input type="text" name="cmd2" id="pass" > 8 <p></p> 9 <input type="submit" name="go" id="run" value="submit"> 10 </form> 11 </body> 12 </html>
1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <time.h> 5 6 void main() 7 { 8 //顯示html文本 9 printf("Cotent-type:text/html\n\n"); 10 //獲取表單信息 11 char szpost[256] = { 0 }; 12 gets(szpost); 13 //輸出表單信息 14 printf("%s", szpost); 15 16 //對錶單信息進行處理,把'+'轉換成' ' 17 char *pstart = szpost; 18 for(int i=0;i<256;i++) 19 { 20 if (szpost[i] == '+') 21 { 22 szpost[i] = ' '; 23 } 24 } 25 26 //處理':'號 27 char *pos1 = strstr(szpost, "%3A"); 28 if (pos1 != NULL) 29 { 30 *pos1 = ':'; 31 *(pos1 + 1) = ' '; 32 *(pos1 + 2) = ' '; 33 } 34 35 //處理'\' 36 pos1 = strstr(szpost, "%2F"); 37 if (pos1 != NULL) 38 { 39 *pos1 = '\\'; 40 *(pos1 + 1) = ' '; 41 *(pos1 + 2) = ' '; 42 } 43 44 //獲取第一個輸入框的內容 45 char *p1 = strchr(szpost, '&'); 46 if (*p1 != NULL) 47 { 48 *p1 = '\0'; 49 } 50 //輸出第一個輸入框的內容 51 printf("%s\r\n", szpost+5); 52 53 //獲取第二個輸入框的內容 54 char *p2 = strchr(p1 + 1, '&'); 55 if (*p2 != NULL) 56 { 57 *p2 = '\0'; 58 } 59 //輸出第二個輸入框的內容 60 printf("%s\r\n",p1+6); 61 62 //整合成cmd指令 63 char cmd[256] = { 0 }; 64 //生成隨機數,寫入到隨機數文件中 65 time_t ts; 66 unsigned data = time(&ts); 67 srand(&ts); 68 int num = rand(); 69 70 //整合cmd指令,並重定向到文件 71 sprintf(cmd, "%s %s >%d.txt", szpost + 5, p1 + 6, num); 72 //文件名 73 char filename[100] = { 0 }; 74 //生成文件名 75 sprintf(filename,"%d.txt", num); 76 //執行指令 77 system(cmd); 78 //打開文件 79 FILE *pf = fopen(filename,"r"); 80 //讀取文件 81 while (!feof(pf)) 82 { 83 char ch = fgetc(pf); 84 putchar(ch); 85 } 86 //關閉文件 87 fclose(pf); 88 }