Skip to content

Commit

Permalink
feat: Rename and add config to the session
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrypt0nn committed Oct 20, 2024
1 parent 12e1a2c commit 4d71b66
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 39 deletions.
14 changes: 7 additions & 7 deletions src/options.rs → src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -36,15 +36,15 @@ 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,
}

#[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,
Expand Down
2 changes: 0 additions & 2 deletions src/logger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pub fn warn(event: impl Into<String>, message: impl Into<String>) {
))
}

#[allow(dead_code)]
pub fn error(event: impl Into<String>, message: impl Into<String>) {
LOGGER.lock().unwrap().println(format!(
"[$[now:time]] [{}{}{}$[reset]] {}",
Expand Down Expand Up @@ -89,7 +88,6 @@ pub fn print(event: impl Into<String>, message: impl Into<String>) {
));
}

#[allow(dead_code)]
pub fn println(event: impl Into<String>, message: impl Into<String>) {
LOGGER.lock().unwrap().println(format!(
"[$[now:time]] [$[effect:bold]$[fg:green]{}$[reset]] {}",
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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::<events::Type>(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();
}
11 changes: 6 additions & 5 deletions src/modules/enumerate_files/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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");
Expand Down
9 changes: 5 additions & 4 deletions src/modules/enumerate_subdomains/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::events;
use crate::session::Session;
use crate::{events, options};

pub mod enumerate_files;
pub mod enumerate_subdomains;
Expand All @@ -11,5 +11,5 @@ pub trait Module {
#[allow(dead_code)]
fn description(&self) -> String;
fn subscribers(&self) -> Vec<events::Type>;
fn execute(&self, session: &Session, opts: &options::Options);
fn execute(&self, session: &Session);
}
11 changes: 6 additions & 5 deletions src/modules/passive_dns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/modules/ready/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::events;
use crate::logger;
use crate::modules::Module;
use crate::options;
use crate::session::Session;

pub struct ModuleReady {}
Expand Down Expand Up @@ -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!",
Expand Down
23 changes: 15 additions & 8 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<events::Type>,
receiver: Receiver<events::Type>,

modules: Vec<Box<dyn Module>>,
discovered_subdomains: Mutex<Vec<String>>,

dev_mode: bool,
}

impl Session {
pub fn new(
options: options::Options,
config: config::Config,
sender: Sender<events::Type>,
receiver: Receiver<events::Type>,
) -> 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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -77,7 +84,7 @@ impl Session {
_ => false,
})
{
module.execute(&self, &self.options);
module.execute(&self);
}
}
}
Expand Down

0 comments on commit 4d71b66

Please sign in to comment.