Skip to content

Commit 88e3eeb

Browse files
committed
Office formats: Implement proper binary hash functions for FMT_BLOB
See #5736
1 parent ba0525c commit 88e3eeb

File tree

4 files changed

+55
-24
lines changed

4 files changed

+55
-24
lines changed

src/office_common.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
/*
22
* Office 2007-2013 cracker patch for JtR, common code. This software is
33
* Copyright (c) 2014 by JimF
4-
* Copyright (c) 2012-2019 magnum
4+
* Copyright (c) 2012-2025 magnum
55
* and is hereby released to the general public under the following terms:
66
* Redistribution and use in source and binary forms, with or without
77
* modification, are permitted.
8-
*
9-
* This file takes replicated but common code, shared between the CPU
10-
* office format, and the GPU office formats, and places it into one
11-
* common location.
128
*/
139

1410
#include "formats.h"
@@ -35,10 +31,17 @@ typedef struct ms_office_binary_blob_t {
3531
uint8_t encryptedVerifierHash[32];
3632
} ms_office_binary_blob;
3733

38-
void *ms_office_common_get_salt(char *ciphertext);
39-
void *ms_office_common_binary(char *ciphertext);
40-
int ms_office_common_valid(char *ciphertext, struct fmt_main *self);
34+
extern void *ms_office_common_get_salt(char *ciphertext);
35+
extern void *ms_office_common_binary(char *ciphertext);
36+
extern int ms_office_common_valid(char *ciphertext, struct fmt_main *self);
4137

4238
/* other 'common' functions for MSOffice */
43-
unsigned int ms_office_common_iteration_count(void *salt);
44-
unsigned int ms_office_common_version(void *salt);
39+
extern unsigned int ms_office_common_iteration_count(void *salt);
40+
extern unsigned int ms_office_common_version(void *salt);
41+
extern int ms_office_binary_hash_0(void *binary);
42+
extern int ms_office_binary_hash_1(void *binary);
43+
extern int ms_office_binary_hash_2(void *binary);
44+
extern int ms_office_binary_hash_3(void *binary);
45+
extern int ms_office_binary_hash_4(void *binary);
46+
extern int ms_office_binary_hash_5(void *binary);
47+
extern int ms_office_binary_hash_6(void *binary);

src/office_common_plug.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/*
2-
* Office 2007-2013 cracker patch for JtR, common code. 2014 by JimF
3-
* This file takes replicated but common code, shared between the CPU
4-
* office format, and the GPU office formats, and places it into one
5-
* common location (with some tiny tweaks, for things like valid).
2+
* Office 2007-2013 cracker patch for JtR, common code. This software is
3+
* Copyright (c) 2014 by JimF
4+
* Copyright (c) 2012-2025 magnum
5+
* and is hereby released to the general public under the following terms:
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted.
68
*/
79

810
#include "arch.h"
@@ -145,3 +147,23 @@ unsigned int ms_office_common_version(void *salt)
145147
{
146148
return ((ms_office_custom_salt*)salt)->version;
147149
}
150+
151+
static int ms_office_binary_hash(void *binary, uint32_t mask)
152+
{
153+
fmt_data *blob = binary;
154+
ms_office_binary_blob *verifiers = blob->blob;
155+
uint8_t *encryptedVerifier = verifiers->encryptedVerifier;
156+
uint32_t hash;
157+
158+
memcpy(&hash, encryptedVerifier, sizeof(hash));
159+
160+
return hash & mask;
161+
}
162+
163+
int ms_office_binary_hash_0(void *binary) { return ms_office_binary_hash(binary, PH_MASK_0); }
164+
int ms_office_binary_hash_1(void *binary) { return ms_office_binary_hash(binary, PH_MASK_1); }
165+
int ms_office_binary_hash_2(void *binary) { return ms_office_binary_hash(binary, PH_MASK_2); }
166+
int ms_office_binary_hash_3(void *binary) { return ms_office_binary_hash(binary, PH_MASK_3); }
167+
int ms_office_binary_hash_4(void *binary) { return ms_office_binary_hash(binary, PH_MASK_4); }
168+
int ms_office_binary_hash_5(void *binary) { return ms_office_binary_hash(binary, PH_MASK_5); }
169+
int ms_office_binary_hash_6(void *binary) { return ms_office_binary_hash(binary, PH_MASK_6); }

src/office_fmt_plug.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Office 2007 cracker patch for JtR. This software is
33
* Copyright (c) 2012 Dhiru Kholia <dhiru.kholia at gmail.com>.
4-
* Copyright (c) 2012-2021 magnum
4+
* Copyright (c) 2012-2025 magnum
55
* and is hereby released to the general public under the following terms:
66
* Redistribution and use in source and binary forms, with or without
77
* modification, are permitted.
@@ -802,13 +802,13 @@ struct fmt_main fmt_office = {
802802
},
803803
fmt_default_source,
804804
{
805-
fmt_default_binary_hash_0,
806-
fmt_default_binary_hash_1,
807-
fmt_default_binary_hash_2,
808-
fmt_default_binary_hash_3,
809-
fmt_default_binary_hash_4,
810-
fmt_default_binary_hash_5,
811-
fmt_default_binary_hash_6
805+
ms_office_binary_hash_0,
806+
ms_office_binary_hash_1,
807+
ms_office_binary_hash_2,
808+
ms_office_binary_hash_3,
809+
ms_office_binary_hash_4,
810+
ms_office_binary_hash_5,
811+
ms_office_binary_hash_6
812812
},
813813
fmt_default_salt_hash,
814814
NULL,

src/opencl_office_fmt_plug.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* MS Office >= 2007 cracker for JtR. OpenCL support by magnum.
33
*
44
* This software is Copyright (c) 2012, Dhiru Kholia <dhiru.kholia at gmail.com>
5-
* and Copyright (c) 2012-2021, magnum
5+
* and Copyright (c) 2012-2025, magnum
66
* and it is hereby released to the general public under the following terms:
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted.
@@ -499,7 +499,13 @@ struct fmt_main fmt_opencl_office = {
499499
},
500500
fmt_default_source,
501501
{
502-
fmt_default_binary_hash
502+
ms_office_binary_hash_0,
503+
ms_office_binary_hash_1,
504+
ms_office_binary_hash_2,
505+
ms_office_binary_hash_3,
506+
ms_office_binary_hash_4,
507+
ms_office_binary_hash_5,
508+
ms_office_binary_hash_6
503509
},
504510
fmt_default_salt_hash,
505511
NULL,

0 commit comments

Comments
 (0)