Skip to content

Add: Implement smb and wmi functions#2197

Open
jjnicola wants to merge 1 commit into
mainfrom
openvasd-smb
Open

Add: Implement smb and wmi functions#2197
jjnicola wants to merge 1 commit into
mainfrom
openvasd-smb

Conversation

@jjnicola

@jjnicola jjnicola commented May 1, 2026

Copy link
Copy Markdown
Member

What:
Add:

  • nasl_smb_connect
  • nasl_smb_close
  • nasl_smb_file_sddl
  • nasl_win_cmd_exec
  • smb_versioninfo

Jira: SC-1432

Why:

How:

Ensure you have access to the windows target and there file exists. Run the following nasl script with the right credentials.
target/debug/scannerctl execute script smb_rs.nasl -t TARGET_IP --kb="SMB/login=DOMAIN\USER" --kb="SMB/password=PASS"

display(smb_versioninfo());
host    = get_host_ip();
usrname = get_kb_item( "SMB/login" );
passwd  = get_kb_item( "SMB/password" );

if( ! host || ! usrname || ! passwd ) exit( 0 );
domain = get_kb_item( "SMB/domain" );
if( domain ) usrname = domain + '\\' + usrname;

handle = smb_connect( share: "C$", username:usrname, password:passwd);
display(handle);
display (smb_file_SDDL(smb_handle: handle, filename: "test.txt"));

smb_close(smb_handle: handle);

Checklist:

  • Tests
  • PR merge commit message adjusted

@jjnicola jjnicola requested a review from a team as a code owner May 1, 2026 16:52
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

Dependency Review

The following issues were found:

  • ✅ 0 vulnerable package(s)
  • ❌ 2 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 2 package(s) with unknown licenses.
  • ⚠️ 5 packages with OpenSSF Scorecard issues.

View full job summary

Comment thread rust/src/nasl/builtin/naslsmb/handle.rs Outdated
Comment on lines +138 to +140
// Note that the first session ID we will
// hand out is an arbitrary high number, this is only to help
// debugging.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment should go on the MIN_HANDLE_ID

Comment thread rust/src/nasl/builtin/naslsmb/mod.rs Outdated
ctx.target().ip_addr()
};

let host = if let Some(_krb5) = kdc.clone() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clone() feels unnecessary here, and the actual match is ignored, so why not
if kdc.is_some() { ... } which avoids the clone

(if let Some(ref krb5) = kdc { ... } would be the alternative if we need the krb5)

Comment thread rust/src/nasl/builtin/naslsmb/mod.rs Outdated
Comment on lines +83 to +88
match lookup_addr(&host) {
Ok(host) => host,
Err(e) => {
return Err(SmbError::InvalidHost(e.to_string()).into());
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lookup_addr(&host).map_err(|e| SmbError::InvalidHost(e.to_string()).into())?

Comment thread rust/src/nasl/builtin/naslsmb/mod.rs Outdated

let username = username.replacen("\\", "/", 1);
let realm = realm.unwrap_or_default();
let target = if let Some(_realm) = username.find("/") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, this is username.find("/").is_some(). Putting underscores in front of variable names is virtually never the rusty thing to do - mutex guards being a notable exception

Comment thread rust/src/nasl/builtin/naslsmb/mod.rs Outdated
Comment on lines +103 to +108
if let Some(krb5) = kdc.clone() {
let first_kdc = if let Some(i) = krb5.find(",") {
krb5[..i].to_string()
} else {
krb5
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

total nitpick but just for curiosities sake: doing

    if let Some(ref krb5) = kdc {
        let first_kdc = if let Some(i) = krb5.find(",") {
            &krb5[..i]
        } else {
            &krb5
        };
        output.arg("-k").arg("-dc-ip").arg(first_kdc);
    }
    output.arg(target).arg(cmd);

would be a way to avoid the clone.

Comment thread rust/src/nasl/builtin/naslsmb/mod.rs Outdated
realm: Option<String>,
kdc: Option<String>,
cmd: String,
) -> Result<Option<String>, FnError> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for fun: The nasl_function macro also allows returning SmbError as the error type of this function (any error type that has a Into<FnError> works) and then add
From<io::Error> and From<AddrParseError> impls to get rid of all of the map_err calls in this function (the ? operator auto-converts via From)

Comment thread rust/src/nasl/builtin/mod.rs Outdated
mod knowledge_base;
mod krb5;
pub mod misc;
mod naslsmb;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal nitpick: This is already in the nasl/builtin/mod.rs, so the nasl is already implied. Why not simply smb? We have a smb.rs in the cryptographic subfolder, but I think it's clear enough that this is something else.

Comment thread rust/Cargo.toml Outdated
cidr = "0.3.2"
smb = "0.11.2"
smb-msg = "0.11.2"
use = "0.0.1-pre.0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused. Also, what is this?

Comment thread rust/Cargo.toml Outdated
rustls-pki-types = { version = "1.14.0", features = ["std"] }
cidr = "0.3.2"
smb = "0.11.2"
smb-msg = "0.11.2"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused dep

Comment thread rust/Cargo.toml Outdated
smb = "0.11.2"
smb-msg = "0.11.2"
use = "0.0.1-pre.0"
smb-dtyp = "0.11.2"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused dep

@jjnicola

Copy link
Copy Markdown
Member Author

Blocked by afiffon/smb-rs#166

@Tehforsch Tehforsch added the waiting_upstream Waiting on a feature or fix in dependencies before this can be merged label Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting_upstream Waiting on a feature or fix in dependencies before this can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants