1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-21 23:58:07 +00:00

This commit splits the native hashcat binary into the hashcat library and hashcat frontend.

I've tested this with Linux and Msys2. I hope it will work on FreeBSD, OSX and Cygwin as well.
There's also four new dedicated makefile targets for install: install_library install_hashcat install_docs install_shared
Also the main_shared.c and its makefile target have been removed, as the main frontend is the best example possible
This commit is contained in:
jsteube 2016-12-29 20:40:07 +01:00
parent 83151ec2bb
commit d2c76d9320
3 changed files with 70 additions and 162 deletions

3
.gitignore vendored
View File

@ -2,6 +2,9 @@
*.bin
*.app
hashcat
hashcat.exe
libhashcat.so
hashcat.dll
*.potfile
*.restore
*.dictstat

View File

@ -3,8 +3,6 @@
## License.....: MIT
##
PROG_NAME := hashcat
##
## Detect Operating System
##
@ -20,7 +18,7 @@ UNAME := $(patsubst MINGW32_NT-%,MSYS2,$(UNAME))
UNAME := $(patsubst MINGW64_NT-%,MSYS2,$(UNAME))
ifeq (,$(filter $(UNAME),Linux FreeBSD Darwin CYGWIN MSYS2))
$(error "! Your Operating System ($(UNAME)) is not supported by $(PROG_NAME) Makefile")
$(error "! Your Operating System ($(UNAME)) is not supported by this Makefile")
endif
ifeq ($(DEBUG),1)
@ -45,8 +43,26 @@ DESTDIR ?=
PREFIX ?= /usr/local
INSTALL_FOLDER ?= $(PREFIX)/bin
SHARED_FOLDER ?= $(PREFIX)/share/$(PROG_NAME)
DOCUMENT_FOLDER ?= $(PREFIX)/share/doc/$(PROG_NAME)
LIBRARY_FOLDER ?= $(PREFIX)/lib
SHARED_FOLDER ?= $(PREFIX)/share/hashcat
DOCUMENT_FOLDER ?= $(PREFIX)/share/doc/hashcat
##
## Filenames for library and frontend
##
HASHCAT_FRONTEND := hashcat
HASHCAT_LIBRARY := libhashcat.so
ifeq ($(UNAME),CYGWIN)
HASHCAT_FRONTEND := hashcat.exe
HASHCAT_LIBRARY := hashcat.dll
endif # CYGWIN
ifeq ($(UNAME),MSYS2)
HASHCAT_FRONTEND := hashcat.exe
HASHCAT_LIBRARY := hashcat.dll
endif # MSYS2
##
## Dependencies
@ -95,8 +111,6 @@ COMPTIME := $(shell date +%s)
VERSION_EXPORT := $Format:%D$
VERSION_TAG := $(shell test -d .git && git describe --tags --dirty=+ || echo "$(VERSION_EXPORT)"|cut -d, -f2|$(SED) -r 's|.* (\w+/)?([^ ]+)|\2|')
BINARY_NATIVE := $(PROG_NAME)
##
## General compiler and linker options
##
@ -255,15 +269,15 @@ include $(CRT_GLOB_INCLUDE_FOLDER)/win_file_globbing.mk
OBJS_ALL := affinity autotune benchmark bitmap bitops combinator common convert cpt cpu_aes cpu_crc32 cpu_des cpu_md4 cpu_md5 cpu_sha1 cpu_sha256 debugfile dictstat dispatch dynloader event ext_ADL ext_nvapi ext_nvml ext_OpenCL ext_sysfs ext_xnvctrl filehandling folder hashcat hashes hlfmt hwmon induct interface locking logfile loopback memory monitor mpsp opencl outfile_check outfile potfile restore rp rp_cpu rp_kernel_on_cpu shared status stdout straight terminal thread timer tuningdb usage user_options weak_hash wordlist
NATIVE_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).NATIVE.o)
NATIVE_OBJS :=
NATIVE_SHARED_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).NATIVE.SHARED.o)
ifeq ($(UNAME),CYGWIN)
NATIVE_OBJS += $(CRT_GLOB)
NATIVE_OBJS += $(CRT_GLOB)
endif # CYGWIN
ifeq ($(UNAME),MSYS2)
NATIVE_OBJS += $(CRT_GLOB)
NATIVE_OBJS += $(CRT_GLOB)
endif # MSYS2
LINUX_32_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).LINUX.32.o)
@ -273,12 +287,10 @@ WIN_32_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).WIN.32.o) $(CRT_
WIN_64_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).WIN.64.o) $(CRT_GLOB_64)
##
## Targets
## Targets: Native Compilation
##
native: hashcat
binaries: linux32 linux64 win32 win64
default: $(HASHCAT_FRONTEND)
clean:
$(RM) -f obj/*.o *.bin *.exe *.so *.dll *.restore *.out *.pot *.log hashcat hashcat_shared core
@ -287,6 +299,12 @@ clean:
$(RM) -rf *.dSYM
$(RM) -rf kernels
##
## Targets: Cross Compilation (for binary release version)
##
binaries: linux32 linux64 win32 win64
linux32: hashcat32.bin
linux64: hashcat64.bin
@ -298,17 +316,16 @@ win64: hashcat64.exe
## How to make /usr/bin/install doing recursive??
##
install: native
install: install_library install_hashcat install_docs install_shared
install_docs:
$(INSTALL) -m 755 -d $(DESTDIR)$(DOCUMENT_FOLDER)
$(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)
$(INSTALL) -m 755 -d $(DESTDIR)$(INSTALL_FOLDER)
$(INSTALL) -m 755 -d $(DESTDIR)$(DOCUMENT_FOLDER)/docs
$(INSTALL) -m 755 -d $(DESTDIR)$(DOCUMENT_FOLDER)/charsets
$(INSTALL) -m 755 -d $(DESTDIR)$(DOCUMENT_FOLDER)/masks
$(INSTALL) -m 755 -d $(DESTDIR)$(DOCUMENT_FOLDER)/rules
$(INSTALL) -m 755 -d $(DESTDIR)$(DOCUMENT_FOLDER)/extra
$(INSTALL) -m 755 -d $(DESTDIR)$(DOCUMENT_FOLDER)/extra/tab_completion
$(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)/charsets
$(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)/masks
$(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)/OpenCL
$(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)/rules
$(INSTALL) -m 644 example.dict $(DESTDIR)$(DOCUMENT_FOLDER)/
$(INSTALL) -m 644 example0.hash $(DESTDIR)$(DOCUMENT_FOLDER)/
$(INSTALL) -m 644 example400.hash $(DESTDIR)$(DOCUMENT_FOLDER)/
@ -319,53 +336,55 @@ install: native
$(INSTALL) -m 644 extra/tab_completion/hashcat.sh $(DESTDIR)$(DOCUMENT_FOLDER)/extra/tab_completion/
$(INSTALL) -m 644 extra/tab_completion/howto.txt $(DESTDIR)$(DOCUMENT_FOLDER)/extra/tab_completion/
$(INSTALL) -m 755 extra/tab_completion/install $(DESTDIR)$(DOCUMENT_FOLDER)/extra/tab_completion/
$(INSTALL) -m 644 hashcat.hcstat $(DESTDIR)$(SHARED_FOLDER)/
$(INSTALL) -m 644 hashcat.hctune $(DESTDIR)$(SHARED_FOLDER)/
$(INSTALL) -m 755 $(BINARY_NATIVE) $(DESTDIR)$(INSTALL_FOLDER)/
$(FIND) docs/ -type d -exec $(INSTALL) -m 755 -d $(DESTDIR)$(DOCUMENT_FOLDER)/{} \;
$(FIND) charsets/ -type d -exec $(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)/{} \;
$(FIND) masks/ -type d -exec $(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)/{} \;
$(FIND) OpenCL/ -type d -exec $(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)/{} \;
$(FIND) rules/ -type d -exec $(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)/{} \;
$(FIND) docs/ -type f -exec $(INSTALL) -m 644 {} $(DESTDIR)$(DOCUMENT_FOLDER)/{} \;
$(FIND) charsets/ -type f -exec $(INSTALL) -m 644 {} $(DESTDIR)$(SHARED_FOLDER)/{} \;
$(FIND) masks/ -type f -exec $(INSTALL) -m 644 {} $(DESTDIR)$(SHARED_FOLDER)/{} \;
$(FIND) OpenCL/ -type f -exec $(INSTALL) -m 644 {} $(DESTDIR)$(SHARED_FOLDER)/{} \;
$(FIND) rules/ -type f -exec $(INSTALL) -m 644 {} $(DESTDIR)$(SHARED_FOLDER)/{} \;
$(FIND) charsets/ -type d -exec $(INSTALL) -m 755 -d $(DESTDIR)$(DOCUMENT_FOLDER)/{} \;
$(FIND) charsets/ -type f -exec $(INSTALL) -m 644 {} $(DESTDIR)$(DOCUMENT_FOLDER)/{} \;
$(FIND) masks/ -type d -exec $(INSTALL) -m 755 -d $(DESTDIR)$(DOCUMENT_FOLDER)/{} \;
$(FIND) masks/ -type f -exec $(INSTALL) -m 644 {} $(DESTDIR)$(DOCUMENT_FOLDER)/{} \;
$(FIND) rules/ -type d -exec $(INSTALL) -m 755 -d $(DESTDIR)$(DOCUMENT_FOLDER)/{} \;
$(FIND) rules/ -type f -exec $(INSTALL) -m 644 {} $(DESTDIR)$(DOCUMENT_FOLDER)/{} \;
$(SED) -i 's/\.\/hashcat/hashcat/' $(DESTDIR)$(DOCUMENT_FOLDER)/example0.sh
$(SED) -i 's/\.\/hashcat/hashcat/' $(DESTDIR)$(DOCUMENT_FOLDER)/example400.sh
$(SED) -i 's/\.\/hashcat/hashcat/' $(DESTDIR)$(DOCUMENT_FOLDER)/example500.sh
install_shared:
$(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)
$(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)/OpenCL
$(INSTALL) -m 644 hashcat.hcstat $(DESTDIR)$(SHARED_FOLDER)/
$(INSTALL) -m 644 hashcat.hctune $(DESTDIR)$(SHARED_FOLDER)/
$(FIND) OpenCL/ -type d -exec $(INSTALL) -m 755 -d $(DESTDIR)$(SHARED_FOLDER)/{} \;
$(FIND) OpenCL/ -type f -exec $(INSTALL) -m 644 {} $(DESTDIR)$(SHARED_FOLDER)/{} \;
install_library: $(HASHCAT_LIBRARY)
$(INSTALL) -m 755 -d $(DESTDIR)$(LIBRARY_FOLDER)
$(INSTALL) -m 755 $(HASHCAT_LIBRARY) $(DESTDIR)$(LIBRARY_FOLDER)/
install_hashcat: $(HASHCAT_FRONTEND)
$(INSTALL) -m 755 -d $(DESTDIR)$(INSTALL_FOLDER)
$(INSTALL) -m 755 $(HASHCAT_FRONTEND) $(DESTDIR)$(INSTALL_FOLDER)/
uninstall:
$(RM) -f $(DESTDIR)$(INSTALL_FOLDER)/$(BINARY_NATIVE)
$(RM) -f $(DESTDIR)$(INSTALL_FOLDER)/$(HASHCAT_FRONTEND)
$(RM) -f $(DESTDIR)$(LIBRARY_FOLDER)/$(HASHCAT_LIBRARY)
$(RM) -rf $(DESTDIR)$(SHARED_FOLDER)
$(RM) -rf $(DESTDIR)$(DOCUMENT_FOLDER)
##
## native compiled hashcat
##
obj/%.NATIVE.o: src/%.c
$(CC) -c $(CFLAGS_NATIVE) -o $@ $^
$(BINARY_NATIVE): $(NATIVE_OBJS) src/main.c
$(CC) $(CFLAGS_NATIVE) -o $@ $^ $(LFLAGS_NATIVE) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\"
##
## native compiled hashcat (shared)
## native compiled hashcat library and frontend
##
obj/%.NATIVE.SHARED.o: src/%.c
$(CC) -c $(CFLAGS_NATIVE_SHARED) -o $@ $^
lib$(BINARY_NATIVE).so: $(NATIVE_SHARED_OBJS)
$(HASHCAT_LIBRARY): $(NATIVE_SHARED_OBJS)
$(CC) -o $@ $^ $(LFLAGS_NATIVE_SHARED) -shared
$(BINARY_NATIVE)_shared: lib$(BINARY_NATIVE).so src/main_shared.c
$(CC) $(CFLAGS_NATIVE_SHARED) -o $@ $^ $(LFLAGS_NATIVE_SHARED) -L. -lhashcat -Wl,-rpath=. -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\"
$(HASHCAT_FRONTEND): $(NATIVE_OBJS) $(HASHCAT_LIBRARY) src/main.c
$(CC) $(CFLAGS_NATIVE) -o $@ $^ $(LFLAGS_NATIVE) -L. -lhashcat -Wl,-rpath=. -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\"
##
## cross compiled hashcat for binary release version
## cross compiled hashcat
##
obj/%.LINUX.32.o: src/%.c

View File

@ -1,114 +0,0 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#include "common.h"
#include <stdio.h>
#include <assert.h>
#include "types.h"
#include "memory.h"
#include "user_options.h"
#include "hashcat.h"
static void main_cracker_hash_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len)
{
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
if (outfile_ctx->fp != NULL) return; // cracked hash was not written to an outfile
fwrite (buf, len, 1, stdout);
fwrite (EOL, strlen (EOL), 1, stdout);
}
static void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len)
{
switch (id)
{
case EVENT_CRACKER_HASH_CRACKED: main_cracker_hash_cracked (hashcat_ctx, buf, len); break;
}
}
int main (MAYBE_UNUSED int argc, MAYBE_UNUSED char **argv)
{
// hashcat main context
hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t));
assert (hashcat_ctx);
const int rc_hashcat_init = hashcat_init (hashcat_ctx, event);
if (rc_hashcat_init == -1) return -1;
// this is a bit ugly, but it's the example you're looking for
char *hash = "8743b52063cd84097a65d1633f5c74f5";
char *mask = "?l?l?l?l?l?l?l";
char *hc_argv[] = { hash, mask, NULL };
// initialize the user options with some defaults (you can override them later)
const int rc_options_init = user_options_init (hashcat_ctx);
if (rc_options_init == -1) return -1;
// your own stuff
user_options_t *user_options = hashcat_ctx->user_options;
user_options->hc_argv = hc_argv;
user_options->hc_argc = 2;
user_options->quiet = true;
user_options->potfile_disable = true;
user_options->attack_mode = ATTACK_MODE_BF; // this is -a 3
user_options->hash_mode = 0; // MD5
user_options->workload_profile = 3;
// init a hashcat session; this initializes opencl devices, hwmon, etc
// it does not actually run the attack but from here you can access opencl devices and hwmon information
const int rc_init = hashcat_session_init (hashcat_ctx, NULL, NULL, 0, NULL, 0);
if (rc_init == 0)
{
// this one actually starts the cracking
const int rc_run = hashcat_session_execute (hashcat_ctx);
if (rc_run == 0)
{
hashcat_status_t hashcat_status;
hashcat_get_status (hashcat_ctx, &hashcat_status);
printf ("Session: %s\n", hashcat_status.session);
printf ("Status: %s\n", hashcat_status.status_string);
}
else if (rc_run == -1)
{
char *msg = hashcat_get_log (hashcat_ctx);
fprintf (stderr, "%s\n", msg);
}
}
else
{
char *msg = hashcat_get_log (hashcat_ctx);
fprintf (stderr, "%s\n", msg);
}
// always destroy those regardless of what the returncodes from the init functions are
hashcat_session_destroy (hashcat_ctx);
hashcat_destroy (hashcat_ctx);
free (hashcat_ctx);
return 0;
}