Skip to content

Commit

Permalink
rustfmt the rest of the owl
Browse files Browse the repository at this point in the history
  • Loading branch information
zcarlson-signifai committed Dec 17, 2023
1 parent 48a0d30 commit f84a962
Show file tree
Hide file tree
Showing 10 changed files with 492 additions and 110 deletions.
2 changes: 1 addition & 1 deletion src/aws_scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@
use encoding::all::ASCII;
use encoding::{DecoderTrap, Encoding};
use log::{self, error, trace};
use rusty_hog_scanner::SecretScanner;
use s3::bucket::Bucket;
use serde_derive::{Deserialize, Serialize};
use simple_error::SimpleError;
use std::str;
use rusty_hog_scanner::SecretScanner;

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, Default)]
/// `serde_json` object that represents a single found secret - finding
Expand Down
103 changes: 83 additions & 20 deletions src/bin/ankamali_hog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ extern crate yup_oauth2 as oauth2;
use clap::{Arg, ArgAction, ArgMatches, Command};
use drive3::DriveHub;
use log::{self, error, info};
use oauth2::{InstalledFlowAuthenticator, InstalledFlowReturnMethod};
use rusty_hog_scanner::{SecretScanner, SecretScannerBuilder};
use rusty_hogs::google_scanning::{GDriveFileInfo, GDriveScanner};
use simple_error::SimpleError;
use std::path::Path;
use rusty_hogs::google_scanning::{GDriveFileInfo, GDriveScanner};
use rusty_hog_scanner::{SecretScanner, SecretScannerBuilder};
use oauth2::{InstalledFlowAuthenticator, InstalledFlowReturnMethod};

/// Main entry function that uses the [clap crate](https://docs.rs/clap/2.33.0/clap/)
#[tokio::main]
Expand All @@ -45,17 +45,77 @@ async fn main() {
.version("1.0.11")
.author("Scott Cutler <[email protected]>")
.about("Google Drive secret scanner in Rust.")
.arg(Arg::new("REGEX").long("regex").action(ArgAction::Set).help("Sets a custom regex JSON file"))
.arg(Arg::new("GDRIVEID").required(true).action(ArgAction::Set).help("The ID of the Google drive file you want to scan"))
.arg(Arg::new("VERBOSE").short('v').long("verbose").action(ArgAction::Count).help("Sets the level of debugging information"))
.arg(Arg::new("ENTROPY").long("entropy").action(ArgAction::SetTrue).help("Enables entropy scanning"))
.arg(Arg::new("DEFAULT_ENTROPY_THRESHOLD").long("default_entropy_threshold").action(ArgAction::Set).help("Default entropy threshold (0.6 by default)"))
.arg(Arg::new("CASE").long("caseinsensitive").action(ArgAction::SetTrue).help("Sets the case insensitive flag for all regexes"))
.arg(Arg::new("OUTPUT").short('o').long("outputfile").action(ArgAction::Set).help("Sets the path to write the scanner results to (stdout by default)"))
.arg(Arg::new("PRETTYPRINT").long("prettyprint").action(ArgAction::SetTrue).help("Outputs the JSON in human readable format"))
.arg(Arg::new("OAUTHSECRETFILE").long("oauthsecret").action(ArgAction::Set).default_value("./clientsecret.json").help("Path to an OAuth secret file (JSON) ./clientsecret.json by default"))
.arg(Arg::new("OAUTHTOKENFILE").long("oauthtoken").action(ArgAction::Set).default_value("./temp_token").help("Path to an OAuth token storage file ./temp_token by default"))
.arg(Arg::new("ALLOWLIST").short('a').long("allowlist").action(ArgAction::Set).help("Sets a custom allowlist JSON file"))
.arg(
Arg::new("REGEX")
.long("regex")
.action(ArgAction::Set)
.help("Sets a custom regex JSON file"),
)
.arg(
Arg::new("GDRIVEID")
.required(true)
.action(ArgAction::Set)
.help("The ID of the Google drive file you want to scan"),
)
.arg(
Arg::new("VERBOSE")
.short('v')
.long("verbose")
.action(ArgAction::Count)
.help("Sets the level of debugging information"),
)
.arg(
Arg::new("ENTROPY")
.long("entropy")
.action(ArgAction::SetTrue)
.help("Enables entropy scanning"),
)
.arg(
Arg::new("DEFAULT_ENTROPY_THRESHOLD")
.long("default_entropy_threshold")
.action(ArgAction::Set)
.help("Default entropy threshold (0.6 by default)"),
)
.arg(
Arg::new("CASE")
.long("caseinsensitive")
.action(ArgAction::SetTrue)
.help("Sets the case insensitive flag for all regexes"),
)
.arg(
Arg::new("OUTPUT")
.short('o')
.long("outputfile")
.action(ArgAction::Set)
.help("Sets the path to write the scanner results to (stdout by default)"),
)
.arg(
Arg::new("PRETTYPRINT")
.long("prettyprint")
.action(ArgAction::SetTrue)
.help("Outputs the JSON in human readable format"),
)
.arg(
Arg::new("OAUTHSECRETFILE")
.long("oauthsecret")
.action(ArgAction::Set)
.default_value("./clientsecret.json")
.help("Path to an OAuth secret file (JSON) ./clientsecret.json by default"),
)
.arg(
Arg::new("OAUTHTOKENFILE")
.long("oauthtoken")
.action(ArgAction::Set)
.default_value("./temp_token")
.help("Path to an OAuth token storage file ./temp_token by default"),
)
.arg(
Arg::new("ALLOWLIST")
.short('a')
.long("allowlist")
.action(ArgAction::Set)
.help("Sets a custom allowlist JSON file"),
)
.get_matches();
match run(matches).await {
Ok(()) => {}
Expand All @@ -65,7 +125,8 @@ async fn main() {

/// Main logic contained here. Get the CLI variables, setup OAuth, setup GDriveScanner and output
/// the results.
async fn run(arg_matches: ArgMatches) -> Result<(), SimpleError> { // Set logging
async fn run(arg_matches: ArgMatches) -> Result<(), SimpleError> {
// Set logging
SecretScanner::set_logging(arg_matches.get_count("VERBOSE").into());

// Initialize some variables
Expand Down Expand Up @@ -93,11 +154,13 @@ async fn run(arg_matches: ArgMatches) -> Result<(), SimpleError> { // Set log
let hub = DriveHub::new(
hyper::Client::builder().build(
hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.https_only()
.enable_all_versions()
.build()
), auth);
.with_native_roots()
.https_only()
.enable_all_versions()
.build(),
),
auth,
);

// get some initial info about the file
let gdriveinfo = GDriveFileInfo::new(file_id, &hub).await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/bin/berkshire_hog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ use simple_error::{require_with, try_with};
use std::str;
use url::Url;

use rusty_hogs::aws_scanning::{S3Finding, S3Scanner};
use rusty_hog_scanner::{SecretScanner, SecretScannerBuilder};
use rusty_hogs::aws_scanning::{S3Finding, S3Scanner};
use std::collections::HashSet;

/// Main entry function that uses the [clap crate](https://docs.rs/clap/2.33.0/clap/)
Expand Down
2 changes: 1 addition & 1 deletion src/bin/berkshire_hog_lambda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ extern crate s3;

use lambda_runtime::{handler_fn, Context, Error};
use log::{self, warn, LevelFilter};
use rusty_hogs::aws_scanning::{S3Finding, S3Scanner};
use rusty_hog_scanner::SecretScannerBuilder;
use rusty_hogs::aws_scanning::{S3Finding, S3Scanner};
use s3::bucket::Bucket;
use s3::creds::Credentials;
use s3::region::Region;
Expand Down
31 changes: 23 additions & 8 deletions src/bin/choctaw_hog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ use simple_error::SimpleError;
use std::str;
use tempdir::TempDir;

use rusty_hogs::git_scanning::GitScanner;
use rusty_hog_scanner::{SecretScanner, SecretScannerBuilder};
use rusty_hogs::git_scanning::GitScanner;

/// Main entry function that uses the [clap crate](https://docs.rs/clap/2.33.0/clap/)
fn main() {
Expand Down Expand Up @@ -84,12 +84,24 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {

// Initialize some more variables
let secret_scanner = SecretScannerBuilder::new().conf_argm(arg_matches).build();
let sshkeypath = arg_matches.get_one::<String>("SSHKEYPATH").map(|s| s.as_str());
let sshkeyphrase = arg_matches.get_one::<String>("SSHKEYPHRASE").map(|s| s.as_str());
let httpsuser = arg_matches.get_one::<String>("HTTPSUSER").map(|s| s.as_str());
let httpspass = arg_matches.get_one::<String>("HTTPSPASS").map(|s| s.as_str());
let since_commit = arg_matches.get_one::<String>("SINCECOMMIT").map(|s| s.as_str());
let until_commit = arg_matches.get_one::<String>("UNTILCOMMIT").map(|s| s.as_str());
let sshkeypath = arg_matches
.get_one::<String>("SSHKEYPATH")
.map(|s| s.as_str());
let sshkeyphrase = arg_matches
.get_one::<String>("SSHKEYPHRASE")
.map(|s| s.as_str());
let httpsuser = arg_matches
.get_one::<String>("HTTPSUSER")
.map(|s| s.as_str());
let httpspass = arg_matches
.get_one::<String>("HTTPSPASS")
.map(|s| s.as_str());
let since_commit = arg_matches
.get_one::<String>("SINCECOMMIT")
.map(|s| s.as_str());
let until_commit = arg_matches
.get_one::<String>("UNTILCOMMIT")
.map(|s| s.as_str());
let recent_days: Option<u32> = match arg_matches.get_one::<u32>("RECENTDAYS") {
Some(d) => {
if *d == 0 {
Expand All @@ -104,7 +116,10 @@ fn run(arg_matches: &ArgMatches) -> Result<(), SimpleError> {
// Get Git objects
let dest_dir = TempDir::new("rusty_hogs").unwrap();
let dest_dir_path = dest_dir.path();
let source_path: &str = arg_matches.get_one::<String>("GITPATH").map(|s| s.as_str()).unwrap();
let source_path: &str = arg_matches
.get_one::<String>("GITPATH")
.map(|s| s.as_str())
.unwrap();

// Do the scan
let git_scanner = GitScanner::new_from_scanner(secret_scanner).init_git_repo(
Expand Down
87 changes: 76 additions & 11 deletions src/bin/duroc_hog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,82 @@ fn main() {
.version("1.0.11")
.author("Scott Cutler <[email protected]>")
.about("File system secret scanner in Rust")
.arg(Arg::new("REGEX").short('r').long("regex").action(ArgAction::Set).value_name("REGEX").help("Sets a custom regex JSON file"))
.arg(Arg::new("FSPATH").required(true).action(ArgAction::Set).value_name("PATH").help("Sets the path of the directory or file to scan."))
.arg(Arg::new("NORECURSIVE").long("norecursive").action(ArgAction::SetTrue).help("Disable recursive scanning of all subdirectories underneath the supplied path"))
.arg(Arg::new("VERBOSE").short('v').long("verbose").action(ArgAction::Count).help("Sets the level of debugging information"))
.arg(Arg::new("ENTROPY").long("entropy").action(ArgAction::SetTrue).help("Enables entropy scanning"))
.arg(Arg::new("DEFAULT_ENTROPY_THRESHOLD").long("default_entropy_threshold").action(ArgAction::Set).default_value("0.6").help("Default entropy threshold (0.6 by default)"))
.arg(Arg::new("UNZIP").short('z').long("unzip").action(ArgAction::SetTrue).help("Recursively scans archives (ZIP and TAR) in memory (dangerous)"))
.arg(Arg::new("CASE").long("caseinsensitive").action(ArgAction::SetTrue).help("Sets the case insensitive flag for all regexes"))
.arg(Arg::new("OUTPUT").short('o').long("outputfile").action(ArgAction::Set).help("Sets the path to write the scanner results to (stdout by default)"))
.arg(Arg::new("PRETTYPRINT").long("prettyprint").action(ArgAction::SetTrue).help("Outputs the JSON in human readable format"))
.arg(Arg::new("ALLOWLIST").short('a').long("allowlist").action(ArgAction::Set).help("Sets a custom allowlist JSON file"))
.arg(
Arg::new("REGEX")
.short('r')
.long("regex")
.action(ArgAction::Set)
.value_name("REGEX")
.help("Sets a custom regex JSON file"),
)
.arg(
Arg::new("FSPATH")
.required(true)
.action(ArgAction::Set)
.value_name("PATH")
.help("Sets the path of the directory or file to scan."),
)
.arg(
Arg::new("NORECURSIVE")
.long("norecursive")
.action(ArgAction::SetTrue)
.help(
"Disable recursive scanning of all subdirectories underneath the supplied path",
),
)
.arg(
Arg::new("VERBOSE")
.short('v')
.long("verbose")
.action(ArgAction::Count)
.help("Sets the level of debugging information"),
)
.arg(
Arg::new("ENTROPY")
.long("entropy")
.action(ArgAction::SetTrue)
.help("Enables entropy scanning"),
)
.arg(
Arg::new("DEFAULT_ENTROPY_THRESHOLD")
.long("default_entropy_threshold")
.action(ArgAction::Set)
.default_value("0.6")
.help("Default entropy threshold (0.6 by default)"),
)
.arg(
Arg::new("UNZIP")
.short('z')
.long("unzip")
.action(ArgAction::SetTrue)
.help("Recursively scans archives (ZIP and TAR) in memory (dangerous)"),
)
.arg(
Arg::new("CASE")
.long("caseinsensitive")
.action(ArgAction::SetTrue)
.help("Sets the case insensitive flag for all regexes"),
)
.arg(
Arg::new("OUTPUT")
.short('o')
.long("outputfile")
.action(ArgAction::Set)
.help("Sets the path to write the scanner results to (stdout by default)"),
)
.arg(
Arg::new("PRETTYPRINT")
.long("prettyprint")
.action(ArgAction::SetTrue)
.help("Outputs the JSON in human readable format"),
)
.arg(
Arg::new("ALLOWLIST")
.short('a')
.long("allowlist")
.action(ArgAction::Set)
.help("Sets a custom allowlist JSON file"),
)
.get_matches();
match run(&matches) {
Ok(()) => {}
Expand Down
Loading

0 comments on commit f84a962

Please sign in to comment.