diff --git a/src/options.rs b/src/config.rs similarity index 82% rename from src/options.rs rename to src/config.rs index cb8eba5..b9f6dd5 100644 --- a/src/options.rs +++ b/src/config.rs @@ -7,24 +7,24 @@ use serde::{Deserialize, Serialize}; about, arg_required_else_help(true) )] -pub struct Options { +pub struct Config { /// Domain to scan for #[arg(short, long)] pub domain: String, #[clap(flatten, next_help_heading = "Enumerate Files")] - pub enumerate_files: EnumerateFilesOptions, + pub enumerate_files: EnumerateFilesConfig, #[clap(flatten, next_help_heading = "Enumerate Subdomains")] - pub enumerate_subdomains: EnumerateSubdomainsOptions, + pub enumerate_subdomains: EnumerateSubdomainsConfig, #[clap(flatten, next_help_heading = "Passive DNS")] - pub passive_dns: PassiveDNSOptions, + pub passive_dns: PassiveDNSConfig, } #[derive(Parser, Debug, Serialize, Deserialize, Clone, Default)] #[group(skip)] -pub(crate) struct PassiveDNSOptions { +pub(crate) struct PassiveDNSConfig { #[clap(long, default_value_t = false)] /// Ignore expired certificates. pub passive_dns_ignore_expired: bool, @@ -36,7 +36,7 @@ pub(crate) struct PassiveDNSOptions { #[derive(Parser, Debug, Serialize, Deserialize, Clone, Default)] #[group(skip)] -pub(crate) struct EnumerateSubdomainsOptions { +pub(crate) struct EnumerateSubdomainsConfig { #[clap(long, default_value = "")] /// The path to the wordlist to use pub enumerate_subdomains_wordlist: String, @@ -44,7 +44,7 @@ pub(crate) struct EnumerateSubdomainsOptions { #[derive(Parser, Debug, Serialize, Deserialize, Clone, Default)] #[group(skip)] -pub(crate) struct EnumerateFilesOptions { +pub(crate) struct EnumerateFilesConfig { #[clap(long, default_value = "")] /// The path to the wordlist to use pub enumerate_files_wordlist: String, diff --git a/src/logger/mod.rs b/src/logger/mod.rs index d23b081..fb6751d 100644 --- a/src/logger/mod.rs +++ b/src/logger/mod.rs @@ -58,7 +58,6 @@ pub fn warn(event: impl Into, message: impl Into) { )) } -#[allow(dead_code)] pub fn error(event: impl Into, message: impl Into) { LOGGER.lock().unwrap().println(format!( "[$[now:time]] [{}{}{}$[reset]] {}", @@ -89,7 +88,6 @@ pub fn print(event: impl Into, message: impl Into) { )); } -#[allow(dead_code)] pub fn println(event: impl Into, message: impl Into) { LOGGER.lock().unwrap().println(format!( "[$[now:time]] [$[effect:bold]$[fg:green]{}$[reset]] {}", diff --git a/src/main.rs b/src/main.rs index e2c4ee7..8dc0329 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,22 +1,22 @@ use clap::Parser; use flume; +mod config; mod events; mod logger; mod modules; -mod options; mod session; -// TODO : Rework the options system, same for the overall modules management +// TODO : Rework the overall modules management // TODO : Allow the events to contain either arguments or some sort of `Context` fn main() { println!("Project Serpens v{}", env!("CARGO_PKG_VERSION")); - let options = options::Options::parse(); + let config = config::Config::parse(); let (tx, rx) = flume::bounded::(100); - let mut session = session::Session::new(options, tx, rx); + let mut session = session::Session::new(config, tx, rx); session.register_default_modules(); session.start(); } diff --git a/src/modules/enumerate_files/mod.rs b/src/modules/enumerate_files/mod.rs index c992878..b4fec06 100644 --- a/src/modules/enumerate_files/mod.rs +++ b/src/modules/enumerate_files/mod.rs @@ -7,7 +7,7 @@ use reqwest::header::USER_AGENT; use crate::modules::Module; use crate::session::Session; -use crate::{events, logger, options}; +use crate::{events, logger}; pub struct ModuleEnumerateFiles {} @@ -36,11 +36,12 @@ impl Module for ModuleEnumerateFiles { vec![events::Type::DiscoveredDomain(String::new())] } - fn execute(&self, _: &Session, opts: &options::Options) { - let domain = &opts.domain; - let wordlist_file = File::open(&opts.enumerate_files.enumerate_files_wordlist) + fn execute(&self, session: &Session) { + let config = session.get_config(); + let domain = &config.domain; + let wordlist_file = File::open(&config.enumerate_files.enumerate_files_wordlist) .expect("Invalid wordlist file path"); - let extension = &opts.enumerate_files.enumerate_files_extension; + let extension = &config.enumerate_files.enumerate_files_extension; let lines = BufReader::new(wordlist_file).lines(); for line in lines.map_while(Result::ok) { let user_agents_file = include_str!("../../../resources/user_agents.txt"); diff --git a/src/modules/enumerate_subdomains/mod.rs b/src/modules/enumerate_subdomains/mod.rs index 0cd5402..e855449 100644 --- a/src/modules/enumerate_subdomains/mod.rs +++ b/src/modules/enumerate_subdomains/mod.rs @@ -6,7 +6,7 @@ use reqwest::header::USER_AGENT; use crate::modules::Module; use crate::session::Session; -use crate::{events, logger, options}; +use crate::{events, logger}; pub struct ModuleEnumerateSubdomains {} @@ -37,9 +37,10 @@ impl Module for ModuleEnumerateSubdomains { vec![events::Type::DiscoveredDomain(String::new())] } - fn execute(&self, session: &Session, opts: &options::Options) { - let domain = &opts.domain; - let wordlist_file = File::open(&opts.enumerate_subdomains.enumerate_subdomains_wordlist) + fn execute(&self, session: &Session) { + let config = session.get_config(); + let domain = &config.domain; + let wordlist_file = File::open(&config.enumerate_subdomains.enumerate_subdomains_wordlist) .expect("Invalid wordlist file path"); let lines = BufReader::new(wordlist_file).lines(); for line in lines.map_while(Result::ok) { diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 5d1782a..eb223d4 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -1,5 +1,5 @@ +use crate::events; use crate::session::Session; -use crate::{events, options}; pub mod enumerate_files; pub mod enumerate_subdomains; @@ -11,5 +11,5 @@ pub trait Module { #[allow(dead_code)] fn description(&self) -> String; fn subscribers(&self) -> Vec; - fn execute(&self, session: &Session, opts: &options::Options); + fn execute(&self, session: &Session); } diff --git a/src/modules/passive_dns/mod.rs b/src/modules/passive_dns/mod.rs index 39319a6..e065f44 100644 --- a/src/modules/passive_dns/mod.rs +++ b/src/modules/passive_dns/mod.rs @@ -7,7 +7,7 @@ use reqwest::header::USER_AGENT; use crate::modules::passive_dns::crt_sh::CrtShItem; use crate::modules::Module; use crate::session::Session; -use crate::{events, logger, options}; +use crate::{events, logger}; mod crt_sh; @@ -52,10 +52,11 @@ impl Module for ModulePassiveDNS { vec![events::Type::DiscoveredDomain(String::new())] } - fn execute(&self, session: &Session, opts: &options::Options) { - let domain = &opts.domain; - let ignore_expired = opts.passive_dns.passive_dns_ignore_expired; - let recent_only = opts.passive_dns.passive_dns_recent_only; + fn execute(&self, session: &Session) { + let config = session.get_config(); + let domain = &config.domain; + let ignore_expired = config.passive_dns.passive_dns_ignore_expired; + let recent_only = config.passive_dns.passive_dns_recent_only; if self.has_processed(domain.to_string()) { return; } diff --git a/src/modules/ready/mod.rs b/src/modules/ready/mod.rs index 2390ce3..bfe0fcf 100644 --- a/src/modules/ready/mod.rs +++ b/src/modules/ready/mod.rs @@ -1,7 +1,6 @@ use crate::events; use crate::logger; use crate::modules::Module; -use crate::options; use crate::session::Session; pub struct ModuleReady {} @@ -31,7 +30,7 @@ impl Module for ModuleReady { vec![events::Type::Ready] } - fn execute(&self, _: &Session, _: &options::Options) { + fn execute(&self, _: &Session) { logger::println( "ready", "Project Serpens is now ready and will start doing its magic!", diff --git a/src/session.rs b/src/session.rs index ef9a445..a9225c0 100644 --- a/src/session.rs +++ b/src/session.rs @@ -3,34 +3,41 @@ use std::sync::Mutex; use flume::{Receiver, Sender}; use crate::modules::Module; -use crate::{events, logger, modules, options}; +use crate::{config, events, logger, modules}; pub struct Session { - dev_mode: bool, - options: options::Options, + config: config::Config, sender: Sender, receiver: Receiver, modules: Vec>, discovered_subdomains: Mutex>, + + dev_mode: bool, } impl Session { pub fn new( - options: options::Options, + config: config::Config, sender: Sender, receiver: Receiver, ) -> Self { Session { - dev_mode: false, - options, + config, sender, receiver, + modules: Vec::new(), discovered_subdomains: Mutex::new(Vec::new()), + + dev_mode: false, } } + pub fn get_config(&self) -> &config::Config { + &self.config + } + pub fn discover_subdomain(&self, subdomain: String) { self.discovered_subdomains.lock().unwrap().push(subdomain) } @@ -62,7 +69,7 @@ impl Session { pub fn start(&mut self) { self.emit(events::Type::Ready); - self.emit(events::Type::DiscoveredDomain(self.options.domain.clone())); + self.emit(events::Type::DiscoveredDomain(self.config.domain.clone())); while let Ok(event) = self.receiver.recv() { for module in &self.modules { @@ -77,7 +84,7 @@ impl Session { _ => false, }) { - module.execute(&self, &self.options); + module.execute(&self); } } }