Skip to content

Commit 9ccaebb

Browse files
committed
Add: entrypoint for Scan Preferences to openvasd
It is now possible to reach the entrypoint /scans/preferences to get a list of all preferences available for a scan. All available preferences are hardcoded, as they are static.
1 parent c5051ae commit 9ccaebb

File tree

8 files changed

+287
-3
lines changed

8 files changed

+287
-3
lines changed

doc/manual/openvas/openvas.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ checks_read_timeout
166166

167167
timeout_retry
168168

169-
: Number of retries when a socket connection attempt timesout.
169+
: Number of retries when a socket connection attempt times out.
170170

171171
open_sock_max_attempts
172172

@@ -202,7 +202,7 @@ non_simult_ports
202202
connections at the same time coming from the same host. This option
203203
allows you to prevent openvas to make two connections on the same
204204
given ports at the same time. The syntax of this option is
205-
\"port1\[, port2\....\]\". Note that you can use the KB notation of
205+
\"port1\[, port2\...\]\". Note that you can use the KB notation of
206206
openvas to designate a service formally. Ex: \"139, Services/www\",
207207
will prevent openvas from making two connections at the same time on
208208
port 139 and on every port which hosts a web server.

rust/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/models/src/scanner_preference.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,36 @@ pub struct ScanPreference {
1414
/// The value of the scanner preference.
1515
pub value: String,
1616
}
17+
18+
/// Preference value
19+
#[derive(Debug, Clone, PartialEq, Eq)]
20+
#[cfg_attr(
21+
feature = "serde_support",
22+
derive(serde::Serialize, serde::Deserialize),
23+
serde(untagged)
24+
)]
25+
pub enum PreferenceValue {
26+
Bool(bool),
27+
Int(i64),
28+
String(&'static str),
29+
}
30+
31+
impl Default for PreferenceValue {
32+
fn default() -> Self {
33+
Self::Int(0)
34+
}
35+
}
36+
37+
/// Configuration preference information for a scan. The type can be derived from the default value.
38+
#[derive(Default, Debug, Clone, PartialEq, Eq)]
39+
#[cfg_attr(feature = "serde_support", derive(serde::Serialize))]
40+
pub struct ScanPreferenceInformation {
41+
/// The ID of the scan preference
42+
pub id: &'static str,
43+
/// Display name of the scan preference
44+
pub name: &'static str,
45+
/// The value of the scan preference
46+
pub default: PreferenceValue,
47+
/// Description of the scan preference
48+
pub description: &'static str,
49+
}

rust/openvasd/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ hyper-util = { version = "0", features = ["tokio"] }
4040
http-body-util = "0.1.0"
4141
http-body = "1"
4242
sysinfo = "0.30.5"
43+
lazy_static = "1.4.0"
4344

4445
[dev-dependencies]
4546
tracing-test = "0.1"

rust/openvasd/src/controller/entry.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ enum HealthOpts {
3434
enum KnownPaths {
3535
/// /scans/{id}
3636
Scans(Option<String>),
37+
/// /scans/preferences
38+
ScanPreferences,
3739
/// /scans/{id}/results/{result_id}
3840
ScanResults(String, Option<String>),
3941
/// /scans/{id}/status
@@ -72,7 +74,13 @@ impl KnownPaths {
7274
),
7375
Some("status") => KnownPaths::ScanStatus(id.to_string()),
7476
Some(_) => KnownPaths::Unknown,
75-
None => KnownPaths::Scans(Some(id.to_string())),
77+
None => {
78+
if id == "preferences" {
79+
KnownPaths::ScanPreferences
80+
} else {
81+
KnownPaths::Scans(Some(id.to_string()))
82+
}
83+
}
7684
},
7785
None => KnownPaths::Scans(None),
7886
}
@@ -129,6 +137,7 @@ impl Display for KnownPaths {
129137
KnownPaths::Health(HealthOpts::Alive) => write!(f, "/health/alive"),
130138
KnownPaths::Health(HealthOpts::Ready) => write!(f, "/health/ready"),
131139
KnownPaths::Health(HealthOpts::Started) => write!(f, "/health/started"),
140+
KnownPaths::ScanPreferences => write!(f, "/scans/preferences"),
132141
}
133142
}
134143
}
@@ -335,6 +344,9 @@ where
335344
Ok(ctx.response.not_found("scans", "all"))
336345
}
337346
}
347+
(&Method::GET, ScanPreferences) => Ok(ctx
348+
.response
349+
.ok_static(&crate::preference::PREFERENCES_JSON.as_bytes())),
338350
(&Method::GET, Scans(Some(id))) => match ctx.scheduler.get_scan(&id).await {
339351
Ok((mut scan, _)) => {
340352
let credentials = scan

rust/openvasd/src/controller/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,24 @@ mod tests {
287287
assert_eq!(resp.headers().get("authentication").unwrap(), "");
288288
}
289289

290+
#[tokio::test]
291+
async fn get_scan_preferences() {
292+
let controller = Arc::new(Context::default());
293+
let req = Request::builder()
294+
.uri("/scans/preferences")
295+
.method(Method::GET)
296+
.body(Empty::<Bytes>::new())
297+
.unwrap();
298+
let cid = Arc::new(ClientIdentifier::Known("42".into()));
299+
entrypoint(req, Arc::clone(&controller), cid)
300+
.await
301+
.unwrap()
302+
.into_body()
303+
.collect()
304+
.await
305+
.unwrap();
306+
}
307+
290308
async fn get_scan_status<S, DB>(id: &str, ctx: Arc<Context<S, DB>>) -> crate::response::Result
291309
where
292310
S: Scanner + 'static + std::marker::Send + std::marker::Sync,

rust/openvasd/src/preference.rs

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
use lazy_static::lazy_static;
2+
use models::{PreferenceValue, ScanPreferenceInformation};
3+
4+
pub const PREFERENCES: [ScanPreferenceInformation; 22] = [
5+
ScanPreferenceInformation {
6+
id: "auto_enable_dependencies",
7+
name: "Automatic Enable Dependencies",
8+
default: PreferenceValue::Bool(true),
9+
description: "OpenVAS plugins use the result of each other to execute their job. For \
10+
instance, a plugin which logs into the remote SMB registry will need the results of the \
11+
plugin which finds the SMB name of the remote host and the results of the plugin which \
12+
attempts to log into the remote host. If you want to only select a subset of the plugins \
13+
available, tracking the dependencies can quickly become tiresome. If you set this option \
14+
to 'yes', openvas will automatically enable the plugins that are depended on.",
15+
},
16+
ScanPreferenceInformation {
17+
id: "cgi_path",
18+
name: "CGI Path",
19+
default: PreferenceValue::String("/cgi-bin:/scripts"),
20+
description: "By default, openvas looks for default CGIs in /cgi-bin and /scripts. \
21+
You may change these to something else to reflect the policy of your \
22+
site. The syntax of this option is the same as the shell $PATH \
23+
variable: path1:path2:...",
24+
},
25+
ScanPreferenceInformation {
26+
id: "checks_read_timeout",
27+
name: "Checks Read Timeout",
28+
default: PreferenceValue::Int(5),
29+
description: "Number of seconds that the security checks will wait for when doing \
30+
a recv(). You should increase this value if you are running openvas \
31+
across a slow network slink (testing a host via a dialup connection \
32+
for instance)",
33+
},
34+
ScanPreferenceInformation {
35+
id: "non_simult_ports",
36+
name: "Non simultaneous ports",
37+
default: PreferenceValue::String("139, 445, 3389, Services/irc"),
38+
description: "Some services (in particular SMB) do not appreciate multiple \
39+
connections at the same time coming from the same host. This option \
40+
allows you to prevent openvas to make two connections on the same \
41+
given ports at the same time. The syntax of this option is \
42+
'port1[, port2...]'. Note that you can use the KB notation of \
43+
openvas to designate a service formally. Ex: '139, Services/www', \
44+
will prevent openvas from making two connections at the same time on \
45+
port 139 and on every port which hosts a web server.",
46+
},
47+
ScanPreferenceInformation {
48+
id: "open_sock_max_attempts",
49+
name: "Maximum Attempts to open Sockets",
50+
default: PreferenceValue::Int(5),
51+
description: "When a port is found as opened at the beginning of the scan, and for \
52+
some reason the status changes to filtered/closed, it will not be \
53+
possible to open a socket. This is the number of unsuccessful \
54+
retries to open the socket before to set the port as closed. This \
55+
avoids to launch plugins which need the opened port as a mandatory \
56+
key, therefore it avoids an overlong scan duration. If the set value \
57+
is 0 or a negative value, this option is disabled. It should be take \
58+
in account that one unsuccessful attempt needs the number of retries \
59+
set in 'Socket timeout retry'.",
60+
},
61+
ScanPreferenceInformation {
62+
id: "timeout_retry",
63+
name: "Socket timeout retry",
64+
default: PreferenceValue::Int(5),
65+
description: "Number of retries when a socket connection attempt times out. This option \
66+
ist different from 'Maximum Attempts to open Sockets', as after the number of retries \
67+
here is reached it counts as a single attempt for open the socket.",
68+
},
69+
ScanPreferenceInformation {
70+
id: "optimize_test",
71+
name: "Optimize Test",
72+
default: PreferenceValue::Bool(true),
73+
description: "By default, optimize_test is enabled which means openvas does trust \
74+
the remote host banners and is only launching plugins against the \
75+
services they have been designed to check. For example it will check \
76+
a web server claiming to be IIS only for IIS related flaws but will \
77+
skip plugins testing for Apache flaws, and so on. This default \
78+
behavior is used to optimize the scanning performance and to avoid \
79+
false positives. If you are not sure that the banners of the remote \
80+
host have been tampered with, you can disable this option.",
81+
},
82+
ScanPreferenceInformation {
83+
id: "plugins_timeout",
84+
name: "Plugins Timeout",
85+
default: PreferenceValue::Int(5),
86+
description: "This is the maximum lifetime, in seconds of a plugin. It may happen \
87+
that some plugins are slow because of the way they are written or \
88+
the way the remote server behaves. This option allows you to make \
89+
sure your scan is never caught in an endless loop because of a \
90+
non-finishing plugin. Doesn't affect ACT_SCANNER plugins, use \
91+
'ACT_SCANNER plugins timeout' for them instead.",
92+
},
93+
ScanPreferenceInformation {
94+
id: "report_host_details",
95+
name: "Report Host Details",
96+
default: PreferenceValue::Bool(true),
97+
description: "Host Details are general Information about a Host collected during a scan. \
98+
These are used internally for plugins, but it is also possible to report these \
99+
as results. In order for this option to work the Plugin 'Host Details' with the OID \
100+
1.3.6.1.4.1.25623.1.0.103997 must also be in the VTs list, as this plugin is responsible \
101+
for doing the actual reporting.",
102+
},
103+
ScanPreferenceInformation {
104+
id: "safe_checks",
105+
name: "Safe Checks",
106+
default: PreferenceValue::Bool(true),
107+
description: "Most of the time, openvas attempts to reproduce an exceptional \
108+
condition to determine if the remote services are vulnerable to \
109+
certain flaws. This includes the reproduction of buffer overflows or \
110+
format strings, which may make the remote server crash. If you set \
111+
this option to 'true', openvas will disable the plugins which have \
112+
the potential to crash the remote services, and will at the same \
113+
time make several checks rely on the banner of the service tested \
114+
instead of its behavior towards a certain input. This reduces false \
115+
positives and makes openvas nicer towards your network, however this \
116+
may make you miss important vulnerabilities (as a vulnerability \
117+
affecting a given service may also affect another one).",
118+
},
119+
ScanPreferenceInformation {
120+
id: "scanner_plugins_timeout",
121+
name: "ACT_SCANNER plugins timeout",
122+
default: PreferenceValue::Int(36000),
123+
description: "Like 'Plugins Timeout', but for ACT_SCANNER plugins.",
124+
},
125+
ScanPreferenceInformation {
126+
id: "time_between_request",
127+
name: "Time between Requests",
128+
default: PreferenceValue::Int(0),
129+
description: "Some devices do not appreciate quick connection establishment and \
130+
termination neither quick request. This option allows you to set a \
131+
wait time between two actions like to open a tcp socket, to send a \
132+
request through the open tcp socket, and to close the tcp socket. \
133+
This value should be given in milliseconds. If the set value is 0 \
134+
(default value), this option is disabled and there is no wait time \
135+
between requests.",
136+
},
137+
ScanPreferenceInformation {
138+
id: "unscanned_closed",
139+
name: "Close unscanned Port TCP",
140+
default: PreferenceValue::Bool(true),
141+
description: "This defines whether TCP ports that were not scanned should be treated like closed ports.",
142+
},
143+
ScanPreferenceInformation {
144+
id: "unscanned_closed_udp",
145+
name: "Close unscanned Port UDP",
146+
default: PreferenceValue::Bool(true),
147+
description: "This defines whether UDP ports that were not scanned should be treated as closed ports.",
148+
},
149+
ScanPreferenceInformation {
150+
id: "expand_vhosts",
151+
name: "Expand VHosts",
152+
default: PreferenceValue::Bool(true),
153+
description: "Whether to expand the target host's list of vhosts with values \
154+
gathered from sources such as reverse-lookup queries and VT checks \
155+
for SSL/TLS certificates.",
156+
},
157+
ScanPreferenceInformation {
158+
id: "test_empty_vhost",
159+
name: "Test Empty VHost",
160+
default: PreferenceValue::Bool(false),
161+
description: "If set to yes, the scanner will also test the target by using empty \
162+
vhost value in addition to the target's associated vhost values.",
163+
},
164+
ScanPreferenceInformation {
165+
id: "alive_test_ports",
166+
name: "Alive Test Ports",
167+
default: PreferenceValue::String(
168+
"21-23,25,53,80,110-111,135,139,143,443,445,993,995,1723,3306,3389,5900,8080",
169+
),
170+
description: "Preference to set the port list for the TCP SYN and TCP ACK alive test \
171+
methods.",
172+
},
173+
ScanPreferenceInformation {
174+
id: "test_alive_hosts_only",
175+
name: "Test Alive Hosts Only",
176+
default: PreferenceValue::Bool(false),
177+
description: "If this option is set to 'true', openvas will scan the target list \
178+
for alive hosts in a separate process while only testing those hosts \
179+
which are identified as alive. This boosts the scan speed of target \
180+
ranges with a high amount of dead hosts significantly.",
181+
},
182+
ScanPreferenceInformation {
183+
id: "test_alive_wait_timeout",
184+
name: "Alive Test Timeout",
185+
default: PreferenceValue::Int(1),
186+
description: "This option is to set how long (in sec) Boreas (alive test) waits for \
187+
replies after last packet was sent.",
188+
},
189+
ScanPreferenceInformation {
190+
id: "table_driven_lsc",
191+
name: "Table Driven LSC",
192+
default: PreferenceValue::Bool(true),
193+
description: "This option will enable table driven local security Checks (LSC). This means \
194+
gathered packages are sent to an specialized scanner. This is far more efficient than doing \
195+
checks via NASL.",
196+
},
197+
ScanPreferenceInformation {
198+
id: "dry_run",
199+
name: "Dry Run",
200+
default: PreferenceValue::Bool(false),
201+
description: "A dry run is a simulated scan, with no actual host scanned. This mode \
202+
is useful for automated testing and also to check up, if the setup is actually working.",
203+
},
204+
ScanPreferenceInformation {
205+
id: "results_per_host",
206+
name: "Results per Host",
207+
default: PreferenceValue::Int(10),
208+
description: "Amount of fake results generated per each host in the target \
209+
list for a dry run scan.",
210+
},
211+
];
212+
213+
lazy_static! {
214+
pub static ref PREFERENCES_JSON: String = serde_json::to_string(&PREFERENCES).unwrap();
215+
}

rust/openvasd/src/response.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ impl Response {
263263
self.create(hyper::StatusCode::OK, value)
264264
}
265265

266+
pub fn ok_static(&self, value: &[u8]) -> Result {
267+
self.ok_json_response(BodyKind::Binary(value.to_vec().into()))
268+
}
269+
266270
pub fn created<T>(&self, value: &T) -> Result
267271
where
268272
T: ?Sized + Serialize + std::fmt::Debug,

0 commit comments

Comments
 (0)