Skip to content

Instantly share code, notes, and snippets.

@geeknik
Created December 31, 2023 00:55
Show Gist options
  • Save geeknik/a74ce04d99dbd77720f5d235fb535586 to your computer and use it in GitHub Desktop.
Save geeknik/a74ce04d99dbd77720f5d235fb535586 to your computer and use it in GitHub Desktop.
Vulnerable Bash
#!/bin/bash
create_secure_file() {
local filename=$1
local dir="/secure_dir"
if [[ ! -d "$dir" ]]; then
mkdir "$dir"
chmod 700 "$dir"
fi
local tmpfile="${dir}/$(basename "$filename").tmp"
touch "$tmpfile"
chmod 644 "$tmpfile"
echo "Secure Content: $(date)" > "$tmpfile"
chmod 600 "$tmpfile"
mv "$tmpfile" "${dir}/${filename}"
echo "Secure file '${dir}/${filename}' created successfully."
}
echo -n "Enter the name of the secure file you want to create: "
read FILENAME
create_secure_file "$FILENAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment