Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for non-interactive shell to nasl_ssh_shell_open(). (backport #744) #753

Merged
merged 4 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [21.04.1] (unreleased)

### Added
- Improve nasl linter to catch more cases of undeclared variables. [#728][(https://github.com/greenbone/openvas-scanner/pull/728)
- Add deprecation warning for source_iface related settings which will be removed with the 21.10 release. [#732][(https://github.com/greenbone/openvas-scanner/pull/732)
- Improve nasl linter to catch more cases of undeclared variables. [#728](https://github.com/greenbone/openvas-scanner/pull/728)
- Add deprecation warning for source_iface related settings which will be removed with the 21.10 release. [#732](https://github.com/greenbone/openvas-scanner/pull/732)
- New Credentials for SSH to get su privileges. Backport of [#744](https://github.com/greenbone/openvas-scanner/pull/744). [#753](https://github.com/greenbone/openvas-scanner/pull/753)

### Changed
- Update default log config [#711](https://github.com/greenbone/openvas-scanner/pull/711)
Expand Down
25 changes: 18 additions & 7 deletions nasl/nasl_ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1649,23 +1649,30 @@ request_ssh_shell_alarm (int signal)
* @brief Open a shell on an ssh channel.
*
* @param[in] channel SSH Channel.
* @param[in] pty 1 interactive shell, 0 non-intercative shell
*
* @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 @@ -1679,6 +1686,8 @@ request_ssh_shell (ssh_channel channel)
* @nasluparam
*
* - An ssh session id.
* - Named param 'pty' to enable/disable the interactive shell. Default is 1
* interactive.
*
* @naslret An int on success or NULL on error.
*
Expand All @@ -1689,12 +1698,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 +1722,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