Skip to content

Commit

Permalink
Change: use [{"start": 22, "end": 24}] to define a port range inste…
Browse files Browse the repository at this point in the history
…ad of 22-24

To improve the readability and structure of port ranges, we have made a change.
Instead of using a string to indicate a port range of 22-24, we will now define
 it as a structured object: [{"start": 22, "end": 24}]. Both the start and end
 ports are inclusive. If the end port is not provided, only the start port will
 be used.
  • Loading branch information
nichtsfrei committed May 3, 2023
1 parent ece68df commit 4271973
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
21 changes: 14 additions & 7 deletions rust/doc/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,15 @@ components:
- udp
- tcp
range:
description: "A comma separated list of port options. A port option is either a single port or a port range given with two numbers with a hyphen."
type: "string"
description: "A list of ranges, start and end are inclusive."
type: "object"
properties:
start:
type: "number"
description: "The inclusive start port. When end is not set only the start port is used"
end:
type: "number"
description: "The inclusive end port."
required:
- range

Expand Down Expand Up @@ -648,7 +655,7 @@ components:
description: "A simple example for creating a scan."
value:
{
"target": { "hosts": ["127.0.0.1"], "ports": [{ "range": "22" }] },
"target": { "hosts": ["127.0.0.1"], "ports": [{ "range": [{ "start": 22}] }] },
"vts": [{ "oid": "1.3.6.1.4.1.25623.1.0.10267" }],
}
scan_full:
Expand All @@ -670,9 +677,9 @@ components:
],
"ports":
[
{ "protocol": "udp", "range": "22, 1024-1030" },
{ "protocol": "tcp", "range": "24-30" },
{ "range": "100-1000" },
{ "protocol": "udp", "range": [{"start": 22}, {"start": 1024, "end": 1030}] },
{ "protocol": "tcp", "range": [{"start": 24, "end": 30 }]},
{ "range": [{"start": 100, "end": 1000 }]},
],
"credentials":
[
Expand Down Expand Up @@ -704,7 +711,7 @@ components:
},
],
"alive_test_ports":
[{ "protocol": "tcp", "range": "1-100" }, { "range": "443" }],
[{ "protocol": "tcp", "range": [ {"start": 1, "end": 100 }]}, { "range": [{"start": 443}] }],
"alive_test_methods":
["icmp", "tcp_syn", "tcp_ack", "arp", "consider_alive"],
"reverse_lookup_unify": true,
Expand Down
14 changes: 7 additions & 7 deletions rust/models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use target::*;
pub use vt::*;

#[cfg(test)]
#[cfg(feature = "serde_support")]
//#[cfg(feature = "serde_support")]
mod tests {
use super::scan::Scan;

Expand All @@ -36,7 +36,7 @@ mod tests {
],
"ports": [
{
"range": "22"
"range": [{"start": 22}]
}
]
},
Expand Down Expand Up @@ -68,14 +68,14 @@ mod tests {
"ports": [
{
"protocol": "udp",
"range": "22,1024-1030"
"range": [{"start": 22}, {"start": 1024, "end": 1030}]
},
{
"protocol": "tcp",
"range": "24-30"
"range": [{"start": 24, "end": 30}]
},
{
"range": "100-1000"
"range": [{"start": 100, "end": 1000}]
}
],
"credentials": [
Expand Down Expand Up @@ -110,10 +110,10 @@ mod tests {
"alive_test_ports": [
{
"protocol": "tcp",
"range": "1-100"
"range": [{"start": 1, "end": 100}]
},
{
"range": "443"
"range": [{ "start": 443 }]
}
],
"alive_test_methods": [
Expand Down
27 changes: 24 additions & 3 deletions rust/models/src/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,30 @@ pub struct Port {
)]
/// Protocol for the given port range. If empty, prot range applies to UDP and TCP
pub protocol: Option<Protocol>,
/// Range for ports to scan. A range is defined by
/// range => <number>[-<number>][,<range>]
pub range: String,
/// Range for ports to scan.
pub range: Vec<PortRange>,
}

/// Range for ports to scan.
#[derive(Debug, Clone)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize)
)]
pub struct PortRange {
/// The required start port.
///
/// It is an inclusive range.
pub start: usize,
/// The optional end port.
///
/// It is an inclusive range.
/// When the end port is not set, only the start port is used.
#[cfg_attr(
feature = "serde_support",
serde(skip_serializing_if = "Option::is_none")
)]
pub end: Option<usize>,
}

/// Enum representing the protocol used for scanning a port.
Expand Down

0 comments on commit 4271973

Please sign in to comment.