-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
422,089 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,45 @@ | ||
[package] | ||
name = "ares_lib" | ||
version = "0.1.0" | ||
version = "0.10.0" | ||
edition = "2021" | ||
description = "Automated decoding tool, Ciphey but in Rust" | ||
license = "MIT" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
[lib] | ||
name = "ares" | ||
path = "src/lib.rs" | ||
bench = false | ||
|
||
[dependencies] | ||
clap = {version = "4.1.1", features = ["derive"]} | ||
log = "0.4" | ||
env_logger = "0.10.0" | ||
base64 = "0.20.0" | ||
rayon = "1.6.1" | ||
lemmeknow = "0.7.0" | ||
include_dir = "0.7.3" | ||
once_cell = "1.17.0" | ||
text_io = "0.1.12" | ||
data-encoding = "2.3.3" | ||
bs58 = "0.4.0" | ||
base91 = "0.1.0" | ||
num = "0.4" | ||
crossbeam = "0.8" | ||
base65536 = "1.0.1" | ||
ansi_term = "0.12.1" | ||
lazy_static = "1.4.0" | ||
lazy-regex = "2.4.1" | ||
regex = "1.7.1" | ||
|
||
[dev-dependencies] | ||
criterion = "0.4.0" | ||
|
||
[profile.release] | ||
lto = "fat" | ||
panic = "abort" | ||
strip = "symbols" | ||
codegen-units = 1 | ||
|
||
[[bench]] | ||
name = "benchmark_crackers" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use ares::checkers::athena::Athena; | ||
use ares::checkers::checker_type::{Check, Checker}; | ||
use ares::checkers::CheckerTypes; | ||
use ares::decoders::base64_decoder::Base64Decoder; | ||
use ares::decoders::interface::{Crack, Decoder}; | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
|
||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
let decode_base64 = Decoder::<Base64Decoder>::new(); | ||
let athena_checker = Checker::<Athena>::new(); | ||
let checker = CheckerTypes::CheckAthena(athena_checker); | ||
c.bench_function("base64 successful decoding", |b| { | ||
b.iter(|| decode_base64.crack(black_box("aGVsbG8gd29ybGQ="), &checker)) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use ares::checkers::athena::Athena; | ||
use ares::checkers::checker_type::{Check, Checker}; | ||
use ares::checkers::CheckerTypes; | ||
use ares::decoders::base64_decoder::Base64Decoder; | ||
use ares::decoders::interface::{Crack, Decoder}; | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
|
||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
let decode_base64 = Decoder::<Base64Decoder>::new(); | ||
let athena_checker = Checker::<Athena>::new(); | ||
let checker = CheckerTypes::CheckAthena(athena_checker); | ||
c.bench_function("base64 successful decoding", |b| { | ||
b.iter(|| decode_base64.crack(black_box("aGVsbG8gd29ybGQ="), &checker)) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
build-all: | ||
cargo build | ||
docker build . | ||
|
||
test: | ||
cargo build | ||
cargo check | ||
cargo clippy | ||
cargo fmt | ||
cargo test | ||
|
||
publish: | ||
cargo publish | ||
docker buildx build --platform linux/arm/v7,linux/amd64,linux/arm64/v8 -t autumnskerritt/ares:latest --push . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/// import general checker | ||
use crate::checkers::{ | ||
checker_type::{Check, Checker}, | ||
default_checker::DefaultChecker, | ||
}; | ||
use lemmeknow::Identifier; | ||
|
||
/// Library input is the default API input | ||
/// The CLI turns its arguments into a LibraryInput struct | ||
pub struct LibraryInput<Type> { | ||
/// The input to be decoded. | ||
/// Given to us by the user. | ||
pub encoded_text: String, | ||
/// A level of verbosity to determine. | ||
/// How much we print in logs. | ||
pub verbose: i32, | ||
/// The checker to use | ||
pub checker: Checker<Type>, | ||
/// The lemmeknow config to use | ||
pub lemmeknow_config: Identifier, | ||
} | ||
|
||
/// Creates a default lemmeknow config | ||
const LEMMEKNOW_DEFAULT_CONFIG: Identifier = Identifier { | ||
min_rarity: 0.0, | ||
max_rarity: 0.0, | ||
tags: vec![], | ||
exclude_tags: vec![], | ||
file_support: false, | ||
boundaryless: false, | ||
}; | ||
|
||
impl Default for LibraryInput<DefaultChecker> { | ||
fn default() -> Self { | ||
LibraryInput { | ||
encoded_text: String::new(), | ||
// this will be of type Checker<DefaultChecker> | ||
verbose: 0, | ||
checker: Checker::new(), | ||
lemmeknow_config: LEMMEKNOW_DEFAULT_CONFIG, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use crate::{checkers::checker_result::CheckResult, config::get_config}; | ||
use lemmeknow::Identifier; | ||
use log::trace; | ||
|
||
use super::{ | ||
checker_type::{Check, Checker}, | ||
english::EnglishChecker, | ||
human_checker, | ||
lemmeknow_checker::LemmeKnow, | ||
regex_checker::RegexChecker, | ||
}; | ||
|
||
/// Athena checker runs all other checkers | ||
pub struct Athena; | ||
|
||
impl Check for Checker<Athena> { | ||
fn new() -> Self { | ||
Checker { | ||
// TODO: Update fields with proper values | ||
name: "Athena Checker", | ||
description: "Runs all available checkers", | ||
link: "", | ||
tags: vec!["athena", "all"], | ||
expected_runtime: 0.01, | ||
popularity: 1.0, | ||
lemmeknow_config: Identifier::default(), | ||
_phantom: std::marker::PhantomData, | ||
} | ||
} | ||
|
||
fn check(&self, text: &str) -> CheckResult { | ||
let config = get_config(); | ||
// Only run regex if its in the config | ||
if config.regex.is_some() { | ||
trace!("running regex"); | ||
let regex_checker = Checker::<RegexChecker>::new(); | ||
let regex_result = regex_checker.check(text); | ||
if regex_result.is_identified { | ||
let mut check_res = CheckResult::new(®ex_checker); | ||
check_res.is_identified = human_checker::human_checker(®ex_result); | ||
return check_res; | ||
} | ||
} else { | ||
// In Ciphey if the user uses the regex checker all the other checkers turn off | ||
// This is because they are looking for one specific bit of information so will not want the other checkers | ||
// TODO: wrap all checkers in oncecell so we only create them once! | ||
let lemmeknow = Checker::<LemmeKnow>::new(); | ||
let lemmeknow_result = lemmeknow.check(text); | ||
if lemmeknow_result.is_identified { | ||
let mut check_res = CheckResult::new(&lemmeknow); | ||
check_res.is_identified = human_checker::human_checker(&lemmeknow_result); | ||
return check_res; | ||
} | ||
|
||
let english = Checker::<EnglishChecker>::new(); | ||
let english_result = english.check(text); | ||
if english_result.is_identified { | ||
let mut check_res = CheckResult::new(&english); | ||
check_res.is_identified = human_checker::human_checker(&english_result); | ||
return check_res; | ||
} | ||
} | ||
|
||
CheckResult::new(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use super::checker_type::Checker; | ||
|
||
/// The checkerResult struct is used to store the results of a checker. | ||
pub struct CheckResult { | ||
/// If our checkers return success, we change this bool to True | ||
pub is_identified: bool, | ||
/// text is the text before we check it. | ||
// we can make this &'text str | ||
// but then crack requires lifetime annotations. | ||
pub text: String, | ||
/// Description of the checked text. | ||
pub description: String, | ||
/// Name of the Checker we are using | ||
pub checker_name: &'static str, | ||
/// Description of the Checker we are using | ||
pub checker_description: &'static str, | ||
/// Link to more info about checker | ||
pub link: &'static str, | ||
} | ||
|
||
/// To save time we have a default | ||
/// for checkResult in case we fail | ||
/// I do not believe the checker is important if failed | ||
/// as we will not use it. To save time we will return a default | ||
/// checker. | ||
impl CheckResult { | ||
/// Creates a default CheckResult | ||
pub fn new<Type>(checker_used: &Checker<Type>) -> CheckResult { | ||
CheckResult { | ||
is_identified: false, | ||
text: "".to_string(), | ||
checker_name: checker_used.name, | ||
checker_description: checker_used.description, | ||
description: "".to_string(), | ||
link: checker_used.link, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// Checker_type is a type used to define checkers | ||
/// This means that we can standardise the way we check for plaintext | ||
use crate::checkers::checker_result::CheckResult; | ||
use lemmeknow::Identifier; | ||
|
||
/// Every checker is of type CheckerType | ||
/// This will let us pick & choose which checkers to use | ||
/// at runtime. | ||
pub struct Checker<Type> { | ||
/// The name of the checker | ||
pub name: &'static str, | ||
/// The description of the checker | ||
/// you can take the first line from Wikipedia | ||
/// Sometimes our checkers do not exist on Wikipedia so we write our own. | ||
pub description: &'static str, | ||
/// The link to the checker's website | ||
/// Wikipedia link, articles, github etc | ||
pub link: &'static str, | ||
/// The tags of the checker | ||
pub tags: Vec<&'static str>, | ||
/// The expected runtime of the checker | ||
/// We get this by bench marking the code | ||
pub expected_runtime: f32, | ||
/// The popularity of the checker | ||
pub popularity: f32, | ||
/// lemmeknow config object | ||
pub lemmeknow_config: Identifier, | ||
/// https://doc.rust-lang.org/std/marker/struct.PhantomData.html | ||
/// Let's us save memory by telling the compiler that our type | ||
/// acts like a type <T> even though it doesn't. | ||
/// Stops the compiler complaining, else we'd need to implement | ||
/// some magic to make it work. | ||
pub _phantom: std::marker::PhantomData<Type>, | ||
} | ||
|
||
/// Every checker must implement this trait | ||
/// Which checks the given text to see if its plaintext | ||
/// and returns CheckResult, which is our results object. | ||
pub trait Check { | ||
/// Returns a new struct of type CheckerType | ||
fn new() -> Self | ||
where | ||
Self: Sized; | ||
/// Checks the given text to see if its plaintext | ||
fn check(&self, text: &str) -> CheckResult; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use lemmeknow::Identifier; | ||
|
||
use super::{ | ||
checker_result::CheckResult, | ||
checker_type::{Check, Checker}, | ||
}; | ||
|
||
/// The default checker is used to check if the text is plaintext | ||
/// Based on what the Ares team has found to be the best checker. | ||
|
||
pub struct DefaultChecker; | ||
|
||
impl Check for Checker<DefaultChecker> { | ||
fn new() -> Self { | ||
Checker { | ||
name: "Template checker", | ||
description: "This is a default template checker. If you're seeing this, it's an error. Please contact us on Discord http://discord.skerritt.blog", | ||
link: "http://discord.skerritt.blog", | ||
tags: vec![], | ||
expected_runtime: 0.0, | ||
popularity: 0.0, | ||
lemmeknow_config: Identifier::default(), | ||
_phantom: std::marker::PhantomData, | ||
} | ||
} | ||
|
||
fn check(&self, _text: &str) -> CheckResult { | ||
CheckResult::new(self) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::checkers::{ | ||
checker_result::CheckResult, | ||
checker_type::{Check, Checker}, | ||
default_checker::DefaultChecker, | ||
}; | ||
|
||
#[test] | ||
fn default_checker_works() { | ||
let checker = Checker::<DefaultChecker>::new(); | ||
let checker_result = CheckResult::new(&checker); | ||
assert!(!checker_result.is_identified); | ||
} | ||
} |
Oops, something went wrong.