diff --git a/Cargo.lock b/Cargo.lock index c155169..35d6558 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,37 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +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.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + [[package]] name = "getopts" version = "0.2.21" @@ -35,6 +66,26 @@ dependencies = [ "proc-macro2", ] +[[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 = "syn" version = "2.0.100" @@ -72,6 +123,7 @@ version = "0.1.0" dependencies = [ "getopts", "obfstr", + "rayon", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index 8d36820..7c7f22d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,4 +13,13 @@ repository = "https://git.cscherr.de/PlexSheep/rs-base" [dependencies] getopts = "0.2.21" obfstr = "0.4.4" +rayon = { version = "1.10.0", optional = true } thiserror = "2.0.12" + +[[bin]] +name = "bf" +path = "src/bf.rs" +required-features = ["rayon"] + +[features] +rayon = ["dep:rayon"] diff --git a/prepare-challenge.sh b/prepare-challenge.sh index e65bf32..210dc0d 100755 --- a/prepare-challenge.sh +++ b/prepare-challenge.sh @@ -2,6 +2,7 @@ EXPORT_DIR="challenge" mkdir -p $EXPORT_DIR +rm -rf $EXPORT_DIR/* cargo build --release --locked cp ./target/release/timars $EXPORT_DIR/timars strip $EXPORT_DIR/timars diff --git a/src/bf.rs b/src/bf.rs new file mode 100644 index 0000000..7aca23e --- /dev/null +++ b/src/bf.rs @@ -0,0 +1,84 @@ +use std::io; +use std::process::Command; +use std::sync::atomic::AtomicBool; +use std::thread::sleep; +use std::time::Duration; + +use rayon::prelude::*; + +const IGNORE_LENGTH: &[usize] = &[60usize, 61usize]; +static WAIT: AtomicBool = AtomicBool::new(false); + +fn format_time(hour: i32, minute: i32) -> String { + format!("{:02}:{:02}", hour, minute) +} + +fn execute(cth: i32, ctm: i32, cfh: i32, cfm: i32, cph: i32, cpm: i32, i: usize) { + while WAIT.load(std::sync::atomic::Ordering::SeqCst) { + sleep(Duration::from_millis(50)); + } + + let to = format_time(cth, ctm); + let fr = format_time(cfh, cfm); + let pa = format_time(cph, cpm); + let cmd = format!("./timars -f {} -t {} -p {}", fr, to, pa); + + let output = Command::new("sh") + .arg("-c") + .arg(&cmd) + .output() + .expect("Failed to execute command"); + + let output_str = String::from_utf8_lossy(&output.stdout); + if output.status.success() && IGNORE_LENGTH.contains(&output_str.len()) { + if i % 53 == 0 { + println!( + "to: {} from: {} pause: {} => len: {}", + to, + fr, + pa, + output_str.len() + ); + } + } else { + println!( + "\n\ + {}\n\ + {}\n\ + ==================\n\ + SOMETHING UNUSUAL!\n\ + LEN: {}\n\ + ", + cmd, + output_str, + output_str.len() + ); + WAIT.store(true, std::sync::atomic::Ordering::SeqCst); + let mut input = String::new(); + println!("Input anything to continue"); + io::stdin() + .read_line(&mut input) + .expect("Failed to read input"); + WAIT.store(false, std::sync::atomic::Ordering::SeqCst); + } +} + +fn main() { + let cph = 13; // NOTE: fix pause to 1337 to make it faster + let cpm = 37; // in a real ctf, this would be hinted at + (0..23).into_par_iter().for_each(|cth| { + let mut i = 0; + for ctm in 0..60 { + for cfh in 0..23 { + for cfm in 0..60 { + // for cph in 0..23 { + // for cpm in 0..60 { + execute(cth, ctm, cfh, cfm, cph, cpm, i); + i += 1; + // } + // } + } + } + } + }); +}