Remote system shell execution

Event Listener: Skynet\EventListener\SkynetEventListenerExec

Skynet allows you to remote shell execution. You can launch shell command (or other application) on remote and Skynet will returns output of it. Note that this option should not be used for nonauthorized operations. Skynet offers 3 different ways to remote shell execution. All of them are based on PHP shell function but they are small different. By sending one parameter you can remotely opens shell execute command and Skynet will return output of the shell execution in response object.

First command for remote shell execution is:

@exec

This is based on PHP exec() function, it takes one argument whitch is command to be executed on remote shell.
Argument with command to execute must be set in cmd parameter.

Example of usage (PHP code):

/src/SkynetUser/MyListener.php
public function onRequest($context)
{
if($context == "beforeSend")
{
$this->request->set('@exec', array('cmd' => 'COMMAND_TO_EXECUTE'));
}
}

Example of usage (webconsole):

@exec cmd:"COMMAND_TO_EXECUTE";

Skynet will remotely open system shell (via exec() function), execute COMMAND_TO_EXECUTE and return output via 3 parameters in response:

@<<execResult ($result)

@<<execReturn ($return)

@<<execOutput ($output)

Whitch are output of:

$result = exec($cmd, $output, $return);


Example:
If you want execute command whoami on remote linux based or Windows system, just use:

@exec cmd:"whoami";

or in PHP code:

/src/SkynetUser/MyListener.php
public function onRequest($context)
{
if($context == "beforeSend")
{
$this->request->set('@exec', array('cmd' => 'whoami'));
}
}

Output of remote execution of command whoami (user name) will be return in response.

Another command is:

@system

This is based on PHP system() function, it takes one argument whitch is command to be executed on remote shell.
Like above, argument with command to execute must be set in cmd parameter.

This command executes remotely:

$result = system($cmd, $return);

And returns in response:

@<<execResult ($result)

@<<execReturn ($return)

Like above if you want to execute whoami just use:

@systen cmd:"whoami";

or in PHP code:

/src/SkynetUser/MyListener.php
public function onRequest($context)
{
if($context == "beforeSend")
{
$this->request->set('@system', array('cmd' => 'whoami'));
}
}

Last command is a little bit complicated and it's based on PHP's:

proc_open()

In Skynet, when you use command:

@proc

It will remotely execute proc_open() function with passed process name as first argument.

Usage of @proc is different than two previous commands.
Process you want to open needs to be passed by proc argument:

@proc proc:"PROCESS_NAME";

or in PHP code:

/src/SkynetUser/MyListener.php
public function onRequest($context)
{
if($context == "beforeSend")
{
$this->request->set('@proc', array('proc' => 'PROCESS_NAME'));
}
}

Skynet will return output like before but here you can manipulate process pipes

At this time you must do this manualy, by editing listener or creating your own.
By default, proc_open() runs under configuration as below:

$descriptorspec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w')
);

$process = proc_open($proc, $descriptorspec, $pipes);

if(is_resource($process))
{
$result = stream_get_contents($pipes[1]);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
$return = proc_close($process);
}

where $proc is process name passed remotely from request and $return is always returned in response via @<<procReturn parameter.
Full API Documentation is included in Skynet packages available on GitHub.