Sunday 15 April 2012

Create a SSH shell using PHP and execute 'powershell.exe'? -



Create a SSH shell using PHP and execute '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 trying execute 'powershell.exe' using php ssh2. script timeouts after 30 seconds always.

i able ssh through normal ssh client

while able execute simple commands

dir

how can come in powershell , execute command ? in advance!

you'll need either enable pty or utilize 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\n"); $ssh->settimeout(2); echo $ssh->read(); //$ssh->write("dir\n"); //$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\n"); $ssh->settimeout(2); echo $ssh->read(); //$ssh->write("command\n"); //$ssh->read('[prompt]'); ?>

php ssh phpseclib

No comments:

Post a Comment