From f45a726376c3f9cf96bacd3f23e48ef25bfb4aa3 Mon Sep 17 00:00:00 2001 From: philsmd Date: Tue, 7 May 2019 15:31:11 +0200 Subject: [PATCH] fixes #2012: add Deflate support for 7-Zip using zlib --- docs/changes.txt | 1 + docs/credits.txt | 7 +++++++ src/Makefile | 39 ++++++++++++++++++++++++++++++++++++++ src/modules/module_11600.c | 34 ++++++++++++++++++++++++++++++++- 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 6f6b68b91..ad9753f58 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -6,6 +6,7 @@ - Fully modularized hash-mode integration via plugin interface and converted all existing hash-modes - Support for inline VeraCrypt PIM Brute-Force +- Support Deflate decompression for the 7-Zip hash type using zlib ## ## Algorithms diff --git a/docs/credits.txt b/docs/credits.txt index 1401406ac..86cd1ed32 100644 --- a/docs/credits.txt +++ b/docs/credits.txt @@ -39,6 +39,13 @@ Other contributors to hashcat * A full list and their commits can be found here: https://github.com/hashcat/hashcat/graphs/contributors +# hashcat relies on some libraries, including: + +* xxHash by Yann Collet (@Cyan4973) +* LZMA-SDK by Igor Pavlov +* zlib by Jean-loup Gailly and Mark Adler +* win-iconv by Yukihiro Nakadaira + # Furthermore the following persons helped the project: Martin "purehate" Bos (@cantcomputer) diff --git a/src/Makefile b/src/Makefile index c2a3c2f8a..96f75d639 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,6 +9,7 @@ PRODUCTION := 0 PRODUCTION_VERSION := v5.1.0 ENABLE_BRAIN := 1 USE_SYSTEM_LZMA := 0 +USE_SYSTEM_ZLIB := 0 USE_SYSTEM_OPENCL := 0 USE_SYSTEM_XXHASH := 0 @@ -112,6 +113,12 @@ else DEPS_LZMA_PATH := $(LIBRARY_DEV_ROOT_FOLDER)/ endif +ifeq ($(USE_SYSTEM_ZLIB),0) +DEPS_ZLIB_PATH := deps/zlib/ +else +DEPS_ZLIB_PATH := $(LIBRARY_DEV_ROOT_FOLDER)/ +endif + ifeq ($(USE_SYSTEM_OPENCL),0) DEPS_OPENCL_PATH := deps/OpenCL-Headers else @@ -168,6 +175,11 @@ ifeq ($(CC),clang) CFLAGS += -Wno-enum-conversion endif +## because ZLIB +ifeq ($(USE_SYSTEM_ZLIB),0) +CFLAGS_ZLIB += -Wno-implicit-fallthrough +endif + ifeq ($(DEBUG),0) CFLAGS += -O2 ifneq ($(UNAME),Darwin) @@ -200,6 +212,12 @@ ifeq ($(USE_SYSTEM_LZMA),1) LFLAGS += -llzmasdk endif +# ZLIB +CFLAGS += -I$(DEPS_ZLIB_PATH) +ifeq ($(USE_SYSTEM_ZLIB),1) +LFLAGS += -lz +endif + # OpenCL CFLAGS += -I$(DEPS_OPENCL_PATH) @@ -298,6 +316,14 @@ LINUX_OBJS += $(foreach OBJ,$(OBJS_LZMA),obj/$(OBJ).LINUX.o) WIN_OBJS += $(foreach OBJ,$(OBJS_LZMA),obj/$(OBJ).WIN.o) endif +ifeq ($(USE_SYSTEM_ZLIB),0) +OBJS_ZLIB := adler32 crc32 zutil inftrees inffast inflate + +NATIVE_OBJS += $(foreach OBJ,$(OBJS_ZLIB),obj/$(OBJ).NATIVE.o) +LINUX_OBJS += $(foreach OBJ,$(OBJS_ZLIB),obj/$(OBJ).LINUX.o) +WIN_OBJS += $(foreach OBJ,$(OBJS_ZLIB),obj/$(OBJ).WIN.o) +endif + ifeq ($(USE_SYSTEM_XXHASH),0) ifeq ($(ENABLE_BRAIN),1) OBJS_XXHASH := xxhash @@ -446,6 +472,11 @@ obj/%.NATIVE.o: $(DEPS_LZMA_PATH)/%.c $(CC) -c $(CFLAGS_NATIVE) $< -o $@ -fpic endif +ifeq ($(USE_SYSTEM_ZLIB),0) +obj/%.NATIVE.o: $(DEPS_ZLIB_PATH)/%.c + $(CC) -c $(CFLAGS_NATIVE) $(CFLAGS_ZLIB) $< -o $@ -fpic +endif + ifeq ($(USE_SYSTEM_XXHASH),0) ifeq ($(ENABLE_BRAIN),1) obj/%.NATIVE.o: $(DEPS_XXHASH_PATH)/%.c @@ -590,6 +621,14 @@ obj/%.WIN.o: $(DEPS_LZMA_PATH)/%.c $(CC_WIN) $(CFLAGS_CROSS_WIN) -c -o $@ $< endif +ifeq ($(USE_SYSTEM_ZLIB),0) +obj/%.LINUX.o: $(DEPS_ZLIB_PATH)/%.c + $(CC_LINUX) $(CFLAGS_CROSS_LINUX) $(CFLAGS_ZLIB) -c -o $@ $< + +obj/%.WIN.o: $(DEPS_ZLIB_PATH)/%.c + $(CC_WIN) $(CFLAGS_CROSS_WIN) $(CFLAGS_ZLIB) -c -o $@ $< +endif + ifeq ($(USE_SYSTEM_XXHASH),0) ifeq ($(ENABLE_BRAIN),1) obj/%.LINUX.o: $(DEPS_XXHASH_PATH)/%.c diff --git a/src/modules/module_11600.c b/src/modules/module_11600.c index 75b09e003..cc29b7d39 100644 --- a/src/modules/module_11600.c +++ b/src/modules/module_11600.c @@ -13,6 +13,7 @@ #include "emu_inc_cipher_aes.h" #include "cpu_crc32.h" #include "ext_lzma.h" +#include "zlib.h" static const u32 ATTACK_EXEC = ATTACK_EXEC_OUTSIDE_KERNEL; static const u32 DGST_POS0 = 0; @@ -220,6 +221,35 @@ void module_hook23 (hc_device_param_t *device_param, const void *hook_salts_buf, { ret = hc_lzma1_decompress (compressed_data, &compressed_data_len, decompressed_data, &decompressed_data_len, coder_attributes); } + else if (data_type == 7) // inflate using zlib (DEFLATE compression) + { + ret = SZ_ERROR_DATA; + + z_stream inf; + + inf.zalloc = Z_NULL; + inf.zfree = Z_NULL; + inf.opaque = Z_NULL; + + inf.avail_in = compressed_data_len; + inf.next_in = compressed_data; + + inf.avail_out = decompressed_data_len; + inf.next_out = decompressed_data; + + // inflate: + + inflateInit2 (&inf, -MAX_WBITS); + + int zlib_ret = inflate (&inf, Z_NO_FLUSH); + + inflateEnd (&inf); + + if ((zlib_ret == Z_OK) || (zlib_ret == Z_STREAM_END)) + { + ret = SZ_OK; + } + } else // we only support LZMA2 in addition to LZMA1 { ret = hc_lzma2_decompress (compressed_data, &compressed_data_len, decompressed_data, &decompressed_data_len, coder_attributes); @@ -464,7 +494,9 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE * verify some data */ - if (data_type > 2) // this includes also 0x80 (special case that means "truncated") + // this check also returns an error with data_type == 0x80 (special case that means "truncated") + + if ((data_type != 0) && (data_type != 1) && (data_type != 2) && (data_type != 7)) { return (PARSER_SALT_VALUE); }