-
-
Save roycewilliams/49b1e6410033ac234fb708fd7ef24c04 to your computer and use it in GitHub Desktop.
newhashcat.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#----------------------------------------------------------------------------- | |
# Created: 2019-04-20 | |
# $Id: newhashcat,v 1.6 2020/06/15 14:54:08 root Exp $ | |
#----------------------------------------------------------------------------- | |
# TODO | |
# - prompt to sync royce code or not | |
# - prompt to use a custom algorithm for testing phase (or 'q' to skip?) | |
# - check if /proc/cpuinfo exists or not | |
# - offer to compare algo lists: wiki, help, test.pl | |
#----------------------------------------------------------------------------- | |
HASHCAT_GITHUBDIR=/usr/local/src/sec/crack/hashcat/github/hashcat | |
HASHCAT_ROYCEDIR=/usr/local/src/sec/crack/hashcat/github/royce/hashcat | |
WORKLOAD=4 | |
HASHCAT_ROYCEMODE= | |
OSFAMILY=$(uname -s) | |
#----------------------------------------------------------------------------- | |
if [ "${OSFAMILY}" == "FreeBSD" ]; then | |
CORECOUNT=$(sysctl hw.ncpu|cut -d\: -f2) | |
CC=$(which gcc 2>/dev/null) | |
if [ -z "${CC}" -o ! -x "${CC}" ]; then | |
echo "- Could not find gcc" | |
exit 1 | |
fi | |
CC_SPEC="CC=gcc" | |
GMAKE=$(which gmake 2>/dev/null) | |
if [ -z "${GMAKE}" -o ! -x "${GMAKE}" ]; then | |
echo "- Could not find gmake" | |
exit 1 | |
fi | |
MYMAKE="gmake ${CC_SPEC}" | |
else | |
# Assume Linux. | |
CORECOUNT=$(grep -c ^processor /proc/cpuinfo) | |
CC_SPEC= | |
MYMAKE="make ${CC_SPEC}" | |
fi | |
#----------------------------------------------------------------------------- | |
# check for existence of tools | |
#----------------------------------------------------------------------------- | |
# cmdline | |
if [ ! -z "$1" ]; then | |
if [ "$1" == 'royce' ]; then | |
HASHCAT_ROYCEMODE=yes | |
echo "- Syncing royce repo with upstream ..." | |
HASHCAT_GITHUBDIR=${HASHCAT_ROYCEDIR} | |
pushd ${HASHCAT_GITHUBDIR} \ | |
&& git fetch upstream \ | |
&& git checkout master \ | |
&& git merge upstream/master \ | |
&& git push | |
else | |
HASHCAT_GITHUBDIR=$1 | |
fi | |
fi | |
#----------------------------------------------------------------------------- | |
echo "" | |
echo "newhashcat: fetches, compiles, and tests the latest hashcat from GitHub" | |
echo "" | |
echo "- OS family: ${OSFAMILY}" | |
echo "- Using source dir: ${HASHCAT_GITHUBDIR}" | |
echo "- Using core count: ${CORECOUNT}" | |
echo "- Using make: ${MYMAKE}" | |
echo "- Testing with -w: ${WORKLOAD}" | |
echo "" | |
if [ ! -d ${HASHCAT_GITHUBDIR} ]; then | |
echo "- Error: Invalid or nonexistent source directory: ${HASHCAT_GITHUBDIR}." | |
echo "- Suggestion:" | |
echo "" | |
echo "mkdir -p ${HASHCAT_GITHUBDIR}" | |
echo "cd ${HASHCAT_GITHUBDIR}/.." | |
echo "rmdir hashcat" | |
echo "git clone https://github.com/hashcat/hashcat" | |
echo "" | |
exit 1 | |
fi | |
#----------------------------------------------------------------------------- | |
# Fetch source. | |
# Two 'git pull' are needed to force display of latest log? | |
echo "- Fetching latest source from GitHub into ${HASHCAT_GITHUBDIR} ..." | |
cd ${HASHCAT_GITHUBDIR} \ | |
&& git submodule update --init \ | |
&& git pull \ | |
&& git pull \ | |
&& echo "" \ | |
&& echo "- Press Enter to see changelog (press 'q' when finished)" \ | |
&& read blah | |
# Log | |
git log ORIG_HEAD | less \ | |
&& echo "- Press Enter to start make (${MYMAKE}, ${CORECOUNT} cores), or Control-Break to abort" \ | |
&& read blah | |
# Compile | |
${MYMAKE} clean \ | |
&& ${MYMAKE} -j ${CORECOUNT} \ | |
&& echo "" \ | |
&& echo "- Press Enter to run test, or Control-Break to abort" \ | |
&& read blah | |
# Test | |
if [ ! -x ./hashcat ]; then | |
echo "Error: hashcat executable not created." | |
exit 2 | |
fi | |
./hashcat -O -w ${WORKLOAD} -b -m 1500 | |
HASHCAT_EXIT=$? | |
if [ "${HASHCAT_EXIT}" != "0" ]; then | |
echo "- Error: Hashcat test completed with exit code ${HASHCAT_EXIT}" | |
echo "- Skipping install." | |
exit 3 | |
fi | |
echo "- Hashcat test completed with exit code $?" | |
echo "" | |
# Install | |
if [ "${HASHCAT_ROYCEMODE}" == 'yes' ]; then | |
echo "- Using royce's repo, skipping install." | |
echo "" | |
exit 4 | |
else | |
echo "" | |
echo "- Checking for installed hashcat components in /usr/local ..." | |
echo "- (These will be removed by '${MYMAKE} uninstall')" | |
sudo find /usr/local -name '*hashcat*' -ls \ | |
| egrep -v '/usr/local/scripts|/usr/local/share/man|hashcatify|hcxhashcat|/usr/local/src/sec/' | |
echo "" | |
echo "- Press Enter to run '${MYMAKE} uninstall' and '${MYMAKE} install', or Control-Break to abort" \ | |
&& read blah | |
fi | |
sudo ${MYMAKE} uninstall && \ | |
sudo ${MYMAKE} install \ | |
&& echo "" \ | |
&& echo "- Install complete." \ | |
&& echo "" \ | |
&& ls -la /usr/local/bin/hashcat \ | |
&& /usr/local/bin/hashcat --version \ | |
&& echo "" \ | |
#----------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment