Run the root command in PHP.

Source: Internet
Author: User
PHP executes the root command-general Linux technology-Linux programming and kernel information. The following is a detailed description. Author: mq110

When PHP was used to run the root command before playing C for a period of time, it never worked until the super plug-in was found one day.

With the increasing days of playing C, I found that the external commands to be run can be wrapped in C. I tried it and succeeded.

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. The current directory of the experiment command iptables is/var/www/html/http
Use the root user to write the program.

We all know that iptables cannot be run by non-root users.

First write a C program

The name is
CODE:

# 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;
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.