When PHP was used to run the root command before playing C for a period of time, it failed until the super plug-in was found one day. As I spent more time playing C, I found that the external commands to be run can be wrapped in C. The experiment is successful. You can use PHP to execute the root command without any external tools. Below me
When PHP was used to run the root command before playing C for a period of time, it failed until the super plug-in was found one day. As I spent more time playing C, I found that the external commands to be run can be wrapped in C. The experiment is successful. You can use PHP to execute the root command without any external tools. Below me
When PHP was used to run the root command before playing C for a period of time, it failed until the super plug-in was found one day.
As I spent more time playing C, I found that the external commands to be run can be wrapped in C. The experiment is successful. You can use PHP to execute the root command without any external tools. I will release the method to you below. If you need to use php to run the root command, you don't have to worry about it.
Platform: Linux
Experiment command iptables. The current directory is/var/www/html/http. When writing a program, the root user is used. We all know that iptables cannot be run by non-root users.
First, write a C program named: ips.c.
# Include
# Include
# Include
# Include
Int main ()
{
Uid_t uid, euid;
Char cmd [1024];
Uid = getuid ();
Euid = geteuid ();
Printf ("my uid: % u/n", getuid (); // The current uid can be commented out.
Printf ("my euid: % u/n", geteuid (); // The current euid is displayed here
If (setreuid (euid, uid) // exchange the two IDs
Perror ("setreuid ");
Printf ("after setreuid uid: % u/n", getuid ());
Printf ("afer sertreuid euid: % u/n", geteuid ());
System ("/sbin/iptables-L"); // execute the iptables-L command
Return 0;
}
|
Compile the file:
Generate the following file: the executable file. If you use a PHP Web page to call this ipt, it will not work even if setreuid is used.
Next, we will do the following:
chmod u+s ./ipt
ls
-rwsr-xr-x 1 root root 5382 Jul 2 21:45 ipt
|
Okay, you have already set it up. Write another php page to call it.
echo '
';
$last_line = system('/var/www/html/http/ipt', $retval);
echo '
Last line of the output: ' . $last_line . '
Return value: ' . $retval;
?>
|
Browse in a browser.
[color=Red]Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
state RELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT)
target prot opt source destination [/color]
[color=Blue]my uid :48
my euid :0
after setreuid uid :0
afer sertreuid euid :48[/color]
---------------------------------------------------------
Last line of the output: afer sertreuid euid :48
---------------------------------------------------------
Return value: 0
|
The command is successfully executed.
Public opinion: the uid of apache is 48. After setreuid is called, the valid user ID and the actual user ID are exchanged. (The chmod u + s must take effect) make apache's current uid 0 so that the root command can be executed. You only need to change the system command in the C file to execute the root command in PHP.
Collect and organize the Linux Alliance