From 0526ef4aeb22a069dee401eff185302f6e38e6ef Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Thu, 20 May 2021 02:49:41 -0500 Subject: [PATCH 1/4] Extend nasl_ssh functions to support non-interactive shell (pty disabled). 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. (cherry picked from commit ef022b433473fc033bc61549043846d30ce61f8e) --- nasl/nasl_ssh.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/nasl/nasl_ssh.c b/nasl/nasl_ssh.c index 88750a128..5f98210bb 100644 --- a/nasl/nasl_ssh.c +++ b/nasl/nasl_ssh.c @@ -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); @@ -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; @@ -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", From c19471c1a7283ed8a9b036e6a39192c18c4d7d90 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Thu, 20 May 2021 02:55:19 -0500 Subject: [PATCH 2/4] Update docstrings (cherry picked from commit aabedb79d3f515b6277e1440f4772c658466dc13) --- nasl/nasl_ssh.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nasl/nasl_ssh.c b/nasl/nasl_ssh.c index 5f98210bb..8dcf3c42d 100644 --- a/nasl/nasl_ssh.c +++ b/nasl/nasl_ssh.c @@ -1649,6 +1649,7 @@ 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. */ @@ -1685,6 +1686,8 @@ request_ssh_shell (ssh_channel channel, int pty) * @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. * From d761fea492eaeed98b88e13903c959a90e461427 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Thu, 20 May 2021 03:01:24 -0500 Subject: [PATCH 3/4] Update Changelog (cherry picked from commit 9cf482ef83a9726852347a819c4f6f65c9cb6114) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3904f4829..ff8f5f2a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +<<<<<<< HEAD +======= +## [21.10] (unreleased) + +### Added +- Add support for volatile keys. [#682](https://github.com/greenbone/openvas/pull/682) +- Extend nasl lint to check Syntax for Arguments for script_xref() function. [#714](https://github.com/greenbone/openvas/pull/714) +- Recheck alive status of host with specified amount of NVT timeouts. [#729](https://github.com/greenbone/openvas/pull/729) +- Add json-glib support for creating JSON result strings. [#739](https://github.com/greenbone/openvas/pull/739) +- Integrate sentry for debugging purposes [#742](https://github.com/greenbone/openvas/pull/742) +- Add support for non-interactive shell to nasl_ssh_shell_open(). [#744](https://github.com/greenbone/openvas/pull/744) + +### Changed +- function script_bugtraq_id getting skipped, linter warns. [#724](https://github.com/greenbone/openvas/pull/724) + +### Fixed + +### Removed +- Remove handling of source_iface related preferences. [#730](https://github.com/greenbone/openvas/pull/730) + +[21.10]: https://github.com/greenbone/openvas-scanner/compare/openvas-21.04...master + +>>>>>>> 9cf482ef (Update Changelog) ## [21.04.1] (unreleased) ### Added From 13fb5908ab11e1da66964a23a818a4046f57f5f7 Mon Sep 17 00:00:00 2001 From: ArnoStiefvater Date: Wed, 2 Jun 2021 11:45:25 +0200 Subject: [PATCH 4/4] Fix changelog --- CHANGELOG.md | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff8f5f2a1..6eeee84ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,34 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -<<<<<<< HEAD -======= -## [21.10] (unreleased) - -### Added -- Add support for volatile keys. [#682](https://github.com/greenbone/openvas/pull/682) -- Extend nasl lint to check Syntax for Arguments for script_xref() function. [#714](https://github.com/greenbone/openvas/pull/714) -- Recheck alive status of host with specified amount of NVT timeouts. [#729](https://github.com/greenbone/openvas/pull/729) -- Add json-glib support for creating JSON result strings. [#739](https://github.com/greenbone/openvas/pull/739) -- Integrate sentry for debugging purposes [#742](https://github.com/greenbone/openvas/pull/742) -- Add support for non-interactive shell to nasl_ssh_shell_open(). [#744](https://github.com/greenbone/openvas/pull/744) - -### Changed -- function script_bugtraq_id getting skipped, linter warns. [#724](https://github.com/greenbone/openvas/pull/724) - -### Fixed - -### Removed -- Remove handling of source_iface related preferences. [#730](https://github.com/greenbone/openvas/pull/730) - -[21.10]: https://github.com/greenbone/openvas-scanner/compare/openvas-21.04...master - ->>>>>>> 9cf482ef (Update Changelog) ## [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)