From e3ad91b7c2e2d97322d6434b4562db08bce9c0cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20Garc=C3=A9s=20Mar=C3=ADn?= Date: Wed, 6 Mar 2024 23:12:06 +0100 Subject: [PATCH] documentation --- CODE_OF_CONDUCT.md | 134 ++++++++++++++++++++++++++ CONTRIBUTING.md | 86 +++++++++++++++++ README.md | 10 +- src/traits/registry/extra/env_vars.rs | 19 ++++ src/traits/registry/mod.rs | 29 +----- src/utils/testing.rs | 25 +++++ src/utils/win/csidl.rs | 2 +- 7 files changed, 275 insertions(+), 30 deletions(-) create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..99943c8 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,134 @@ + +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official email address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[INSERT CONTACT METHOD]. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available +at [https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e8a1adc --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,86 @@ +# Contributing to ForensicRS + +Thanks for your help improving the project! + +## Reporting issues + +If you believe you've discovered a bug in ForensicRS, please check if the bug is +already known or [create an issue](https://github.com/ForensicRS/forensic-rs/issues) on +github. Please also report an issue if you find documentation that you think is +confusing or could be improved. + +When creating a new issue, make sure to include as many details as possible to +help us understand the problem. When reporting a bug, always specify which +version of forensic-rs you're using and which operating system you're using. + +## Documentation + +If you find an API that is not documented, unclear or missing examples, please +file an issue. If you make changes to the documentation, please read +[How To Write Documentation] and make sure your changes conform to the +format outlined in [Documenting Components]. + +[How To Write Documentation]: https://doc.rust-lang.org/rustdoc/how-to-write-documentation.html +[Documenting Components]: https://doc.rust-lang.org/rustdoc/how-to-write-documentation.html#documenting-components + +## Fixing bugs and implementing new features + +Make sure that your work is tracked by an issue or a (draft) pull request, this +helps us avoid duplicating work. If your work includes publicly visible changes, +make sure those are properly documented as explained in the section above. + +### Running tests + +Run the unit tests with `cargo test`. + +### Commits + +It is a recommended best practice to keep your changes as logically grouped as +possible within individual commits. If while you're developing you prefer doing +a number of commits that are "checkpoints" and don't represent a single logical +change, please squash those together before asking for a review. + +#### Commit message guidelines + +A good commit message should describe what changed and why. + +1. The first line should: + - Contain a short description of the change (preferably 50 characters or less, + and no more than 72 characters) + - Be entirely in lowercase with the exception of proper nouns, acronyms, and + the words that refer to code, like function/variable names + - Be prefixed with the name of the sub crate being changed + + Examples: + - `forensic-rs: new artifact type prefetch` + - `frnsc-taskbar: translate AUMID into executable path` + +1. Keep the second line blank. +1. Wrap all other lines at 72 columns (except for long URLs). +1. If your patch fixes an open issue, you can add a reference to it at the end + of the log. Use the `Fixes: #` prefix and the issue number. For other + references use `Refs: #`. `Refs` may include multiple issues, separated by a + comma. + + Examples: + + - `Fixes: #1234` + - `Refs: #1000` + +Sample complete commit message: + +```txt +subcrate: explain the commit in one line + +Body of commit message is a few lines of text, explaining things +in more detail, possibly giving some background about the issue +being fixed, etc. + +The body of the commit message can be several paragraphs, and +please do proper word-wrap and keep columns shorter than about +72 characters or so. That way, `git log` will show things +nicely even when it is indented. + +Fixes: #1234 +Refs: #1000, #1100 +``` \ No newline at end of file diff --git a/README.md b/README.md index f4373ea..7e76920 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,16 @@ A Rust-based framework to build tools that analyze forensic artifacts and can be Note: still in Alpha version ## Community -[![Telegram](https://img.shields.io/badge/-telegram-gray?style=for-the-badge&logo=telegram)](https://t.me/forensic_rs) + +[![Discord][discord-badge]][chat-url] + +Join [the conversation on Discord][chat-url] to discuss anything related to ForensicRS. + +[chat-url]: https://discord.gg/uVq4289B +[discord-badge]: https://img.shields.io/badge/Discord-chat-5865F2?style=for-the-badge&logo=discord ## Introduction -The idea behind the framework is to allow the reuse of forensic artifact analysis tools. For this reason, the framework allows decoupling the code of the analysis tools from the reading of the artifacts. Thus, a tool that analyzes [UAL](https://learn.microsoft.com/en-us/windows-server/administration/user-access-logging/get-started-with-user-access-logging +The idea behind the framework is to allow the reuse of forensic artifact analysis tools. For this reason, the framework decouples the code of the analysis tools that parses or reads artifacts from the ones that access the readed value: registry keys, files, SQL rows. Thus, a tool that analyzes [UAL](https://learn.microsoft.com/en-us/windows-server/administration/user-access-logging/get-started-with-user-access-logging ) artifacts can be used regardless of whether the artifact is inside a ZIP as a result of triage or directly on the file system. In this way, the same tools can be used if we want to make a triage processor like [Plaso](https://plaso.readthedocs.io/en/latest/), a module within an EDR or even a tool with a graphical interface like Eric Zimmerman's [Registry Explorer](https://ericzimmerman.github.io) with the advantage of the reliability of the Rust code and its easy integration into Python scripts. diff --git a/src/traits/registry/extra/env_vars.rs b/src/traits/registry/extra/env_vars.rs index 639fe14..2c61c96 100644 --- a/src/traits/registry/extra/env_vars.rs +++ b/src/traits/registry/extra/env_vars.rs @@ -5,6 +5,22 @@ use crate::err::ForensicResult; use crate::traits::registry::{RegValue, RegistryReader, HKLM, HKU}; +/// Extract the principal environment variables for all users which have a profile: +/// * USERPROFILE +/// * SystemRoot +/// * windir +/// * SystemDrive +/// * ProgramFiles +/// * ProgramData +/// * ProgramFiles(x86) +/// * ProgramW6432 +/// * LOCALAPPDATA +/// * APPDATA +/// * TMP +/// * TEMP +/// * HOMEPATH +/// * HOMEDRIVE +/// * USERNAME pub fn get_env_vars_of_users( reg_reader: &dyn RegistryReader, ) -> ForensicResult { @@ -65,6 +81,9 @@ fn list_all_profiles(reg_reader: &dyn RegistryReader, system_root : &str) -> For profile_path = format!("{}{}", system_root, &profile_path[12..]) } if !profile_path.is_empty() { + if user_sid == "S-1-5-18" { + map.insert(String::new(), profile_path.clone()); + } map.insert(user_sid, profile_path); } reg_reader.close_key(user_key); diff --git a/src/traits/registry/mod.rs b/src/traits/registry/mod.rs index 5a4f1b5..7a4ddd9 100644 --- a/src/traits/registry/mod.rs +++ b/src/traits/registry/mod.rs @@ -1,9 +1,7 @@ use crate::{ - core::UsersEnvVars, err::{ForensicError, ForensicResult}, utils::time::Filetime + err::{ForensicError, ForensicResult}, utils::time::Filetime }; -use self::extra::env_vars::get_env_vars_of_users; - use super::vfs::{VirtualFile, VirtualFileSystem}; pub const HKCR : RegHiveKey = RegHiveKey::HkeyClassesRoot; @@ -12,7 +10,7 @@ pub const HKCU : RegHiveKey = RegHiveKey::HkeyCurrentUser; pub const HKLM : RegHiveKey = RegHiveKey::HkeyLocalMachine; pub const HKU : RegHiveKey = RegHiveKey::HkeyUsers; -mod extra; +pub mod extra; #[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug)] pub enum RegHiveKey { @@ -223,9 +221,6 @@ pub trait RegistryReader { /// Closes a handle to the specified registry key. #[allow(unused_variables)] fn close_key(&self, hkey: RegHiveKey) {} -} - -pub trait RegistryReaderUtils : RegistryReader { /// Get the same value as the env var "%SystemRoot%"". It's usually "C:\Windows" fn get_system_root(&self) -> ForensicResult { @@ -252,28 +247,8 @@ pub trait RegistryReaderUtils : RegistryReader { let value = self.read_value(key, "CurrentBuild")?; Ok(value.try_into()?) } - /// Extract the principal environment variables for all users which have a profile: - /// * USERPROFILE - /// * SystemRoot - /// * windir - /// * SystemDrive - /// * ProgramFiles - /// * ProgramData - /// * ProgramFiles(x86) - /// * ProgramW6432 - /// * LOCALAPPDATA - /// * APPDATA - /// * TMP - /// * TEMP - /// * HOMEPATH - /// * HOMEDRIVE - /// * USERNAME - fn get_env_vars_of_users(&self) -> ForensicResult where Self: Sized { - get_env_vars_of_users(self) - } } - /// Simplify the process of closing Registry keys /// /// ```rust diff --git a/src/utils/testing.rs b/src/utils/testing.rs index 97c1da9..9d59751 100644 --- a/src/utils/testing.rs +++ b/src/utils/testing.rs @@ -413,3 +413,28 @@ fn basic_registry() -> BTreeMap { map.insert("HKU".into(), hkcu_cell); map } + +pub fn init_testing_logger() { + let rcv = crate::notifications::testing_notifier_dummy(); + std::thread::spawn(move || loop { + let msg = match rcv.recv() { + Ok(v) => v, + Err(_) => return, + }; + println!( + "{:?} - {} - {}:{} - {}", + msg.r#type, msg.module, msg.file, msg.line, msg.data + ); + }); + let rcv = crate::logging::testing_logger_dummy(); + std::thread::spawn(move || loop { + let msg = match rcv.recv() { + Ok(v) => v, + Err(_) => return, + }; + println!( + "{:?} - {} - {}:{} - {}", + msg.level, msg.module, msg.file, msg.line, msg.data + ); + }); +} \ No newline at end of file diff --git a/src/utils/win/csidl.rs b/src/utils/win/csidl.rs index 5fe53a3..5707cb6 100644 --- a/src/utils/win/csidl.rs +++ b/src/utils/win/csidl.rs @@ -325,7 +325,7 @@ pub fn csidl_value(csidl: &str) -> Option<&'static str> { /// ``` pub fn interpolate_csidl_path(pth : &mut str, env_vars : &UserEnvVars) -> Option { if !pth.starts_with('{') { - return None + return Some(pth.to_string()) } let pos = pth.as_bytes().iter().position(|&v| v == b'}')?; (&mut pth[0..pos + 1]).make_ascii_uppercase();