php_audit--Command Injection attack

Source: Internet
Author: User

You can use the following 5 functions to execute an external application or function in PHP:

    string System (string command,int &Return_var)    Note: command to execute commands, Return_var A status value that holds the execution of the execution    of the command;string exec (string command,array &output,int $return _var)    Note: Output obtains the execution name for each line of the string    void PassThru (string command,int &Return_var)      string shell_exec (string  command)    ":    same function as Shell_exec

# # Vulnerability Example # #

<? PHP     error_reporting (0);     $dir=$_get[' dir '];     if (isset($dir)) {        system("Ls-al").  $dir);    }        ? >

# eval Injection Attack #

# # Vulnerability Example # #

    <? PHP     $var= "var";     if (isset($_get[' arg '])) {        $arg=$_get[' Arg '];         Eval ("\ $var =$arg;" );         Echo "\ $var =". $var ;    }    ? >

# dynamic Function #

# # Vulnerability Example # #

    <? php    func A () {        dosomething ();    }    Func B () {        dosomething ();    }     if (isset($_get["func"])) {        $myfunc=$_get["func"] ;         Echo $myfunc ();    }    ? >

# Defense Method #

    1 , try not to execute external    commands 2 , using custom functions or libraries to override the functionality    of external commands 3 , using the Escapeshellarg function to handle command    parameters 4 , using Safe_mode_exec_dir to specify the path to the executable    Esacpeshellarg function will escape any character that causes the argument or command to end, single quote "'", replace with "\", double quote "" ", replace with" \ "", semicolon ";" Replace with "\;"    Using Safe_mode_exec_dir to specify the path to the executable file, you can put the command that will be    used into this path in advance = on     safe_mode_exec_di r=/usr/local/ php/bin/

php_audit--Command Injection attack

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.