Skip to content

Instantly share code, notes, and snippets.

@godevnet
Created June 9, 2015 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save godevnet/804650b72f3b1644c045 to your computer and use it in GitHub Desktop.
Save godevnet/804650b72f3b1644c045 to your computer and use it in GitHub Desktop.
Bash script to test shadow user (sha512) with awk and python crypt getpass modules
#/bin/bash
# testpwd.sh
user=$1
dic=$2
shadow=/etc/shadow
original=$(<$shadow awk -v user=$user -F : 'user == $1 {print $2}')
prefix=${original%"${original#\$*\$*\$}"}
for pass in $(cat $dic); do
echo "Password : $pass"
computed=$(python -c "import crypt, getpass, pwd; print crypt.crypt('$pass', '$prefix')")
echo "Original : $original"; echo "Computed : $computed"
if [ "$computed" = "$original" ]; then echo "Matched !!!" ; else echo "No match"; fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment