Skip to content

Commit

Permalink
Fix: use the right method to get vts from nvticache (#1684)
Browse files Browse the repository at this point in the history
* Fix: use the right method to get vts from nvticache

* Fix: format for date. Use always int instead of strings for timestamp, as notus does

* Fix: clippy warnings
  • Loading branch information
jjnicola authored Jul 29, 2024
1 parent e4d9526 commit cab57e3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions rust/feed/src/transpile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ trait Matcher {
fn matches(&self, s: &Statement) -> bool;
}

#[allow(dead_code)]
#[derive(Clone, Debug)]
struct CallMatcher {}

impl Matcher for CallMatcher {
fn matches(&self, s: &Statement) -> bool {
// Although Exit and Include are handled differently they share the call nature and hence
Expand Down
1 change: 1 addition & 0 deletions rust/nasl-builtin-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ impl NaslHttp {
/// nasl named param
/// - handle The handle identifier
/// - header_item A string to add to the header
///
/// On success the function returns an integer. 0 on success. Null on error.
fn set_custom_header(
&self,
Expand Down
5 changes: 3 additions & 2 deletions rust/nasl-builtin-raw-ip/src/frame_forgery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ fn nasl_get_local_mac_address_from_ip(
///This function forges a datalink layer frame.
/// - src_haddr: is a string containing the source MAC address
/// - dst_haddr: is a string containing the destination MAC address
/// -ether_proto: is an int containing the ethernet type (normally given as hexadecimal). It is optional and its default value is 0x0800. A list of Types can be e.g. looked up here.
/// -payload: is any data, which is then attached as payload to the frame.
/// - ether_proto: is an int containing the ethernet type (normally given as hexadecimal).
/// It is optional and its default value is 0x0800. A list of Types can be e.g. looked up here.
/// - payload: is any data, which is then attached as payload to the frame.
fn nasl_forge_frame(register: &Register, _: &Context) -> Result<NaslValue, FunctionErrorKind> {
let src_haddr = validate_mac_address(register.named("src_haddr"))?;
let dst_haddr = validate_mac_address(register.named("dst_haddr"))?;
Expand Down
2 changes: 1 addition & 1 deletion rust/nasl-builtin-raw-ip/src/packet_forgery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ fn format_flags(pkt: &TcpPacket) -> String {
/// - uh_sum: is the UDP checksum. Although it is not compulsory, the right value is computed by default.
/// - uh_ulen: is the data length. By default it is set to the length the data argument plus the size of the UDP header.
/// - update_ip_len: is a flag (TRUE by default). If set, NASL will recompute the size field of the IP datagram.

///
/// Returns the modified IP datagram or NULL on error.
fn forge_udp_packet(
register: &Register,
Expand Down
5 changes: 3 additions & 2 deletions rust/nasl-builtin-ssh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ impl Ssh {
/// - scciphers SSH server-to-client ciphers.
///
/// - timeout Set a timeout for the connection in seconds. Defaults to 10
/// seconds (defined by libssh internally) if not given.
/// seconds (defined by libssh internally) if not given.
///
/// nasl return An integer to identify the ssh session. Zero on error.
fn nasl_ssh_connect(
Expand Down Expand Up @@ -1208,7 +1208,7 @@ impl Ssh {
///
/// nasl named params
/// - timeout: Enable the blocking ssh read until it gives the timeout or there is no
/// bytes left to read.
/// bytes left to read.
///
/// return A string on success or NULL on error.
fn nasl_ssh_shell_read(
Expand Down Expand Up @@ -1942,6 +1942,7 @@ impl Ssh {
///
/// nasluparam
/// - An SSH session id.
///
/// naslret An int on success or NULL on error.
///
/// param[in] lexic Lexical context of NASL interpreter.
Expand Down
4 changes: 2 additions & 2 deletions rust/openvasd/src/storage/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ where
let url = self.url.to_string();
let nr = tokio::task::spawn_blocking(move || {
let mut nvt_redis = RedisCtx::open(&url, FEEDUPDATE_SELECTOR)?;
nvt_redis.redis_get_advisory(&aoid)
nvt_redis.redis_get_vt(&aoid)
})
.await
.unwrap()?;
Expand Down Expand Up @@ -243,7 +243,7 @@ where
.keys("nvt:*")?
.into_iter()
.filter_map(|x| x.split('/').last().map(|x| x.to_string()))
.filter_map(move |oid| nvt_redis.redis_get_vt(&oid).ok())
.filter_map(move |oid| nvt_redis.redis_get_vt(&oid[4..]).ok())
.flatten();
Ok::<_, Error>(foids)
});
Expand Down
10 changes: 9 additions & 1 deletion rust/redis-storage/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,15 @@ pub trait RedisGetNvt: RedisWrapper {

for (k, v) in tag_list.into_iter() {
if let Ok(tk) = TagKey::from_str(k) {
tag_map.insert(tk, TagValue::from(v));
match tk {
TagKey::CreationDate | TagKey::LastModification | TagKey::SeverityDate => {
tag_map.insert(
tk,
TagValue::from(i64::from_str(v).expect("Valid timestamp")),
)
}
_ => tag_map.insert(tk, TagValue::from(v)),
};
}
}

Expand Down

0 comments on commit cab57e3

Please sign in to comment.