From dff05944e0972f50c8c2ab51dace4d5b2d59e04a Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Tue, 7 Jan 2025 15:33:17 +0100 Subject: [PATCH 01/10] Add bash script to check for missing SPDX headers --- check_license_header.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 check_license_header.sh diff --git a/check_license_header.sh b/check_license_header.sh new file mode 100755 index 000000000..94a0c719e --- /dev/null +++ b/check_license_header.sh @@ -0,0 +1,20 @@ +any_missing_headers=0 + +for folder in src misc rust/src; do + echo "Checking $folder" + for f in $(find $folder -regex ".*\.\(rs\|c\|h\)"); do + header=$(head -n 3 "$f") + if ! [[ "$header" =~ SPDX ]]; then + echo "File does not contain license header: $f" + any_missing_headers=1 + + if [[ "$1" == add_header ]]; then + tmpfile=$(mktemp) + cp "$f" "$tmpfile" + echo -e "// SPDX-FileCopyrightText: 2025 Greenbone AG\n//\n// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception\n" | cat - $tmpfile > "$f" + fi + fi + done +done + +exit $any_missing_headers From dcfa5fa6a79c2269a5c0a08446b9d346c6185b7a Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Tue, 7 Jan 2025 15:37:08 +0100 Subject: [PATCH 02/10] Add github workflow for license header check. --- .github/workflows/linting.yml | 7 +++++++ check_license_header.sh => check_license_headers.sh | 0 2 files changed, 7 insertions(+) rename check_license_header.sh => check_license_headers.sh (100%) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index e882f604a..4e8675e98 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -41,3 +41,10 @@ jobs: - uses: actions/checkout@v4 - run: cargo install cargo-audit - run: cargo audit + License-Headers: + runs-on: ubuntu-latest + steps: + - name: Check out openvas-scanner + uses: actions/checkout@v4 + - name: Check license headers + run: bash ./check_license_headers.sh diff --git a/check_license_header.sh b/check_license_headers.sh similarity index 100% rename from check_license_header.sh rename to check_license_headers.sh From 7fc1809bdec6205767380b9e47ac7f86f74c79c8 Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Wed, 8 Jan 2025 10:53:58 +0100 Subject: [PATCH 03/10] Add license header to source code files that were missing one --- misc/openvas-krb5.c | 4 ++++ misc/openvas-krb5.h | 4 ++++ rust/src/feed/transpile/error.rs | 4 ++++ rust/src/lib.rs | 4 ++++ rust/src/models/resources/check.rs | 4 ++++ rust/src/models/resources/mod.rs | 4 ++++ rust/src/nasl/builtin/cryptographic/tests/mod.rs | 4 ++++ rust/src/nasl/builtin/error.rs | 4 ++++ rust/src/nasl/builtin/http/error.rs | 4 ++++ rust/src/nasl/builtin/network/tcp.rs | 4 ++++ rust/src/nasl/builtin/network/tls.rs | 4 ++++ rust/src/nasl/builtin/network/udp.rs | 4 ++++ rust/src/nasl/builtin/raw_ip/tests/mod.rs | 4 ++++ rust/src/nasl/builtin/report_functions/mod.rs | 4 ++++ rust/src/nasl/builtin/ssh/error.rs | 4 ++++ rust/src/nasl/builtin/ssh/libssh/channel.rs | 4 ++++ rust/src/nasl/builtin/ssh/libssh/session.rs | 4 ++++ rust/src/nasl/builtin/ssh/mod.rs | 4 ++++ rust/src/nasl/builtin/ssh/russh/mod.rs | 4 ++++ rust/src/nasl/builtin/ssh/russh/session.rs | 4 ++++ rust/src/nasl/builtin/ssh/sessions.rs | 4 ++++ rust/src/nasl/builtin/ssh/tests/mod.rs | 4 ++++ rust/src/nasl/builtin/ssh/tests/server.rs | 4 ++++ rust/src/nasl/builtin/ssh/utils.rs | 4 ++++ rust/src/nasl/builtin/sys/mod.rs | 4 ++++ rust/src/nasl/builtin/tests.rs | 4 ++++ rust/src/nasl/interpreter/code_interpreter.rs | 4 ++++ rust/src/nasl/interpreter/tests/mod.rs | 4 ++++ rust/src/nasl/interpreter/tests/retry.rs | 4 ++++ rust/src/nasl/mod.rs | 4 ++++ rust/src/nasl/test_utils.rs | 4 ++++ rust/src/nasl/utils/executor/mod.rs | 4 ++++ rust/src/nasl/utils/executor/nasl_function.rs | 4 ++++ rust/src/nasl/utils/function/from_nasl_value.rs | 4 ++++ rust/src/nasl/utils/function/maybe.rs | 4 ++++ rust/src/nasl/utils/function/mod.rs | 4 ++++ rust/src/nasl/utils/function/positionals.rs | 4 ++++ rust/src/nasl/utils/function/to_nasl_result.rs | 4 ++++ rust/src/nasl/utils/function/types.rs | 4 ++++ rust/src/nasl/utils/function/utils.rs | 4 ++++ rust/src/notus/tests.rs | 4 ++++ rust/src/scanner/mod.rs | 4 ++++ rust/src/scanner/running_scan.rs | 4 ++++ rust/src/scanner/scanner_stack.rs | 4 ++++ rust/src/scanner/vt_runner.rs | 4 ++++ rust/src/storage/infisto/error.rs | 4 ++++ 46 files changed, 184 insertions(+) diff --git a/misc/openvas-krb5.c b/misc/openvas-krb5.c index b07e7d6ff..b5c9b2dc9 100644 --- a/misc/openvas-krb5.c +++ b/misc/openvas-krb5.c @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + #include "openvas-krb5.h" #include diff --git a/misc/openvas-krb5.h b/misc/openvas-krb5.h index 9da377907..a3a890b60 100644 --- a/misc/openvas-krb5.h +++ b/misc/openvas-krb5.h @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + #include #include #ifndef OPENVAS_KRB5 diff --git a/rust/src/feed/transpile/error.rs b/rust/src/feed/transpile/error.rs index 26c006eb7..64a02ccb6 100644 --- a/rust/src/feed/transpile/error.rs +++ b/rust/src/feed/transpile/error.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use thiserror::Error; use crate::nasl::syntax::{LoadError, Statement}; diff --git a/rust/src/lib.rs b/rust/src/lib.rs index d761293ad..42a0d031b 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + pub mod feed; pub mod models; pub mod nasl; diff --git a/rust/src/models/resources/check.rs b/rust/src/models/resources/check.rs index 292b93e8d..bbdbd5def 100644 --- a/rust/src/models/resources/check.rs +++ b/rust/src/models/resources/check.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use crate::models::scanner::ObservableResources; /// Checks for relative resource availability. diff --git a/rust/src/models/resources/mod.rs b/rust/src/models/resources/mod.rs index d43270fa6..ab7bacd8f 100644 --- a/rust/src/models/resources/mod.rs +++ b/rust/src/models/resources/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + pub mod check; #[derive(Debug)] diff --git a/rust/src/nasl/builtin/cryptographic/tests/mod.rs b/rust/src/nasl/builtin/cryptographic/tests/mod.rs index b9ec1aca2..a959c028f 100644 --- a/rust/src/nasl/builtin/cryptographic/tests/mod.rs +++ b/rust/src/nasl/builtin/cryptographic/tests/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + mod aes_cbc; mod aes_ccm; mod aes_cmac; diff --git a/rust/src/nasl/builtin/error.rs b/rust/src/nasl/builtin/error.rs index ed874edbd..7899d10a7 100644 --- a/rust/src/nasl/builtin/error.rs +++ b/rust/src/nasl/builtin/error.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use thiserror::Error; use crate::nasl::prelude::*; diff --git a/rust/src/nasl/builtin/http/error.rs b/rust/src/nasl/builtin/http/error.rs index 7e28c6d1d..b856ca0a1 100644 --- a/rust/src/nasl/builtin/http/error.rs +++ b/rust/src/nasl/builtin/http/error.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::io; use thiserror::Error; diff --git a/rust/src/nasl/builtin/network/tcp.rs b/rust/src/nasl/builtin/network/tcp.rs index 953e4078f..caa3d7ccc 100644 --- a/rust/src/nasl/builtin/network/tcp.rs +++ b/rust/src/nasl/builtin/network/tcp.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::{ io::{self, BufRead, BufReader, Read, Write}, net::{IpAddr, SocketAddr}, diff --git a/rust/src/nasl/builtin/network/tls.rs b/rust/src/nasl/builtin/network/tls.rs index 4744898eb..1c5148c2b 100644 --- a/rust/src/nasl/builtin/network/tls.rs +++ b/rust/src/nasl/builtin/network/tls.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use core::fmt; use std::{ fmt::{Display, Formatter}, diff --git a/rust/src/nasl/builtin/network/udp.rs b/rust/src/nasl/builtin/network/udp.rs index be911ebca..2c371cb15 100644 --- a/rust/src/nasl/builtin/network/udp.rs +++ b/rust/src/nasl/builtin/network/udp.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::{ io::{self, Read, Write}, net::{IpAddr, SocketAddr, UdpSocket}, diff --git a/rust/src/nasl/builtin/raw_ip/tests/mod.rs b/rust/src/nasl/builtin/raw_ip/tests/mod.rs index 0e4b602bf..69a8b0cf5 100644 --- a/rust/src/nasl/builtin/raw_ip/tests/mod.rs +++ b/rust/src/nasl/builtin/raw_ip/tests/mod.rs @@ -1,2 +1,6 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + mod frame_forgery; mod packet_forgery; diff --git a/rust/src/nasl/builtin/report_functions/mod.rs b/rust/src/nasl/builtin/report_functions/mod.rs index a874c0c46..920d8612d 100644 --- a/rust/src/nasl/builtin/report_functions/mod.rs +++ b/rust/src/nasl/builtin/report_functions/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::sync::{Arc, RwLock}; use crate::models::{self, Protocol, ResultType}; diff --git a/rust/src/nasl/builtin/ssh/error.rs b/rust/src/nasl/builtin/ssh/error.rs index 396acd60d..dffee816f 100644 --- a/rust/src/nasl/builtin/ssh/error.rs +++ b/rust/src/nasl/builtin/ssh/error.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::fmt; use thiserror::Error; diff --git a/rust/src/nasl/builtin/ssh/libssh/channel.rs b/rust/src/nasl/builtin/ssh/libssh/channel.rs index ed53a8771..823cca61b 100644 --- a/rust/src/nasl/builtin/ssh/libssh/channel.rs +++ b/rust/src/nasl/builtin/ssh/libssh/channel.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::time::Duration; use crate::nasl::builtin::ssh::error::SshErrorKind; diff --git a/rust/src/nasl/builtin/ssh/libssh/session.rs b/rust/src/nasl/builtin/ssh/libssh/session.rs index 95999ec69..3f7bd1318 100644 --- a/rust/src/nasl/builtin/ssh/libssh/session.rs +++ b/rust/src/nasl/builtin/ssh/libssh/session.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use libssh_rs::{AuthMethods, AuthStatus, InteractiveAuthInfo, Session, Sftp, SshKey, SshOption}; use std::{os::fd::AsRawFd, time::Duration}; use tokio::sync::{Mutex, MutexGuard}; diff --git a/rust/src/nasl/builtin/ssh/mod.rs b/rust/src/nasl/builtin/ssh/mod.rs index c8ad39b62..c60f367d0 100644 --- a/rust/src/nasl/builtin/ssh/mod.rs +++ b/rust/src/nasl/builtin/ssh/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + mod error; mod sessions; mod utils; diff --git a/rust/src/nasl/builtin/ssh/russh/mod.rs b/rust/src/nasl/builtin/ssh/russh/mod.rs index 487c047ed..ff1835437 100644 --- a/rust/src/nasl/builtin/ssh/russh/mod.rs +++ b/rust/src/nasl/builtin/ssh/russh/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + mod session; pub use session::SshSession; diff --git a/rust/src/nasl/builtin/ssh/russh/session.rs b/rust/src/nasl/builtin/ssh/russh/session.rs index d3ac115cc..73aa786f1 100644 --- a/rust/src/nasl/builtin/ssh/russh/session.rs +++ b/rust/src/nasl/builtin/ssh/russh/session.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::borrow::Cow; use std::time::Duration; use std::{net::IpAddr, sync::Arc}; diff --git a/rust/src/nasl/builtin/ssh/sessions.rs b/rust/src/nasl/builtin/ssh/sessions.rs index 4ce9f7bab..a40530761 100644 --- a/rust/src/nasl/builtin/ssh/sessions.rs +++ b/rust/src/nasl/builtin/ssh/sessions.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::collections::{HashMap, HashSet}; use tokio::sync::{Mutex, MutexGuard}; diff --git a/rust/src/nasl/builtin/ssh/tests/mod.rs b/rust/src/nasl/builtin/ssh/tests/mod.rs index 84a9183e0..0bf46e9d4 100644 --- a/rust/src/nasl/builtin/ssh/tests/mod.rs +++ b/rust/src/nasl/builtin/ssh/tests/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + mod server; use std::sync::Arc; diff --git a/rust/src/nasl/builtin/ssh/tests/server.rs b/rust/src/nasl/builtin/ssh/tests/server.rs index 3b53c9f74..33d053773 100644 --- a/rust/src/nasl/builtin/ssh/tests/server.rs +++ b/rust/src/nasl/builtin/ssh/tests/server.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::collections::HashMap; use std::net::SocketAddr; use std::sync::Arc; diff --git a/rust/src/nasl/builtin/ssh/utils.rs b/rust/src/nasl/builtin/ssh/utils.rs index 446c2501c..409773004 100644 --- a/rust/src/nasl/builtin/ssh/utils.rs +++ b/rust/src/nasl/builtin/ssh/utils.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use russh::cipher; use russh_keys::key; diff --git a/rust/src/nasl/builtin/sys/mod.rs b/rust/src/nasl/builtin/sys/mod.rs index 24edbfcc7..03a323ea0 100644 --- a/rust/src/nasl/builtin/sys/mod.rs +++ b/rust/src/nasl/builtin/sys/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::{ env, io, path::{Path, PathBuf}, diff --git a/rust/src/nasl/builtin/tests.rs b/rust/src/nasl/builtin/tests.rs index b691dd56c..6a2d13766 100644 --- a/rust/src/nasl/builtin/tests.rs +++ b/rust/src/nasl/builtin/tests.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + //! This module contains tests for the nasl_function proc macro. //! It would be nicer to have this within the proc_macro crate itself, //! but testing proc_macros comes with a lot of difficulties and the tests diff --git a/rust/src/nasl/interpreter/code_interpreter.rs b/rust/src/nasl/interpreter/code_interpreter.rs index efdb3e009..5e7339352 100644 --- a/rust/src/nasl/interpreter/code_interpreter.rs +++ b/rust/src/nasl/interpreter/code_interpreter.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + //! Contains implementations of Interpreter that handle the simulation of forking methods for the //! caller. diff --git a/rust/src/nasl/interpreter/tests/mod.rs b/rust/src/nasl/interpreter/tests/mod.rs index 6663b80cc..787f8a065 100644 --- a/rust/src/nasl/interpreter/tests/mod.rs +++ b/rust/src/nasl/interpreter/tests/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + mod description; mod local_var; mod retry; diff --git a/rust/src/nasl/interpreter/tests/retry.rs b/rust/src/nasl/interpreter/tests/retry.rs index 6e64c6ad4..b4871ac85 100644 --- a/rust/src/nasl/interpreter/tests/retry.rs +++ b/rust/src/nasl/interpreter/tests/retry.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + //! Checks that errors that specify that they are solvable by //! retrying are actually retried within the interpreter. diff --git a/rust/src/nasl/mod.rs b/rust/src/nasl/mod.rs index 4436e50bb..b35c81bab 100644 --- a/rust/src/nasl/mod.rs +++ b/rust/src/nasl/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + mod builtin; pub mod interpreter; pub mod syntax; diff --git a/rust/src/nasl/test_utils.rs b/rust/src/nasl/test_utils.rs index 553605326..8247030be 100644 --- a/rust/src/nasl/test_utils.rs +++ b/rust/src/nasl/test_utils.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + //! Utilities to test the outcome of NASL functions use std::{ diff --git a/rust/src/nasl/utils/executor/mod.rs b/rust/src/nasl/utils/executor/mod.rs index 772abd521..17406d378 100644 --- a/rust/src/nasl/utils/executor/mod.rs +++ b/rust/src/nasl/utils/executor/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + //! This module contains the `Executor` type, as well as utility functions and macros //! to conveniently build sets of functions for a particular purpose. //! diff --git a/rust/src/nasl/utils/executor/nasl_function.rs b/rust/src/nasl/utils/executor/nasl_function.rs index 084fe9860..69b5244f8 100644 --- a/rust/src/nasl/utils/executor/nasl_function.rs +++ b/rust/src/nasl/utils/executor/nasl_function.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::{future::Future, pin::Pin}; use crate::nasl::{Context, NaslResult, Register}; diff --git a/rust/src/nasl/utils/function/from_nasl_value.rs b/rust/src/nasl/utils/function/from_nasl_value.rs index 932b24a97..8a5455b3a 100644 --- a/rust/src/nasl/utils/function/from_nasl_value.rs +++ b/rust/src/nasl/utils/function/from_nasl_value.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::{collections::HashMap, path::Path}; use crate::nasl::prelude::*; diff --git a/rust/src/nasl/utils/function/maybe.rs b/rust/src/nasl/utils/function/maybe.rs index f7e868892..762967f6f 100644 --- a/rust/src/nasl/utils/function/maybe.rs +++ b/rust/src/nasl/utils/function/maybe.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use crate::nasl::syntax::NaslValue; use crate::nasl::FnError; diff --git a/rust/src/nasl/utils/function/mod.rs b/rust/src/nasl/utils/function/mod.rs index f6bc176ff..beaddb234 100644 --- a/rust/src/nasl/utils/function/mod.rs +++ b/rust/src/nasl/utils/function/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + //! This module provides machinery to handle typical usecases //! while parsing the input arguments to NASL functions. diff --git a/rust/src/nasl/utils/function/positionals.rs b/rust/src/nasl/utils/function/positionals.rs index fa58697ed..7b312d7e9 100644 --- a/rust/src/nasl/utils/function/positionals.rs +++ b/rust/src/nasl/utils/function/positionals.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::{marker::PhantomData, ops::Index}; use crate::nasl::{FnError, Register}; diff --git a/rust/src/nasl/utils/function/to_nasl_result.rs b/rust/src/nasl/utils/function/to_nasl_result.rs index b4d79523d..6cba1331c 100644 --- a/rust/src/nasl/utils/function/to_nasl_result.rs +++ b/rust/src/nasl/utils/function/to_nasl_result.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::collections::HashMap; use std::path::PathBuf; diff --git a/rust/src/nasl/utils/function/types.rs b/rust/src/nasl/utils/function/types.rs index b4d911775..6b3c718fd 100644 --- a/rust/src/nasl/utils/function/types.rs +++ b/rust/src/nasl/utils/function/types.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use crate::nasl::prelude::*; /// `Some(string)` if constructed from either a `NaslValue::String` diff --git a/rust/src/nasl/utils/function/utils.rs b/rust/src/nasl/utils/function/utils.rs index 94802d668..95747fad8 100644 --- a/rust/src/nasl/utils/function/utils.rs +++ b/rust/src/nasl/utils/function/utils.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + //! Convenience functions, used internally in the `NaslFunctionArg` macro. use super::super::lookup_keys::FC_ANON_ARGS; diff --git a/rust/src/notus/tests.rs b/rust/src/notus/tests.rs index 176eb3d82..b7c1458fe 100644 --- a/rust/src/notus/tests.rs +++ b/rust/src/notus/tests.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::path::{Path, PathBuf}; use crate::models::{FixedPackage, FixedVersion, Specifier}; diff --git a/rust/src/scanner/mod.rs b/rust/src/scanner/mod.rs index 6b76236ef..f8bd30703 100644 --- a/rust/src/scanner/mod.rs +++ b/rust/src/scanner/mod.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + //! Overview of the structure of this module: The `Scanner` is the //! single instance managing all scans during a run with Openvasd //! scanner type. To do so, it starts a number of `RunningScan`s, diff --git a/rust/src/scanner/running_scan.rs b/rust/src/scanner/running_scan.rs index e2884fe3f..3f66de6b3 100644 --- a/rust/src/scanner/running_scan.rs +++ b/rust/src/scanner/running_scan.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use std::{ sync::{ atomic::{AtomicBool, Ordering}, diff --git a/rust/src/scanner/scanner_stack.rs b/rust/src/scanner/scanner_stack.rs index 6ddac8ead..e18f75e90 100644 --- a/rust/src/scanner/scanner_stack.rs +++ b/rust/src/scanner/scanner_stack.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use crate::nasl::syntax::{FSPluginLoader, Loader}; use crate::storage::{DefaultDispatcher, Storage}; diff --git a/rust/src/scanner/vt_runner.rs b/rust/src/scanner/vt_runner.rs index 0ed9b997c..17f1b4134 100644 --- a/rust/src/scanner/vt_runner.rs +++ b/rust/src/scanner/vt_runner.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use crate::models::{Host, Parameter, Protocol, ScanId}; use crate::nasl::syntax::{Loader, NaslValue}; use crate::nasl::utils::context::Target; diff --git a/rust/src/storage/infisto/error.rs b/rust/src/storage/infisto/error.rs index f70f62d15..2609e8025 100644 --- a/rust/src/storage/infisto/error.rs +++ b/rust/src/storage/infisto/error.rs @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + use thiserror::Error; #[derive(Debug, Error, PartialEq, Eq)] From 4277acfbedb4993b6389dba8703ea190af4842e6 Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Wed, 8 Jan 2025 12:07:25 +0100 Subject: [PATCH 04/10] Rename script to .bash, add shebang --- .github/workflows/linting.yml | 2 +- check_license_headers.sh => check_license_headers.bash | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) rename check_license_headers.sh => check_license_headers.bash (96%) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 4e8675e98..e0d357537 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -47,4 +47,4 @@ jobs: - name: Check out openvas-scanner uses: actions/checkout@v4 - name: Check license headers - run: bash ./check_license_headers.sh + run: bash ./check_license_headers.bash diff --git a/check_license_headers.sh b/check_license_headers.bash similarity index 96% rename from check_license_headers.sh rename to check_license_headers.bash index 94a0c719e..67ce64b6a 100755 --- a/check_license_headers.sh +++ b/check_license_headers.bash @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + any_missing_headers=0 for folder in src misc rust/src; do From d9e16f4f275f5cec15aa9d93d46b05ab84b12ee8 Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Wed, 8 Jan 2025 15:21:19 +0100 Subject: [PATCH 05/10] Fix minor things in the script: 1. Fix whitespace splitting due to forloop 2. Adjust comment string depending on file extension 3. Use all directories except for specific ones 4. Add nasl and cmake files. --- check_license_headers.bash | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/check_license_headers.bash b/check_license_headers.bash index 67ce64b6a..7ab3aa0e3 100755 --- a/check_license_headers.bash +++ b/check_license_headers.bash @@ -1,10 +1,20 @@ #!/usr/bin/env bash +function comment_string () { + ext=$1 + if [[ $ext == "c" || $ext == "h" || $ext == "rs" ]]; then + echo "//" + elif [[ $ext == "nasl" || $ext == "cmake" ]]; then + echo "#" + fi +} + any_missing_headers=0 -for folder in src misc rust/src; do - echo "Checking $folder" - for f in $(find $folder -regex ".*\.\(rs\|c\|h\)"); do +exts="c h nasl cmake" + +for ext in $exts; do + find . -not -path "./rust/target/*" -not -path "./rust/crates/nasl-c-lib/tmp/*" -regex ".*\.\($ext\)" -print0 | while read -d $'\0' f; do header=$(head -n 3 "$f") if ! [[ "$header" =~ SPDX ]]; then echo "File does not contain license header: $f" @@ -13,7 +23,8 @@ for folder in src misc rust/src; do if [[ "$1" == add_header ]]; then tmpfile=$(mktemp) cp "$f" "$tmpfile" - echo -e "// SPDX-FileCopyrightText: 2025 Greenbone AG\n//\n// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception\n" | cat - $tmpfile > "$f" + comment=$(comment_string $ext) + echo -e "$comment SPDX-FileCopyrightText: 2025 Greenbone AG\n$comment\n$comment SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception\n" | cat - $tmpfile > "$f" fi fi done From 39f11717983c671507b7430f94541d370915a17b Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Thu, 9 Jan 2025 12:25:22 +0100 Subject: [PATCH 06/10] Add header to newly detected files --- nasl/nasl_krb5.c | 4 ++++ nasl/nasl_krb5.h | 4 ++++ rust/examples/feed/nasl/1.nasl | 4 ++++ rust/examples/feed/nasl/2.nasl | 4 ++++ rust/examples/feed/nasl/error_message.nasl | 4 ++++ rust/examples/feed/nasl/http2_get.nasl | 4 ++++ rust/examples/feed/nasl/log_message.nasl | 4 ++++ rust/examples/feed/nasl/security_message.nasl | 4 ++++ rust/examples/feed/nasl/sha256sums | 12 ++++++------ rust/examples/get_kb_item.nasl | 4 ++++ rust/examples/gss.nasl | 4 ++++ rust/examples/ssh_netconf.nasl | 4 ++++ rust/examples/wmi-exec.nasl | 4 ++++ rust/tests/data/crash-prefix-recursion.nasl | 4 ++++ rust/tests/data/crash-recursion-depth.nasl | 4 ++++ rust/tests/nasl_syntax_missing_input_validation.rs | 4 ++-- 16 files changed, 64 insertions(+), 8 deletions(-) diff --git a/nasl/nasl_krb5.c b/nasl/nasl_krb5.c index cd2e2c5ed..2c0363173 100644 --- a/nasl/nasl_krb5.c +++ b/nasl/nasl_krb5.c @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + #include "nasl_krb5.h" #include "../misc/openvas-krb5.h" diff --git a/nasl/nasl_krb5.h b/nasl/nasl_krb5.h index 661bd6010..ecaa41156 100644 --- a/nasl/nasl_krb5.h +++ b/nasl/nasl_krb5.h @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2025 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + #include "nasl_lex_ctxt.h" #include "nasl_tree.h" diff --git a/rust/examples/feed/nasl/1.nasl b/rust/examples/feed/nasl/1.nasl index 4ff723b7d..e5a1278fa 100644 --- a/rust/examples/feed/nasl/1.nasl +++ b/rust/examples/feed/nasl/1.nasl @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + if (description) { script_oid("0.0.0.0.0.0.0.0.0.1"); diff --git a/rust/examples/feed/nasl/2.nasl b/rust/examples/feed/nasl/2.nasl index ecf71c4dd..51b8c42b7 100644 --- a/rust/examples/feed/nasl/2.nasl +++ b/rust/examples/feed/nasl/2.nasl @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + if (description) { script_oid("0.0.0.0.0.0.0.0.0.2"); diff --git a/rust/examples/feed/nasl/error_message.nasl b/rust/examples/feed/nasl/error_message.nasl index 2396aaeb8..49d1822d2 100644 --- a/rust/examples/feed/nasl/error_message.nasl +++ b/rust/examples/feed/nasl/error_message.nasl @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + if (description) { script_oid("0.0.0.0.0.0.0.0.0.5"); diff --git a/rust/examples/feed/nasl/http2_get.nasl b/rust/examples/feed/nasl/http2_get.nasl index 2a06248ee..31b399e60 100644 --- a/rust/examples/feed/nasl/http2_get.nasl +++ b/rust/examples/feed/nasl/http2_get.nasl @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + if (description) { script_oid("0.0.0.0.0.0.0.0.0.6"); diff --git a/rust/examples/feed/nasl/log_message.nasl b/rust/examples/feed/nasl/log_message.nasl index e78d9c7ab..4d32def30 100644 --- a/rust/examples/feed/nasl/log_message.nasl +++ b/rust/examples/feed/nasl/log_message.nasl @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + if (description) { script_oid("0.0.0.0.0.0.0.0.0.3"); diff --git a/rust/examples/feed/nasl/security_message.nasl b/rust/examples/feed/nasl/security_message.nasl index fc8adb7d5..d161b06a5 100644 --- a/rust/examples/feed/nasl/security_message.nasl +++ b/rust/examples/feed/nasl/security_message.nasl @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + if (description) { script_oid("0.0.0.0.0.0.0.0.0.4"); diff --git a/rust/examples/feed/nasl/sha256sums b/rust/examples/feed/nasl/sha256sums index 26e6f6309..10a1448a1 100644 --- a/rust/examples/feed/nasl/sha256sums +++ b/rust/examples/feed/nasl/sha256sums @@ -1,7 +1,7 @@ -1685505110659defb2d310f54950128fa5cc8867f89ff35cb647228e091e87e9 ./1.nasl -88924cd3cbec2b070afd45fcd4aabd9096763379eb816c200b3dc4abfae96b08 ./2.nasl +85e4c46356ab18d34de67efd6c3b778d61e2de858d334ce17cc3ca8d0ee62c69 ./error_message.nasl +97669d7129c6a92197bfd414c610feb89eeaa0be7fe1b3d7b2c25fa49b16fa8c ./2.nasl +8f349ff124775d38be5242c97caa8a8568e66de4a334599a549e1f0f444fc8ee ./1.nasl +2cd9f921dd86b4170f4499e0e7d2aae393b7a014976a72dc81d28b4fa7e1dd5f ./http2_get.nasl +4837adf4f6ff07b1378ca6deb3d468621242e89d2349a21c0744b294c35af4cf ./security_message.nasl +85902178e00a8a25b4559936504685ed41a2815c7f16e23f8926b515711d8239 ./log_message.nasl 2e21d3f6973e02e74ebc10dcc4ca77e7fbe414d6a8b985b2e0cda0111199a6aa ./plugin_feed_info.inc -35c0de9dcf2cdf84d3f7731a9ca036bb6ad97bbbbc595bb3c0c90094c1e8577e ./log_message.nasl -82b8531619fc6518c31f04b29207b702098357b2bd7538642d063488447d5b2e ./security_message.nasl -231eda974fc891bc72dd53a9923cfeb1c39d6284e59ec7bf3dd941e48678f07e ./error_message.nasl -c22fd805b4cee8b230bf1b00a6ebfd0c44770784eacc89edef18edcac2c77a31 ./http2_get.nasl diff --git a/rust/examples/get_kb_item.nasl b/rust/examples/get_kb_item.nasl index 808e65376..d29a405ac 100644 --- a/rust/examples/get_kb_item.nasl +++ b/rust/examples/get_kb_item.nasl @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + set_kb_item(name: "test", value: 1); set_kb_item(name: "test", value: 2); set_kb_item(name: "test", value: 3); diff --git a/rust/examples/gss.nasl b/rust/examples/gss.nasl index 1c84820ef..b999c564b 100644 --- a/rust/examples/gss.nasl +++ b/rust/examples/gss.nasl @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + #display('do more hate-driven-development'); #result = krb5_gss_init(); #if (krb5_is_failure(result)) { diff --git a/rust/examples/ssh_netconf.nasl b/rust/examples/ssh_netconf.nasl index 6ba4afd50..25a6ab5af 100644 --- a/rust/examples/ssh_netconf.nasl +++ b/rust/examples/ssh_netconf.nasl @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + ## This script uses a non-interactive (non pty) shell to elevate privileges ## in an ssh session. diff --git a/rust/examples/wmi-exec.nasl b/rust/examples/wmi-exec.nasl index 86b035ff2..bfa4ebfb6 100644 --- a/rust/examples/wmi-exec.nasl +++ b/rust/examples/wmi-exec.nasl @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + login = string( get_kb_item( "KRB5/login_filled/0" ) ); password = string( get_kb_item( "KRB5/password_filled/0" ) ); realm = string( get_kb_item( "KRB5/realm_filled/0" ) ); diff --git a/rust/tests/data/crash-prefix-recursion.nasl b/rust/tests/data/crash-prefix-recursion.nasl index 763de54a3..e5592ff31 100644 --- a/rust/tests/data/crash-prefix-recursion.nasl +++ b/rust/tests/data/crash-prefix-recursion.nasl @@ -1 +1,5 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + [3 [-p0[[S[[[[[[[[z4[[a[[[[,[[[[[[[[[[[z4[[a[[[,[[[[[[[[[[[[[[[[s[[[[[[[[[[[[[[[[[a[[[[,[[[[[[[[[[[[[[[[[[s[[[[[[[[[[[[[[[[[[[,[[[[[[[[[[[[[[[[a[[[[,[[[[[[[[[[[[[[[[[[s[[[[[[[[[[[[[[[[[[[,[[[[[[[[[[[[[[[[[[[[[[s[[[[[[[[[[[[[[[,[[[[[[[[[[[[[[s[[[[[[[[[[[[[[[[[a[[[[,[[[[[[[[[Q[[[[[[[[[[[[[[[a[[[[,[[[[[[[[[[[[[[[[[[s[[[[[[[[[[[[[[[,[[[[[[[[[[[[[[s[[[[[[[[[[[[[[[[[a[[[[,[[[[[[[[s[[[[[[[[[[[[[[[[[a[[[[,[[[[[[[[[[[[[[[[[[s[[[[[[[[[[[[[[[,[[[[[[[[[[[[[[s[[[[[[[[[[[[[[[[[a[[[[,[[[[[[[[[Q[[[[[[[[[[[[[[[[[[[%[[[[[[[[[[ \ No newline at end of file diff --git a/rust/tests/data/crash-recursion-depth.nasl b/rust/tests/data/crash-recursion-depth.nasl index 59de8f745..1b7c5071d 100644 --- a/rust/tests/data/crash-recursion-depth.nasl +++ b/rust/tests/data/crash-recursion-depth.nasl @@ -1 +1,5 @@ +# SPDX-FileCopyrightText: 2025 Greenbone AG +# +# SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + i~f&((((((((((((((((((((((((((((((((+(((((((((((re(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((~f&((((((((((((((((((((((((((((((((+(((((((((((re(((((((((((((((((((((((((((((((((((((((((((((((((((((~f&((((((((((((((((((((((((((((((((+(((((((((((re((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((~f&((((((((((((((((((((((((((((((((+(((((((((((re(((((((((((,i \ No newline at end of file diff --git a/rust/tests/nasl_syntax_missing_input_validation.rs b/rust/tests/nasl_syntax_missing_input_validation.rs index 8efd48ad6..7c1c0ab58 100644 --- a/rust/tests/nasl_syntax_missing_input_validation.rs +++ b/rust/tests/nasl_syntax_missing_input_validation.rs @@ -7,7 +7,7 @@ fn validate_recursion_depth_to_prevent_stackoverflow() { // Reported by @sepehrdaddev, VSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:H/SC:N/SI:L/SA:H // Crash due to depth limit on recursion. let code = include_str!("data/crash-recursion-depth.nasl"); - assert_eq!(code.len(), 587); + assert_eq!(code.len(), 708); let result = scannerlib::nasl::syntax::parse(code).collect::>(); assert_eq!( @@ -17,7 +17,7 @@ fn validate_recursion_depth_to_prevent_stackoverflow() { ); let code = include_str!("data/crash-prefix-recursion.nasl"); - assert_eq!(code.len(), 515); + assert_eq!(code.len(), 636); let result = scannerlib::nasl::syntax::parse(code).collect::>(); assert_eq!( result.iter().filter_map(|x| x.as_ref().ok()).count(), From aaccc04d1cc2c4c3c354d41daed7cf2e4e166b51 Mon Sep 17 00:00:00 2001 From: Philipp Eder Date: Mon, 16 Dec 2024 10:11:10 +0000 Subject: [PATCH 07/10] Add: scannerctl ospd command Adds a new command scannerctl osp which allows to transform start scan osp commands to a scan json that can be send to openvasd/scans. This allows us to quickly transform osp start scan commands to the new json format. --- rust/Cargo.lock | 351 ++++---- rust/Cargo.toml | 3 +- rust/adapted-full-and-fast.json | 0 rust/examples/double-fork2.nasl | 7 + rust/examples/if-assignment.nasl | 2 + rust/src/models/credential.rs | 14 + rust/src/models/parameter.rs | 2 +- rust/src/models/target.rs | 21 + rust/src/models/vt.rs | 2 +- rust/src/nasl/syntax/loader.rs | 11 + rust/src/openvasd/controller/entry.rs | 1 + rust/src/osp/commands.rs | 5 +- rust/src/osp/response.rs | 16 +- rust/src/scannerctl/error.rs | 72 +- rust/src/scannerctl/feed/update.rs | 2 +- rust/src/scannerctl/main.rs | 5 + rust/src/scannerctl/ospd/mod.rs | 297 ++++++ ...n__test__pare_credential_without_port.snap | 37 + ..._scan__test__parse_without_credential.snap | 33 + ...tl__ospd__start_scan__test__parse_xml.snap | 38 + ...est__parse_xml_with_empty_credentials.snap | 34 + .../scannerctl__ospd__tests__print_back.snap | 38 + ...nnerctl__ospd__tests__print_scan_json.snap | 123 +++ rust/src/scannerctl/ospd/start_scan.rs | 846 ++++++++++++++++++ rust/src/scannerctl/scanconfig.rs | 2 +- 25 files changed, 1735 insertions(+), 227 deletions(-) create mode 100644 rust/adapted-full-and-fast.json create mode 100644 rust/examples/double-fork2.nasl create mode 100644 rust/examples/if-assignment.nasl create mode 100644 rust/src/scannerctl/ospd/mod.rs create mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__pare_credential_without_port.snap create mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_without_credential.snap create mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml.snap create mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml_with_empty_credentials.snap create mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_back.snap create mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_scan_json.snap create mode 100644 rust/src/scannerctl/ospd/start_scan.rs diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 8e274e6a0..c8a7e83ee 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -133,9 +133,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775" +checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" [[package]] name = "ascii-canvas" @@ -152,7 +152,7 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef1e3e699d84ab1b0911a1010c5c106aa34ae89aeac103be5ce0c3859db1e891" dependencies = [ - "term 1.0.0", + "term 1.0.1", ] [[package]] @@ -179,7 +179,7 @@ checksum = "965c2d33e53cb6b267e148a4cb0760bc01f4904c1cd4bb4002a085bb016d1490" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", "synstructure", ] @@ -191,7 +191,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -202,7 +202,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -219,9 +219,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "aws-lc-rs" -version = "1.11.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f47bb8cc16b669d267eeccf585aea077d0882f4777b1c1f740217885d6e6e5a3" +checksum = "f409eb70b561706bf8abba8ca9c112729c481595893fd06a2dd9af8ed8441148" dependencies = [ "aws-lc-sys", "paste", @@ -230,9 +230,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.23.1" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2101df3813227bbaaaa0b04cd61c534c7954b22bd68d399b440be937dc63ff7" +checksum = "8478a5c29ead3f3be14aff8a202ad965cf7da6856860041bfca271becf8ba48b" dependencies = [ "bindgen", "cc", @@ -328,7 +328,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.89", + "syn 2.0.90", "which", ] @@ -404,9 +404,9 @@ dependencies = [ [[package]] name = "buffered-reader" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd098763fdb64579407a8c83cf0d751e6d4a7e161d0114c89cc181a2ca760ec8" +checksum = "fabd1c5e55587a8e8526172d63ad2ba665fa18c8acb39ec9a77af1708c982b9b" dependencies = [ "lazy_static", "libc", @@ -426,9 +426,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" +checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" [[package]] name = "capnp" @@ -474,9 +474,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.1" +version = "1.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" +checksum = "c31a0499c1dc64f458ad13872de75c0eb7e3fdb0e67964610c914b034fc5956e" dependencies = [ "jobserver", "libc", @@ -523,9 +523,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.38" +version = "0.4.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" dependencies = [ "android-tzdata", "iana-time-zone", @@ -580,14 +580,14 @@ checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" dependencies = [ "glob", "libc", - "libloading 0.8.5", + "libloading 0.8.6", ] [[package]] name = "clap" -version = "4.5.21" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" dependencies = [ "clap_builder", "clap_derive", @@ -595,9 +595,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.21" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" dependencies = [ "anstream", "anstyle", @@ -614,14 +614,14 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] name = "clap_lex" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "cmac" @@ -667,14 +667,14 @@ checksum = "e57e3272f0190c3f1584272d613719ba5fc7df7f4942fe542e63d949cf3a649b" [[package]] name = "console" -version = "0.15.8" +version = "0.15.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +checksum = "ea3c6ecd8059b57859df5c69830340ed3c41d30e3da0c1cbed90a96ac853041b" dependencies = [ "encode_unicode", - "lazy_static", "libc", - "windows-sys 0.52.0", + "once_cell", + "windows-sys 0.59.0", ] [[package]] @@ -765,18 +765,18 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.13" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-deque" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -793,9 +793,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crunchy" @@ -869,7 +869,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -991,7 +991,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -1002,7 +1002,7 @@ checksum = "e5766087c2235fec47fafa4cfecc81e494ee679d0fd4a59887ea0919bfb0e4fc" dependencies = [ "cfg-if", "libc", - "socket2 0.5.7", + "socket2 0.5.8", "windows-sys 0.48.0", ] @@ -1095,9 +1095,9 @@ dependencies = [ [[package]] name = "encode_unicode" -version = "0.3.6" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" [[package]] name = "encoding_rs" @@ -1127,12 +1127,12 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.9" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1147,9 +1147,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "ff" @@ -1285,7 +1285,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -1414,7 +1414,7 @@ dependencies = [ "fnv", "futures-core", "futures-sink", - "http 1.1.0", + "http 1.2.0", "indexmap", "slab", "tokio", @@ -1488,11 +1488,11 @@ dependencies = [ [[package]] name = "home" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1508,9 +1508,9 @@ dependencies = [ [[package]] name = "http" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea" dependencies = [ "bytes", "fnv", @@ -1535,7 +1535,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", - "http 1.1.0", + "http 1.2.0", ] [[package]] @@ -1546,7 +1546,7 @@ checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" dependencies = [ "bytes", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "pin-project-lite", ] @@ -1565,9 +1565,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.31" +version = "0.14.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c08302e8fa335b151b788c775ff56e7a03ae64ff85c548ee820fecb70356e85" +checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" dependencies = [ "bytes", "futures-channel", @@ -1580,7 +1580,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.5.7", + "socket2 0.5.8", "tokio", "tower-service", "tracing", @@ -1589,15 +1589,15 @@ dependencies = [ [[package]] name = "hyper" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97818827ef4f364230e16705d4706e2897df2bb60617d6ca15d598025a3c481f" +checksum = "256fb8d4bd6413123cc9d91832d78325c48ff41677595be797d90f42969beae0" dependencies = [ "bytes", "futures-channel", "futures-util", "h2 0.4.7", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "httparse", "httpdate", @@ -1616,7 +1616,7 @@ checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", "http 0.2.12", - "hyper 0.14.31", + "hyper 0.14.32", "rustls 0.21.12", "tokio", "tokio-rustls 0.24.1", @@ -1624,20 +1624,20 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.3" +version = "0.27.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +checksum = "f6884a48c6826ec44f524c7456b163cebe9e55a18d7b5e307cb4f100371cc767" dependencies = [ "futures-util", - "http 1.1.0", - "hyper 1.5.1", + "http 1.2.0", + "hyper 1.5.2", "hyper-util", "log", - "rustls 0.23.19", + "rustls 0.23.20", "rustls-native-certs", "rustls-pki-types", "tokio", - "tokio-rustls 0.26.0", + "tokio-rustls 0.26.1", "tower-service", ] @@ -1650,11 +1650,11 @@ dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", - "hyper 1.5.1", + "hyper 1.5.2", "pin-project-lite", - "socket2 0.5.7", + "socket2 0.5.8", "tokio", "tower-service", "tracing", @@ -1798,7 +1798,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -1824,9 +1824,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown", @@ -1941,10 +1941,11 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.72" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" dependencies = [ + "once_cell", "wasm-bindgen", ] @@ -1994,7 +1995,7 @@ dependencies = [ "regex-syntax 0.8.5", "sha3", "string_cache", - "term 1.0.0", + "term 1.0.1", "unicode-xid", "walkdir", ] @@ -2038,7 +2039,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -2058,9 +2059,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.166" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "libgcrypt-sys" @@ -2078,9 +2079,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", "windows-targets 0.52.6", @@ -2241,20 +2242,19 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.8.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" dependencies = [ "adler2", ] [[package]] name = "mio" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" dependencies = [ - "hermit-abi 0.3.9", "libc", "wasi", "windows-sys 0.52.0", @@ -2274,7 +2274,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -2451,7 +2451,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -2885,7 +2885,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -2908,9 +2908,9 @@ dependencies = [ [[package]] name = "quick-xml" -version = "0.28.2" +version = "0.37.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ce5e73202a820a31f8a0ee32ada5e21029c81fd9e3ebf668a40832e4219d9d1" +checksum = "f22f29bdff3987b4d8632ef95fd6424ec7e4e0a57e2f4fc63e489e75357f6a03" dependencies = [ "memchr", "serde", @@ -3000,9 +3000,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" dependencies = [ "bitflags 2.6.0", ] @@ -3076,7 +3076,7 @@ dependencies = [ "h2 0.3.26", "http 0.2.12", "http-body 0.4.6", - "hyper 0.14.31", + "hyper 0.14.32", "hyper-rustls 0.24.2", "ipnet", "js-sys", @@ -3305,15 +3305,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.41" +version = "0.38.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" dependencies = [ "bitflags 2.6.0", - "errno 0.3.9", + "errno 0.3.10", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3330,9 +3330,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.19" +version = "0.23.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" +checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b" dependencies = [ "aws-lc-rs", "log", @@ -3375,9 +3375,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16f1201b3c9a7ee8039bcadc17b7e605e2945b27eee7631788c1bd2b0643674b" +checksum = "d2bf47e6ff922db3825eb750c4e2ff784c6ff8fb9e13046ef6a1d1c5401b0b37" [[package]] name = "rustls-webpki" @@ -3463,11 +3463,11 @@ dependencies = [ "h2 0.4.7", "hex", "hmac", - "http 1.1.0", + "http 1.2.0", "http-body 1.0.1", "http-body-util", - "hyper 1.5.1", - "hyper-rustls 0.27.3", + "hyper 1.5.2", + "hyper-rustls 0.27.4", "hyper-util", "insta", "itertools 0.12.1", @@ -3500,7 +3500,7 @@ dependencies = [ "rsa", "russh", "russh-keys", - "rustls 0.23.19", + "rustls 0.23.20", "rustls-pemfile 1.0.4", "rustls-pemfile 2.2.0", "sequoia-ipc", @@ -3509,12 +3509,12 @@ dependencies = [ "serde_json", "sha1", "sha2", - "socket2 0.5.7", + "socket2 0.5.8", "sysinfo", "thiserror", "time", "tokio", - "tokio-rustls 0.26.0", + "tokio-rustls 0.26.1", "toml", "tracing", "tracing-subscriber", @@ -3578,9 +3578,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "3.0.1" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1415a607e92bec364ea2cf9264646dcce0f91e6d65281bd6f2819cca3bf39c8" +checksum = "81d3f8c9bfcc3cbb6b0179eb57042d75b1582bdc65c3cb95f3fa999509c03cbc" dependencies = [ "bitflags 2.6.0", "core-foundation 0.10.0", @@ -3591,9 +3591,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.12.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" +checksum = "1863fd3768cd83c56a7f60faa4dc0d403f1b6df0a38c3c25f44b7894e45370d5" dependencies = [ "core-foundation-sys", "libc", @@ -3601,9 +3601,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba" [[package]] name = "sequoia-ipc" @@ -3636,9 +3636,9 @@ dependencies = [ [[package]] name = "sequoia-openpgp" -version = "1.21.2" +version = "1.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13261ee216b44d932ef93b2d4a75d45199bef77864bcc5b77ecfc7bc0ecb02d6" +checksum = "e858e4e9e48ff079cede92e1b45c942a5466ce9a4e3cc0c2a7e66586a718ef59" dependencies = [ "anyhow", "base64 0.22.1", @@ -3664,22 +3664,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -3850,9 +3850,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" dependencies = [ "libc", "windows-sys 0.52.0", @@ -3969,9 +3969,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.89" +version = "2.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" dependencies = [ "proc-macro2", "quote", @@ -3992,7 +3992,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -4057,9 +4057,9 @@ dependencies = [ [[package]] name = "term" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4df4175de05129f31b80458c6df371a15e7fc3fd367272e6bf938e5c351c7ea0" +checksum = "a3bb6001afcea98122260987f8b7b5da969ecad46dbf0b5453702f776b491a41" dependencies = [ "home", "windows-sys 0.52.0", @@ -4082,7 +4082,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -4097,9 +4097,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.36" +version = "0.3.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +checksum = "35e7868883861bd0e56d9ac6efcaaca0d6d5d82a2a7ec8209ff492c07cf37b21" dependencies = [ "deranged", "itoa", @@ -4118,9 +4118,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +checksum = "2834e6017e3e5e4b9834939793b282bc03b37a3336245fa820e35e233e2a85de" dependencies = [ "num-conv", "time-core", @@ -4157,9 +4157,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.41.1" +version = "1.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" +checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" dependencies = [ "backtrace", "bytes", @@ -4168,7 +4168,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.7", + "socket2 0.5.8", "tokio-macros", "windows-sys 0.52.0", ] @@ -4181,7 +4181,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -4196,20 +4196,19 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.26.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37" dependencies = [ - "rustls 0.23.19", - "rustls-pki-types", + "rustls 0.23.20", "tokio", ] [[package]] name = "tokio-stream" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" +checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" dependencies = [ "futures-core", "pin-project-lite", @@ -4218,9 +4217,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.12" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" +checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078" dependencies = [ "bytes", "futures-core", @@ -4272,9 +4271,9 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" -version = "0.1.40" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ "pin-project-lite", "tracing-attributes", @@ -4289,7 +4288,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -4315,9 +4314,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" dependencies = [ "matchers", "nu-ansi-term", @@ -4349,7 +4348,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04659ddb06c87d233c566112c1c9c5b9e98256d9af50ec3bc9c8327f873a7568" dependencies = [ "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -4483,9 +4482,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" dependencies = [ "cfg-if", "once_cell", @@ -4494,36 +4493,36 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.45" +version = "0.4.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" +checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" dependencies = [ "cfg-if", "js-sys", + "once_cell", "wasm-bindgen", "web-sys", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4531,28 +4530,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" [[package]] name = "web-sys" -version = "0.3.72" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" +checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" dependencies = [ "js-sys", "wasm-bindgen", @@ -4910,7 +4909,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", "synstructure", ] @@ -4932,7 +4931,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -4952,7 +4951,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", "synstructure", ] @@ -4973,7 +4972,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] [[package]] @@ -4995,5 +4994,5 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.89", + "syn 2.0.90", ] diff --git a/rust/Cargo.toml b/rust/Cargo.toml index f04ba6f8e..19497726d 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -47,7 +47,8 @@ md4 = "0.10.2" num_cpus = "1.16.0" pbkdf2 = { version = "0.12.2", features = ["password-hash"] } pkcs8 = { version = "0.10.2", features = ["encryption", "pem", "std"] } -quick-xml = { version = "0.28.1", features = ["serialize"] } +quick-xml = { version = "0.37.1", features = ["serde", "serde-types", "serialize"] } + rand = "0.8.5" redis = "0.22.3" regex = "1.10.6" diff --git a/rust/adapted-full-and-fast.json b/rust/adapted-full-and-fast.json new file mode 100644 index 000000000..e69de29bb diff --git a/rust/examples/double-fork2.nasl b/rust/examples/double-fork2.nasl new file mode 100644 index 000000000..efc7d9392 --- /dev/null +++ b/rust/examples/double-fork2.nasl @@ -0,0 +1,7 @@ +set_kb_item(name: "port", value: 1); +set_kb_item(name: "port", value: 2); +set_kb_item(name: "host", value: "a"); +set_kb_item(name: "host", value: "b"); + +a = get_kb_item("port") + ":" + get_kb_item("host"); +display(a); diff --git a/rust/examples/if-assignment.nasl b/rust/examples/if-assignment.nasl new file mode 100644 index 000000000..cd21cca84 --- /dev/null +++ b/rust/examples/if-assignment.nasl @@ -0,0 +1,2 @@ +if (a = 1) display (a); +if ((a = 1)) display('a', a); diff --git a/rust/src/models/credential.rs b/rust/src/models/credential.rs index 7aa1289c8..2d0e5f8fe 100644 --- a/rust/src/models/credential.rs +++ b/rust/src/models/credential.rs @@ -99,6 +99,20 @@ impl AsRef for Service { } } +impl TryFrom<&str> for Service { + type Error = String; + + fn try_from(value: &str) -> Result { + Ok(match value { + "ssh" => Service::SSH, + "smb" => Service::SMB, + "esxi" => Service::ESXi, + "snmp" => Service::SNMP, + value => return Err(value.to_string()), + }) + } +} + #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr( feature = "serde_support", diff --git a/rust/src/models/parameter.rs b/rust/src/models/parameter.rs index 6fbbe3cad..dbc49cef6 100644 --- a/rust/src/models/parameter.rs +++ b/rust/src/models/parameter.rs @@ -4,7 +4,7 @@ use std::fmt::Display; -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] #[cfg_attr( feature = "serde_support", derive(serde::Serialize, serde::Deserialize) diff --git a/rust/src/models/target.rs b/rust/src/models/target.rs index 0c4a4192a..3aee3d597 100644 --- a/rust/src/models/target.rs +++ b/rust/src/models/target.rs @@ -52,3 +52,24 @@ pub enum AliveTestMethods { ConsiderAlive = 0x08, TcpSyn = 0x10, } + +#[derive(Debug, thiserror::Error)] +pub enum AliveTestMethodsError { + #[error("Invalid value for AliveTestMethods: {0:#04x}")] + InvalidValue(u8), +} + +impl TryFrom for AliveTestMethods { + type Error = AliveTestMethodsError; + + fn try_from(value: u8) -> Result { + match value { + 0x01 => Ok(AliveTestMethods::TcpAck), + 0x02 => Ok(AliveTestMethods::Icmp), + 0x04 => Ok(AliveTestMethods::Arp), + 0x08 => Ok(AliveTestMethods::ConsiderAlive), + 0x10 => Ok(AliveTestMethods::TcpSyn), + _ => Err(AliveTestMethodsError::InvalidValue(value)), + } + } +} diff --git a/rust/src/models/vt.rs b/rust/src/models/vt.rs index d11aa57b7..a2c786e51 100644 --- a/rust/src/models/vt.rs +++ b/rust/src/models/vt.rs @@ -5,7 +5,7 @@ use super::parameter::Parameter; /// A VT to execute during a scan, including its parameters -#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)] #[cfg_attr( feature = "serde_support", derive(serde::Serialize, serde::Deserialize) diff --git a/rust/src/nasl/syntax/loader.rs b/rust/src/nasl/syntax/loader.rs index 7a8f7c10b..98463c42f 100644 --- a/rust/src/nasl/syntax/loader.rs +++ b/rust/src/nasl/syntax/loader.rs @@ -29,6 +29,17 @@ pub enum LoadError { Dirty(String), } +impl LoadError { + pub fn filename(&self) -> &str { + match self { + LoadError::Retry(x) => &x, + LoadError::NotFound(x) => &x, + LoadError::PermissionDenied(x) => &x, + LoadError::Dirty(x) => &x, + } + } +} + /// Loads the content of the path to String by parsing each byte to a character. /// /// Unfortunately the feed is not completely written in utf8 enforcing us to parse the content diff --git a/rust/src/openvasd/controller/entry.rs b/rust/src/openvasd/controller/entry.rs index aa9e01c69..49c41aceb 100644 --- a/rust/src/openvasd/controller/entry.rs +++ b/rust/src/openvasd/controller/entry.rs @@ -302,6 +302,7 @@ where } } (&Method::POST, Scans(None)) => { + // We could enhance the API to accept a list of scans as well. match crate::request::json_request::(&ctx.response, req).await { Ok(mut scan) => { let id = if !scan.scan_id.is_empty() { diff --git a/rust/src/osp/commands.rs b/rust/src/osp/commands.rs index 6191381ad..3e827730b 100644 --- a/rust/src/osp/commands.rs +++ b/rust/src/osp/commands.rs @@ -207,7 +207,10 @@ fn write_int_element(writer: &mut Writer, name: &str, value: i64) -> Result<()> Event::Text(BytesText::new(&value.to_string())), ) } -fn write_event<'a, E: AsRef>>(name: &str, writer: &mut Writer, event: E) -> Result<()> { +fn write_event<'a, E: AsRef>>(name: &str, writer: &mut Writer, event: E) -> Result<()> +where + quick_xml::events::Event<'a>: From, +{ writer.write_event(Event::Start(BytesStart::new(name)))?; writer.write_event(event)?; writer.write_event(Event::End(BytesEnd::new(name)))?; diff --git a/rust/src/osp/response.rs b/rust/src/osp/response.rs index c879fb6d6..8812d3e69 100644 --- a/rust/src/osp/response.rs +++ b/rust/src/osp/response.rs @@ -5,7 +5,11 @@ //! # Responses of OSPD commands use std::{collections::HashMap, fmt}; -use serde::{de::Visitor, Deserialize}; +use redis::ToRedisArgs; +use serde::{ + de::{IntoDeserializer, Visitor}, + Deserialize, Serializer, +}; use super::commands::Error; @@ -684,8 +688,6 @@ mod tests { #[test] fn empty_optional_fields() { - // types Alarm, Log Message, nn - // TODO write tests for Log Message, Error Message, Alarm let xml = r#" @@ -721,11 +723,11 @@ mod tests { assert_eq!(status.text, "OK"); assert_eq!(status.code, 200.into()); if let Some(scan) = scan { - assert_eq!(scan.results.result[0].severity, None); + assert_eq!(scan.results.result[0].severity, Some(Default::default())); assert_eq!(scan.results.result[1].severity, None); assert_eq!(scan.results.result[1].hostname, None); assert_eq!(scan.results.result[1].host, None); - assert_eq!(scan.results.result[1].test_id, None); + assert_eq!(scan.results.result[1].test_id, Some(Default::default())); } else { panic!("no scan"); } @@ -815,10 +817,10 @@ mod tests { assert_eq!(scan.status, "finished".into()); assert_eq!(scan.start_time, Some(1432824206.into())); assert_eq!(scan.results.result[0].host, Some("192.168.1.252".into())); - assert_eq!(scan.results.result[0].hostname, None); + assert_eq!(scan.results.result[0].hostname, Some(Default::default())); assert_eq!(scan.results.result[0].severity, Some(2.5.into())); assert_eq!(scan.results.result[0].port, Some("443/tcp".into())); - assert_eq!(scan.results.result[0].test_id, None); + assert_eq!(scan.results.result[0].test_id, Some(Default::default())); assert_eq!(scan.results.result[0].name, "Path disclosure vulnerability"); assert_eq!(scan.results.result[0].result_type, ResultType::Log); assert_eq!(scan.results.result[0].description, "bla"); diff --git a/rust/src/scannerctl/error.rs b/rust/src/scannerctl/error.rs index 18f3e1771..81186170f 100644 --- a/rust/src/scannerctl/error.rs +++ b/rust/src/scannerctl/error.rs @@ -16,20 +16,32 @@ use scannerlib::{ scanner::ExecuteError, }; -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] + pub enum CliErrorKind { + #[error("Wrong action")] WrongAction, + #[error("Plugin path ({0}) is not a directory.")] PluginPathIsNotADir(PathBuf), + #[error("openvas ({args:?}) failed: {err_msg}.")] Openvas { args: Option, err_msg: String, }, + #[error("{0}")] InterpretError(InterpretError), + #[error("{0}")] ExecuteError(ExecuteError), + #[error("{0}")] LoadError(LoadError), + #[error("{0}")] StorageError(StorageError), + #[error("{0}")] SyntaxError(SyntaxError), + #[error("Missing arguments: {0:?}")] + MissingArguments(Vec), + #[error("{0}")] Corrupt(String), } @@ -52,8 +64,12 @@ impl CliErrorKind { } } -#[derive(Debug)] +#[derive(Debug, thiserror::Error)] +#[error("{kind} ({filename})")] pub struct CliError { + // FIXME: unlike previous assumptions most cases don't have a clear filename + // associated to it. This information should be in specific unter categories + // of CliErrorKind instead. pub filename: String, pub kind: CliErrorKind, } @@ -67,41 +83,6 @@ impl CliError { } } -impl Display for CliErrorKind { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - CliErrorKind::WrongAction => write!(f, "wrong action."), - CliErrorKind::PluginPathIsNotADir(e) => write!(f, "expected {e:?} to be a dir."), - CliErrorKind::Openvas { args, err_msg } => write!( - f, - "openvas {} failed with: {err_msg}", - args.clone().unwrap_or_default() - ), - CliErrorKind::InterpretError(e) => write!(f, "{e}"), - CliErrorKind::LoadError(e) => write!(f, "{e}"), - CliErrorKind::StorageError(e) => write!(f, "{e}"), - CliErrorKind::SyntaxError(e) => write!(f, "{e}"), - CliErrorKind::Corrupt(x) => write!(f, "Corrupt: {x}"), - CliErrorKind::ExecuteError(x) => write!(f, "{x}"), - } - } -} - -impl Display for CliError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}{}: {}", - self.filename, - self.kind - .as_token() - .map(|x| { format!(", line: {}, col: {}", x.line_column.0, x.line_column.1) }) - .unwrap_or_default(), - self.kind - ) - } -} - impl From for CliError { fn from(value: std::io::Error) -> Self { CliError { @@ -111,11 +92,17 @@ impl From for CliError { } } +impl From for CliErrorKind { + fn from(value: serde_json::Error) -> Self { + CliErrorKind::Corrupt(value.to_string()) + } +} + impl From for CliError { fn from(value: serde_json::Error) -> Self { CliError { filename: Default::default(), - kind: CliErrorKind::Corrupt(value.to_string()), + kind: value.into(), } } } @@ -180,6 +167,15 @@ impl From for CliErrorKind { } } +impl From for CliError { + fn from(value: LoadError) -> Self { + Self { + filename: value.filename().to_string(), + kind: value.into(), + } + } +} + impl From for CliError { fn from(value: feed::UpdateError) -> Self { let kind = match value.kind { diff --git a/rust/src/scannerctl/feed/update.rs b/rust/src/scannerctl/feed/update.rs index dc7326df8..08039d59f 100644 --- a/rust/src/scannerctl/feed/update.rs +++ b/rust/src/scannerctl/feed/update.rs @@ -45,7 +45,7 @@ where }); } } - } + } updater.perform_update().await?; diff --git a/rust/src/scannerctl/main.rs b/rust/src/scannerctl/main.rs index 879ee0f02..575828605 100644 --- a/rust/src/scannerctl/main.rs +++ b/rust/src/scannerctl/main.rs @@ -8,6 +8,7 @@ mod execute; mod feed; mod interpret; mod notusupdate; +mod ospd; mod scanconfig; mod syntax; @@ -61,6 +62,7 @@ async fn main() { ); let matches = syntax::extend_args(matches); let matches = scanconfig::extend_args(matches); + let matches = ospd::extend_args(matches); let matches = execute::extend_args(matches); let matches = notusupdate::scanner::extend_args(matches); let matches = feed::extend_args(matches).get_matches(); @@ -98,6 +100,9 @@ async fn run(matches: &ArgMatches) -> Result<(), CliError> { if let Some(result) = notusupdate::scanner::run(matches).await { return result; } + if let Some(result) = ospd::run(matches).await { + return result; + } Err(CliError { filename: "".to_string(), kind: CliErrorKind::Corrupt(format!( diff --git a/rust/src/scannerctl/ospd/mod.rs b/rust/src/scannerctl/ospd/mod.rs new file mode 100644 index 000000000..13e6e1df8 --- /dev/null +++ b/rust/src/scannerctl/ospd/mod.rs @@ -0,0 +1,297 @@ +// SPDX-FileCopyrightText: 2024 Greenbone AG +// +// SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception + +use std::io::BufRead; +use std::{io::BufReader, path::PathBuf, sync::Arc}; + +use clap::{arg, value_parser, Arg, ArgAction, Command}; +use scannerlib::models::{Parameter, Scan, VT}; +use scannerlib::storage::{self, DefaultDispatcher, Retriever, StorageError}; +use start_scan::StartScan; + +use crate::{CliError, CliErrorKind}; +use scannerlib::storage::item::{NVTField, NVTKey}; +use scannerlib::storage::Field; +use scannerlib::storage::Retrieve; +mod start_scan; + +pub fn extend_args(cmd: Command) -> Command { + cmd.subcommand(crate::add_verbose( + Command::new("ospd") + .about("Transforms a ospd-start-scan xml to a scan json for openvasd. ") + .arg( + arg!(-p --path "Path to the feed.") + .required(false) + .value_parser(value_parser!(PathBuf)), + ) + .arg( + Arg::new("ospd_xml") + .required(false), + ) + .arg( + arg!(-b --back "Serializes start scan command and pretty prints it back to stdout.") + .required(false) + .action(ArgAction::SetTrue), + ), + )) +} + +pub async fn may_start_scan( + print_back: bool, + feed: Option, + reader: R, +) -> Option> +where + R: BufRead, + S: storage::Retriever, +{ + match quick_xml::de::from_reader(reader) { + Ok(x) if print_back => Some(Ok(format!("{x}"))), + Ok(x) if feed.is_some() => Some(start_scan(feed.unwrap(), x).await), + Ok(_) => Some(Err(CliErrorKind::MissingArguments( + vec!["path".to_string()], + ))), + Err(_) => None, + } +} + +async fn start_scan(feed: S, sc: StartScan) -> Result +where + S: storage::Retriever, +{ + // currently we ignore the previous order as the scanner will reorder + // when scheduling internally anyway. + let svts = sc + .vt_selection + .vt_single + .into_iter() + .flat_map(|x| x) + .map(|x| VT { + oid: x.id, + parameters: x + .vt_value + .into_iter() + .flat_map(|x| x) + .filter_map(|x| x.id.parse().ok().map(|y| (y, x.text))) + .filter_map(|(id, x)| x.map(|v| Parameter { id, value: v })) + .collect(), + }) + .collect(); + let gvts = sc + .vt_selection + .vt_group + .into_iter() + .flat_map(|x| x) + .filter_map( + |x| match x.filter.split_once('=').map(|(k, v)| (k.trim(), v.trim())) { + Some(("family", v)) => Some(v.to_string()), + filter => { + tracing::warn!(?filter, "only family is supported, ignoring entry"); + None + } + }, + ); + let mut scan = Scan { + scan_id: sc.id.unwrap_or_default(), + scan_preferences: sc.scanner_params.values, + target: sc.targets.target.into(), + vts: svts, + }; + // we iterate here to return an error when storage is behaving in an unexpected fashion + for family in gvts { + let fvts: Vec = match feed.retry_retrieve_by_field( + Field::NVT(NVTField::Family(family.to_string())), + Retrieve::NVT(Some(NVTKey::Oid)), + 5, + ) { + Ok(x) => x + .flat_map(|(_, f)| match &f { + Field::NVT(NVTField::Oid(oid)) => Some(VT { + oid: oid.clone(), + ..Default::default() + }), + _ => None, + }) + .collect(), + Err(StorageError::NotFound(_)) => { + tracing::debug!(family, "not found"); + Vec::new() + } + Err(e) => return Err(e.into()), + }; + scan.vts.extend(fvts); + } + scan.vts.sort(); + let scan_json = match serde_json::to_string_pretty(&scan) { + Ok(s) => s, + Err(e) => return Err(e.into()), + }; + Ok(scan_json) +} + +pub async fn run(root: &clap::ArgMatches) -> Option> { + let (args, _) = crate::get_args_set_logging(root, "ospd")?; + + let feed = match args.get_one::("path") { + Some(feed) => { + tracing::info!("loading feed. This may take a while."); + let storage = Arc::new(DefaultDispatcher::new()); + crate::feed::update::run(Arc::clone(&storage), feed.to_owned(), false) + .await + .unwrap(); + tracing::info!("feed loaded."); + Some(storage) + } + None => None, + }; + + let config = args.get_one::("ospd_xml"); + let mut bufreader: BufReader> = { + if let Some(config) = config { + let file = match std::fs::File::open(config) { + Ok(x) => x, + Err(e) => return Some(Err(e.into())), + }; + BufReader::new(Box::new(file)) + } else { + BufReader::new(Box::new(std::io::stdin())) + } + }; + let print_back = args.get_one::("back").cloned().unwrap_or_default(); + // currently we just support start scan if that changes chain the options. + let output = may_start_scan(print_back, feed, &mut bufreader).await; + let result = match output { + Some(Ok(x)) => { + println!("{x}"); + Ok(()) + } + Some(Err(e)) => Err(CliError { + filename: config.cloned().unwrap_or_default(), + kind: e, + }), + None => Err(CliError { + filename: config.cloned().unwrap_or_default(), + kind: CliErrorKind::Corrupt(format!("Unknown ospd command.")), + }), + }; + + Some(result) +} + +#[cfg(test)] +mod tests { + use std::io::Cursor; + + use scannerlib::storage::{item::NVTField, ContextKey, DefaultDispatcher, Field, Storage}; + use storage::Dispatcher; + use x509_parser::nom::ExtendInto; + + use super::*; + + #[tokio::test] + #[tracing_test::traced_test] + async fn print_scan_json() { + let input = r#" + + + + + 127.0.0.1 + T:80-80,443-443 + T:80-80,443-443 + 2 + + + PASSWORD + USER + + + localhost + + + + + + postgres + + + + + 0 + 5 + /cgi-bin:/scripts + 0 + + + + + "#; + let reader = BufReader::new(Cursor::new(input)); + let d = DefaultDispatcher::new(); + let dispatch = |k: &str, f: &str| { + let key = ContextKey::FileName(format!("{k}.nasl")); + d.dispatch(&key, Field::NVT(NVTField::Family(f.into()))) + .unwrap(); + + d.dispatch(&key, Field::NVT(NVTField::Oid(k.into()))) + .unwrap(); + }; + dispatch("0", "A"); + dispatch("1", "A"); + dispatch("2", "A"); + dispatch("3", "A"); + + let output = may_start_scan(false, Some(d), reader) + .await + .unwrap() + .unwrap(); + insta::assert_snapshot!(output); + } + + #[tokio::test] + #[tracing_test::traced_test] + async fn print_back() { + let input = r#" + + + + + 127.0.0.1 + T:80-80,443-443 + T:80-80,443-443 + 2 + + + PASSWORD + USER + + + localhost + + + + + + postgres + + + + + 0 + 5 + /cgi-bin:/scripts + 0 + + + + + "#; + let reader = BufReader::new(Cursor::new(input)); + let output = may_start_scan::<_, DefaultDispatcher>(true, None, reader) + .await + .unwrap() + .unwrap(); + insta::assert_snapshot!(output); + } +} diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__pare_credential_without_port.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__pare_credential_without_port.snap new file mode 100644 index 000000000..174874017 --- /dev/null +++ b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__pare_credential_without_port.snap @@ -0,0 +1,37 @@ +--- +source: src/scannerctl/ospd/start_scan.rs +expression: sc +--- + + + + 127.0.0.1 + T:80-80,443-443 + + 1 + + localhost + + + PASSWORD + USER + + + + + + + + postgres + + + + + 0 + 5 + /cgi-bin:/scripts + 0 + + + + diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_without_credential.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_without_credential.snap new file mode 100644 index 000000000..88aca68f6 --- /dev/null +++ b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_without_credential.snap @@ -0,0 +1,33 @@ +--- +source: src/scannerctl/ospd/start_scan.rs +expression: sc +--- + + + + 127.0.0.1 + T:80-80,443-443 + + 1 + + localhost + localhost + + + + + + + postgres + + + + + 0 + 5 + /cgi-bin:/scripts + 0 + + + + diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml.snap new file mode 100644 index 000000000..ec17357b5 --- /dev/null +++ b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml.snap @@ -0,0 +1,38 @@ +--- +source: src/scannerctl/ospd/start_scan.rs +expression: sc +--- + + + + 127.0.0.1 + T:80-80,443-443 + T:80-80,443-443 + + 1 + + localhost + + + PASSWORD + USER + + + + + + + + postgres + + + + + 0 + 5 + /cgi-bin:/scripts + 0 + + + + diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml_with_empty_credentials.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml_with_empty_credentials.snap new file mode 100644 index 000000000..7d9e6ea49 --- /dev/null +++ b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml_with_empty_credentials.snap @@ -0,0 +1,34 @@ +--- +source: src/scannerctl/ospd/start_scan.rs +expression: sc +--- + + + + 127.0.0.1 + T:80-80,443-443 + + 1 + + localhost + + + + + + + + + postgres + + + + + 0 + 5 + /cgi-bin:/scripts + 0 + + + + diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_back.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_back.snap new file mode 100644 index 000000000..2defc56fb --- /dev/null +++ b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_back.snap @@ -0,0 +1,38 @@ +--- +source: src/scannerctl/ospd/mod.rs +expression: output +--- + + + + 127.0.0.1 + T:80-80,443-443 + T:80-80,443-443 + + 1 + + localhost + + + PASSWORD + USER + + + + + + + + postgres + + + + + 0 + 5 + /cgi-bin:/scripts + 0 + + + + diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_scan_json.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_scan_json.snap new file mode 100644 index 000000000..8c3e2ebaa --- /dev/null +++ b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_scan_json.snap @@ -0,0 +1,123 @@ +--- +source: src/scannerctl/ospd/mod.rs +expression: output +--- +{ + "scan_id": "36389b56-f5a0-11e9-bba4-482ae354ac4c", + "target": { + "hosts": [ + "127.0.0.1" + ], + "ports": [ + { + "protocol": "tcp", + "range": [ + { + "start": 80, + "end": 80 + } + ] + }, + { + "protocol": "tcp", + "range": [ + { + "start": 443, + "end": 443 + } + ] + } + ], + "excluded_hosts": [ + "localhost" + ], + "credentials": [ + { + "service": "ssh", + "port": 22, + "up": { + "username": "USER", + "password": "PASSWORD" + } + } + ], + "alive_test_ports": [ + { + "protocol": "tcp", + "range": [ + { + "start": 80, + "end": 80 + } + ] + }, + { + "protocol": "tcp", + "range": [ + { + "start": 443, + "end": 443 + } + ] + } + ], + "alive_test_methods": [ + "icmp" + ], + "reverse_lookup_unify": null, + "reverse_lookup_only": null + }, + "scan_preferences": [ + { + "id": "use_mac_addr", + "value": "0" + }, + { + "id": "checks_read_timeout", + "value": "5" + }, + { + "id": "cgi_path", + "value": "/cgi-bin:/scripts" + }, + { + "id": "time_between_request", + "value": "0" + }, + { + "id": "vhosts_ip", + "value": "" + }, + { + "id": "vhosts", + "value": "" + } + ], + "vts": [ + { + "oid": "0", + "parameters": [] + }, + { + "oid": "1", + "parameters": [] + }, + { + "oid": "1.3.6.1.4.1.25623.1.0.100151", + "parameters": [ + { + "id": 1, + "value": "postgres" + } + ] + }, + { + "oid": "2", + "parameters": [] + }, + { + "oid": "3", + "parameters": [] + } + ] +} diff --git a/rust/src/scannerctl/ospd/start_scan.rs b/rust/src/scannerctl/ospd/start_scan.rs new file mode 100644 index 000000000..360fb1293 --- /dev/null +++ b/rust/src/scannerctl/ospd/start_scan.rs @@ -0,0 +1,846 @@ +use std::collections::HashMap; +use std::fmt::{self, Display}; + +use itertools::Itertools; +use scannerlib::models::{self, CredentialType, Service}; +use serde::de::{self, MapAccess, Visitor}; +use serde::{Deserialize, Serialize, Serializer}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Targets { + pub target: Target, +} + +#[derive(Default, Debug, Clone, PartialEq, Eq)] +pub struct Target { + pub hosts: Vec, + pub ports: Option>, + pub alive_test_ports: Option>, + pub alive_test_methods: Option>, + pub exclude_hosts: Option>, + pub finished_hosts: Option>, + pub reverse_lookup_unify: Option, + pub reverse_lookup_only: Option, + pub credentials: Option, +} + +impl Into for Target { + fn into(self) -> models::Target { + let credentials = self + .credentials + .into_iter() + .flat_map(|x| { + x.credential.into_iter().flat_map(|x| x).map(|x| { + fn find_key(key: &str, x: &[(String, String)]) -> Option { + x.iter().find(|(k, _)| k == key).map(|(_, v)| v.to_string()) + } + fn key(key: &str, x: &[(String, String)]) -> String { + find_key(key, x).unwrap_or_default() + } + let username = key("username", &x.credentials); + let password = key("password", &x.credentials); + + let privilege = find_key("priv_username", &x.credentials).map(|y| { + models::PrivilegeInformation { + username: y, + password: key("priv_password", &x.credentials), + } + }); + let kind = match &x.kind as &str { + "usk" => CredentialType::USK { + username, + password, + private_key: key("private", &x.credentials), + privilege, + }, + "snmp" => CredentialType::SNMP { + username, + password, + community: key("community", &x.credentials), + auth_algorithm: key("auth_algorithm", &x.credentials), + privacy_password: key("privacy_password", &x.credentials), + privacy_algorithm: key("privacy_algorithm", &x.credentials), + }, + _ => CredentialType::UP { + username, + password, + privilege, + }, + }; + models::Credential { + service: (&x.service as &str).try_into().ok().unwrap_or(Service::SSH), + port: x.port.map(|x| x.parse().ok()).flatten(), + credential_type: kind, + } + }) + }) + .collect(); + + models::Target { + hosts: self.hosts, + ports: self.ports.unwrap_or_default(), + excluded_hosts: self.exclude_hosts.unwrap_or_default(), + credentials, + alive_test_ports: self.alive_test_ports.unwrap_or_default(), + alive_test_methods: self.alive_test_methods.unwrap_or_default(), + reverse_lookup_unify: self.reverse_lookup_unify, + reverse_lookup_only: self.reverse_lookup_only, + } + } +} + +// Parses T:80-80,U:80-90 into a vector of ports +fn ports_from_ospd_string(ports: Option<&str>) -> Option> { + let ports = ports?; + let mut result = vec![]; + let mut start = 0; + let mut end = None; + let mut protocol = None; + for port in ports.split(',') { + for p in port.split(':') { + match p { + "T" => { + protocol = Some(models::Protocol::TCP); + } + "U" => { + protocol = Some(models::Protocol::UDP); + } + _ => { + for (i, r) in p.split('-').enumerate() { + if i == 0 { + start = r.parse().unwrap(); + } else if i == 1 { + end = Some(r.parse().unwrap()); + } else { + panic!("invalid port range"); + } + } + let range = models::Port { + protocol, + range: vec![scannerlib::models::PortRange { start, end }], + }; + start = 0; + end = None; + result.push(range); + } + }; + } + } + Some(result) +} + +fn ports_to_ospd_string(ports: Option<&[models::Port]>) -> Option { + fn range_to_string(r: &[models::PortRange]) -> String { + r.iter().map(|x| x.to_string()).join(",") + } + let ports = ports?; + let mut tcp = Vec::new(); + let mut udp = Vec::new(); + for x in ports { + let rs = range_to_string(&x.range); + if rs.is_empty() { + continue; + } + + match x.protocol { + Some(models::Protocol::TCP) => tcp.push(rs), + Some(models::Protocol::UDP) => udp.push(rs), + None => { + tcp.push(rs.clone()); + udp.push(rs); + } + } + } + match (tcp.is_empty(), udp.is_empty()) { + (true, true) => None, + (false, false) => Some(format!("T:{},U:{}", tcp.join(","), udp.join(","))), + (true, false) => Some(format!("U:{}", udp.join(","))), + (false, true) => Some(format!("T:{}", tcp.join(","))), + } +} + +fn ospd_string_to_bool(v: &str) -> bool { + match &v.to_lowercase() as &str { + "1" | "true" | "yes" => true, + _ => false, + } +} + +fn bool_to_ospd_string(v: bool) -> &'static str { + match v { + true => "1", + false => "0", + } +} + +impl Serialize for Target { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + fn ospd_bool( + map: &mut ::SerializeMap, + key: &str, + value: Option, + ) -> Result<(), S::Error> + where + S: Serializer, + { + match value { + Some(x) => map.serialize_entry(key, bool_to_ospd_string(x)), + None => { + tracing::trace!(key, "ignoring empty"); + Ok(()) + } + } + } + let mut map = serializer.serialize_map(Some(5))?; + let hosts = self.hosts.join(","); + map.serialize_entry("hosts", &hosts)?; + map.serialize_entry( + "ports", + &ports_to_ospd_string(self.ports.as_ref().map(|x| x as &[_])), + )?; + if let Some(alp) = &self.alive_test_ports { + map.serialize_entry("alive_test_ports", &ports_to_ospd_string(Some(alp as &[_])))?; + } + if let Some(atm) = &self.alive_test_methods { + let fields: HashMap<&'static str, &'static str> = atm + .iter() + .map(|x| match x { + models::AliveTestMethods::TcpAck => ("icmp_ack", "1"), + models::AliveTestMethods::Icmp => ("icmp", "1"), + models::AliveTestMethods::Arp => ("arp", "1"), + models::AliveTestMethods::ConsiderAlive => ("consider_alive", "1"), + models::AliveTestMethods::TcpSyn => ("tcp_sync", "1"), + }) + .collect(); + if !fields.is_empty() { + map.serialize_entry("alive_test_methods", &fields)?; + } + } + + if let Some(v) = &self.exclude_hosts { + let exclude_hosts = v.join(","); + map.serialize_entry("exclude_hosts", &exclude_hosts)?; + } + if let Some(v) = &self.finished_hosts { + let finished_hosts = v.join(","); + map.serialize_entry("finished_hosts", &finished_hosts)?; + } + + map.serialize_entry("credentials", &self.credentials)?; + ospd_bool::(&mut map, "reverse_lookup_only", self.reverse_lookup_only)?; + ospd_bool::(&mut map, "reverse_lookup_unify", self.reverse_lookup_unify)?; + map.end() + } +} + +impl<'de> Deserialize<'de> for Target { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct CredentialVisitor; + + impl<'de> Visitor<'de> for CredentialVisitor { + type Value = Target; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("a target XML element") + } + + fn visit_map(self, mut map: A) -> Result + where + A: MapAccess<'de>, + { + fn comma_sep_to_vec<'de, A>(mut map: A) -> Result, A::Error> + where + A: MapAccess<'de>, + { + let hosts: String = map.next_value()?; + Ok(hosts + .split(',') + .filter(|x| !x.is_empty()) + .map(|x| x.to_string()) + .collect_vec()) + } + + fn ospd_bool<'de, A>(mut map: A) -> Result + where + A: MapAccess<'de>, + { + let value: String = map.next_value()?; + Ok(ospd_string_to_bool(&value)) + } + let mut result = Target::default(); + + while let Some(key) = map.next_key::()? { + match key.as_str() { + "hosts" => result.hosts = comma_sep_to_vec(&mut map)?, + "ports" => { + result.ports = { + let ports: Option = map.next_value().ok(); + ports_from_ospd_string(ports.as_ref().map(|x| x as &str)) + } + } + + "alive_test_ports" => { + result.alive_test_ports = { + let ports: Option = map.next_value().ok(); + ports_from_ospd_string(ports.as_ref().map(|x| x as &str)) + } + } + "alive_test" => { + if let Some(at) = map.next_value::().ok() { + if let Ok(at) = at.parse::() { + if let Ok(at) = models::AliveTestMethods::try_from(at) { + result.alive_test_methods = Some(vec![at]); + continue; + } + } + return Err(de::Error::custom(format!("{at} is not a valid number. It must be a number of 1, 2, 4, 8 or 16."))); + } + } + "alive_test_methods" => { + if let Some(at) = map.next_value::>().ok() { + let alive_test_methods = at + .iter() + .filter_map(|(k, v)| { + if ospd_string_to_bool(&v) { + match &k.to_lowercase() as &str { + "icmp" => Some(models::AliveTestMethods::Icmp), + "tcp_syn" => Some(models::AliveTestMethods::TcpSyn), + "tcp_ack" => Some(models::AliveTestMethods::TcpAck), + "arp" => Some(models::AliveTestMethods::Arp), + "consider_alive" => { + Some(models::AliveTestMethods::ConsiderAlive) + } + _ => None, + } + } else { + None + } + }) + .collect::>(); + if !alive_test_methods.is_empty() { + result.alive_test_methods = Some(alive_test_methods); + } + } + } + "exclude_hosts" => result.exclude_hosts = comma_sep_to_vec(&mut map).ok(), + "finished_hosts" => result.finished_hosts = comma_sep_to_vec(&mut map).ok(), + "credentials" => result.credentials = map.next_value().ok(), + "reverse_lookup_only" => { + result.reverse_lookup_only = ospd_bool(&mut map).ok() + } + "reverse_lookup_unify" => { + result.reverse_lookup_unify = ospd_bool(&mut map).ok() + } + _ => { + tracing::warn!(key, "skipping unknown field") + } + } + } + Ok(result) + } + } + + deserializer.deserialize_map(CredentialVisitor) + } +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +// TODO: replace kind, username and password with enum +pub struct Credentials { + pub credential: Option>, +} +#[derive(Default, Debug, Clone, PartialEq, Eq)] +// TODO: replace kind, username and password with enum +pub struct Credential { + pub kind: String, + pub service: String, + pub port: Option, + /// Contains all fields + /// + /// ```xml + /// + /// PASSWORD + /// USER + /// + /// ``` + /// + /// credentials will hold the fields: + /// - username + /// - password + /// + /// This is done so that we don't have to explicitely create fields for all + /// credential types as there is an explicit verification later on when we + /// transform it to models::Credential + pub credentials: Vec<(String, String)>, +} +use serde::ser::SerializeMap; + +impl Serialize for Credential { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut map = serializer.serialize_map(Some(3 + self.credentials.len()))?; + map.serialize_entry("@type", &self.kind)?; + map.serialize_entry("@service", &self.service)?; + map.serialize_entry("@port", &self.port)?; + for (key, value) in &self.credentials { + map.serialize_entry(key, value)?; + } + map.end() + } +} + +// Custom Deserialize Implementation +impl<'de> Deserialize<'de> for Credential { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct CredentialVisitor; + + impl<'de> Visitor<'de> for CredentialVisitor { + type Value = Credential; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("a credential XML element") + } + + fn visit_map(self, mut map: A) -> Result + where + A: MapAccess<'de>, + { + let mut result = Credential::default(); + + while let Some(key) = map.next_key::()? { + match key.as_str() { + "@type" => result.kind = map.next_value()?, + "@service" => result.service = map.next_value()?, + "@port" => result.port = map.next_value().ok(), + key => { + if let Some(value) = map.next_value()? { + result.credentials.push((key.to_string(), value)); + } + } + } + } + Ok(result) + } + } + deserializer.deserialize_map(CredentialVisitor) + } +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct VtSelection { + pub vt_group: Option>, + pub vt_single: Option>, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct VtGroup { + #[serde(rename = "@filter")] + pub filter: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct VtSingle { + #[serde(rename = "@id")] + pub id: String, + pub vt_value: Option>, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct VtValue { + #[serde(rename = "@id")] + pub id: String, + #[serde(rename = "$text")] + pub text: Option, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ScannerParameter { + pub values: Vec, +} + +impl Serialize for ScannerParameter { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut map = serializer.serialize_map(Some(self.values.len()))?; + for x in &self.values { + map.serialize_entry(&x.id, &x.value)?; + } + map.end() + } +} + +impl<'de> Deserialize<'de> for ScannerParameter { + fn deserialize(deserializer: D) -> Result + where + D: de::Deserializer<'de>, + { + struct SPVisitor; + + impl<'de> Visitor<'de> for SPVisitor { + type Value = ScannerParameter; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("a credential XML element") + } + + fn visit_map(self, mut map: A) -> Result + where + A: MapAccess<'de>, + { + let mut values = Vec::new(); + + while let Some(key) = map.next_key::()? { + match key.as_str() { + key => { + let value: String = map.next_value()?; + values.push(models::ScanPreference { + id: key.to_string(), + value, + }); + } + } + } + + Ok(ScannerParameter { values }) + } + } + + deserializer.deserialize_map(SPVisitor) + } +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[serde(rename = "start_scan")] +pub struct StartScan { + #[serde(rename = "@parallel")] + pub parallel: Option, + #[serde(rename = "@scan_id")] + pub id: Option, + pub targets: Targets, + pub vt_selection: VtSelection, + pub scanner_params: ScannerParameter, +} +impl Display for StartScan { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut ser = quick_xml::se::Serializer::new(f); + ser.indent(' ', 2); + self.serialize(ser) + .map_err(|x| { + tracing::warn!(error=?x, "unable to serialize StartScan"); + fmt::Error + }) + .map(|_| ()) + } +} + +impl From for Credential { + fn from(value: models::Credential) -> Self { + let service = value.service.as_ref().to_string(); + let port = value.port.map(|x| x.to_string()); + let kind = value.credential_type.as_ref().to_string(); + let mut credentials = Vec::new(); + match value.credential_type { + models::CredentialType::UP { + username, + password, + privilege, + } => { + credentials.push(("username".to_string(), username)); + credentials.push(("password".to_string(), password)); + if let Some(p) = privilege { + credentials.push(("priv_username".to_string(), p.username)); + credentials.push(("priv_password".to_string(), p.password)); + } + } + models::CredentialType::USK { + username, + password, + private_key, + privilege, + } => { + credentials.push(("username".to_string(), username)); + credentials.push(("password".to_string(), password)); + credentials.push(("private".to_string(), private_key)); + if let Some(p) = privilege { + credentials.push(("priv_username".to_string(), p.username)); + credentials.push(("priv_password".to_string(), p.password)); + } + } + models::CredentialType::SNMP { + username, + password, + community, + auth_algorithm, + privacy_password, + privacy_algorithm, + } => { + credentials.push(("username".to_string(), username)); + credentials.push(("password".to_string(), password)); + credentials.push(("community".to_string(), community)); + credentials.push(("auth_algorithm".to_string(), auth_algorithm)); + credentials.push(("privacy_passwor".to_string(), privacy_password)); + credentials.push(("privacy_algorithm".to_string(), privacy_algorithm)); + } + }; + Credential { + kind, + service, + port, + credentials, + } + } +} + +impl From> for Credentials { + fn from(value: Vec) -> Self { + Credentials { + credential: Some(value.into_iter().map(|x| x.into()).collect()), + } + } +} + +impl From for Target { + fn from(value: models::Target) -> Self { + Target { + hosts: value.hosts, + ports: Some(value.ports), + alive_test_ports: Some(value.alive_test_ports), + alive_test_methods: Some(value.alive_test_methods), + exclude_hosts: Some(value.excluded_hosts), + finished_hosts: None, + reverse_lookup_unify: value.reverse_lookup_unify, + reverse_lookup_only: value.reverse_lookup_only, + credentials: Some(value.credentials.into()), + } + } +} + +impl From for Targets { + fn from(value: models::Target) -> Self { + Targets { + target: value.into(), + } + } +} + +impl From> for VtSelection { + fn from(value: Vec) -> Self { + let sv = value + .into_iter() + .map(|x| { + let vt_value = { + let v = x + .parameters + .into_iter() + .map(|x| VtValue { + id: x.id.to_string(), + text: Some(x.value), + }) + .collect::>(); + if v.is_empty() { + None + } else { + Some(v) + } + }; + VtSingle { + id: x.oid, + vt_value, + } + }) + .collect(); + VtSelection { + vt_group: None, + vt_single: Some(sv), + } + } +} + +impl From> for ScannerParameter { + fn from(value: Vec) -> Self { + ScannerParameter { values: value } + } +} + +impl From for StartScan { + fn from(value: models::Scan) -> Self { + StartScan { + parallel: None, + id: Some(value.scan_id), + targets: value.target.into(), + vt_selection: value.vts.into(), + scanner_params: value.scan_preferences.into(), + } + } +} + +#[cfg(test)] +mod test { + use quick_xml::de::from_str; + + use super::StartScan; + + #[test] + fn pare_credential_without_port() { + let input = r#" + + + + + 127.0.0.1 + T:80-80,443-443 + 2 + + + PASSWORD + USER + + + localhost + + + + + + postgres + + + + + 0 + 5 + /cgi-bin:/scripts + 0 + + + + + "#; + let sc: StartScan = from_str(&input).unwrap(); + insta::assert_snapshot!(sc); + } + + #[test] + fn parse_xml_with_empty_credentials() { + let input = r#" + + + + + 127.0.0.1 + T:80-80,443-443 + 2 + + localhost + + + + + + postgres + + + + + 0 + 5 + /cgi-bin:/scripts + 0 + + + + + "#; + let sc: StartScan = from_str(&input).unwrap(); + insta::assert_snapshot!(sc); + } + + #[test] + fn parse_without_credential() { + let input = r#" + + + + + 127.0.0.1 + T:80-80,443-443 + 2 + localhost + localhost + + + + + + postgres + + + + + 0 + 5 + /cgi-bin:/scripts + 0 + + + + + "#; + let sc: StartScan = from_str(&input).unwrap(); + insta::assert_snapshot!(sc); + } + + #[test] + fn parse_xml() { + let input = r#" + + + + + 127.0.0.1 + T:80-80,443-443 + T:80-80,443-443 + 2 + + + PASSWORD + USER + + + localhost + + + + + + postgres + + + + + 0 + 5 + /cgi-bin:/scripts + 0 + + + + + "#; + let sc: StartScan = from_str(&input).unwrap(); + insta::assert_snapshot!(sc); + } +} diff --git a/rust/src/scannerctl/scanconfig.rs b/rust/src/scannerctl/scanconfig.rs index bf4e27613..28c5b2294 100644 --- a/rust/src/scannerctl/scanconfig.rs +++ b/rust/src/scannerctl/scanconfig.rs @@ -300,7 +300,7 @@ where }); acc }); - + let oid_to_vt = |oid: &String| -> Result { let parameters = preference_lookup.get(oid).unwrap_or(&vec![]).clone(); Ok(VT { From 7e272c9ef24f794f89aa9456ae723cd8889cf56e Mon Sep 17 00:00:00 2001 From: Philipp Eder Date: Wed, 8 Jan 2025 13:29:16 +0000 Subject: [PATCH 08/10] Clippy fixes --- rust/src/nasl/builtin/ssh/tests/mod.rs | 8 ++-- rust/src/nasl/mod.rs | 8 ++-- rust/src/nasl/syntax/loader.rs | 8 ++-- rust/src/nasl/test_utils.rs | 10 ++--- rust/src/openvasd/storage/file.rs | 2 +- rust/src/osp/response.rs | 6 +-- rust/src/scanner/scan_runner.rs | 2 +- rust/src/scannerctl/error.rs | 5 +-- rust/src/scannerctl/ospd/mod.rs | 13 +++--- rust/src/scannerctl/ospd/start_scan.rs | 57 +++++++++++--------------- rust/src/scannerctl/scanconfig.rs | 2 +- 11 files changed, 52 insertions(+), 69 deletions(-) diff --git a/rust/src/nasl/builtin/ssh/tests/mod.rs b/rust/src/nasl/builtin/ssh/tests/mod.rs index 84a9183e0..32a3be194 100644 --- a/rust/src/nasl/builtin/ssh/tests/mod.rs +++ b/rust/src/nasl/builtin/ssh/tests/mod.rs @@ -35,7 +35,7 @@ fn default_config() -> ServerConfig { } async fn run_test( - f: impl Fn(&mut TestBuilder) -> () + Send + Sync + 'static, + f: impl Fn(&mut TestBuilder) + Send + Sync + 'static, config: ServerConfig, ) { // Acquire the global lock to prevent multiple @@ -58,7 +58,7 @@ async fn run_test( #[tokio::main] async fn run_client( - f: impl Fn(&mut TestBuilder) -> () + Send + Sync + 'static, + f: impl Fn(&mut TestBuilder) + Send + Sync + 'static, ) { std::thread::sleep(Duration::from_millis(100)); let mut t = TestBuilder::default(); @@ -126,7 +126,7 @@ async fn ssh_userauth() { .. }, ); - userauth(&mut t); + userauth(t); }, default_config(), ) @@ -148,7 +148,7 @@ async fn ssh_request_exec() { format!(r#"session_id = ssh_connect(port: {});"#, PORT), MIN_SESSION_ID, ); - userauth(&mut t); + userauth(t); t.ok( r#"auth = ssh_request_exec(session_id, stdout: 1, stderr: 0, cmd: "write_foo_stdout");"#, "foo", diff --git a/rust/src/nasl/mod.rs b/rust/src/nasl/mod.rs index 4436e50bb..f406cc95f 100644 --- a/rust/src/nasl/mod.rs +++ b/rust/src/nasl/mod.rs @@ -34,6 +34,10 @@ pub mod prelude { pub use prelude::*; +pub use builtin::nasl_std_functions; + +pub use syntax::NoOpLoader; + #[cfg(test)] pub mod test_prelude { pub use super::prelude::*; @@ -43,7 +47,3 @@ pub mod test_prelude { pub use crate::check_code_result_matches; pub use crate::check_err_matches; } - -pub use builtin::nasl_std_functions; - -pub use syntax::NoOpLoader; diff --git a/rust/src/nasl/syntax/loader.rs b/rust/src/nasl/syntax/loader.rs index 98463c42f..b8891279e 100644 --- a/rust/src/nasl/syntax/loader.rs +++ b/rust/src/nasl/syntax/loader.rs @@ -32,10 +32,10 @@ pub enum LoadError { impl LoadError { pub fn filename(&self) -> &str { match self { - LoadError::Retry(x) => &x, - LoadError::NotFound(x) => &x, - LoadError::PermissionDenied(x) => &x, - LoadError::Dirty(x) => &x, + LoadError::Retry(x) => x, + LoadError::NotFound(x) => x, + LoadError::PermissionDenied(x) => x, + LoadError::Dirty(x) => x, } } } diff --git a/rust/src/nasl/test_utils.rs b/rust/src/nasl/test_utils.rs index 553605326..34973188d 100644 --- a/rust/src/nasl/test_utils.rs +++ b/rust/src/nasl/test_utils.rs @@ -42,7 +42,7 @@ where } } -impl<'a> Clone for Box { +impl Clone for Box { fn clone(&self) -> Self { (**self).clone_box() } @@ -238,7 +238,7 @@ where // let code = self.lines.join("\n"); // let context = self.context(); - let parser = CodeInterpreter::new(&code, register, &context); + let parser = CodeInterpreter::new(code, register, context); parser.stream().map(|res| { res.map_err(|e| match e.kind { InterpretErrorKind::FunctionCallError(f) => f.kind, @@ -375,10 +375,8 @@ impl Drop for TestBuilder { fn drop(&mut self) { if tokio::runtime::Handle::try_current().is_ok() { panic!("To use TestBuilder in an asynchronous context, explicitly call async_verify()"); - } else { - if let Err(err) = futures::executor::block_on(self.verify()) { - panic!("{}", err) - } + } else if let Err(err) = futures::executor::block_on(self.verify()) { + panic!("{}", err) } } } diff --git a/rust/src/openvasd/storage/file.rs b/rust/src/openvasd/storage/file.rs index 574563af8..c7beffd50 100644 --- a/rust/src/openvasd/storage/file.rs +++ b/rust/src/openvasd/storage/file.rs @@ -591,7 +591,7 @@ pub(crate) mod tests { scan.scan_id = "aha".to_string(); let tmp_path = "/tmp/openvasd/credential"; clear_tmp_files(Path::new(tmp_path)); - let storage = example_feed_file_storage(&tmp_path).await; + let storage = example_feed_file_storage(tmp_path).await; storage.insert_scan(scan.clone()).await.unwrap(); let (scan2, _) = storage.get_scan("aha").await.unwrap(); assert_eq!(scan, scan2); diff --git a/rust/src/osp/response.rs b/rust/src/osp/response.rs index 8812d3e69..17ccab121 100644 --- a/rust/src/osp/response.rs +++ b/rust/src/osp/response.rs @@ -5,11 +5,7 @@ //! # Responses of OSPD commands use std::{collections::HashMap, fmt}; -use redis::ToRedisArgs; -use serde::{ - de::{IntoDeserializer, Visitor}, - Deserialize, Serializer, -}; +use serde::{de::Visitor, Deserialize}; use super::commands::Error; diff --git a/rust/src/scanner/scan_runner.rs b/rust/src/scanner/scan_runner.rs index 221b93ced..e0f08b112 100644 --- a/rust/src/scanner/scan_runner.rs +++ b/rust/src/scanner/scan_runner.rs @@ -458,7 +458,7 @@ exit({rc}); } fn make_test_dispatcher(vts: &[(String, Nvt)]) -> DefaultDispatcher { - let dispatcher = prepare_vt_storage(&vts); + let dispatcher = prepare_vt_storage(vts); dispatcher .dispatch( &ContextKey::Scan("sid".into(), Some("test.host".into())), diff --git a/rust/src/scannerctl/error.rs b/rust/src/scannerctl/error.rs index 81186170f..7a3b76d61 100644 --- a/rust/src/scannerctl/error.rs +++ b/rust/src/scannerctl/error.rs @@ -2,10 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later WITH x11vnc-openssl-exception -use std::{ - fmt::Display, - path::{Path, PathBuf}, -}; +use std::path::{Path, PathBuf}; use feed::VerifyError; use scannerlib::nasl::{interpreter::InterpretError, syntax::LoadError}; diff --git a/rust/src/scannerctl/ospd/mod.rs b/rust/src/scannerctl/ospd/mod.rs index 13e6e1df8..e97d25c60 100644 --- a/rust/src/scannerctl/ospd/mod.rs +++ b/rust/src/scannerctl/ospd/mod.rs @@ -7,7 +7,7 @@ use std::{io::BufReader, path::PathBuf, sync::Arc}; use clap::{arg, value_parser, Arg, ArgAction, Command}; use scannerlib::models::{Parameter, Scan, VT}; -use scannerlib::storage::{self, DefaultDispatcher, Retriever, StorageError}; +use scannerlib::storage::{self, DefaultDispatcher, StorageError}; use start_scan::StartScan; use crate::{CliError, CliErrorKind}; @@ -66,13 +66,13 @@ where .vt_selection .vt_single .into_iter() - .flat_map(|x| x) + .flatten() .map(|x| VT { oid: x.id, parameters: x .vt_value .into_iter() - .flat_map(|x| x) + .flatten() .filter_map(|x| x.id.parse().ok().map(|y| (y, x.text))) .filter_map(|(id, x)| x.map(|v| Parameter { id, value: v })) .collect(), @@ -82,7 +82,7 @@ where .vt_selection .vt_group .into_iter() - .flat_map(|x| x) + .flatten() .filter_map( |x| match x.filter.split_once('=').map(|(k, v)| (k.trim(), v.trim())) { Some(("family", v)) => Some(v.to_string()), @@ -172,7 +172,7 @@ pub async fn run(root: &clap::ArgMatches) -> Option> { }), None => Err(CliError { filename: config.cloned().unwrap_or_default(), - kind: CliErrorKind::Corrupt(format!("Unknown ospd command.")), + kind: CliErrorKind::Corrupt("Unknown ospd command.".to_string()), }), }; @@ -183,9 +183,8 @@ pub async fn run(root: &clap::ArgMatches) -> Option> { mod tests { use std::io::Cursor; - use scannerlib::storage::{item::NVTField, ContextKey, DefaultDispatcher, Field, Storage}; + use scannerlib::storage::{item::NVTField, ContextKey, DefaultDispatcher, Field}; use storage::Dispatcher; - use x509_parser::nom::ExtendInto; use super::*; diff --git a/rust/src/scannerctl/ospd/start_scan.rs b/rust/src/scannerctl/ospd/start_scan.rs index 360fb1293..4db802c3f 100644 --- a/rust/src/scannerctl/ospd/start_scan.rs +++ b/rust/src/scannerctl/ospd/start_scan.rs @@ -24,13 +24,13 @@ pub struct Target { pub credentials: Option, } -impl Into for Target { - fn into(self) -> models::Target { - let credentials = self +impl From for models::Target { + fn from(val: Target) -> Self { + let credentials = val .credentials .into_iter() .flat_map(|x| { - x.credential.into_iter().flat_map(|x| x).map(|x| { + x.credential.into_iter().flatten().map(|x| { fn find_key(key: &str, x: &[(String, String)]) -> Option { x.iter().find(|(k, _)| k == key).map(|(_, v)| v.to_string()) } @@ -69,7 +69,7 @@ impl Into for Target { }; models::Credential { service: (&x.service as &str).try_into().ok().unwrap_or(Service::SSH), - port: x.port.map(|x| x.parse().ok()).flatten(), + port: x.port.and_then(|x| x.parse().ok()), credential_type: kind, } }) @@ -77,14 +77,14 @@ impl Into for Target { .collect(); models::Target { - hosts: self.hosts, - ports: self.ports.unwrap_or_default(), - excluded_hosts: self.exclude_hosts.unwrap_or_default(), + hosts: val.hosts, + ports: val.ports.unwrap_or_default(), + excluded_hosts: val.exclude_hosts.unwrap_or_default(), credentials, - alive_test_ports: self.alive_test_ports.unwrap_or_default(), - alive_test_methods: self.alive_test_methods.unwrap_or_default(), - reverse_lookup_unify: self.reverse_lookup_unify, - reverse_lookup_only: self.reverse_lookup_only, + alive_test_ports: val.alive_test_ports.unwrap_or_default(), + alive_test_methods: val.alive_test_methods.unwrap_or_default(), + reverse_lookup_unify: val.reverse_lookup_unify, + reverse_lookup_only: val.reverse_lookup_only, } } } @@ -160,10 +160,7 @@ fn ports_to_ospd_string(ports: Option<&[models::Port]>) -> Option { } fn ospd_string_to_bool(v: &str) -> bool { - match &v.to_lowercase() as &str { - "1" | "true" | "yes" => true, - _ => false, - } + matches!(&v.to_lowercase() as &str, "1" | "true" | "yes") } fn bool_to_ospd_string(v: bool) -> &'static str { @@ -292,7 +289,7 @@ impl<'de> Deserialize<'de> for Target { } } "alive_test" => { - if let Some(at) = map.next_value::().ok() { + if let Ok(at) = map.next_value::() { if let Ok(at) = at.parse::() { if let Ok(at) = models::AliveTestMethods::try_from(at) { result.alive_test_methods = Some(vec![at]); @@ -303,11 +300,11 @@ impl<'de> Deserialize<'de> for Target { } } "alive_test_methods" => { - if let Some(at) = map.next_value::>().ok() { + if let Ok(at) = map.next_value::>() { let alive_test_methods = at .iter() .filter_map(|(k, v)| { - if ospd_string_to_bool(&v) { + if ospd_string_to_bool(v) { match &k.to_lowercase() as &str { "icmp" => Some(models::AliveTestMethods::Icmp), "tcp_syn" => Some(models::AliveTestMethods::TcpSyn), @@ -503,15 +500,11 @@ impl<'de> Deserialize<'de> for ScannerParameter { let mut values = Vec::new(); while let Some(key) = map.next_key::()? { - match key.as_str() { - key => { - let value: String = map.next_value()?; - values.push(models::ScanPreference { - id: key.to_string(), - value, - }); - } - } + let value: String = map.next_value()?; + values.push(models::ScanPreference { + id: key.to_string(), + value, + }); } Ok(ScannerParameter { values }) @@ -729,7 +722,7 @@ mod test { "#; - let sc: StartScan = from_str(&input).unwrap(); + let sc: StartScan = from_str(input).unwrap(); insta::assert_snapshot!(sc); } @@ -764,7 +757,7 @@ mod test { "#; - let sc: StartScan = from_str(&input).unwrap(); + let sc: StartScan = from_str(input).unwrap(); insta::assert_snapshot!(sc); } @@ -799,7 +792,7 @@ mod test { "#; - let sc: StartScan = from_str(&input).unwrap(); + let sc: StartScan = from_str(input).unwrap(); insta::assert_snapshot!(sc); } @@ -840,7 +833,7 @@ mod test { "#; - let sc: StartScan = from_str(&input).unwrap(); + let sc: StartScan = from_str(input).unwrap(); insta::assert_snapshot!(sc); } } diff --git a/rust/src/scannerctl/scanconfig.rs b/rust/src/scannerctl/scanconfig.rs index 28c5b2294..1ced388eb 100644 --- a/rust/src/scannerctl/scanconfig.rs +++ b/rust/src/scannerctl/scanconfig.rs @@ -293,7 +293,7 @@ where .iter() .fold(HashMap::new(), |mut acc, p| { let oid = p.nvt.oid.clone(); - let parameters = acc.entry(oid).or_insert(vec![]); + let parameters = acc.entry(oid).or_default(); parameters.push(Parameter { id: p.id, value: p.value.clone(), From 3eb3ee4122f6418d73470485ccc44da21a807c01 Mon Sep 17 00:00:00 2001 From: Philipp Eder Date: Thu, 9 Jan 2025 12:30:27 +0000 Subject: [PATCH 09/10] Create Into> for Credentials --- rust/src/openvasd/controller/entry.rs | 1 - rust/src/scannerctl/error.rs | 3 - rust/src/scannerctl/ospd/start_scan.rs | 100 +++++++++++++------------ 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/rust/src/openvasd/controller/entry.rs b/rust/src/openvasd/controller/entry.rs index 49c41aceb..aa9e01c69 100644 --- a/rust/src/openvasd/controller/entry.rs +++ b/rust/src/openvasd/controller/entry.rs @@ -302,7 +302,6 @@ where } } (&Method::POST, Scans(None)) => { - // We could enhance the API to accept a list of scans as well. match crate::request::json_request::(&ctx.response, req).await { Ok(mut scan) => { let id = if !scan.scan_id.is_empty() { diff --git a/rust/src/scannerctl/error.rs b/rust/src/scannerctl/error.rs index 7a3b76d61..96848bfdd 100644 --- a/rust/src/scannerctl/error.rs +++ b/rust/src/scannerctl/error.rs @@ -64,9 +64,6 @@ impl CliErrorKind { #[derive(Debug, thiserror::Error)] #[error("{kind} ({filename})")] pub struct CliError { - // FIXME: unlike previous assumptions most cases don't have a clear filename - // associated to it. This information should be in specific unter categories - // of CliErrorKind instead. pub filename: String, pub kind: CliErrorKind, } diff --git a/rust/src/scannerctl/ospd/start_scan.rs b/rust/src/scannerctl/ospd/start_scan.rs index 4db802c3f..c91425006 100644 --- a/rust/src/scannerctl/ospd/start_scan.rs +++ b/rust/src/scannerctl/ospd/start_scan.rs @@ -1,3 +1,4 @@ +use serde::ser::SerializeMap; use std::collections::HashMap; use std::fmt::{self, Display}; @@ -24,57 +25,61 @@ pub struct Target { pub credentials: Option, } -impl From for models::Target { - fn from(val: Target) -> Self { - let credentials = val - .credentials +impl Into> for Credentials { + fn into(self) -> Vec { + self.credential .into_iter() - .flat_map(|x| { - x.credential.into_iter().flatten().map(|x| { - fn find_key(key: &str, x: &[(String, String)]) -> Option { - x.iter().find(|(k, _)| k == key).map(|(_, v)| v.to_string()) - } - fn key(key: &str, x: &[(String, String)]) -> String { - find_key(key, x).unwrap_or_default() - } - let username = key("username", &x.credentials); - let password = key("password", &x.credentials); + .flatten() + .map(|x| { + fn find_key(key: &str, x: &[(String, String)]) -> Option { + x.iter().find(|(k, _)| k == key).map(|(_, v)| v.to_string()) + } + fn key(key: &str, x: &[(String, String)]) -> String { + find_key(key, x).unwrap_or_default() + } + let username = key("username", &x.credentials); + let password = key("password", &x.credentials); - let privilege = find_key("priv_username", &x.credentials).map(|y| { - models::PrivilegeInformation { - username: y, - password: key("priv_password", &x.credentials), - } - }); - let kind = match &x.kind as &str { - "usk" => CredentialType::USK { - username, - password, - private_key: key("private", &x.credentials), - privilege, - }, - "snmp" => CredentialType::SNMP { - username, - password, - community: key("community", &x.credentials), - auth_algorithm: key("auth_algorithm", &x.credentials), - privacy_password: key("privacy_password", &x.credentials), - privacy_algorithm: key("privacy_algorithm", &x.credentials), - }, - _ => CredentialType::UP { - username, - password, - privilege, - }, - }; - models::Credential { - service: (&x.service as &str).try_into().ok().unwrap_or(Service::SSH), - port: x.port.and_then(|x| x.parse().ok()), - credential_type: kind, + let privilege = find_key("priv_username", &x.credentials).map(|y| { + models::PrivilegeInformation { + username: y, + password: key("priv_password", &x.credentials), } - }) + }); + let kind = match &x.kind as &str { + "usk" => CredentialType::USK { + username, + password, + private_key: key("private", &x.credentials), + privilege, + }, + "snmp" => CredentialType::SNMP { + username, + password, + community: key("community", &x.credentials), + auth_algorithm: key("auth_algorithm", &x.credentials), + privacy_password: key("privacy_password", &x.credentials), + privacy_algorithm: key("privacy_algorithm", &x.credentials), + }, + _ => CredentialType::UP { + username, + password, + privilege, + }, + }; + models::Credential { + service: (&x.service as &str).try_into().ok().unwrap_or(Service::SSH), + port: x.port.and_then(|x| x.parse().ok()), + credential_type: kind, + } }) - .collect(); + .collect() + } +} + +impl From for models::Target { + fn from(val: Target) -> Self { + let credentials = val.credentials.map(|x| x.into()).unwrap_or_default(); models::Target { hosts: val.hosts, @@ -376,7 +381,6 @@ pub struct Credential { /// transform it to models::Credential pub credentials: Vec<(String, String)>, } -use serde::ser::SerializeMap; impl Serialize for Credential { fn serialize(&self, serializer: S) -> Result From fb7f58c2be652c74a2635bf62cb434c9ba9297b7 Mon Sep 17 00:00:00 2001 From: Philipp Eder Date: Thu, 9 Jan 2025 12:54:58 +0000 Subject: [PATCH 10/10] Rename ospd to osp, minor refactoring for clarity --- rust/adapted-full-and-fast.json | 0 rust/examples/double-fork2.nasl | 7 - rust/examples/if-assignment.nasl | 2 - rust/src/scannerctl/main.rs | 6 +- rust/src/scannerctl/{ospd => osp}/mod.rs | 74 ++++++----- .../scannerctl/{ospd => osp}/start_scan.rs | 0 ...n__test__pare_credential_without_port.snap | 37 ------ ..._scan__test__parse_without_credential.snap | 33 ----- ...tl__ospd__start_scan__test__parse_xml.snap | 38 ------ ...est__parse_xml_with_empty_credentials.snap | 34 ----- .../scannerctl__ospd__tests__print_back.snap | 38 ------ ...nnerctl__ospd__tests__print_scan_json.snap | 123 ------------------ 12 files changed, 41 insertions(+), 351 deletions(-) delete mode 100644 rust/adapted-full-and-fast.json delete mode 100644 rust/examples/double-fork2.nasl delete mode 100644 rust/examples/if-assignment.nasl rename rust/src/scannerctl/{ospd => osp}/mod.rs (86%) rename rust/src/scannerctl/{ospd => osp}/start_scan.rs (100%) delete mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__pare_credential_without_port.snap delete mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_without_credential.snap delete mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml.snap delete mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml_with_empty_credentials.snap delete mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_back.snap delete mode 100644 rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_scan_json.snap diff --git a/rust/adapted-full-and-fast.json b/rust/adapted-full-and-fast.json deleted file mode 100644 index e69de29bb..000000000 diff --git a/rust/examples/double-fork2.nasl b/rust/examples/double-fork2.nasl deleted file mode 100644 index efc7d9392..000000000 --- a/rust/examples/double-fork2.nasl +++ /dev/null @@ -1,7 +0,0 @@ -set_kb_item(name: "port", value: 1); -set_kb_item(name: "port", value: 2); -set_kb_item(name: "host", value: "a"); -set_kb_item(name: "host", value: "b"); - -a = get_kb_item("port") + ":" + get_kb_item("host"); -display(a); diff --git a/rust/examples/if-assignment.nasl b/rust/examples/if-assignment.nasl deleted file mode 100644 index cd21cca84..000000000 --- a/rust/examples/if-assignment.nasl +++ /dev/null @@ -1,2 +0,0 @@ -if (a = 1) display (a); -if ((a = 1)) display('a', a); diff --git a/rust/src/scannerctl/main.rs b/rust/src/scannerctl/main.rs index 575828605..7d3835fec 100644 --- a/rust/src/scannerctl/main.rs +++ b/rust/src/scannerctl/main.rs @@ -8,7 +8,7 @@ mod execute; mod feed; mod interpret; mod notusupdate; -mod ospd; +mod osp; mod scanconfig; mod syntax; @@ -62,7 +62,7 @@ async fn main() { ); let matches = syntax::extend_args(matches); let matches = scanconfig::extend_args(matches); - let matches = ospd::extend_args(matches); + let matches = osp::extend_args(matches); let matches = execute::extend_args(matches); let matches = notusupdate::scanner::extend_args(matches); let matches = feed::extend_args(matches).get_matches(); @@ -100,7 +100,7 @@ async fn run(matches: &ArgMatches) -> Result<(), CliError> { if let Some(result) = notusupdate::scanner::run(matches).await { return result; } - if let Some(result) = ospd::run(matches).await { + if let Some(result) = osp::run(matches).await { return result; } Err(CliError { diff --git a/rust/src/scannerctl/ospd/mod.rs b/rust/src/scannerctl/osp/mod.rs similarity index 86% rename from rust/src/scannerctl/ospd/mod.rs rename to rust/src/scannerctl/osp/mod.rs index e97d25c60..e2e21eb2c 100644 --- a/rust/src/scannerctl/ospd/mod.rs +++ b/rust/src/scannerctl/osp/mod.rs @@ -6,9 +6,9 @@ use std::io::BufRead; use std::{io::BufReader, path::PathBuf, sync::Arc}; use clap::{arg, value_parser, Arg, ArgAction, Command}; -use scannerlib::models::{Parameter, Scan, VT}; +use scannerlib::models::{self, Parameter, Scan, VT}; use scannerlib::storage::{self, DefaultDispatcher, StorageError}; -use start_scan::StartScan; +use start_scan::{StartScan, VtSelection}; use crate::{CliError, CliErrorKind}; use scannerlib::storage::item::{NVTField, NVTKey}; @@ -18,8 +18,8 @@ mod start_scan; pub fn extend_args(cmd: Command) -> Command { cmd.subcommand(crate::add_verbose( - Command::new("ospd") - .about("Transforms a ospd-start-scan xml to a scan json for openvasd. ") + Command::new("osp") + .about("Transforms a osp start-scan xml to a scan json for openvasd. ") .arg( arg!(-p --path "Path to the feed.") .required(false) @@ -37,7 +37,7 @@ pub fn extend_args(cmd: Command) -> Command { )) } -pub async fn may_start_scan( +pub async fn may_transform_start_scan( print_back: bool, feed: Option, reader: R, @@ -48,7 +48,7 @@ where { match quick_xml::de::from_reader(reader) { Ok(x) if print_back => Some(Ok(format!("{x}"))), - Ok(x) if feed.is_some() => Some(start_scan(feed.unwrap(), x).await), + Ok(x) if feed.is_some() => Some(transform_start_scan(feed.unwrap(), x).await), Ok(_) => Some(Err(CliErrorKind::MissingArguments( vec!["path".to_string()], ))), @@ -56,14 +56,11 @@ where } } -async fn start_scan(feed: S, sc: StartScan) -> Result +async fn transform_vts(feed: S, vts: VtSelection) -> Result, CliErrorKind> where S: storage::Retriever, { - // currently we ignore the previous order as the scanner will reorder - // when scheduling internally anyway. - let svts = sc - .vt_selection + let mut result: Vec<_> = vts .vt_single .into_iter() .flatten() @@ -78,26 +75,16 @@ where .collect(), }) .collect(); - let gvts = sc - .vt_selection - .vt_group - .into_iter() - .flatten() - .filter_map( - |x| match x.filter.split_once('=').map(|(k, v)| (k.trim(), v.trim())) { - Some(("family", v)) => Some(v.to_string()), - filter => { - tracing::warn!(?filter, "only family is supported, ignoring entry"); - None - } - }, - ); - let mut scan = Scan { - scan_id: sc.id.unwrap_or_default(), - scan_preferences: sc.scanner_params.values, - target: sc.targets.target.into(), - vts: svts, - }; + let gvts = vts.vt_group.into_iter().flatten().filter_map(|x| { + match x.filter.split_once('=').map(|(k, v)| (k.trim(), v.trim())) { + Some(("family", v)) => Some(v.to_string()), + filter => { + tracing::warn!(?filter, "only family is supported, ignoring entry"); + None + } + } + }); + // we iterate here to return an error when storage is behaving in an unexpected fashion for family in gvts { let fvts: Vec = match feed.retry_retrieve_by_field( @@ -120,9 +107,24 @@ where } Err(e) => return Err(e.into()), }; - scan.vts.extend(fvts); + result.extend(fvts); } - scan.vts.sort(); + result.sort(); + Ok(result) +} + +async fn transform_start_scan(feed: S, sc: StartScan) -> Result +where + S: storage::Retriever, +{ + // currently we ignore the previous order as the scanner will reorder + // when scheduling internally anyway. + let scan = Scan { + scan_id: sc.id.unwrap_or_default(), + scan_preferences: sc.scanner_params.values, + target: sc.targets.target.into(), + vts: transform_vts(feed, sc.vt_selection).await?, + }; let scan_json = match serde_json::to_string_pretty(&scan) { Ok(s) => s, Err(e) => return Err(e.into()), @@ -160,7 +162,7 @@ pub async fn run(root: &clap::ArgMatches) -> Option> { }; let print_back = args.get_one::("back").cloned().unwrap_or_default(); // currently we just support start scan if that changes chain the options. - let output = may_start_scan(print_back, feed, &mut bufreader).await; + let output = may_transform_start_scan(print_back, feed, &mut bufreader).await; let result = match output { Some(Ok(x)) => { println!("{x}"); @@ -241,7 +243,7 @@ mod tests { dispatch("2", "A"); dispatch("3", "A"); - let output = may_start_scan(false, Some(d), reader) + let output = may_transform_start_scan(false, Some(d), reader) .await .unwrap() .unwrap(); @@ -287,7 +289,7 @@ mod tests { "#; let reader = BufReader::new(Cursor::new(input)); - let output = may_start_scan::<_, DefaultDispatcher>(true, None, reader) + let output = may_transform_start_scan::<_, DefaultDispatcher>(true, None, reader) .await .unwrap() .unwrap(); diff --git a/rust/src/scannerctl/ospd/start_scan.rs b/rust/src/scannerctl/osp/start_scan.rs similarity index 100% rename from rust/src/scannerctl/ospd/start_scan.rs rename to rust/src/scannerctl/osp/start_scan.rs diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__pare_credential_without_port.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__pare_credential_without_port.snap deleted file mode 100644 index 174874017..000000000 --- a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__pare_credential_without_port.snap +++ /dev/null @@ -1,37 +0,0 @@ ---- -source: src/scannerctl/ospd/start_scan.rs -expression: sc ---- - - - - 127.0.0.1 - T:80-80,443-443 - - 1 - - localhost - - - PASSWORD - USER - - - - - - - - postgres - - - - - 0 - 5 - /cgi-bin:/scripts - 0 - - - - diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_without_credential.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_without_credential.snap deleted file mode 100644 index 88aca68f6..000000000 --- a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_without_credential.snap +++ /dev/null @@ -1,33 +0,0 @@ ---- -source: src/scannerctl/ospd/start_scan.rs -expression: sc ---- - - - - 127.0.0.1 - T:80-80,443-443 - - 1 - - localhost - localhost - - - - - - - postgres - - - - - 0 - 5 - /cgi-bin:/scripts - 0 - - - - diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml.snap deleted file mode 100644 index ec17357b5..000000000 --- a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml.snap +++ /dev/null @@ -1,38 +0,0 @@ ---- -source: src/scannerctl/ospd/start_scan.rs -expression: sc ---- - - - - 127.0.0.1 - T:80-80,443-443 - T:80-80,443-443 - - 1 - - localhost - - - PASSWORD - USER - - - - - - - - postgres - - - - - 0 - 5 - /cgi-bin:/scripts - 0 - - - - diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml_with_empty_credentials.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml_with_empty_credentials.snap deleted file mode 100644 index 7d9e6ea49..000000000 --- a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__start_scan__test__parse_xml_with_empty_credentials.snap +++ /dev/null @@ -1,34 +0,0 @@ ---- -source: src/scannerctl/ospd/start_scan.rs -expression: sc ---- - - - - 127.0.0.1 - T:80-80,443-443 - - 1 - - localhost - - - - - - - - - postgres - - - - - 0 - 5 - /cgi-bin:/scripts - 0 - - - - diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_back.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_back.snap deleted file mode 100644 index 2defc56fb..000000000 --- a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_back.snap +++ /dev/null @@ -1,38 +0,0 @@ ---- -source: src/scannerctl/ospd/mod.rs -expression: output ---- - - - - 127.0.0.1 - T:80-80,443-443 - T:80-80,443-443 - - 1 - - localhost - - - PASSWORD - USER - - - - - - - - postgres - - - - - 0 - 5 - /cgi-bin:/scripts - 0 - - - - diff --git a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_scan_json.snap b/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_scan_json.snap deleted file mode 100644 index 8c3e2ebaa..000000000 --- a/rust/src/scannerctl/ospd/snapshots/scannerctl__ospd__tests__print_scan_json.snap +++ /dev/null @@ -1,123 +0,0 @@ ---- -source: src/scannerctl/ospd/mod.rs -expression: output ---- -{ - "scan_id": "36389b56-f5a0-11e9-bba4-482ae354ac4c", - "target": { - "hosts": [ - "127.0.0.1" - ], - "ports": [ - { - "protocol": "tcp", - "range": [ - { - "start": 80, - "end": 80 - } - ] - }, - { - "protocol": "tcp", - "range": [ - { - "start": 443, - "end": 443 - } - ] - } - ], - "excluded_hosts": [ - "localhost" - ], - "credentials": [ - { - "service": "ssh", - "port": 22, - "up": { - "username": "USER", - "password": "PASSWORD" - } - } - ], - "alive_test_ports": [ - { - "protocol": "tcp", - "range": [ - { - "start": 80, - "end": 80 - } - ] - }, - { - "protocol": "tcp", - "range": [ - { - "start": 443, - "end": 443 - } - ] - } - ], - "alive_test_methods": [ - "icmp" - ], - "reverse_lookup_unify": null, - "reverse_lookup_only": null - }, - "scan_preferences": [ - { - "id": "use_mac_addr", - "value": "0" - }, - { - "id": "checks_read_timeout", - "value": "5" - }, - { - "id": "cgi_path", - "value": "/cgi-bin:/scripts" - }, - { - "id": "time_between_request", - "value": "0" - }, - { - "id": "vhosts_ip", - "value": "" - }, - { - "id": "vhosts", - "value": "" - } - ], - "vts": [ - { - "oid": "0", - "parameters": [] - }, - { - "oid": "1", - "parameters": [] - }, - { - "oid": "1.3.6.1.4.1.25623.1.0.100151", - "parameters": [ - { - "id": 1, - "value": "postgres" - } - ] - }, - { - "oid": "2", - "parameters": [] - }, - { - "oid": "3", - "parameters": [] - } - ] -}