Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to crack a LUKS partition given a fuzzy passphrase pattern
#!/usr/bin/env bash
set -e
the_pattern=$1
# We need to export because xargs runs in a subshell
export the_file=$2
if [ -z "${the_pattern}" ]; then
echo pattern missing
exit 1
fi
if [ -z "${the_file}" ]; then
echo file missing
exit 1
fi
crack_maybe=$(cat <<'EOF'
echo PASS | cryptsetup open --test-passphrase ${the_file}
rc=$?
if [ "$rc" -ne "2" ]; then
echo "return code $rc on input PASS"
exit 255
fi
EOF
)
echo "starting..."
stutter ${the_pattern} \
| parallel --ungroup --block-size 1k --progress --pipe --halt now,fail=1 \
" xargs -n 1 -I PASS sh -c '$crack_maybe'"
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment