Skip to content

Instantly share code, notes, and snippets.

@domenukk
Last active August 21, 2023 03:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domenukk/7f9b353d2887d1b98fe370ff254069d7 to your computer and use it in GitHub Desktop.
Save domenukk/7f9b353d2887d1b98fe370ff254069d7 to your computer and use it in GitHub Desktop.
Funsafe Rust Jail (for HackIM CTF 2023)
#!/bin/bash
echo "Your code please."
FOLDER=$(mktemp -d)
cp flag.txt "$FOLDER"
cd "$FOLDER"
mkdir src
cat <<EOF > Cargo.toml
[package]
name = "funsafe"
version = "0.1.0"
edition = "2021"
[lib]
name = "funsafe"
path = "src/lib.rs"
[[bin]]
name = "funsafe-bin"
path = "src/main.rs"
[dependencies]
ctor = "0.2.4"
[profile.release]
panic = "abort"
EOF
read program
echo "#![no_std] ${program//!/}" > src/lib.rs
echo "use funsafe::fun; pub fn main() {fun()}" > src/main.rs
RUSTFLAGS="$RUSTFLAGS -Funsafe-code -Zsanitizer=address" timeout 20 cargo +nightly run --target x86_64-unknown-linux-gnu --release
rm -rf "$FOLDER"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment