commit 3d9b4f83f62bc5488263f19f8d6865286becdbdf Author: Michel ten Voorde Date: Sun Apr 13 20:30:34 2025 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82f9802 --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +.gradle/ \ No newline at end of file diff --git a/gchashcrack_console/.gitignore b/gchashcrack_console/.gitignore new file mode 100644 index 0000000..ca35f2d --- /dev/null +++ b/gchashcrack_console/.gitignore @@ -0,0 +1,25 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/gchashcrack_console/pom.xml b/gchashcrack_console/pom.xml new file mode 100644 index 0000000..aa43e3a --- /dev/null +++ b/gchashcrack_console/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + org.example + gchashcrack + 1.0-SNAPSHOT + jar + + + 11 + + + + + + commons-cli + commons-cli + 1.4 + + + org.projectlombok + lombok + 1.18.12 + provided + + + commons-codec + commons-codec + 1.14 + + + org.openjfx + javafx-controls + 14 + + + + + + + + maven-compiler-plugin + + 11 + 11 + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + + + org.tenvoorde.gchashcrack.GcHashCrack + + + + + jar-with-dependencies + + + + + + + org.openjfx + javafx-maven-plugin + 0.0.4 + + HelloFX + + + + + \ No newline at end of file diff --git a/gchashcrack_console/src/main/java/org/tenvoorde/gchashcrack/GcHashCrack.java b/gchashcrack_console/src/main/java/org/tenvoorde/gchashcrack/GcHashCrack.java new file mode 100644 index 0000000..35f08a9 --- /dev/null +++ b/gchashcrack_console/src/main/java/org/tenvoorde/gchashcrack/GcHashCrack.java @@ -0,0 +1,181 @@ +package org.tenvoorde.gchashcrack; + +import lombok.Builder; +import lombok.Data; +import org.apache.commons.cli.*; +import org.apache.commons.codec.digest.DigestUtils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class GcHashCrack { + private static String format; + private static String digest; + private static String hash; + + private static List rangeVariables = new ArrayList<>(); + private static String formattedString; + + private static int totalCombinations = 1; + + @Builder + @Data + private static class RangeVariable { + private int lower; + private int upper; + } + + public static void main(String[] args) { + if (!parseOptions(args)) { + System.exit(255); + } + parseFormattedString(); + startCracking(); + } + + private static void startCracking() { + Integer[] loopVar = new Integer[rangeVariables.size()]; + for (int i = 0; i < rangeVariables.size(); i++) { + loopVar[i] = rangeVariables.get(i).getLower(); + totalCombinations *= (rangeVariables.get(i).getUpper() - rangeVariables.get(i).getLower() + 1); + } + + System.out.println("Total combinations: " + totalCombinations); + + boolean success = false; + String stringToHash; + int counter = 0; + int percentage = 0; + int percentage10 = 0; + do { + counter++; + stringToHash = String.format(formattedString, (Object[]) loopVar); + success = testHash(stringToHash); + if ((100 * counter / totalCombinations) > percentage) { + System.out.print("."); + percentage = 100 * counter / totalCombinations; + } + if ((percentage / 10) > (percentage10 / 10)) { + System.out.print(percentage + "%"); + //percentage10 = + } + if (!increaseLoopVars(loopVar)) { + break; + } + } while (!success); + if (success) { + System.out.println("Success: " + stringToHash); + } else { + System.out.println("No match found"); + } + } + + private static boolean testHash(String stringToHash) { + String generatedHash; + switch(digest) { + case "MD5": + generatedHash = DigestUtils.md5Hex(stringToHash); + break; + default: + System.err.println("Illegal digest: " + digest); + } + return stringToHash.equalsIgnoreCase(hash); + } + + private static boolean increaseLoopVars(Integer[] loopVar) { + boolean done = false; + int cursor = 0; + do { + if (cursor == rangeVariables.size()) { + return false; + } + loopVar[cursor]++; + if (loopVar[cursor] > rangeVariables.get(cursor).getUpper()) { + loopVar[cursor] = rangeVariables.get(cursor).getLower(); + cursor++; + } else { + done = true; + } + } while (!done); + + return true; + } + + private static void parseFormattedString() { + // \[[0-9]-[0-9]\] + // N52 [0-5][0-9].[0-9][0-9][0-9] E005 [0-5][0-9].[0-9][0-9][0-9] + String pattern = "\\[[0-9]-[0-9]\\]"; + Pattern p = Pattern.compile(pattern); + + Matcher matcher = p.matcher(format); + + int count = 0; + while (matcher.find()) { + String range = format.substring(matcher.start(), matcher.end()); + rangeVariables.add(rangeVariableFromFormat(range)); + } + + formattedString = format.replaceAll(pattern, "%d"); + System.out.println(formattedString); + } + + private static RangeVariable rangeVariableFromFormat(String range) { + range = range.substring(1, range.length() - 1); + return RangeVariable.builder() + .lower(Integer.parseInt(range.substring(0, 1))) + .upper(Integer.parseInt(range.substring(2, 3))) + .build(); + } + + private static boolean parseOptions(String[] args) { + CommandLineParser parser = new DefaultParser(); + + Option formatOption = Option.builder("f").desc("Formatted string (between \"\" quotes) to be hashed").hasArg(true).numberOfArgs(1).optionalArg(false).longOpt("formattedString").build(); + Option digestOption = Option.builder("d").desc("Digest type (currently supported: MD5)").hasArg(true).numberOfArgs(1).optionalArg(false).longOpt("digest").build(); + Option hashOption = Option.builder("h").desc("Hash to compare with").hasArg(true).numberOfArgs(1).optionalArg(false).longOpt("hash").build(); + Options options = new Options(); + options.addOption(formatOption); + options.addOption(digestOption); + options.addOption(hashOption); + + CommandLine line = null; + + try { + line = parser.parse( options, args ); + } catch( ParseException exp ) { + System.err.println(exp.getMessage()); + } + + boolean errorInCmdLine = false; + + if (!line.hasOption("f")) { + System.err.println("Missing argument: -f"); + errorInCmdLine = true; + } + if (!line.hasOption("d")) { + System.err.println("Missing argument: -d"); + errorInCmdLine = true; + } + if (!line.hasOption("h")) { + System.err.println("Missing argument: -h"); + errorInCmdLine = true; + } + + if (!errorInCmdLine) { + format = line.getOptionValue("f"); + digest = line.getOptionValue("d"); + hash = line.getOptionValue("h"); + } else { + HelpFormatter formatter = new HelpFormatter(); + formatter.setLongOptSeparator("="); + formatter.printHelp(160, "gcHashCrack", "\n", options, "Example: gcHashCrack --hash=c35d8729ca887d26366da4ef9b843c08 --string=\"N52 [4-5][0-9].[0-9][0-9][0-9] E005 58.[0-9][0-9][0-9]\" --digest=MD5", true); + errorInCmdLine = true; + } + + return !errorInCmdLine; + } + +} diff --git a/hashcracker-installer/.gitignore b/hashcracker-installer/.gitignore new file mode 100644 index 0000000..ca35f2d --- /dev/null +++ b/hashcracker-installer/.gitignore @@ -0,0 +1,25 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/hashcracker-installer/pom.xml b/hashcracker-installer/pom.xml new file mode 100644 index 0000000..1491af4 --- /dev/null +++ b/hashcracker-installer/pom.xml @@ -0,0 +1,94 @@ + + + 4.0.0 + + org.tenvoorde + hashcracker-installer + 1.0-SNAPSHOT + + izpack-jar + + + + ${project.build.directory}/staging + HashCracker + + ${basedir}/src/main/izpack + ${staging.dir}/appfiles + + + + + org.tenvoorde + hashcracker + 1.0-SNAPSHOT + + + + + + + org.codehaus.izpack + izpack-maven-plugin + 5.1.3 + true + + ${staging.dir.app} + ${izpack.dir.app}/install.xml + ${project.build.directory} + ${project.build.finalName} + + true + false + false + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.7 + + + default-cli + process-resources + + run + + + + + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.10 + + ${staging.dir}/lib + true + true + true + true + true + system + + + + copy + process-resources + + copy-dependencies + + + + + + + \ No newline at end of file diff --git a/hashcracker-installer/src/main/izpack/install.xml b/hashcracker-installer/src/main/izpack/install.xml new file mode 100644 index 0000000..ee04fac --- /dev/null +++ b/hashcracker-installer/src/main/izpack/install.xml @@ -0,0 +1,52 @@ + + + + HashCracker + 1.0 + + 11 + + + + + + + + + images/peas_load.gif + + + + + + + + + + + + + + + + + + + + + + + < + + The core files needed for the application + + + + + + \ No newline at end of file diff --git a/hashcracker/.gitignore b/hashcracker/.gitignore new file mode 100644 index 0000000..ca35f2d --- /dev/null +++ b/hashcracker/.gitignore @@ -0,0 +1,25 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/hashcracker/build.gradle b/hashcracker/build.gradle new file mode 100644 index 0000000..57dda1d --- /dev/null +++ b/hashcracker/build.gradle @@ -0,0 +1,39 @@ +plugins { + id 'org.openjfx.javafxplugin' version '0.0.8' + id 'org.beryx.runtime' version '1.8.5' + id 'com.github.johnrengelman.shadow' version '5.2.0' +// id 'org.beryx.jlink' version '2.19.0' + id "io.freefair.lombok" version "5.1.0" +} + +repositories { + mavenLocal() + mavenCentral() +} + +dependencies { + implementation 'org.openjfx:javafx-controls:14' +// compileOnly 'org.projectlombok:lombok:1.18.12' +// annotationProcessor 'org.projectlombok:lombok:1.18.12' +// testCompileOnly 'org.projectlombok:lombok:1.18.12' +// testAnnotationProcessor 'org.projectlombok:lombok:1.18.12' + implementation 'org.mapstruct:mapstruct-processor:1.3.1.Final' + implementation 'org.apache.commons:commons-lang3:3.10' + implementation 'commons-codec:commons-codec:1.14' + implementation 'org.jfxtras:jmetro:11.6.11' +} + +javafx { + version = "14" + modules = [ 'javafx.controls'] +} + +mainClassName = 'org.tenvoorde.hashcracker.Launcher' +//application.mainModule = 'hashcracker' + +//jlink { +// forceMerge 'lombok' +//} +runtime { + options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages'] +} \ No newline at end of file diff --git a/hashcracker/build.gradle.uit b/hashcracker/build.gradle.uit new file mode 100644 index 0000000..908ff73 --- /dev/null +++ b/hashcracker/build.gradle.uit @@ -0,0 +1,22 @@ +plugins { + id 'org.openjfx.' version '0.0.5' + id 'org.beryx.runtime' version '1.0.0' + id "com.github.johnrengelman.shadow" version "4.0.3" +} + +repositories { + mavenCentral() +} + +dependencies { +} + +javafx { + modules = [ 'javafx.controls' ] +} + +mainClassName = 'hellofx.Launcher' + +runtime { + options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages'] +} \ No newline at end of file diff --git a/hashcracker/gradle/wrapper/gradle-wrapper.jar b/hashcracker/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..62d4c05 Binary files /dev/null and b/hashcracker/gradle/wrapper/gradle-wrapper.jar differ diff --git a/hashcracker/gradle/wrapper/gradle-wrapper.properties b/hashcracker/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a4f0001 --- /dev/null +++ b/hashcracker/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/hashcracker/gradlew b/hashcracker/gradlew new file mode 100644 index 0000000..fbd7c51 --- /dev/null +++ b/hashcracker/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/hashcracker/gradlew.bat b/hashcracker/gradlew.bat new file mode 100644 index 0000000..5093609 --- /dev/null +++ b/hashcracker/gradlew.bat @@ -0,0 +1,104 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/hashcracker/lombok.config b/hashcracker/lombok.config new file mode 100644 index 0000000..6aa51d7 --- /dev/null +++ b/hashcracker/lombok.config @@ -0,0 +1,2 @@ +# This file is generated by the 'io.freefair.lombok' Gradle plugin +config.stopBubbling = true diff --git a/hashcracker/pom.xml b/hashcracker/pom.xml new file mode 100644 index 0000000..05b1ac2 --- /dev/null +++ b/hashcracker/pom.xml @@ -0,0 +1,105 @@ + + 4.0.0 + org.tenvoorde + hashcracker + 1.0-SNAPSHOT + + UTF-8 + 11 + 11 + 5.1.3 + ${project.build.directory}/staging + 14 + + + + org.openjfx + javafx-controls + ${javafx.version} + + + org.projectlombok + lombok + 1.18.12 + + + org.mapstruct + mapstruct-processor + 1.3.1.Final + + + org.apache.commons + commons-lang3 + 3.10 + + + commons-codec + commons-codec + 1.14 + + + org.jfxtras + jmetro + 11.6.11 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 11 + + + + org.openjfx + javafx-maven-plugin + 0.0.4 + + + default-cli + + org.tenvoorde.hashcracker.HashCracker + + + + debug + + + + + org.tenvoorde.hashcracker.HashCracker + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + true + project-classifier + shade\${project.artifactId}.jar + + + hellofx.Launcher + + + + + + + + + \ No newline at end of file diff --git a/hashcracker/settings.gradle b/hashcracker/settings.gradle new file mode 100644 index 0000000..a21b256 --- /dev/null +++ b/hashcracker/settings.gradle @@ -0,0 +1,5 @@ +/* + * This file was generated by the Gradle 'init' task. + */ + +rootProject.name = 'hashcracker' diff --git a/hashcracker/src/main/java/module-info.java.uit b/hashcracker/src/main/java/module-info.java.uit new file mode 100644 index 0000000..d196146 --- /dev/null +++ b/hashcracker/src/main/java/module-info.java.uit @@ -0,0 +1,9 @@ +module hashcracker { + requires javafx.controls; + requires org.apache.commons.codec; + requires org.apache.commons.lang3; + requires lombok; + requires org.jfxtras.styles.jmetro; + + exports org.tenvoorde.hashcracker; +} \ No newline at end of file diff --git a/hashcracker/src/main/java/org/tenvoorde/hashcracker/Digest.java b/hashcracker/src/main/java/org/tenvoorde/hashcracker/Digest.java new file mode 100644 index 0000000..3c20599 --- /dev/null +++ b/hashcracker/src/main/java/org/tenvoorde/hashcracker/Digest.java @@ -0,0 +1,38 @@ +package org.tenvoorde.hashcracker; + +import org.apache.commons.codec.digest.DigestUtils; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.function.Function; + +public enum Digest { + MD5(DigestUtils::md5Hex), + MD2(DigestUtils::md2Hex), + SHA1(DigestUtils::sha1Hex), + SHA256(DigestUtils::sha256Hex); +// MD5(input -> { +// try { +// MessageDigest md = null; +// md = MessageDigest.getInstance("MD5"); +// byte[] messageDigest = md.digest(input.getBytes()); +// BigInteger no = new BigInteger(1, messageDigest); +// String hashtext = no.toString(16); +// while (hashtext.length() < 32) { +// hashtext = "0" + hashtext; +// } +// return hashtext; +// } catch (NoSuchAlgorithmException e) { +// e.printStackTrace(); +// return null; +// } +// }); + + + Function getDigest; + + Digest(Function getDigest) { + this.getDigest = getDigest; + } +} diff --git a/hashcracker/src/main/java/org/tenvoorde/hashcracker/FormattedStringParser.java b/hashcracker/src/main/java/org/tenvoorde/hashcracker/FormattedStringParser.java new file mode 100644 index 0000000..c2df28b --- /dev/null +++ b/hashcracker/src/main/java/org/tenvoorde/hashcracker/FormattedStringParser.java @@ -0,0 +1,73 @@ +package org.tenvoorde.hashcracker; + +import lombok.Builder; +import lombok.Data; + +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +@Builder +@Data +class ParseResult { + private long totalCombinations; + private List rangeVariables; + private String formattedStringWithRanges; + private List log = new ArrayList<>(); +} + +public class FormattedStringParser { + + + public static ParseResult parse(String format) { + long totalCombinations; + List rangeVariables = new ArrayList<>(); + List log = new ArrayList<>(); + String formattedStringWithRanges; + String pattern = "\\[[0-9]-[0-9]\\]"; + Pattern p = Pattern.compile(pattern); + totalCombinations = 1; + + Matcher matcher = p.matcher(format); + + while (matcher.find()) { + String range = format.substring(matcher.start(), matcher.end()); + RangeVariable rv = RangeVariable.rangeVariableFromFormat(range); + rangeVariables.add(rv); + totalCombinations *= (rv.getUpper() - rv.getLower() + 1); + } + + formattedStringWithRanges = format.replaceAll(pattern, "%d"); + + if (rangeVariables.isEmpty()) { + log.add("Warning: no ranges found in formatted string."); + } + + Integer[] loopVar = new Integer[rangeVariables.size()]; + + for (int i = 0; i < rangeVariables.size(); i++) { + loopVar[i] = rangeVariables.get(i).getLower(); + } + String formattedStringWithLowerBounds = String.format(formattedStringWithRanges, (Object[]) loopVar); + + for (int i = 0; i < rangeVariables.size(); i++) { + loopVar[i] = rangeVariables.get(i).getUpper(); + } + String formattedStringWithUpperBounds = String.format(formattedStringWithRanges, (Object[]) loopVar); + + log.add("Testing from " + formattedStringWithLowerBounds + " to " + formattedStringWithUpperBounds); + + log.add("Total combinations to test: " + NumberFormat.getIntegerInstance().format(totalCombinations) + "."); + + return ParseResult.builder() + .formattedStringWithRanges(formattedStringWithRanges) + .rangeVariables(rangeVariables) + .totalCombinations(totalCombinations) + .log(log) + .build(); + } + + +} diff --git a/hashcracker/src/main/java/org/tenvoorde/hashcracker/HackWorker.java b/hashcracker/src/main/java/org/tenvoorde/hashcracker/HackWorker.java new file mode 100644 index 0000000..3085082 --- /dev/null +++ b/hashcracker/src/main/java/org/tenvoorde/hashcracker/HackWorker.java @@ -0,0 +1,4 @@ +package org.tenvoorde.hashcracker; + +public class HackWorker { +} diff --git a/hashcracker/src/main/java/org/tenvoorde/hashcracker/HashCracker.java b/hashcracker/src/main/java/org/tenvoorde/hashcracker/HashCracker.java new file mode 100644 index 0000000..83a1108 --- /dev/null +++ b/hashcracker/src/main/java/org/tenvoorde/hashcracker/HashCracker.java @@ -0,0 +1,260 @@ +package org.tenvoorde.hashcracker; + +import javafx.application.Application; +import javafx.concurrent.Task; +import javafx.geometry.Insets; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.image.Image; +import javafx.scene.layout.ColumnConstraints; +import javafx.scene.layout.GridPane; +import javafx.scene.text.Text; +import javafx.scene.text.TextFlow; +import javafx.stage.Stage; +import jfxtras.styles.jmetro.JMetro; +import jfxtras.styles.jmetro.Style; +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; + +public class HashCracker extends Application { + + private Task task; + + private TextField formatTxtBox; + private TextField hashTxtBox; + private ComboBox digestCombo; + private Button resetBtn; + private Button checkBtn; + private Button startBtn; + private ProgressBar progressBar; + private TextArea log; + + private String format; + private Digest digest; + @Getter + private String hash; + + private List rangeVariables; + private String formattedStringWithRanges; + + private long totalCombinations; + + @Override + public void start(Stage stage) { + buildGridPane(stage); + setEventHandlers(); + appendLog("HashCrack 1.0 started."); + } + + private void setEventHandlers() { + this.formatTxtBox.textProperty().addListener((observable, oldValue, newValue) -> { + this.startBtn.setDisable(true); + if (StringUtils.isAnyEmpty(newValue, this.hashTxtBox.getText())) { + this.checkBtn.setDisable(true); + } else { + this.checkBtn.setDisable(false); + } + }); + + this.hashTxtBox.textProperty().addListener((observable, oldValue, newValue) -> { + this.startBtn.setDisable(true); + if (StringUtils.isAnyEmpty(newValue, this.formatTxtBox.getText())) { + this.checkBtn.setDisable(true); + } else { + this.checkBtn.setDisable(false); + } + }); + + this.resetBtn.setOnAction(event -> { + this.formatTxtBox.setText(""); + this.hashTxtBox.setText(""); + }); + + this.checkBtn.setOnAction(event -> { + this.format = this.formatTxtBox.getText(); + this.hash = this.hashTxtBox.getText(); + this.digest = this.digestCombo.getValue(); + + ParseResult parseResult = FormattedStringParser.parse(this.format); + this.rangeVariables = parseResult.getRangeVariables(); + this.formattedStringWithRanges = parseResult.getFormattedStringWithRanges(); + this.totalCombinations = parseResult.getTotalCombinations(); + appendLog(parseResult.getLog()); + + this.startBtn.setDisable(false); + }); + + this.startBtn.setOnAction(event -> { + this.progressBar.setStyle("-fx-accent: #0000ff;"); + appendLog("Search started."); + + startCracking(); + }); + } + + private void startCracking() { + task = new Task<>() { + @Override + protected Boolean call() throws Exception { + Integer[] loopVar = new Integer[rangeVariables.size()]; + for (int i = 0; i < rangeVariables.size(); i++) { + loopVar[i] = rangeVariables.get(i).getLower(); + } + + boolean success = false; + String stringToHash; + int counter = 0; + do { + counter++; + updateProgress(counter, totalCombinations); + stringToHash = String.format(formattedStringWithRanges, (Object[]) loopVar); + + success = digest.getDigest.apply(stringToHash).equalsIgnoreCase(getHash()); + if (!RangeVariable.increaseLoopVars(loopVar, rangeVariables)) { + break; + } + } while (!success); + if (success) { + appendLog("Success: " + stringToHash + "."); + } else { + appendLog("No match found."); + } + return success; + } + }; + + task.setOnSucceeded(event -> { + Boolean success = task.getValue(); + if (success) { + this.progressBar.setStyle("-fx-accent: green;"); + } else { + this.progressBar.setStyle("-fx-accent: red;"); + } + this.resetBtn.setDisable(false); + this.checkBtn.setDisable(false); + this.startBtn.setDisable(false); + }); + + this.progressBar.progressProperty().bind(task.progressProperty()); + + final Thread thread = new Thread(task, "task-thread"); + + this.startBtn.setDisable(true); + this.checkBtn.setDisable(true); + this.resetBtn.setDisable(true); + thread.setDaemon(true); + thread.start(); + + } + + private void appendLog(List logLines) { + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss"); + LocalDateTime now = LocalDateTime.now(); + for (String logLine : logLines) { + this.log.appendText(dtf.format(now) + " | " + logLine + "\n"); + } + } + + private void appendLog(String logLine) { + appendLog(List.of(logLine)); + } + + + private void buildGridPane(Stage stage) { + + GridPane pane = new GridPane(); + + pane.setPadding(new Insets(10, 10, 10, 10)); + pane.setVgap(5); + pane.setHgap(5); + + this.formatTxtBox = new TextField(); + this.formatTxtBox.setPrefColumnCount(40); + this.formatTxtBox.setTooltip(new Tooltip("Example: N52 12.[0-9][0-9][0-9] E005 [0-5][0-9].[0-9][0-9][0-9]")); + var formatLabel = new Label("Formatted string"); + + this.hashTxtBox = new TextField(); + this.hashTxtBox.setPrefColumnCount(40); + var hashLabel = new Label("Hash"); + + this.digestCombo = new ComboBox<>(); + this.digestCombo.getItems().addAll(Digest.values()); + this.digestCombo.setEditable(false); + this.digestCombo.getSelectionModel().selectFirst(); + var digestLabel = new Label("Digest"); + + this.resetBtn = new Button("Reset"); + this.checkBtn = new Button("Check"); + this.checkBtn.setDisable(true); + this.startBtn = new Button("Start"); + this.startBtn.setDisable(true); + + this.progressBar = new ProgressBar(); + this.progressBar.setProgress(0.0); + this.progressBar.setPrefWidth(640); + this.progressBar.setStyle("-fx-accent: blue;"); + + this.log = new TextArea(); + this.log.setEditable(false); + this.log.setMinHeight(265); + this.log.setFocusTraversable(false); + + pane.getColumnConstraints().add(new ColumnConstraints(100)); + pane.getColumnConstraints().add(new ColumnConstraints(100)); + pane.getColumnConstraints().add(new ColumnConstraints(100)); + pane.getColumnConstraints().add(new ColumnConstraints(300)); + + pane.add(formatLabel, 0, 2); + pane.add(this.formatTxtBox, 1, 2, 3, 1); + pane.add(hashLabel, 0, 5); + pane.add(this.hashTxtBox, 1, 5, 3, 1); + pane.add(digestLabel, 0, 8); + pane.add(this.digestCombo, 1, 8); + pane.add(this.resetBtn, 0, 13, 1, 1); + pane.add(this.checkBtn, 1, 13, 1, 1); + pane.add(this.startBtn, 2, 13, 1, 1); + pane.add(this.progressBar, 0, 16, 4, 1); + pane.add(this.log, 0, 18, 4, 1); + +// this.pane.setGridLinesVisible(true); + + Tab decodeTab = new Tab("Decode"); + decodeTab.setClosable(false); + decodeTab.setContent(pane); + + TextFlow encodeText = new TextFlow(new Text("Coming soon.")); + + Tab encodeTab = new Tab("Encode"); + encodeTab.setClosable(false); + encodeTab.setContent(encodeText); + + TextFlow aboutText = new TextFlow(); + aboutText.getChildren().add(new Text("HashCracker 1.0 by Michel ten Voorde")); + + Tab aboutTab = new Tab("About"); + aboutTab.setClosable(false); + aboutTab.setContent(aboutText); + + + TabPane tabPane = new TabPane(decodeTab, encodeTab, aboutTab); + + var scene = new Scene(tabPane, 636, 520); + JMetro jMetro = new JMetro(Style.LIGHT); + jMetro.setScene(scene); + stage.setTitle("GcHashCrack"); + stage.getIcons().add(new Image(HashCracker.class.getResourceAsStream("/images/hash.png"))); + stage.setResizable(false); + stage.setScene(scene); + stage.show(); + + } + + public static void main(String[] args) { + launch(); + } + +} \ No newline at end of file diff --git a/hashcracker/src/main/java/org/tenvoorde/hashcracker/Launcher.java b/hashcracker/src/main/java/org/tenvoorde/hashcracker/Launcher.java new file mode 100644 index 0000000..6c1b6f9 --- /dev/null +++ b/hashcracker/src/main/java/org/tenvoorde/hashcracker/Launcher.java @@ -0,0 +1,8 @@ +package org.tenvoorde.hashcracker; + +public class Launcher { + + public static void main(String[] args) { + HashCracker.main(args); + } +} diff --git a/hashcracker/src/main/java/org/tenvoorde/hashcracker/RangeVariable.java b/hashcracker/src/main/java/org/tenvoorde/hashcracker/RangeVariable.java new file mode 100644 index 0000000..09de760 --- /dev/null +++ b/hashcracker/src/main/java/org/tenvoorde/hashcracker/RangeVariable.java @@ -0,0 +1,46 @@ +package org.tenvoorde.hashcracker; + +import lombok.Builder; +import lombok.Data; + +import java.util.List; + +@Builder +@Data +public class RangeVariable { + private int lower; + private int upper; + + public static RangeVariable rangeVariableFromFormat(String range) { + range = range.substring(1, range.length() - 1); + return RangeVariable.builder() + .lower(Integer.parseInt(range.substring(0, 1))) + .upper(Integer.parseInt(range.substring(2, 3))) + .build(); + } + + /** + * Increase int array by way of a RangeVariable array. + * @param loopVar array of + * @return false if done, true if otherwise. + */ + public static boolean increaseLoopVars(Integer[] loopVar, List rangeVariables) { + boolean done = false; + int cursor = 0; + do { + if (cursor == rangeVariables.size()) { + return false; + } + loopVar[cursor]++; + if (loopVar[cursor] > rangeVariables.get(cursor).getUpper()) { + loopVar[cursor] = rangeVariables.get(cursor).getLower(); + cursor++; + } else { + done = true; + } + } while (!done); + + return true; + } + +} diff --git a/hashcracker/src/main/resources/images/hash.png b/hashcracker/src/main/resources/images/hash.png new file mode 100644 index 0000000..ad27a3e Binary files /dev/null and b/hashcracker/src/main/resources/images/hash.png differ