-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change: make async the methods for preference handling. (#1572)
Also, improve the creating the RedisHelper, since at this point the nvti cache and a main kb for the scan should have been created. Usage example. (Needs a running redis instance with an up-to-date nvticache) ``` ```use std::sync::{Arc, Mutex}; use models::{AliveTestMethods, Credential, PortRange, Port, Scan, Parameter}; use openvas::{pref_handler::PreferenceHandler, openvas_redis::RedisHelper}; use redis_storage::{NameSpaceSelector, RedisCtx}; async fn main() -> Result<(), std::fmt::Error> { // Create an scan config let mut scan = Scan::default(); scan.scan_id = Some("123-456".to_string()); scan.target.alive_test_methods = vec![AliveTestMethods::Icmp, AliveTestMethods::TcpSyn]; scan.target.credentials = vec![Credential { service: models::Service::SSH, port: Some(22), credential_type: models::CredentialType::UP { username: "user".to_string(), password: "pass".to_string(), privilege_credential: None, }, }]; scan.vts.push(models::VT { oid: "1.3.6.1.4.1.25623.1.0.112771".to_string(), parameters: vec![Parameter { id: 1, value: "llala".to_string() }] }); scan.target.excluded_hosts = vec!["127.0.0.1".to_string()]; scan.target.hosts = vec!["127.0.0.2".to_string()]; scan.target.ports = vec![Port { protocol: Some(models::Protocol::TCP), range: vec![ PortRange { start: 22, end: Some(25), }, PortRange { start: 80, end: None, }, ], }]; let redis_url = "unix:///run/redis-openvas/redis.sock"; // In this example, a fix db is taken,but the next free can be taken, using the name space selector NameSpaceSelector::Free let mut rctx = RedisCtx::open(redis_url, &[NameSpaceSelector::Fix(6)]).unwrap(); rctx.delete_namespace().unwrap(); // Create a redis connection to the nvticache, and a connection to the mainkb(). let cache = RedisCtx::open(redis_url, &[NameSpaceSelector::Key("nvticache")]).unwrap(); // New redis helper with access to the main kb for storing the preferences, and access to the nvticache // for getting info to build preferences. let rc = RedisHelper::<RedisCtx>::init(Arc::new(Mutex::new(cache)),Arc::new(Mutex::new(rctx))).unwrap(); let mut p = PreferenceHandler::new(scan, rc); Ok(p.prepare_preferences_for_openvas().await.expect("aaa")) }
- Loading branch information
Showing
4 changed files
with
57 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters