审计DVWA命令执行的代码(初学php代码浅试代码审计)

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {

//判断post提交的值是否为空。

    // Get input

    $target = trim($_REQUEST[ 'ip' ]);

//设置黑名单

    // Set blacklist

    $substitutions = array(

        '&'  => '',

        ';'  => '',

        '| ' => '',

        '-'  => '',

        '$'  => '',

        '('  => '',

        ')'  => '',

        '`'  => '',

        '||' => '',

    );  //定义$substitutions=数组

    // Remove any of the charactars in the array (blacklist)./删除数组中的任何字符(黑名单)。

    $target = str_replace( array_keys( $substitutions ), $substitutions, $target );

//将数组中设置的值替换

// Determine OS and execute the ping command.

//判断操作系统,执行ping命令

    if( stristr( php_uname( 's' ), 'Windows NT' ) ) {

        // Windows

//忽略大小写查看当前运行php的系统版本是否为Windows

        $cmd = shell_exec( 'ping  ' . $target );

    }  //如果是则执行cmd进行ping

else {

//否则

        // *nix

        $cmd = shell_exec( 'ping  -c 4 ' . $target );

    }执行ping 4下

    // Feedback for the end user

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

} //保留原有格式,最后输出ping的值

impossible难度的命令执行

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {

    //判断post提交的值是否为空

    checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );

//检查令牌(接收传参用户令牌并建立连接)

   

$target = $_REQUEST[ 'ip' ];

//接收前端传送的ip

    $target = stripslashes( $target );

//去除函数的反斜杆

    

    $octet = explode( ".", $target );

//使用一个字符串分割另一个字符串用.和ip地址进行拼接

    

    if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && ( is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && ( sizeof( $octet ) == 4 ) ) {

      

        $target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3];

       

        if( stristr( php_uname( 's' ), 'Windows NT' ) ) {

            //判断操作系统,执行ping命令

            $cmd = shell_exec( 'ping  ' . $target );

        } //运行ping命令

        else {

            //则

            $cmd = shell_exec( 'ping  -c 4 ' . $target );

        } //ping4 次

       

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

   //输出ping的结果

 }

    else {

       //则

        echo '<pre>ERROR: You have entered an invalid IP.</pre>';

    }  //输出您输入的IP地址错误

}

generateSessionToken();

//生成会话令牌

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值