Skip to content

Commit

Permalink
v1.1.11
Browse files Browse the repository at this point in the history
- Extracted relevant methods from other Hifumi Tech repositories
- Created banner for README.md + updated README.md
- Published new version of the crate on crates.io
  • Loading branch information
Hifumi1337 committed Nov 1, 2022
1 parent e3c447b commit 4dcaec2
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [Hifumi1337]
patreon: hifumitech
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Generated by Cargo
# will have compiled files and executables
/target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
19 changes: 19 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "mercy"
version = "1.1.11"
edition = "2021"
authors = ["Hifumi1337"]
license = "BSD-2-Clause"
categories = ["cryptography", "encoding"]
keywords = ["hashing", "decode", "encode", "cracking"]
description = "Mercy is a public Rust crate created to assist with building cybersecurity frameworks, assessment tools, and numerous other projects"
repository = "https://github.com/hifumitech/mercy"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
base64 = "0.13.0"
sha2 = "0.10"
md5 = "0.7.0"
hexdump = "0.1.1"
sys-info = "0.9.0"
82 changes: 80 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,80 @@
# mercy
Open source Rust crate created to assist with creating cybersecurity frameworks and projects
<h1 align="center">
<img src="assets/mercy_banner_v1.png" />
<br />
Mercy
</h1>

<h3 align="center">
📚 <a href="https://docs.rs/mercy/latest/mercy/">Documentation</a>
</h3>
<br>

Mercy is a public Rust crate created to assist with building cybersecurity frameworks, assessment tools, and numerous other projects. We hope to create a sustainable crate to make creating security tools in Rust a little easier and not require so much bloat in your project.

## Usage
Since Mercy is a standard crate, it can easily be utilized in any project already initialized with the Cargo configuration.

Add the following line to your `Cargo.toml` file:
```toml
mercy = "1.1.11"
```

Once the `Cargo.toml` file has been updated, you can import the crate and use the provided methods by running `cargo run`.

### Cryptographic Processes
Here's a quick example for decoding and encoding using the base64 protocol:
```rust
use mercy::{
mercy_decode,
mercy_encode
};

fn main() {
// Encode string "Hifumi Technologies"
mercy_encode("base64", "Hifumi Technologies");

// Decode string "TWVsYW5jaG9seSBMYWJz"
mercy_decode("base64", "SGlmdW1pIFRlY2hub2xvZ2llcw==");
}
```

### Hexadecimal Dumping
Here's how to dump hexadecimal values in a single line using Mercy:
```rust
use mercy::mercy_hex;

fn main() {
mercy_hex("hex_dump", "/Location/of/file");
}
```

### Miscellaneous Methods
Some extra methods have been included to assist with local data collection. We currently allow you to collect the internal ip address of your device or dump certain information, specified by the user.
```rust
use mercy::mercy_extra;

fn main() {
// Contains the internal ip address of the user's system
mercy_extra("internal_ip", "");

// This method is extensive, but the "all" parameter allows the user to dump everything we have set in Mercy
mercy_extra("system_info", "all");
}
```
We can also use the following paremeters, replacing the "all" keyword:

- hostname
- cpu_cores
- cpu_speed
- os_release
- proc

### More Info
If ever in doubt, feel free to run this special function to display more information about the crate.
```rust
use mercy::source;

fn main() {
mercy_source();
}
```
Binary file added assets/mercy_banner_v1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
219 changes: 219 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/*
Hifumi Technologies (https://github.com/hifumitech)
File: src/lib.rs
Author(s): {
Hifumi1337 (https://github.com/Hifumi1337)
}
*/

use std::{
path::Path,
fs::{self, File},
io::Read,
net::UdpSocket
};

use base64;
use md5;
use sha2::{Sha256, Digest};
use hexdump::hexdump;

use sys_info::{
hostname,
cpu_num,
cpu_speed,
os_release,
proc_total
};

pub fn mercy_source() -> String {
const VERSION: &str = "1.1.11";
const AUTHOR: &str = "Hifumi Technologies (https://github.com/hifumitech)";
return format!("Author: {}\nVersion: {}\nDocumentation: https://docs.rs/crate/mercy/latest", AUTHOR, VERSION);
}

/*
Public decoding methods provided by Mercy
*/
pub fn mercy_decode(mercy_call: &str, mercy_string: &str) -> String {
match mercy_call {
"base64" => base64_decode(mercy_string.to_string()),
"rot13" => rot13_decode(mercy_string.to_string()),
_ => unknown_msg("Unable to decode message")
}
}

/*
Public encoding methods provided by Mercy
*/
pub fn mercy_encode(mercy_call: &str, mercy_string: &str) -> String {
match mercy_call {
"base64" => base64_encode(mercy_string.to_string()),
_ => unknown_msg("Unable to encode message")
}
}

/*
Public hash methods provided by Mercy
*/
pub fn mercy_hash(mercy_call: &str, mercy_string: &str) -> String {
match mercy_call {
"sha2_256" => sha2_256_hash(mercy_string.to_string()),
"md5" => md5_hash(mercy_string.to_string()),
_ => unknown_msg("Unable to hash message")
}
}

/*
Public hexadecimal methods provided by Mercy
*/
pub fn mercy_hex(mercy_call: &str, mercy_file: &str) -> String {
match mercy_call {
"hex_dump" => collect_file_hex(mercy_file),
_ => unknown_msg("Unable to provide hexadecimal dump for file specified")
}
}

/*
Public extra methods provided by Mercy
*/
pub fn mercy_extra(mercy_call: &str, mercy_choose: &str) -> String {
match mercy_call {
"internal_ip" => internal_ip(),
"system_info" => system_info(mercy_choose),
_ => unknown_msg("Unable to provide the information you requested")
}
}

/*
Decoding methods
*/

// Base64 decode
fn base64_decode(encoded_msg: String) -> String {
// Converts into bytes
let bytes = base64::decode(encoded_msg.to_string()).expect("Unable to decode provided string");

// Converts into a more readable format
let final_out = String::from_utf8_lossy(&bytes);

return final_out.to_string();
}

// rot13 algorithm
fn rot13_decode(encoded_msg: String) -> String {
let mut result_str = String::from("");

// Iterates over encoded_msg
for x in encoded_msg.chars() {
let charcode = x as u32;

if x.is_lowercase() {
// Checks if character in string is lowercase
let check_text = 'a' as u32;
let rot_final = ((charcode - check_text + 13) % 26) + check_text;
result_str.push(char::from_u32(rot_final).unwrap());
} else if x.is_uppercase() {
// Checks if character in string is uppercse
let check_text = 'A' as u32;
let rot_final = ((charcode - check_text + 13) % 26) + check_text;
result_str.push(char::from_u32(rot_final).unwrap());
} else {
result_str.push(x);
}
}

return result_str.to_string();
}

/*
Encoding methods
*/

fn base64_encode(plaintext_msg: String) -> String {
// Converts into bytes
let encoded_msg = base64::encode(plaintext_msg.as_bytes());
return encoded_msg.to_string();
}

/*
Hashing methods
*/

fn sha2_256_hash(plaintext_msg: String) -> String {
let mut run_hash = Sha256::new();
run_hash.update(plaintext_msg.as_bytes());

let hash = run_hash.finalize();
return format!("{:x}", hash);
}

fn md5_hash(plaintext_msg: String) -> String {
let hash = md5::compute(plaintext_msg.as_bytes());
return format!("{:x}", hash);
}

/*
Hexadecimal manipulation
*/

// Converts file/bytes to a readable vector
fn byte_to_vec(filename: &str) -> Vec<u8> {
let mut file = File::open(&filename).expect("Unable to locate file");
let file_metadata = fs::metadata(&filename).expect("Unable to read file metadata");
let mut buffer = vec![0; file_metadata.len() as usize];

// Writes buffer data to the hex file
for i in 0..buffer.len() {
file.read(&mut buffer).expect("Buffer overflow detected. Stopping operation...");

if i == buffer.len() {
println!("Buffer limit exceeded");
break;
}
}

buffer
}

fn collect_file_hex(convert_file: &str) -> String {
// convert_file requires an absolute path to work 100% of the time
if Path::new(convert_file).exists() {
// Dumps hex data to stdout
return format!("{:#?}", hexdump(&byte_to_vec(convert_file)));
} else {
return format!("Unable to locate the file specified");
}
}

/*
Miscellaneous
*/

// Quick method for collecting the internal ip address of the local system
fn internal_ip() -> String {
let socket = UdpSocket::bind("0.0.0.0:0").expect("Unable to bind UDP socket");
socket.connect("8.8.8.8:80").expect("Unable to connect to address");
let addr = socket.local_addr().expect("Unable to return the socket address");
return addr.ip().to_string();
}

fn system_info(data: &str) -> String {

let all_system_info = format!("\nHostname: {}\nNumber of CPU cores: {}\nCPU Fan Speed: {} MHz\nOperating System Release Version: {}\nNumber of Processes: {}\n", hostname().unwrap(), cpu_num().unwrap(), cpu_speed().unwrap(), os_release().unwrap(), proc_total().unwrap());

match data {
"hostname" => return format!("Hostname: {}", hostname().unwrap()),
"cpu_cores" => return format!("Number of CPU cores: {}", cpu_num().unwrap()),
"cpu_speed" => return format!("CPU Fan Speed: {} MHz", cpu_speed().unwrap()),
"os_release" => return format!("Operating System Release Version: {}", os_release().unwrap()),
"proc" => return format!("Number of Processes: {}", proc_total().unwrap()),
"all" => return format!("{}", all_system_info),
_ => return format!("Unable to gather system information")
}
}

fn unknown_msg(custom_msg: &str) -> String {
return format!("{}", custom_msg);
}

0 comments on commit 4dcaec2

Please sign in to comment.