Automatic execution of commands in Telnet/SSH

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Automatic execution of commands in Telnet/SSH

McRoy, Jeffrey (GE Healthcare)

Hi Everyone,

 

Has anyone experimented with automatically executing a command on the remote system directly after logging in using the Telnet or SSH protocol plugins?

 

 

Thanks & Regards,

Jeff

 


smime.p7s (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Automatic execution of commands in Telnet/SSH

vnick
Jeff,
Guacamole does not work any different in this regard than logging into the SSH or Telnet system with a terminal emulator.  So, you can certainly set a command to run at login, which will be executed in the context of the user's login shell and environment, but there's no special way that Guacamole has to inject commands into the login process that either bypass the user's login shell or execute something just because it's coming from Guacamole.

There are ways to accomplish this - like setting the SSH session startup command to a particular shell script that runs and then drops the user into a shell.  But, again, this is exactly the same process you'd use if you wanted to do this for someone using ssh or telnet on a command line.

-Nick

On Mon, Oct 2, 2017 at 4:46 PM, McRoy, Jeffrey (GE Healthcare) <[hidden email]> wrote:

Hi Everyone,

 

Has anyone experimented with automatically executing a command on the remote system directly after logging in using the Telnet or SSH protocol plugins?

 

 

Thanks & Regards,

Jeff

 


Reply | Threaded
Open this post in threaded view
|

Re: Automatic execution of commands in Telnet/SSH

McRoy, Jeffrey (GE Healthcare)
In reply to this post by McRoy, Jeffrey (GE Healthcare)

Thanks for the comments Nick. :)

 

-Jeff

 

 

From: Nick Couchman <[hidden email]>
Reply-To: "[hidden email]" <[hidden email]>
Date: Monday, October 2, 2017 at 7:24 PM
To: "[hidden email]" <[hidden email]>
Subject: EXT: Re: Automatic execution of commands in Telnet/SSH

 

Jeff,

Guacamole does not work any different in this regard than logging into the SSH or Telnet system with a terminal emulator.  So, you can certainly set a command to run at login, which will be executed in the context of the user's login shell and environment, but there's no special way that Guacamole has to inject commands into the login process that either bypass the user's login shell or execute something just because it's coming from Guacamole.

 

There are ways to accomplish this - like setting the SSH session startup command to a particular shell script that runs and then drops the user into a shell.  But, again, this is exactly the same process you'd use if you wanted to do this for someone using ssh or telnet on a command line.

 

-Nick

 

On Mon, Oct 2, 2017 at 4:46 PM, McRoy, Jeffrey (GE Healthcare) <[hidden email]> wrote:

Hi Everyone,

 

Has anyone experimented with automatically executing a command on the remote system directly after logging in using the Telnet or SSH protocol plugins?

 

 

Thanks & Regards,

Jeff

 

 


smime.p7s (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Automatic execution of commands in Telnet/SSH

McRoy, Jeffrey (GE Healthcare)
In reply to this post by McRoy, Jeffrey (GE Healthcare)

Hi Nick,

 

Imagine having a dropdown in the client UI that allows a user to select and execute pre-defined commands. That’s more what I’m thinking of instead of running a command specific to a user’s login. Would Guacamole have a way to programmatically inject commands into the input stream?

 

 

Thanks & Regards,

Jeff

 

 

 

 

From: Nick Couchman <[hidden email]>
Reply-To: "[hidden email]" <[hidden email]>
Date: Monday, October 2, 2017 at 7:24 PM
To: "[hidden email]" <[hidden email]>
Subject: EXT: Re: Automatic execution of commands in Telnet/SSH

 

Jeff,

Guacamole does not work any different in this regard than logging into the SSH or Telnet system with a terminal emulator.  So, you can certainly set a command to run at login, which will be executed in the context of the user's login shell and environment, but there's no special way that Guacamole has to inject commands into the login process that either bypass the user's login shell or execute something just because it's coming from Guacamole.

 

There are ways to accomplish this - like setting the SSH session startup command to a particular shell script that runs and then drops the user into a shell.  But, again, this is exactly the same process you'd use if you wanted to do this for someone using ssh or telnet on a command line.

 

-Nick

 

On Mon, Oct 2, 2017 at 4:46 PM, McRoy, Jeffrey (GE Healthcare) <[hidden email]> wrote:

Hi Everyone,

 

Has anyone experimented with automatically executing a command on the remote system directly after logging in using the Telnet or SSH protocol plugins?

 

 

Thanks & Regards,

Jeff

 

 


smime.p7s (8K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Automatic execution of commands in Telnet/SSH

Mike Jumper
On Tue, Oct 3, 2017 at 3:00 PM, McRoy, Jeffrey (GE Healthcare) <[hidden email]> wrote:

... Would Guacamole have a way to programmatically inject commands into the input stream?


It's important to distinguish between commands and input events here. In general, yes, you can inject input events into the stream. Assuming you're building your own web application driven by the Guacamole API, there is an API at the JavaScript level which facilitates this [1], and you can leverage that to send a sequence of key press/release events to replicate what a user would type.

The concept of a "command" doesn't exist at the Guacamole level, though. There's no way that Guacamole would be able to know that the keystrokes being sent are not actually being sent in the middle of a command that the user already partially typed, or that they're actually being handled by a text editor and not the shell, etc. You would also need to take into account the current keyboard state (what if the user is holding down Ctrl? or Shift?), and maybe even reset the keyboard entirely prior to sending any events [2].

- Mike


Reply | Threaded
Open this post in threaded view
|

Re: Automatic execution of commands in Telnet/SSH

McRoy, Jeffrey (GE Healthcare)
In reply to this post by McRoy, Jeffrey (GE Healthcare)

Hi Everyone,

 

After digging into this a bit deeper it looks like there are two basic options, use a pipe stream or use key events. A pipe stream is way more efficient when sending very large amounts of data, but (as far as I can tell) Guacamole’s SSH support does not handle inbound pipe streams or using them as a source for keystrokes. So, something like below won’t work.

 

var stream = client.createPipeStream("text/plain", "MyStream");

var writer = new Guacamole.StringWriter(stream);

writer.sendText("Hello world!");

writer.sendEnd();

 

 

A function to “type” a command at the command prompt like below could be used.

 

function sendCommand(client, cmd) {

    for (var i=0; i < cmd.length; i++) {

 

        // Get current codepoint

        var codepoint = cmd.charCodeAt(i);

 

        // Convert to keysym

        var keysym;

        if (codepoint >= 0x0100)

            keysym = 0x01000000 | codepoint;

        else

            keysym = codepoint;

 

        // Press and release key

        client.sendKeyEvent(1, keysym);

        client.sendKeyEvent(0, keysym);

    }

}

 

A small delay must be injected between making the client connection and the start of sending keystrokes. The delay is only needed once to give the connection and Telnet or SSH session time to start. For a single one time command execution the function call could be included in a setTimeout statement like below.

 

setTimeout(function() { sendCommand (guac, "ls -al\r"); }, 1000);

 

 

 

Regards,

Jeff

 

 

 

From: "McRoy, Jeffrey (GE Healthcare)" <[hidden email]>
Reply-To: <[hidden email]>
Date: Tuesday, October 3, 2017 at 5:00 PM
To: "[hidden email]" <[hidden email]>
Subject: EXT: Re: Automatic execution of commands in Telnet/SSH

 

Hi Nick,

 

Imagine having a dropdown in the client UI that allows a user to select and execute pre-defined commands. That’s more what I’m thinking of instead of running a command specific to a user’s login. Would Guacamole have a way to programmatically inject commands into the input stream?

 

 

Thanks & Regards,

Jeff

 

 

 

 

From: Nick Couchman <[hidden email]>
Reply-To: "[hidden email]" <[hidden email]>
Date: Monday, October 2, 2017 at 7:24 PM
To: "[hidden email]" <[hidden email]>
Subject: EXT: Re: Automatic execution of commands in Telnet/SSH

 

Jeff,

Guacamole does not work any different in this regard than logging into the SSH or Telnet system with a terminal emulator.  So, you can certainly set a command to run at login, which will be executed in the context of the user's login shell and environment, but there's no special way that Guacamole has to inject commands into the login process that either bypass the user's login shell or execute something just because it's coming from Guacamole.

 

There are ways to accomplish this - like setting the SSH session startup command to a particular shell script that runs and then drops the user into a shell.  But, again, this is exactly the same process you'd use if you wanted to do this for someone using ssh or telnet on a command line.

 

-Nick

 

On Mon, Oct 2, 2017 at 4:46 PM, McRoy, Jeffrey (GE Healthcare) <[hidden email]> wrote:

Hi Everyone,

 

Has anyone experimented with automatically executing a command on the remote system directly after logging in using the Telnet or SSH protocol plugins?

 

 

Thanks & Regards,

Jeff

 

 


smime.p7s (8K) Download Attachment