Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Citrix CTX1 #86

Merged
merged 4 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ once_cell = "1.16.0"
text_io = "0.1.12"
data-encoding = "2.3.2"
bs58 = "0.4.0"
num = "0.4"

[dev-dependencies]
criterion = "0.4.0"
Expand Down
87 changes: 46 additions & 41 deletions src/decoders/citrix_ctx1_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Crack for Decoder<CitrixCTX1Decoder> {
let mut results = CrackResult::new(self, text.to_string());

if decoded_text.is_none() {
debug!("Failed to decode citrix_ctx1 because the length is not a multiple of 4");
debug!("Failed to decode citrix_ctx1");
SkeletalDemise marked this conversation as resolved.
Show resolved Hide resolved
return results;
}

Expand Down Expand Up @@ -65,10 +65,6 @@ fn decode_citrix_ctx1(text: &str) -> Option<String> {
return None;
}

if text.to_uppercase() != text || !text.chars().all(|c| c.is_ascii()) {
return None;
}

let mut rev = text.as_bytes().to_vec();
rev.reverse();
let mut result = Vec::new();
Expand All @@ -78,9 +74,12 @@ fn decode_citrix_ctx1(text: &str) -> Option<String> {
if i + 2 >= rev.len() {
temp = 0;
} else {
temp = ((rev[i + 2] - 0x41) & 0xF) ^ (((rev[i + 3] - 0x41) << 4) & 0xF0);
temp = ((rev[i + 2].checked_sub(0x41))? & 0xF)
^ (((rev[i + 3].checked_sub(0x41))? << 4) & 0xF0);
}
temp ^= (((rev[i] - 0x41) & 0xF) ^ (((rev[i + 1] - 0x41) << 4) & 0xF0)) ^ 0xA5;
temp ^= (((rev[i].checked_sub(0x41))? & 0xF)
^ (((rev[i + 1].checked_sub(0x41))? << 4) & 0xF0))
^ 0xA5;
result.push(temp);
}

Expand Down Expand Up @@ -110,78 +109,84 @@ mod tests {

#[test]
fn test_citrix_ctx1() {
// This tests if Citrix CTX1 can decode Citrix CTX1 successfully
SkeletalDemise marked this conversation as resolved.
Show resolved Hide resolved
let decoder = Decoder::<CitrixCTX1Decoder>::new();
let result = decoder.crack(
"MNGIKIANMEGBKIANMHGCOHECJADFPPFKINCIOBEEIFCA",
&get_athena_checker(),
);
assert_eq!(result.unencrypted_text.unwrap(), "hello world");
}

#[test]
fn citrix_ctx1_decode_empty_string() {
// Citrix_ctx1 returns an empty string, this is a valid citrix_ctx1 string
// but returns False on check_string_success
fn test_citrix_ctx1_lowercase() {
// This tests if Citrix CTX1 can decode lowercase strings
SkeletalDemise marked this conversation as resolved.
Show resolved Hide resolved
let decoder = Decoder::<CitrixCTX1Decoder>::new();
let result = decoder.crack(
"pbfejjdmpaffidcgkdagmkgpljbmjjdmpffajkdponeiiicnpkfpjjdmpifnilcoooelmoglincioeebjadfocehilcopdfgndhgjadfmegbjmdjknai",
&get_athena_checker(),
);
assert_eq!(
result.unencrypted_text.unwrap(),
"This is lowercase Citrix CTX1"
);
}

#[test]
fn test_citrix_ctx1_substraction_overflows() {
// This tests if Citrix CTX1 can handle substraction overflows
SkeletalDemise marked this conversation as resolved.
Show resolved Hide resolved
// It should return None and not panic
let citrix_ctx1_decoder = Decoder::<CitrixCTX1Decoder>::new();
let result = citrix_ctx1_decoder
.crack("", &get_athena_checker())
.crack("NUWEN43XR44TLAYHSU4DVI2ISF======", &get_athena_checker())
.unencrypted_text;
assert!(result.is_none());
}

#[test]
fn test_citrix_ctx1_length() {
// This tests if Citrix CTX1 can handle strings with length that are not divisible by 4
// It should return None
SkeletalDemise marked this conversation as resolved.
Show resolved Hide resolved
let citrix_ctx1_decoder = Decoder::<CitrixCTX1Decoder>::new();
let result = citrix_ctx1_decoder
.crack("AAA", &get_athena_checker())
.unencrypted_text;
assert!(result.is_none());
}

#[test]
fn citrix_ctx1_decode_handles_panics() {
// This tests if Citrix CTX1 can handle panics
// It should return None
let citrix_ctx1_decoder = Decoder::<CitrixCTX1Decoder>::new();
let result = citrix_ctx1_decoder
.crack(
"hello my name is panicky mc panic face!",
&get_athena_checker(),
)
.unencrypted_text;
if result.is_some() {
panic!("Decode_citrix_ctx1 did not return an option with Some<t>.")
} else {
// If we get here, the test passed
// Because the citrix_ctx1_decoder.crack function returned None
// as it should do for the input
assert_eq!(true, true);
}
assert!(result.is_none());
}

#[test]
fn citrix_ctx1_handle_panic_if_empty_string() {
// This tests if Citrix CTX1 can handle an empty string
// It should return None
let citrix_ctx1_decoder = Decoder::<CitrixCTX1Decoder>::new();
let result = citrix_ctx1_decoder
.crack("", &get_athena_checker())
.unencrypted_text;
if result.is_some() {
assert_eq!(true, true);
}
}

#[test]
fn citrix_ctx1_work_if_string_not_citrix_ctx1() {
// You can citrix_ctx1 decode a string that is not citrix_ctx1
// This string decodes to:
// ```.ée¢
// (uÖ²```
// https://gchq.github.io/CyberChef/#recipe=From_Base58('A-Za-z0-9%2B/%3D',true)&input=aGVsbG8gZ29vZCBkYXkh
let citrix_ctx1_decoder = Decoder::<CitrixCTX1Decoder>::new();
let result = citrix_ctx1_decoder
.crack("hello good day!", &get_athena_checker())
.unencrypted_text;
if result.is_some() {
assert_eq!(true, true);
}
assert!(result.is_none());
}

#[test]
fn citrix_ctx1_handle_panic_if_emoji() {
// This tests if Citrix CTX1 can handle an emoji
// It should return None
let citrix_ctx1_decoder = Decoder::<CitrixCTX1Decoder>::new();
let result = citrix_ctx1_decoder
.crack("😂", &get_athena_checker())
.unencrypted_text;
if result.is_some() {
assert_eq!(true, true);
}
assert!(result.is_none());
}
}