Rust fixme 1
Name: Rust fixme 1 Description: Have you heard of Rust? Fix the syntax errors in this Rust file to print the flag! Download the Rust code here. Author: Taylor McCampbell Tags: Easy, General Skills, picoCTF 2025 Challenge from: picoCTF 2025 Files: fixme1.tar.gz Hints: 1. Cargo is Rust's package manager and will make your life easier. See the getting started page here 2. println! 3. Rust has some pretty great compiler error messages. Read them maybe?
Theory
According to the description, to get the flag we to download some rust code, and fix the errors. Before doing that, comes the hard part, setting up rust. I used Replit, which is a platform to run many programming languages online, including rust, and believe me, I tried installing rust at first, but was met with a lot of dead ends, downloaded 4.5 gigabytes of content, and didn't really get to actually run it, so I just used Replit, which everything is already set up, and I just had to paste the code and libraries (which it downloads automatically) from the tar file. And when you create the project, it's instantly public, which I am so sorry, but I missed that for the entire competition, I literally had the rust codes public on my Replit already solved and with the flags on it, so I could've been disqualified, but luckily nobody noticed my mistake, which you can find here, just ignore the name of the repl. Anyways, onto the actual challenge.
Solution
First let's paste our code:
use xor_cryptor::XORCryptor; fn main() { // Key for decryption let key = String::from("CSUCKS") // How do we end statements in Rust? // Encrypted flag values let hex_values = ["41", "30", "20", "63", "4a", "45", "54", "76", "01", "1c", "7e", "59", "63", "e1", "61", "25", "7f", "5a", "60", "50", "11", "38", "1f", "3a", "60", "e9", "62", "20", "0c", "e6", "50", "d3", "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(); // Create decrpytion object let res = XORCryptor::new(&key); if res.is_err() { ret; // How do we return in rust? } let xrc = res.unwrap(); // Decrypt flag and print it out let decrypted_buffer = xrc.decrypt_vec(encrypted_buffer); println!( ":?", // How do we print out a variable in the println function? String::from_utf8_lossy(&decrypted_buffer) ); }
So right off the bat, we can see that there are three comments highlighting the three errors in the code. How do we end statements in Rust? With a semicolon (;). How do we return in rust? Using `return;`. How do we print out a variable in the println function? In that example specifically we can use `{:?}`. Also I'm gonna remove all the comments for no reason at all:
use xor_cryptor::XORCryptor; fn main() { let key = String::from("CSUCKS"); let hex_values = ["41", "30", "20", "63", "4a", "45", "54", "76", "01", "1c", "7e", "59", "63", "e1", "61", "25", "7f", "5a", "60", "50", "11", "38", "1f", "3a", "60", "e9", "62", "20", "0c", "e6", "50", "d3", "35"]; let encrypted_buffer: Vec<u8> = hex_values.iter() .map(|&hex| u8::from_str_radix(hex, 16).unwrap()) .collect(); let res = XORCryptor::new(&key); if res.is_err() { return; } let xrc = res.unwrap(); let decrypted_buffer = xrc.decrypt_vec(encrypted_buffer); println!( "{:?}", String::from_utf8_lossy(&decrypted_buffer) ); }
And when we run this code:
Blocking waiting for file lock on package cache Blocking waiting for file lock on package cache Blocking waiting for file lock on package cache Blocking waiting for file lock on package cache Compiling rust_proj v0.1.0 (/home/runner/workspace) Building [=======================> ] 11/12: rust_proj(bin) Finished `dev` profile [unoptimized + debuginfo] target(s) in 5.30s Running `target/debug/rust_proj` "picoCTF{4r3_y0u_4_ru$t4c30n_n0w?}"
There we go! That's the flag.
I rated this level as "good"! :3
https://play.picoctf.org/practice/challenge/461