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

时间:2014-10-16 10:06:09

标签: php ssh phpseclib

<?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;
?>

我正在尝试执行&#39; powershell.exe&#39;使用PHP SSH2。脚本 30秒后超时始终。

我可以通过普通的SSH客户端进行SSH连接

enter image description here

虽然我能够执行像

这样的简单命令
dir

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

1 个答案:

答案 0 :(得分:1)

您需要启用PTY或使用交互式shell。例如

<?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\n");
$ssh->setTimeout(2);
echo $ssh->read();
//$ssh->write("dir\n");
//$ssh->read('[prompt]');
?>

...或:

<?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\n");
$ssh->setTimeout(2);
echo $ssh->read();
//$ssh->write("command\n");
//$ssh->read('[prompt]');
?>