Skip to content

Commit cc99c08

Browse files
committed
general rust-fixme-3
1 parent 58807fc commit cc99c08

File tree

136 files changed

+434
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+434
-0
lines changed
1.73 KB
Binary file not shown.

src/PICOCTF/GENERAL/rust-fixme-3/fixme3/Cargo.lock

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "rust_proj"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
xor_cryptor = "1.2.3"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use xor_cryptor::XORCryptor;
2+
3+
fn decrypt(encrypted_buffer: Vec<u8>, borrowed_string: &mut String) {
4+
// Key for decryption
5+
let key = String::from("CSUCKS");
6+
7+
// Editing our borrowed value
8+
borrowed_string.push_str("PARTY FOUL! Here is your flag: ");
9+
10+
// Create decryption object
11+
let res = XORCryptor::new(&key);
12+
if res.is_err() {
13+
return;
14+
}
15+
let xrc = res.unwrap();
16+
17+
// Decrypt the flag
18+
let decrypted_buffer = xrc.decrypt_vec(encrypted_buffer);
19+
20+
// Append the decrypted result to the borrowed string
21+
borrowed_string.push_str(&String::from_utf8_lossy(&decrypted_buffer));
22+
23+
println!("{}", borrowed_string);
24+
}
25+
26+
fn main() {
27+
// Encrypted flag values
28+
let hex_values = [
29+
"41", "30", "20", "63", "4a", "45", "54", "76", "12", "90", "7e", "53", "63", "e1", "01", "35",
30+
"7e", "59", "60", "f6", "03", "86", "7f", "56", "41", "29", "30", "6f", "08", "c3", "61", "f9", "35",
31+
];
32+
33+
// Convert the hexadecimal strings to bytes and collect them into a vector
34+
let encrypted_buffer: Vec<u8> = hex_values.iter()
35+
.map(|&hex| u8::from_str_radix(hex, 16).unwrap())
36+
.collect();
37+
38+
let mut party_foul = String::from("Using memory unsafe languages is a: ");
39+
decrypt(encrypted_buffer, &mut party_foul);
40+
}
41+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use xor_cryptor::XORCryptor;
2+
3+
fn decrypt(encrypted_buffer: Vec<u8>, borrowed_string: &mut String) {
4+
// Key for decryption
5+
let key = String::from("CSUCKS");
6+
7+
// Editing our borrowed value
8+
borrowed_string.push_str("PARTY FOUL! Here is your flag: ");
9+
10+
// Create decryption object
11+
let res = XORCryptor::new(&key);
12+
if res.is_err() {
13+
return;
14+
}
15+
let xrc = res.unwrap();
16+
17+
// Did you know you have to do "unsafe operations in Rust?
18+
// https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
19+
// Even though we have these memory safe languages, sometimes we need to do things outside of the rules
20+
// This is where unsafe rust comes in, something that is important to know about in order to keep things in perspective
21+
22+
// unsafe {
23+
// Decrypt the flag operations
24+
let decrypted_buffer = xrc.decrypt_vec(encrypted_buffer);
25+
26+
// Creating a pointer
27+
let decrypted_ptr = decrypted_buffer.as_ptr();
28+
let decrypted_len = decrypted_buffer.len();
29+
30+
// Unsafe operation: calling an unsafe function that dereferences a raw pointer
31+
let decrypted_slice = std::slice::from_raw_parts(decrypted_ptr, decrypted_len);
32+
33+
borrowed_string.push_str(&String::from_utf8_lossy(decrypted_slice));
34+
// }
35+
println!("{}", borrowed_string);
36+
}
37+
38+
fn main() {
39+
// Encrypted flag values
40+
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"];
41+
42+
// Convert the hexadecimal strings to bytes and collect them into a vector
43+
let encrypted_buffer: Vec<u8> = hex_values.iter()
44+
.map(|&hex| u8::from_str_radix(hex, 16).unwrap())
45+
.collect();
46+
47+
let mut party_foul = String::from("Using memory unsafe languages is a: ");
48+
decrypt(encrypted_buffer, &mut party_foul);
49+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"rustc_fingerprint":16153101823103919521,"outputs":{"13331785392996375709":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/usr\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n","stderr":""},"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.85.1 (4eb161250 2025-03-15) (Arch Linux rust 1:1.85.1-1)\nbinary: rustc\ncommit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181\ncommit-date: 2025-03-15\nhost: x86_64-unknown-linux-gnu\nrelease: 1.85.1\nLLVM version: 19.1.7\n","stderr":""}},"successes":{}}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Signature: 8a477f597d28d172789f06886806bc55
2+
# This file is a cache directory tag created by cargo.
3+
# For information about cache directory tags see https://bford.info/cachedir/

src/PICOCTF/GENERAL/rust-fixme-3/fixme3/target/debug/.cargo-lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file has an mtime of when this was started.

0 commit comments

Comments
 (0)