dqp21271
dqp21271
2014-10-16 10:06
浏览 56
已采纳

使用PHP创建SSH shell并执行'powershell.exe'?

<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('10.106.240.212');
$ssh->login('Administrator', 'Nbv12345') or die("Login failed");
echo $ssh->exec('powershell.exe');
echo connected;
?>

I am trying to execute 'powershell.exe' using PHP SSH2. The script timeouts after 30 seconds always.

I am able to SSH through a normal SSH client

enter image description here

While I am able to execute simple commands like

dir

How can I enter powershell and execute a command ? Thanks in advance!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drqja5919276
    drqja5919276 2014-10-16 13:40
    已采纳

    You'll need to either enable a PTY or use an interactive shell. eg.

    <?php
    include('Net/SSH2.php');
    $ssh = new Net_SSH2('10.106.240.212');
    $ssh->login('Administrator', 'Nbv12345') or die("Login failed");
    $ssh->write("powershell.exe
    ");
    $ssh->setTimeout(2);
    echo $ssh->read();
    //$ssh->write("dir
    ");
    //$ssh->read('[prompt]');
    ?>
    

    ...or:

    <?php
    include('Net/SSH2.php');
    $ssh = new Net_SSH2('10.106.240.212');
    $ssh->login('Administrator', 'Nbv12345') or die("Login failed");
    $ssh->enablePTY()
    $ssh->exec("powershell.exe
    ");
    $ssh->setTimeout(2);
    echo $ssh->read();
    //$ssh->write("command
    ");
    //$ssh->read('[prompt]');
    ?>
    
    点赞 评论

相关推荐