diff --git a/modules/harness/onion-http.lua b/modules/harness/onion-http.lua index ec906a1..41c296c 100644 --- a/modules/harness/onion-http.lua +++ b/modules/harness/onion-http.lua @@ -1,5 +1,6 @@ -- Description: Send a request to a hidden service -- Version: 0.1.0 +-- Stealth: passive -- License: GPL-3.0 function run() diff --git a/modules/harness/selftest.lua b/modules/harness/selftest.lua index f4d4e3d..f7a2fe0 100644 --- a/modules/harness/selftest.lua +++ b/modules/harness/selftest.lua @@ -1,5 +1,6 @@ -- Description: basic selftest -- Version: 0.1.0 +-- Stealth: offline -- License: GPL-3.0 function run() diff --git a/modules/harness/stdin.lua b/modules/harness/stdin.lua index 3fad3aa..4fe61fb 100644 --- a/modules/harness/stdin.lua +++ b/modules/harness/stdin.lua @@ -1,5 +1,6 @@ -- Description: Read from stdin -- Version: 0.1.0 +-- Stealth: offline -- License: GPL-3.0 function run() diff --git a/modules/harness/xss.lua b/modules/harness/xss.lua index 50baab3..1fe178f 100644 --- a/modules/harness/xss.lua +++ b/modules/harness/xss.lua @@ -1,6 +1,7 @@ -- Description: jaVasCript:/*-/*`/*\`/*'/*"/**/(/* */oNcliCk=alert() )//%0D%0A%0d%0a//\x3csVg/\x3e -- Version: 0.1.0 -- License: GPL-3.0 +-- Stealth: loud -- Source: domains function run() diff --git a/sn0int-common/src/metadata.rs b/sn0int-common/src/metadata.rs index a69ded0..179b5c6 100644 --- a/sn0int-common/src/metadata.rs +++ b/sn0int-common/src/metadata.rs @@ -110,11 +110,11 @@ impl FromStr for Source { } } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] pub enum Stealth { Loud, Normal, - Silent, + Passive, Offline, } @@ -126,7 +126,7 @@ impl FromStr for Stealth { "loud" => Ok(Stealth::Loud), // This is also the default level if none is provided "normal" => Ok(Stealth::Normal), - "silent" => Ok(Stealth::Silent), + "passive" => Ok(Stealth::Passive), "offline" => Ok(Stealth::Offline), x => bail!("Unknown stealth: {:?}", x), } @@ -291,7 +291,7 @@ mod tests { let metadata = Metadata::from_str(r#"-- Description: Hello world, this is my description -- Version: 1.0.0 -- Source: domains --- Stealth: silent +-- Stealth: passive -- Author: kpcyrd -- Author: kpcyrd's cat -- Repository: https://github.com/kpcyrd/sn0int @@ -303,7 +303,7 @@ mod tests { version: "1.0.0".to_string(), license: License::WTFPL, source: Some(Source::Domains), - stealth: Stealth::Silent, + stealth: Stealth::Passive, authors: vec![ "kpcyrd ".to_string(), "kpcyrd's cat".to_string(), diff --git a/src/cmd/pkg_cmd.rs b/src/cmd/pkg_cmd.rs index f8eab64..f4e5c02 100644 --- a/src/cmd/pkg_cmd.rs +++ b/src/cmd/pkg_cmd.rs @@ -5,13 +5,14 @@ use crate::api::Client; use crate::args; use crate::config::Config; use crate::cmd::{Cmd, LiteCmd}; -use crate::engine::Library; +use crate::engine::{Library, Module}; use crate::registry::{self, InstallTask, UpdateTask, Updater}; use crate::shell::Shell; use crate::update::AutoUpdater; use crate::worker; -use colored::Colorize; +use colored::{Color, Colorize}; use sn0int_common::ModuleID; +use sn0int_common::metadata::Stealth; use std::collections::HashSet; use std::fmt::Write; use std::sync::Arc; @@ -71,7 +72,7 @@ pub struct List { pub source: Option, /// List outdated modules #[structopt(long="outdated")] - pub outdated: bool, + pub outdated_only: bool, /// Filter by pattern #[structopt(default_value="*")] pub pattern: String, @@ -96,6 +97,34 @@ enum ModuleReload { No, } +#[inline] +fn write_tag(out: &mut String, color: Color, txt: &str) -> Result<()> { + write!(out, " [{}]", txt.color(color))?; + Ok(()) +} + +fn print_module(module: &Module, is_outdated: bool) -> Result<()> { + let mut out = String::new(); + write!(&mut out, "{}/{} {}", module.author().purple(), + module.name(), + module.version().blue())?; + + match module.stealth() { + Stealth::Loud => write_tag(&mut out, Color::Yellow, "LOUD")?, + Stealth::Normal => (), + Stealth::Passive => write_tag(&mut out, Color::Green, "passive")?, + Stealth::Offline => write_tag(&mut out, Color::Green, "offline")?, + }; + + if is_outdated { + write_tag(&mut out, Color::Red, "outdated")?; + } + + println!("{}", out.bold()); + println!(" {}", module.description()); + Ok(()) +} + fn run_subcommand(subcommand: SubCommand, library: &Library, config: &Config) -> Result { match subcommand { SubCommand::List(list) => { @@ -115,16 +144,12 @@ fn run_subcommand(subcommand: SubCommand, library: &Library, config: &Config) -> continue; } - let mut out = String::new(); - write!(&mut out, "{} ({})", canonical.green(), - module.version().yellow())?; - if autoupdate.is_outdated(&canonical) { - write!(&mut out, " {}", "[outdated]".red())?; - } else if list.outdated { + let is_outdated = autoupdate.is_outdated(&canonical); + if list.outdated_only && !is_outdated { continue; } - println!("{}", out); - println!("\t{}", module.description()); + + print_module(module, is_outdated)?; } Ok(ModuleReload::No) }, diff --git a/src/engine/mod.rs b/src/engine/mod.rs index 5a485e3..494873b 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -14,7 +14,7 @@ use std::sync::{Arc, Mutex}; use crate::engine::ctx::Script; use crate::ipc::child::IpcChild; use sn0int_common::ModuleID; -use sn0int_common::metadata::{Metadata, Source}; +use sn0int_common::metadata::{Metadata, Source, Stealth}; use chrootable_https::dns::Resolver; use crate::psl::PslReader; use crate::paths; @@ -226,6 +226,8 @@ pub struct Module { version: String, source: Option, keyring_access: Vec, + stealth: Stealth, + private_module: bool, script: Script, } @@ -248,11 +250,18 @@ impl Module { version: metadata.version, source: metadata.source, keyring_access: metadata.keyring_access, + stealth: metadata.stealth, + private_module, script, }) } + #[inline] + pub fn author(&self) -> &str { + &self.author + } + #[inline] pub fn name(&self) -> &str { &self.name @@ -290,6 +299,11 @@ impl Module { &self.keyring_access } + #[inline] + pub fn stealth(&self) -> &Stealth { + &self.stealth + } + #[inline] pub fn is_private(&self) -> bool { self.private_module