misc/rust_fixme_3
This commit is contained in:
Generated
+70
@@ -0,0 +1,70 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d"
|
||||
dependencies = [
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
|
||||
dependencies = [
|
||||
"either",
|
||||
"rayon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon-core"
|
||||
version = "1.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
|
||||
dependencies = [
|
||||
"crossbeam-deque",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust_proj"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"xor_cryptor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "xor_cryptor"
|
||||
version = "1.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72e5adf4efbff008434783ea27dab065d79d4c4eb61d2f6eb1299bec75139209"
|
||||
dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "rust_proj"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
xor_cryptor = "1.2.3"
|
||||
@@ -0,0 +1,49 @@
|
||||
use xor_cryptor::XORCryptor;
|
||||
|
||||
fn decrypt(encrypted_buffer: Vec<u8>, borrowed_string: &mut String) {
|
||||
// Key for decryption
|
||||
let key = String::from("CSUCKS");
|
||||
|
||||
// Editing our borrowed value
|
||||
borrowed_string.push_str("PARTY FOUL! Here is your flag: ");
|
||||
|
||||
// Create decryption object
|
||||
let res = XORCryptor::new(&key);
|
||||
if res.is_err() {
|
||||
return;
|
||||
}
|
||||
let xrc = res.unwrap();
|
||||
|
||||
// Did you know you have to do "unsafe operations in Rust?
|
||||
// https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
|
||||
// Even though we have these memory safe languages, sometimes we need to do things outside of the rules
|
||||
// This is where unsafe rust comes in, something that is important to know about in order to keep things in perspective
|
||||
|
||||
unsafe {
|
||||
// Decrypt the flag operations
|
||||
let decrypted_buffer = xrc.decrypt_vec(encrypted_buffer);
|
||||
|
||||
// Creating a pointer
|
||||
let decrypted_ptr = decrypted_buffer.as_ptr();
|
||||
let decrypted_len = decrypted_buffer.len();
|
||||
|
||||
// Unsafe operation: calling an unsafe function that dereferences a raw pointer
|
||||
let decrypted_slice = std::slice::from_raw_parts(decrypted_ptr, decrypted_len);
|
||||
|
||||
borrowed_string.push_str(&String::from_utf8_lossy(decrypted_slice));
|
||||
}
|
||||
println!("{}", borrowed_string);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Encrypted flag values
|
||||
let hex_values = ["41", "30", "20", "63", "4a", "45", "54", "76", "12", "90", "7e", "53", "63", "e1", "01", "35", "7e", "59", "60", "f6", "03", "86", "7f", "56", "41", "29", "30", "6f", "08", "c3", "61", "f9", "35"];
|
||||
|
||||
// Convert the hexadecimal strings to bytes and collect them into a vector
|
||||
let encrypted_buffer: Vec<u8> = hex_values.iter()
|
||||
.map(|&hex| u8::from_str_radix(hex, 16).unwrap())
|
||||
.collect();
|
||||
|
||||
let mut party_foul = String::from("Using memory unsafe languages is a: ");
|
||||
decrypt(encrypted_buffer, &mut party_foul);
|
||||
}
|
||||
Reference in New Issue
Block a user