Skip to content

Commit

Permalink
chore: improved register_plugin macro
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed Aug 21, 2024
1 parent e967136 commit 06aabac
Show file tree
Hide file tree
Showing 26 changed files with 85 additions and 47 deletions.
4 changes: 3 additions & 1 deletion src/plugins/amqp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ pub(crate) mod options;

const PROTOCOL_HEADER_091: &[u8] = &[b'A', b'M', b'Q', b'P', 0, 0, 9, 1];

super::manager::register_plugin!("amqp", AMQP::new());
super::manager::register_plugin! {
"amqp" => AMQP::new()
}

#[derive(Clone)]
pub(crate) struct AMQP {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::creds::Credentials;

pub(crate) mod options;

super::manager::register_plugin!("cmd", Command::new());
super::manager::register_plugin! {
"cmd" => Command::new()
}

#[derive(Clone)]
pub(crate) struct Command {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/dns/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use super::plugin::PayloadStrategy;

pub(crate) mod options;

super::manager::register_plugin!("dns", DNS::new());
super::manager::register_plugin! {
"dns" => DNS::new()
}

#[derive(Clone)]
pub(crate) struct DNS {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/ftp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::Plugin;

use crate::creds::Credentials;

super::manager::register_plugin!("ftp", FTP::new());
super::manager::register_plugin! {
"ftp" => FTP::new()
}

#[derive(Clone)]
pub(crate) struct FTP {}
Expand Down
27 changes: 10 additions & 17 deletions src/plugins/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::Options;
use crate::creds::Credentials;
use crate::plugins::Plugin;

use super::{manager::PluginRegistrar, plugin::PayloadStrategy};
use super::plugin::PayloadStrategy;

mod csrf;
mod ntlm;
Expand All @@ -28,22 +28,15 @@ const HTTP_USERNAME_VAR: &str = "{$username}";
const HTTP_PASSWORD_VAR: &str = "{$password}";
const HTTP_PAYLOAD_VAR: &str = "{$payload}";

super::manager::register_plugin!(
"http",
HTTP::new(Strategy::Request),
"http.form",
HTTP::new(Strategy::Form),
"http.basic",
HTTP::new(Strategy::BasicAuth),
"http.ntlm1",
HTTP::new(Strategy::NLTMv1),
"http.ntlm2",
HTTP::new(Strategy::NLTMv2),
"http.enum",
HTTP::new(Strategy::Enumeration),
"http.vhost",
HTTP::new(Strategy::VHostEnum)
);
super::manager::register_plugin! {
"http" => HTTP::new(Strategy::Request),
"http.form" => HTTP::new(Strategy::Form),
"http.basic" => HTTP::new(Strategy::BasicAuth),
"http.ntlm1" => HTTP::new(Strategy::NLTMv1),
"http.ntlm2" => HTTP::new(Strategy::NLTMv2),
"http.enum" => HTTP::new(Strategy::Enumeration),
"http.vhost" => HTTP::new(Strategy::VHostEnum)
}

fn method_requires_payload(method: &Method) -> bool {
matches!(method, &Method::POST | &Method::PUT | &Method::PATCH)
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/imap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use crate::Plugin;
use crate::creds::Credentials;
use crate::utils;

super::manager::register_plugin!("imap", IMAP::new());
super::manager::register_plugin! {
"imap" => IMAP::new()
}

#[derive(Clone)]
pub(crate) struct IMAP {}
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/kerberos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ mod transport;

pub(crate) mod options;

super::manager::register_plugin!("kerberos", Kerberos::new());
super::manager::register_plugin! {
"kerberos" => Kerberos::new()
}

#[derive(Clone)]
pub(crate) struct Kerberos {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/ldap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::utils;

pub(crate) mod options;

super::manager::register_plugin!("ldap", LDAP::new());
super::manager::register_plugin! {
"ldap" => LDAP::new()
}

#[derive(Clone)]
pub(crate) struct LDAP {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::plugin::PayloadStrategy;
type Inventory = BTreeMap<&'static str, Box<dyn Plugin>>;

macro_rules! register_plugin {
($($name:literal, $instance:expr),+) => {
($($name:literal => $instance:expr),+) => {
pub(super) fn register(registrar: &mut impl $crate::plugins::manager::PluginRegistrar) {
$(
registrar.register($name, $instance);
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/mongodb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use crate::{utils, Options};

use crate::creds::Credentials;

super::manager::register_plugin!("mongodb", MongoDB::new());
super::manager::register_plugin! {
"mongodb" => MongoDB::new()
}

#[derive(Clone)]
pub(crate) struct MongoDB {}
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/mqtt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::creds::Credentials;

pub(crate) mod options;

super::manager::register_plugin!("mqtt", Mqtt::new());
super::manager::register_plugin! {
"mqtt" => Mqtt::new()
}

#[derive(Clone)]
pub(crate) struct Mqtt {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/mssql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const MS_PACKET_LANGP: &[u8] = &[

const MS_MAX_LEN: usize = 30;

super::manager::register_plugin!("mssql", MSSQL::new());
super::manager::register_plugin! {
"mssql" => MSSQL::new()
}

#[derive(Clone)]
pub(crate) struct MSSQL {}
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/oracle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::Plugin;

pub(crate) mod options;

super::manager::register_plugin!("oracle", Oracle::new());
super::manager::register_plugin! {
"oracle" => Oracle::new()
}

#[derive(Clone)]
pub(crate) struct Oracle {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/pop3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::utils;

pub(crate) mod options;

super::manager::register_plugin!("pop3", POP3::new());
super::manager::register_plugin! {
"pop3" => POP3::new()
}

#[derive(Clone)]
pub(crate) struct POP3 {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/port_scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use super::plugin::PayloadStrategy;
mod grabbers;
pub(crate) mod options;

super::manager::register_plugin!("port.scanner", PortScanner::new());
super::manager::register_plugin! {
"port.scanner" => PortScanner::new()
}

#[derive(Clone)]
pub(crate) struct PortScanner {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/rdp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use crate::creds::Credentials;

pub(crate) mod options;

super::manager::register_plugin!("rdp", RDP::new());
super::manager::register_plugin! {
"rdp" => RDP::new()
}

#[derive(Clone)]
pub(crate) struct RDP {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/redis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::creds::Credentials;

pub(crate) mod options;

super::manager::register_plugin!("redis", Redis::new());
super::manager::register_plugin! {
"redis" => Redis::new()
}

#[derive(Clone)]
pub(crate) struct Redis {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/samba/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ lazy_static! {
static ref PAVAO_LOCK: Mutex<bool> = tokio::sync::Mutex::new(true);
}

super::manager::register_plugin!("smb", SMB::new());
super::manager::register_plugin! {
"smb" => SMB::new()
}

#[derive(Clone)]
pub(crate) struct SMB {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/scylla/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use crate::Plugin;

use crate::creds::Credentials;

super::manager::register_plugin!("scylla", Scylla::new());
super::manager::register_plugin! {
"scylla" => Scylla::new()
}

#[derive(Clone)]
pub(crate) struct Scylla {}
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/smtp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use crate::utils;

pub(crate) mod options;

super::manager::register_plugin!("smtp", SMTP::new());
super::manager::register_plugin! {
"smtp" => SMTP::new()
}

#[derive(Clone)]
pub(crate) struct SMTP {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/socks5/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::creds::Credentials;

pub(crate) mod options;

super::manager::register_plugin!("socks5", Socks5::new());
super::manager::register_plugin! {
"socks5" => Socks5::new()
}

#[derive(Clone)]
pub(crate) struct Socks5 {
Expand Down
10 changes: 4 additions & 6 deletions src/plugins/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ lazy_static! {
HashMap::from([(Flavour::My, 3306), (Flavour::PG, 5432),]);
}

super::manager::register_plugin!(
"mysql",
SQL::new(Flavour::My),
"pgsql",
SQL::new(Flavour::PG)
);
super::manager::register_plugin! {
"mysql" => SQL::new(Flavour::My),
"pgsql" => SQL::new(Flavour::PG)
}

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) enum Flavour {
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/ssh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use crate::Plugin;

pub(crate) mod options;

super::manager::register_plugin!("ssh", SSH::new(), "sftp", SSH::new());
super::manager::register_plugin! {
"ssh" => SSH::new(),
"sftp" => SSH::new()
}

#[derive(Clone)]
pub(crate) struct SSH {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/stomp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::creds::Credentials;

const CONNECTED_RESPONSE: &[u8] = &[67, 79, 78, 78, 69, 67, 84, 69, 68];

super::manager::register_plugin!("stomp", STOMP::new());
super::manager::register_plugin! {
"stomp" => STOMP::new()
}

#[derive(Clone)]
pub(crate) struct STOMP {}
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/telnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use crate::Plugin;

pub(crate) mod options;

super::manager::register_plugin!("telnet", Telnet::new());
super::manager::register_plugin! {
"telnet" => Telnet::new()
}

#[derive(Clone)]
pub(crate) struct Telnet {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/vnc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::creds::Credentials;

use super::plugin::PayloadStrategy;

super::manager::register_plugin!("vnc", VNC::new());
super::manager::register_plugin! {
"vnc" => VNC::new()
}

#[derive(Clone)]
pub(crate) struct VNC {}
Expand Down

0 comments on commit 06aabac

Please sign in to comment.