Jump to content

What would be the best way to send a command?


ChrisMartino

Recommended Posts

Well basicaly i have a linux dedicated server, And i have a webhost with openssl installed, What would be the best way to remotley send a command to the box withought using SSH?

 

This is my hosts phpinfo() :

 

http://fotosnap.net/phpinfo.php

here's a script I threw together in a couple minutes.  It's not too secure, so I reccommend that you run this on your local machine to make the connections, but only if you have the required software to do this.  If you need help setting it up, let me know:

<form method="POST" action="?">
<table border="0">
	<tr>
		<td>Secret word to run this:</td>
		<td><input type="password" name="secret"></td>
	</tr>
	<tr>
		<td>User:</td>
		<td><input type="text" name="username"></td>
	</tr>
	<tr>
		<td>Pass:</td>
		<td><input type="password" name="password"></td>
	</tr>
	<tr>
		<td>Command to run:</td>
		<td><input type="text" name="cmd"></td>
	</tr>
	<tr>
		<td><input type="submit" value="Execute Command"></td>
		<td> </td>
	</tr>
</table>
</form>
<?php
$secret_word = "cheeseburgerinparadise";
if (isset($_POST) && isset($_POST['secret']) && $_POST['secret'] == $secret_word){
run_ssh_command($_POST['cmd'], $_POST['username'], $_POST['password']);
}
function run_ssh_command($commaind, $user, $password){
$your_server = "example.com"; /* <-- Change to your server */
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
if(!($con = ssh2_connect($your_server, 22))){
	echo "fail: unable to establish connection\n";
} else {
	// try to authenticate with username root, password secretpassword
	if(!ssh2_auth_password($con, $user, $password)) {
		echo "fail: unable to authenticate\n";
	} else {
		// allright, we're in!
		echo "okay: logged in...\n";

		// execute a command
		if(!($stream = ssh2_exec($con, "ls -al" )) ){
			echo "fail: unable to execute command\n";
		} else{
			// collect returning data from command
			stream_set_blocking( $stream, true );
			$data = "";
			while( $buf = fread($stream,4096) ){
				$data .= $buf;
			}
			fclose($stream);
		}
	}
}
}
?>

EDITED to fix a small error.

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.