审计dvwa高难度命令执行漏洞的代码,编写实例说明如下函数的用法

审计dvwa高难度命令执行漏洞的代码

,编写实例说明如下函数的用法

代码:



if( isset( $_POST[ 'Submit' ]  ) ) {
    // Get input
    $target = trim($_REQUEST[ 'ip' ]);

    // Set blacklist
    $substitutions = array(
        '&'  => '',
        ';'  => '',
        '| ' => '',
        '-'  => '',
        '$'  => '',
        '('  => '',
        ')'  => '',
        '`'  => '',
        '||' => '',
    );

    // Remove any of the charactars in the array (blacklist).
    $target = str_replace( array_keys( $substitutions ), $substitutions, $target );

    // Determine OS and execute the ping command.
    if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
        // Windows
        $cmd = shell_exec( 'ping  ' . $target );
    }
    else {
        // *nix
        $cmd = shell_exec( 'ping  -c 4 ' . $target );
    }

    // Feedback for the end user
    echo "
{$cmd}
"
; } ?>

trim

此函数用于删除字符串两侧的空白字符或其他预定义字符。


    $username = $_GET['username'];
    $username = trim($username);
    echo($username)
?>

接受表单传递过来的用户名,并使用trim() 函数删除其两侧任意的空格。

str_replace

这个函数用于搜索一个字符串并替换与另一个字符串匹配的部分。


    $test = "hello world!";
    $test = str_replace("world", "zs", $test);
    echo $test;    // 输出为:"hello zs!"
?>

使用str_replace() 函数讲“world”替换为“zs”

审计dvwa高难度命令执行漏洞的代码,编写实例说明如下函数的用法_第1张图片

array_keys

这个函数返回数组中所有键名的一个新数组。


    $test = array('a' => 'apple', 'b' => 'banana', 'c' => 'cherry');
    print_r(array_keys($test));     // 输出  Array ( [0] => a [1] => b [2] => c ) 
?>

使用array_keys()函数获取数组中的所有键名。

stristr 

这个函数查找字符串在另一字符串中的第一次出现。


    $string = "hello world!";
    $findme = "world";
    $pos = strpos($string,$findme);

    if ($pos === false) {
        echo "The string '$findme' was not found in the string '$string'";
    } else {
        echo "The string '$findme' was found in the string '$string'";
    }
?>

使用strpos()函数查找"World"是否存在于字符串"Hello, World!"中。

php_uname

这个函数返回关于服务器的信息,如主机名、操作系统名称和版本号等。


    echo php_uname();
    // 输出 Windows NT WIN-37QPUN7NO81 6.2 build 9200 (Windows Server 2012 Standard Edition) i586
?>

使用php_uname()函数获取服务器信息。

你可能感兴趣的:(笔记,安全,笔记)