From eeaf79dc1361e321d904c59d0769ba42d65c5818 Mon Sep 17 00:00:00 2001 From: SadlyNotSappho Date: Fri, 29 Sep 2023 11:55:16 -0700 Subject: [PATCH] move structs to structs.rs, add get_home(), i hate perms i hate perms i hate perms i hate perms --- src/lib.rs | 56 +++++++++++++++---------------- src/main.rs | 37 ++++++++++++++++----- src/structs.rs | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 39 deletions(-) create mode 100644 src/structs.rs diff --git a/src/lib.rs b/src/lib.rs index ad058c4..0541bb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,33 +1,29 @@ -pub struct Data { - pub vulnerable_folders: Vec, - pub pinged_home: bool, - pub known_malware: Vec, - pub cam_access: bool, - pub mic_access: bool, -} +pub mod structs; -pub struct Folder { - pub path: String, - pub r#type: FolderType, - pub name: String -} +use std::process; -pub enum FolderType { - ApplicationData, - Binary, - SystemData, - Kernel -} - -pub struct Malware { - pub r#type: Vec, - pub name: String, -} - -pub enum MalwareType { - DataThief, // sells data to ad companies (cough cough google chrome cough cough) - LoginStealer, // fuckin skyblock mods, probably - TrojanHorse, // pretends to be something its not (cough cough google chrome cough cough) - Ransomware, // encrypts your files and makes you pay to get them back - Spyware, // parental controls apps +pub fn get_home() -> String { + match std::env::consts::OS { + "linux" => match std::env::var("HOME") { + Ok(var) => var, + Err(why) => { + eprintln!("lib::get_home: Couldn't get $HOME on Linux: {why:?}"); + process::exit(1); + } + }, + "windows" => match std::env::var("userprofile") { + Ok(var) => var, + Err(why) => { + eprintln!("lib::get_home: Couldn't get $userprofile on Windows: {why:?}"); + process::exit(1) + } + }, + _ => match std::env::var("HOME") { + Ok(var) => var, + Err(why) => { + eprintln!("lib::get_home: Couldn't get $HOME on other OS: {why:?}"); + process::exit(1) + } + }, + } } diff --git a/src/main.rs b/src/main.rs index 896dbc0..89ab0c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,14 @@ -use std::{fmt::Write, thread, time::Duration, sync::mpsc}; - +use std::{fmt::Write, thread, time::Duration, sync::mpsc, process, fs}; use indicatif::{ProgressBar, ProgressState, ProgressStyle}; +use security_checker::{structs::Folder, get_home}; fn main() { - println!("Running SCAM..."); + // TODO: add support for other OSes + if std::env::consts::OS != "linux" { + println!("This currently only supports linux. Sorry!"); + process::exit(1) + } + println!("SCAMing you..."); let pb = ProgressBar::new(100); pb.set_style(ProgressStyle::with_template("[{elapsed_precise}] [{wide_bar:.cyan/blue}] {pos}/{len} ({eta})") .unwrap() @@ -20,14 +25,28 @@ fn main() { let (tx, rx) = mpsc::channel(); thread::spawn(move || { - let val = String::from("hi i ran :D"); - thread::sleep(Duration::from_secs(60)); - tx.send(val).unwrap(); + let mut out = vec![]; + let folders = Folder::linux(); + for mut folder in folders { + folder.path = folder.path.replace('~', &get_home()[..]); + + // check if we have write perms for all of the folders, if so, push to out + let md = fs::metadata(&folder.path).unwrap(); + let perms = md.permissions(); + let readonly = perms.readonly(); + + println!("{readonly} - {}", folder.path); + if !readonly { + println!("can write to {}", folder.path); + out.push(folder) + } + }; + tx.send(out) }); pb.finish(); - println!("Ran SCAM. Here's your output!") + println!("Ran SCAM. Here's your output!"); - // let recieved = rx.recv().unwrap(); - // println!("{recieved:?}"); + let recieved = rx.recv().unwrap(); + println!("{recieved:?}"); } diff --git a/src/structs.rs b/src/structs.rs new file mode 100644 index 0000000..308251c --- /dev/null +++ b/src/structs.rs @@ -0,0 +1,90 @@ +pub struct Data { + pub vulnerable_folders: Vec, + pub pinged_home: bool, + pub known_malware: Vec, + pub cam_access: bool, + pub mic_access: bool, + pub root: bool, +} + +#[derive(Debug)] +pub struct Folder { + pub path: String, + pub r#type: FolderType, + pub contains: String, +} + +#[derive(Debug)] +pub enum FolderType { + ApplicationData, + Binary, + SystemData, + Kernel, +} + +pub struct Malware { + pub r#type: Vec, + pub name: String, +} + +pub enum MalwareType { + DataThief, // sells data to ad companies (cough cough google chrome cough cough) + LoginStealer, // fuckin skyblock mods, probably + TrojanHorse, // pretends to be something its not (cough cough google chrome cough cough) + Ransomware, // encrypts your files and makes you pay to get them back + Spyware, // parental controls apps +} + +impl Folder { + pub fn linux() -> Vec { + vec![ + // system folders + Folder { + path: String::from("/usr/bin"), + r#type: FolderType::Binary, + contains: "Installed Programs".to_string(), + }, + Folder { + path: "/boot".to_string(), + r#type: FolderType::Kernel, + contains: "Boot Files, Kernel".to_string(), + }, + Folder { + path: "/lib".to_string(), + r#type: FolderType::SystemData, + contains: "Kernel Modules, Libraries".to_string(), + }, + Folder { + path: "/usr/lib".to_string(), + r#type: FolderType::SystemData, + contains: "Libraries, Object Files".to_string(), + }, + Folder { + path: "/dev".to_string(), + r#type: FolderType::SystemData, + contains: "Access To All Devices".to_string(), + }, + Folder { + path: "/tmp".to_string(), + r#type: FolderType::ApplicationData, + contains: "Temporary Application Data".to_string() + }, + // user specific files + Folder { + path: "~/.config".to_string(), + r#type: FolderType::ApplicationData, + contains: "Permanent Application Data, Login Info".to_string() + }, + Folder { + path: "~/.local/share".to_string(), + r#type: FolderType::ApplicationData, + contains: String::from("Permanent Application Data, Login Info") + }, + Folder { + path: "~/.cache".to_string(), + r#type: FolderType::ApplicationData, + contains: "Cached Data From Applications".to_string() + } + ] + } +}