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

演示环境

dvwa靶场

Low

<?php

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

    if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
        $cmd = shell_exec( 'ping' . $target );
    }
    else {
        $cmd = shell_exec( 'ping -c 4' .$target );
    }

    echo "<pre>{$cmd}</pre>";
}

?>

isset的作用是用来检查某一变量是否被定义并赋值,如果未定义或值为空,则返回false,否则返回true。

 stristr的作用是从第一个即(php_uname( 's' ))中查找第二个即(’Windows NT‘)

此处表达为如果有’Windows NT‘则执行下面代码,否则else

 php_uname()的作用是返回运行 PHP 的系统的有关信息。该函数主要用于获取服务器或操作系统的详细信息,如内核版本、处理器类型、操作系统类型和名称等。

这里php_uname( 's' )中s代表只取操作系统名称 

 Medium


<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
    // Get input
    $target = $_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 "<pre>{$cmd}</pre>";
}

?>

 

array_keys它用于获取数组中的所有键名。这里获取的就是'&&'和';'

str_replace它用于替换字符串中的某些字符或子字符串。这里最后要将值存储到$target中

前面开始替换将'&&'和';'替换为空

 trim它用于删除字符串两侧的空白字符和其他预定义字符。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值