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

使用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!

图片转代码服务由CSDN问答提供 功能建议

 &lt;?php 
include('Net / SSH2.php'); 
 $ ssh = 新的Net_SSH2('10 .106.240.212'); 
 $ ssh-&gt;登录('管理员','Nbv12345')或死(“登录失败”); 
echo $ ssh-&gt; exec('powershell.exe'  ); 
echo connected; 
?&gt; 
   
 
 

我正在尝试使用PHP SSH2执行'powershell.exe'。 脚本 30秒后超时总是。

我能够通过正常的SSH客户端进行SSH连接

虽然我能够执行像

  dir 
   
 
 

如何输入powershell并执行命令? 提前致谢!

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 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]');
    ?>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题