Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Adjust scanner preferences #1615

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions rust/doc/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,9 @@ components:
properties:
target:
$ref: "#/components/schemas/Target"
scanner_preferences:
description: "Overwrite the default settings of the Scanner."
type: "array"
items:
$ref: "#/components/schemas/ScannerPreference"
scan_preferences:
description: "Overwrite the default settings for a scan. Setting are id-value pairs."
type: "object"
vts:
type: "array"
description: "A collection of VTs, which are run for the given target."
Expand All @@ -445,11 +443,11 @@ components:
$ref: "#/components/schemas/ScanID"
target:
$ref: "#/components/schemas/Target"
scanner_preferences:
scan_preferences:
description: "Overwrite the default settings of the Scanner."
type: "array"
items:
$ref: "#/components/schemas/ScannerPreference"
$ref: "#/components/schemas/ScanPreference"
vts:
type: "array"
description: "A collection of VTs, which are run for the given target."
Expand Down Expand Up @@ -634,7 +632,7 @@ components:
- aes
- des

ScannerPreference:
ScanPreference:
description: "Consists of a preference ID and its value."
type: "object"
properties:
Expand Down Expand Up @@ -897,10 +895,7 @@ components:
"2002::1234:abcd:ffff:c0a8:101/64",
"examplehost",
],
"excluded_hosts":
[
"192.168.0.14"
],
"excluded_hosts": ["192.168.0.14"],
"ports":
[
{
Expand Down Expand Up @@ -949,12 +944,12 @@ components:
"reverse_lookup_unify": true,
"reverse_lookup_only": false,
},
"scanner_preferences":
[
{ "id": "target_port", "value": "443" },
{ "id": "use_https", "value": "1" },
{ "id": "profile", "value": "fast_scan" },
],
"scan_preferences":
{
"target_port": 443,
"use_https": true,
"cgi_path": "/cgi-bin:/scripts",
},
"vts":
[
{
Expand Down Expand Up @@ -1030,7 +1025,7 @@ components:
"reverse_lookup_unify": true,
"reverse_lookup_only": false,
},
"scanner_preferences":
"scan_preferences":
[
{ "id": "target_port", "value": "443" },
{ "id": "use_https", "value": "1" },
Expand Down
69 changes: 32 additions & 37 deletions rust/doc/reverse-sensor-openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,22 +152,22 @@ paths:
parameters:
- $ref: "#/components/parameters/ScanID"
requestBody:
description: "The new status"
content:
application/json:
description: "The new status"
content:
application/json:
schema:
$ref: "#/components/schemas/Status"
examples:
schema:
$ref: "#/components/schemas/Status"
examples:
schema:
description: "Schema of a status response."
status of a stored scan:
$ref: "#/components/examples/scan_status_stored"
status of a running scan:
$ref: "#/components/examples/scan_status_running"
status of a succeeded scan:
$ref: "#/components/examples/scan_status_success"
status of a failed scan:
$ref: "#/components/examples/scan_status_fail"
description: "Schema of a status response."
status of a stored scan:
$ref: "#/components/examples/scan_status_stored"
status of a running scan:
$ref: "#/components/examples/scan_status_running"
status of a succeeded scan:
$ref: "#/components/examples/scan_status_success"
status of a failed scan:
$ref: "#/components/examples/scan_status_fail"
responses:
"204":
description: "Status received"
Expand Down Expand Up @@ -228,11 +228,9 @@ components:
$ref: "#/components/schemas/ScanID"
target:
$ref: "#/components/schemas/Target"
scanner_preferences:
description: "Overwrite the default settings of the Scanner."
type: "array"
items:
$ref: "#/components/schemas/ScannerPreference"
scan_preferences:
description: "Overwrite the default settings for a scan. Setting are id-value pairs."
type: "object"
vts:
type: "array"
description: "A collection of VTs, which are run for the given target."
Expand Down Expand Up @@ -396,7 +394,7 @@ components:
- aes
- des

ScannerPreference:
ScanPreference:
description: "Consists of a preference ID and its value."
type: "object"
properties:
Expand Down Expand Up @@ -573,14 +571,10 @@ components:
items:
$ref: "#/components/schemas/ScanAction"


examples:
sensor_simple:
description: "A simple example for sensor."
value:
{
"sensor_id": "6c591f83-8f7b-452a-8c78-ba35779e682f"
}
value: { "sensor_id": "6c591f83-8f7b-452a-8c78-ba35779e682f" }
scan_simple:
description: "A simple example for creating a scan."
value:
Expand Down Expand Up @@ -656,12 +650,12 @@ components:
"reverse_lookup_unify": true,
"reverse_lookup_only": false,
},
"scanner_preferences":
[
{ "id": "target_port", "value": "443" },
{ "id": "use_https", "value": "1" },
{ "id": "profile", "value": "fast_scan" },
],
"scan_preferences":
{
"target_port": 443,
"use_https": true,
"cgi_path": "/cgi-bin:/scripts",
},
"vts":
[
{
Expand All @@ -677,19 +671,20 @@ components:
value: "6c591f83-8f7b-452a-8c78-ba35779e682f"
scan_actions:
description: "Actions to perform"
value: [
value:
[
{
"scan_id": "6c591f83-8f7b-452a-8c78-ba35779e682f",
"action": "start"
"action": "start",
},
{
"scan_id": "24591f83-8f7b-452a-8c78-ba35779e6816",
"action": "stop"
"action": "stop",
},
{
"scan_id": "13591f83-8f74-45da-8c7d-ba35779e682a",
"action": "delete"
}
"action": "delete",
},
]

scan_results:
Expand Down
23 changes: 7 additions & 16 deletions rust/models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ mod product;
mod result;
mod scan;
mod scan_action;
mod scan_preference;
pub mod scanner;
mod scanner_preference;
mod status;
mod target;
mod vt;
Expand All @@ -26,7 +26,7 @@ pub use product::*;
pub use result::*;
pub use scan::*;
pub use scan_action::*;
pub use scanner_preference::*;
pub use scan_preference::*;
pub use status::*;
pub use target::*;
pub use vt::*;
Expand Down Expand Up @@ -137,20 +137,11 @@ mod tests {
"reverse_lookup_unify": true,
"reverse_lookup_only": false
},
"scanner_preferences": [
{
"id": "target_port",
"value": "443"
},
{
"id": "use_https",
"value": "1"
},
{
"id": "profile",
"value": "fast_scan"
}
],
"scan_preferences": {
"target_port": 443,
"use_https": true,
"cgi_path": "/cgi-bin:/scripts"
},
"vts": [
{
"oid": "1.3.6.1.4.1.25623.1.0.10662",
Expand Down
11 changes: 8 additions & 3 deletions rust/models/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
//
// SPDX-License-Identifier: GPL-2.0-or-later

use super::{scanner_preference::ScannerPreference, target::Target, vt::VT};
use std::collections::HashMap;

use super::{scan_preference::PreferenceValue, target::Target, vt::VT};

/// Struct for creating and getting a scan
#[derive(Default, Debug, Clone, PartialEq, Eq)]
Expand All @@ -17,9 +19,12 @@ pub struct Scan {
pub scan_id: String,
/// Information about the target to scan
pub target: Target,
#[cfg_attr(feature = "serde_support", serde(default))]
#[cfg_attr(
feature = "serde_support",
serde(default, alias = "scanner_preferences")
)]
/// Configuration options for the scanner
pub scanner_preferences: Vec<ScannerPreference>,
pub scan_preferences: HashMap<String, PreferenceValue>,
/// List of VTs to execute for the target
pub vts: Vec<VT>,
}
34 changes: 34 additions & 0 deletions rust/models/src/scan_preference.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2023 Greenbone AG
//
// SPDX-License-Identifier: GPL-2.0-or-later

use std::fmt::Display;

/// Preference value
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize),
serde(untagged)
)]
pub enum PreferenceValue {
Bool(bool),
Int(i64),
String(String),
}

impl Default for PreferenceValue {
fn default() -> Self {
Self::Int(0)
}
}

impl Display for PreferenceValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
PreferenceValue::Bool(v) => write!(f, "{v}"),
PreferenceValue::Int(v) => write!(f, "{v}"),
PreferenceValue::String(v) => write!(f, "{v}"),
}
}
}
16 changes: 0 additions & 16 deletions rust/models/src/scanner_preference.rs

This file was deleted.

4 changes: 2 additions & 2 deletions rust/openvas/src/pref_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ where
async fn prepare_scan_params_for_openvas(&mut self) -> RedisStorageResult<()> {
let options = self
.scan_config
.scanner_preferences
.scan_preferences
.clone()
.iter()
.map(|x| format!("{}|||{}", x.id, x.value))
.map(|x| format!("{}|||{}", x.0, x.1))
.collect::<Vec<String>>();

if options.is_empty() {
Expand Down
1 change: 1 addition & 0 deletions rust/openvasd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod controller;
pub mod crypt;
pub mod feed;
pub mod notus;
pub mod preference;
pub mod request;
pub mod response;
mod scheduling;
Expand Down
10 changes: 5 additions & 5 deletions rust/osp/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ fn write_vts(scan: &Scan, writer: &mut Writer) -> Result<()> {
})
}

// In the openvasd API it is called scanner preferences while in the OSP side
// In the openvasd API it is called scan preferences while in the OSP side
// it is called scanner parameters.
fn write_scanner_prefs(scan: &Scan, writer: &mut Writer) -> Result<()> {
writer.write_event(Event::Start(BytesStart::new("scanner_params")))?;
for p in &scan.scanner_preferences {
writer.write_event(Event::Start(BytesStart::new(&p.id)))?;
writer.write_event(Event::Text(BytesText::new(&p.value)))?;
writer.write_event(Event::End(BytesEnd::new(&p.id)))?;
for p in &scan.scan_preferences {
writer.write_event(Event::Start(BytesStart::new(p.0)))?;
writer.write_event(Event::Text(BytesText::new(p.1.to_string().as_str())))?;
writer.write_event(Event::End(BytesEnd::new(p.0)))?;
}

writer.write_event(Event::End(BytesEnd::new("scanner_params")))?;
Expand Down
Loading