Skip to content

Instantly share code, notes, and snippets.

@nmattia
Created March 4, 2017 23:15
Show Gist options
  • Save nmattia/8d3bca0540bf0ffca8c26669051965e4 to your computer and use it in GitHub Desktop.
Save nmattia/8d3bca0540bf0ffca8c26669051965e4 to your computer and use it in GitHub Desktop.
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