Skip to content

Commit

Permalink
Extend nasl_ssh functions to support non-interactive shell (pty disab…
Browse files Browse the repository at this point in the history
…led).

Currently there are two options:

- an interactive shell with pty enabled, which responses are quite verbose (cmds, prompt, etc).
- one shot cmd exec which close the channel, with the response of the command only.

The new option allows to run multiple commands and only get the answer of this command, whitout the extra data like prompts and commands sent to the target.
  • Loading branch information
jjnicola committed Jun 1, 2021
1 parent 1c04a50 commit ef022b4
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions nasl/nasl_ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,19 +1653,25 @@ request_ssh_shell_alarm (int signal)
* @return 0 if success, -1 if error.
*/
static int
request_ssh_shell (ssh_channel channel)
request_ssh_shell (ssh_channel channel, int pty)
{
assert (channel);

/* Work-around for LibSSH calling poll() with an infinite timeout. */
signal (SIGALRM, request_ssh_shell_alarm);
alarm (30);
if (ssh_channel_request_pty (channel))
return -1;
if (ssh_channel_change_pty_size (channel, 80, 24))
return -1;

if (pty == 1)
{
if (ssh_channel_request_pty (channel))
return -1;

if (ssh_channel_change_pty_size (channel, 80, 24))
return -1;
}
if (ssh_channel_request_shell (channel))
return -1;

alarm (0);
signal (SIGALRM, _exit);

Expand All @@ -1689,12 +1695,14 @@ request_ssh_shell (ssh_channel channel)
tree_cell *
nasl_ssh_shell_open (lex_ctxt *lexic)
{
int tbl_slot, session_id;
int tbl_slot, session_id, pty;
ssh_channel channel;
ssh_session session;
tree_cell *retc;

session_id = get_int_var_by_num (lexic, 0, -1);
pty = get_int_var_by_name (lexic, "pty", 1);

if (!verify_session_id (session_id, "ssh_shell_open", &tbl_slot, lexic))
return NULL;
session = session_table[tbl_slot].session;
Expand All @@ -1711,7 +1719,7 @@ nasl_ssh_shell_open (lex_ctxt *lexic)
return NULL;
}

if (request_ssh_shell (channel))
if (request_ssh_shell (channel, pty))
{
g_message ("Function %s (calling internal function %s) called from %s: "
"request_ssh_shell: %s",
Expand Down

0 comments on commit ef022b4

Please sign in to comment.