[GH-ISSUE #2842] Raw MD5 format cannot handle uppercase hexadecimal characters (fixed for CPU, need fix for OpenCL) #1814

Open
opened 2026-10-15 04:25:10 +07:00 by bsakaguchi · 14 comments
Owner

Originally created by @dnet on GitHub (Nov 2, 2017).
Original GitHub issue: https://github.com/openwall/john/issues/2842

Although it shouldn't matter in case of hexadecimal encoding, the Raw MD5 format not only cannot handle uppercase characters, but the error message is not really helpful.

Steps to reproduce

Using uppercase hexadecimal characters (unexpected behavior)

run ➤ echo -ne "foobar" | md5sum | tr 'a-z' 'A-Z' | cut -c -32 | tee foobar.RAWMD5
3858F62230AC3C915F300C664312C63F
run ➤ ./john --format=Raw-MD5 foobar.RAWMD5
Using default input encoding: UTF-8
No password hashes loaded (see FAQ)

Using lowercase hexadecimal characters (expected behavior for uppercase)

run ➤ echo -ne "foobar" | md5sum | cut -c -32 | tee foobar.rawmd5
3858f62230ac3c915f300c664312c63f
run ➤ ./john --format=Raw-MD5 foobar.rawmd5
Using default input encoding: UTF-8
Loaded 1 password hash (Raw-MD5 [MD5 256/256 AVX2 8x3])
Warning: no OpenMP support for this hash type, consider --fork=4
Press 'q' or Ctrl-C to abort, almost any other key for status
foobar           (?)
1g 0:00:00:00 DONE 2/3 (2017-11-02 13:59) 2.380g/s 6285p/s 6285c/s 6285C/s rosita..denali
Use the "--show" option to display all of the cracked passwords reliably
Session completed

System configuration

Although the environment shouldn't matter in this case, I'm running this on Debian testing x86_64, I compiled John from bleeding-jumbo (in this case 7c4e6d423).

run ➤ ./john --list=build-info
Version: 1.8.0-jumbo-1-5985-g7c4e6d423
Build: linux-gnu 64-bit AVX2-ac OMP
SIMD: AVX2, interleaving: MD4:3 MD5:3 SHA1:1 SHA256:1 SHA512:1
CPU tests: AVX2
$JOHN is ./
Format interface version: 14
Max. number of reported tunable costs: 4
Rec file version: REC4
Charset file version: CHR3
CHARSET_MIN: 1 (0x01)
CHARSET_MAX: 255 (0xff)
CHARSET_LENGTH: 24
SALT_HASH_SIZE: 1048576
Max. Markov mode level: 400
Max. Markov mode password length: 30
gcc version: 7.2.0
GNU libc version: 2.24 (loaded: 2.24)
Crypto library: OpenSSL
OpenSSL library version: 01010006f
OpenSSL 1.1.0f  25 May 2017
GMP library version: 6.1.2
File locking: fcntl()
fseek(): fseek
ftell(): ftell
fopen(): fopen
memmem(): System's
Originally created by @dnet on GitHub (Nov 2, 2017). Original GitHub issue: https://github.com/openwall/john/issues/2842 Although it shouldn't matter in case of hexadecimal encoding, the Raw MD5 format not only cannot handle uppercase characters, but the error message is not really helpful. ### Steps to reproduce #### Using uppercase hexadecimal characters (unexpected behavior) ``` run ➤ echo -ne "foobar" | md5sum | tr 'a-z' 'A-Z' | cut -c -32 | tee foobar.RAWMD5 3858F62230AC3C915F300C664312C63F run ➤ ./john --format=Raw-MD5 foobar.RAWMD5 Using default input encoding: UTF-8 No password hashes loaded (see FAQ) ``` #### Using lowercase hexadecimal characters (expected behavior for uppercase) ``` run ➤ echo -ne "foobar" | md5sum | cut -c -32 | tee foobar.rawmd5 3858f62230ac3c915f300c664312c63f run ➤ ./john --format=Raw-MD5 foobar.rawmd5 Using default input encoding: UTF-8 Loaded 1 password hash (Raw-MD5 [MD5 256/256 AVX2 8x3]) Warning: no OpenMP support for this hash type, consider --fork=4 Press 'q' or Ctrl-C to abort, almost any other key for status foobar (?) 1g 0:00:00:00 DONE 2/3 (2017-11-02 13:59) 2.380g/s 6285p/s 6285c/s 6285C/s rosita..denali Use the "--show" option to display all of the cracked passwords reliably Session completed ``` ### System configuration Although the environment shouldn't matter in this case, I'm running this on Debian testing x86_64, I compiled John from `bleeding-jumbo` (in this case 7c4e6d423). ``` run ➤ ./john --list=build-info Version: 1.8.0-jumbo-1-5985-g7c4e6d423 Build: linux-gnu 64-bit AVX2-ac OMP SIMD: AVX2, interleaving: MD4:3 MD5:3 SHA1:1 SHA256:1 SHA512:1 CPU tests: AVX2 $JOHN is ./ Format interface version: 14 Max. number of reported tunable costs: 4 Rec file version: REC4 Charset file version: CHR3 CHARSET_MIN: 1 (0x01) CHARSET_MAX: 255 (0xff) CHARSET_LENGTH: 24 SALT_HASH_SIZE: 1048576 Max. Markov mode level: 400 Max. Markov mode password length: 30 gcc version: 7.2.0 GNU libc version: 2.24 (loaded: 2.24) Crypto library: OpenSSL OpenSSL library version: 01010006f OpenSSL 1.1.0f 25 May 2017 GMP library version: 6.1.2 File locking: fcntl() fseek(): fseek ftell(): ftell fopen(): fopen memmem(): System's ```
Author
Owner

@solardiz commented on GitHub (Nov 2, 2017):

This is on purpose. Not only for raw-md5, but for many hex-encoded hashes. We actually spent some time cleaning this up some years back, as there were cases where mixed-case hex encodings were accepted and caused trouble later.

As to the error message, it results from no format's valid() method recognizing the hash. It'd be tricky and dirty and inefficient to improve upon that. Would we introduce almostvalid() methods or also invoke valid() on lowercased versions of strings? This would slow down loading of multi-million hash dumps, which people fairly commonly do these days.

<!-- gh-comment-id:341422853 --> @solardiz commented on GitHub (Nov 2, 2017): This is on purpose. Not only for `raw-md5`, but for many hex-encoded hashes. We actually spent some time cleaning this up some years back, as there were cases where mixed-case hex encodings were accepted and caused trouble later. As to the error message, it results from no format's valid() method recognizing the hash. It'd be tricky and dirty and inefficient to improve upon that. Would we introduce almostvalid() methods or also invoke valid() on lowercased versions of strings? This would slow down loading of multi-million hash dumps, which people fairly commonly do these days.
Author
Owner

@dnet commented on GitHub (Nov 2, 2017):

there were cases where mixed-case hex encodings were accepted and caused trouble later

Could you elaborate on this, please?

<!-- gh-comment-id:341426668 --> @dnet commented on GitHub (Nov 2, 2017): > there were cases where mixed-case hex encodings were accepted and caused trouble later Could you elaborate on this, please?
Author
Owner

@solardiz commented on GitHub (Nov 2, 2017):

Speaking of the trouble from different-case and mixed-case hex encodings, when and where those were inadvertently supported before, it was mostly about not always recognizing matching hashes. JtR loader's own duplicate hash check and --show would then absolutely depend on comparing the binary versions of the hashes and on relying solely upon the result of that comparison, ignoring the ASCII. And even then we'd continue to confuse various external scripts that people write, or require them to also be aware of this detail.

On the other hand, we retained partial(?) support for that by keeping ldr_cracked_hash() case-insensitive, and we still/again have a similar problem with JimF's dynamic formats where different (or lack of) prefixes could effectively refer to the same hash type - e.g., there are at least 3 different ways in which an effectively raw-md5 hash can be prefixed in JtR input files.

<!-- gh-comment-id:341427210 --> @solardiz commented on GitHub (Nov 2, 2017): Speaking of the trouble from different-case and mixed-case hex encodings, when and where those were inadvertently supported before, it was mostly about not always recognizing matching hashes. JtR loader's own duplicate hash check and `--show` would then absolutely depend on comparing the binary versions of the hashes and on relying solely upon the result of that comparison, ignoring the ASCII. And even then we'd continue to confuse various external scripts that people write, or require them to also be aware of this detail. On the other hand, we retained partial(?) support for that by keeping `ldr_cracked_hash()` case-insensitive, and we still/again have a similar problem with JimF's dynamic formats where different (or lack of) prefixes could effectively refer to the same hash type - e.g., there are at least 3 different ways in which an effectively `raw-md5` hash can be prefixed in JtR input files.
Author
Owner

@solardiz commented on GitHub (Nov 2, 2017):

We actually support arbitrary- and mixed-case encodings for some hash types, such as LM and NT, where we unify the case in split() and set the flag FMT_SPLIT_UNIFIES_CASE. (And IIRC us having ldr_cracked_hash() as case-insensitive is somehow related to that support, but I forgot exactly how. Apparently, there's a code path or use case where non-split() strings reach the loader's hash table.)

Now that I've just re-checked, I was surprised to find that we also have this in many of the raw-* formats, with raw-md4, raw-md5, and raw-md5-flat (maybe some others) actually being exceptions here. This means we do in fact have a valid format-specific issue here, and should fix those formats to be consistent with other similar ones.

We should continue not to allow unexpected-case hex in strings that our own *2john tools generate, or where the target systems themselves use a hex encoding of a specific known case.

<!-- gh-comment-id:341433020 --> @solardiz commented on GitHub (Nov 2, 2017): We actually support arbitrary- and mixed-case encodings for some hash types, such as LM and NT, where we unify the case in `split()` and set the flag `FMT_SPLIT_UNIFIES_CASE`. (And IIRC us having `ldr_cracked_hash()` as case-insensitive is somehow related to that support, but I forgot exactly how. Apparently, there's a code path or use case where non-`split()` strings reach the loader's hash table.) Now that I've just re-checked, I was surprised to find that we also have this in many of the `raw-*` formats, with `raw-md4`, `raw-md5`, and `raw-md5-flat` (maybe some others) actually being exceptions here. This means we do in fact have a valid format-specific issue here, and should fix those formats to be consistent with other similar ones. We should continue not to allow unexpected-case hex in strings that our own `*2john` tools generate, or where the target systems themselves use a hex encoding of a specific known case.
Author
Owner

@dnet commented on GitHub (Nov 2, 2017):

we [...] should fix those formats to be consistent with other similar ones

Just to make sure I understood correctly, is the expected behavior handling uppercase hex strings as well? BTW Raw-MD5u (note the trailing u) handles it this way:

run ➤ echo abc123 | iconv -t utf16 | cut -b 3- | tr -d '\n' \
pipe pipe pipe> | md5sum | tr 'a-z' 'A-Z' | cut -c -32 | tee unimd5upper.txt
6E9B3A7620AAF77F362775150977EEB8
run ➤ ./john --format=Raw-MD5u unimd5upper.txt
Using default input encoding: UTF-8
Loaded 1 password hash (Raw-MD5u [md5(utf16($p)) 256/256 AVX2 8x3])
Warning: no OpenMP support for this hash type, consider --fork=4
Press 'q' or Ctrl-C to abort, almost any other key for status
abc123           (?)
1g 0:00:00:00 DONE 2/3 (2017-11-02 17:00) 2.564g/s 61.53p/s 61.53c/s 61.53C/s 123456..hello
Use the "--show" option to display all of the cracked passwords reliably
Session completed
<!-- gh-comment-id:341470973 --> @dnet commented on GitHub (Nov 2, 2017): > we [...] should fix those formats to be consistent with other similar ones Just to make sure I understood correctly, is the expected behavior handling uppercase hex strings as well? BTW `Raw-MD5u` (note the trailing `u`) handles it this way: ``` run ➤ echo abc123 | iconv -t utf16 | cut -b 3- | tr -d '\n' \ pipe pipe pipe> | md5sum | tr 'a-z' 'A-Z' | cut -c -32 | tee unimd5upper.txt 6E9B3A7620AAF77F362775150977EEB8 run ➤ ./john --format=Raw-MD5u unimd5upper.txt Using default input encoding: UTF-8 Loaded 1 password hash (Raw-MD5u [md5(utf16($p)) 256/256 AVX2 8x3]) Warning: no OpenMP support for this hash type, consider --fork=4 Press 'q' or Ctrl-C to abort, almost any other key for status abc123 (?) 1g 0:00:00:00 DONE 2/3 (2017-11-02 17:00) 2.564g/s 61.53p/s 61.53c/s 61.53C/s 123456..hello Use the "--show" option to display all of the cracked passwords reliably Session completed ```
Author
Owner

@solardiz commented on GitHub (Nov 2, 2017):

Yes, we need to make the behavior of the 3 formats I listed same as for Raw-MD5u wrt case of hex characters.

<!-- gh-comment-id:341475305 --> @solardiz commented on GitHub (Nov 2, 2017): Yes, we need to make the behavior of the 3 formats I listed same as for `Raw-MD5u` wrt case of hex characters.
Author
Owner

@solardiz commented on GitHub (Nov 2, 2017):

BTW, this would be moderately easy for a new contributor to implement (maybe as their very first contribution), given that we already have examples in other raw-* formats. Unfortunately, we don't have a GitHub label to indicate that, although GitHub itself recommends such label names for projects; this could be something we could want to add.

<!-- gh-comment-id:341476637 --> @solardiz commented on GitHub (Nov 2, 2017): BTW, this would be moderately easy for a new contributor to implement (maybe as their very first contribution), given that we already have examples in other `raw-*` formats. Unfortunately, we don't have a GitHub label to indicate that, although GitHub itself recommends such label names for projects; this could be something we could want to add.
Author
Owner

@dnet commented on GitHub (Nov 2, 2017):

Sounds great, I'll look into it!

<!-- gh-comment-id:341559196 --> @dnet commented on GitHub (Nov 2, 2017): Sounds great, I'll look into it!
Author
Owner

@kholia commented on GitHub (Nov 3, 2017):

@solardiz Custom labels can be added at the following URL,

https://github.com/magnumripper/JohnTheRipper/issues/labels

I am not sure what a good label name would be for such cases. Earlier I used to add easy-enough / trivial labels to such cases but these labels were removed at some point.

<!-- gh-comment-id:341615371 --> @kholia commented on GitHub (Nov 3, 2017): @solardiz Custom labels can be added at the following URL, https://github.com/magnumripper/JohnTheRipper/issues/labels I am not sure what a good label name would be for such cases. Earlier I used to add `easy-enough` / `trivial` labels to such cases but these labels were removed at some point.
Author
Owner

@solardiz commented on GitHub (Nov 3, 2017):

GitHub itself runs this ad:

Add labels for new contributors

Now, GitHub will help potential first-time contributors discover issues labeled with `help wanted` or `good first issue`

I've just added good first issue and renamed our RFC / Help wanted to RFC / discussion to avoid confusion with GitHub's suggested use of help wanted (which is different from what we meant). We might want to add help wanted as well.

BTW, in GitHub's ad help wanted originally appeared as red and good first issue as green, but I didn't keep the page open and don't recall what exact shade of green that was. When I added the label, I chose a certain shade of green and then the ad started displaying exactly that one (I suppose only on our project pages). That's smart of GitHub, yet we could want to stick to use of those colors in case they become familiar to GitHub users from other projects.

<!-- gh-comment-id:341675118 --> @solardiz commented on GitHub (Nov 3, 2017): GitHub itself runs this ad: ``` Add labels for new contributors Now, GitHub will help potential first-time contributors discover issues labeled with `help wanted` or `good first issue` ``` I've just added `good first issue` and renamed our `RFC / Help wanted` to `RFC / discussion` to avoid confusion with GitHub's suggested use of `help wanted` (which is different from what we meant). We might want to add `help wanted` as well. BTW, in GitHub's ad `help wanted` originally appeared as red and `good first issue` as green, but I didn't keep the page open and don't recall what exact shade of green that was. When I added the label, I chose a certain shade of green and then the ad started displaying exactly that one (I suppose only on our project pages). That's smart of GitHub, yet we could want to stick to use of those colors in case they become familiar to GitHub users from other projects.
Author
Owner

@solardiz commented on GitHub (Nov 3, 2017):

Or maybe magnum actually meant by the Help wanted part of RFC / Help wanted the same thing that GitHub means? If so, OK to rename back. I'll leave this to magnum now.

<!-- gh-comment-id:341676998 --> @solardiz commented on GitHub (Nov 3, 2017): Or maybe magnum actually meant by the `Help wanted` part of `RFC / Help wanted` the same thing that GitHub means? If so, OK to rename back. I'll leave this to magnum now.
Author
Owner

@dnet commented on GitHub (Nov 3, 2017):

I submitted PR #2845

<!-- gh-comment-id:341700772 --> @dnet commented on GitHub (Nov 3, 2017): I submitted PR #2845
Author
Owner

@solardiz commented on GitHub (Mar 3, 2018):

FWIW, looks like at least raw-md5-opencl still doesn't load uppercase hex. I think we missed the -opencl formats when adjusting the corresponding CPU ones.

<!-- gh-comment-id:370165171 --> @solardiz commented on GitHub (Mar 3, 2018): FWIW, looks like at least `raw-md5-opencl` still doesn't load uppercase hex. I think we missed the `-opencl` formats when adjusting the corresponding CPU ones.
Author
Owner

@magnumripper commented on GitHub (Mar 3, 2018):

Ideally they'd even use the very same functions for valid, split and binary.

<!-- gh-comment-id:370179600 --> @magnumripper commented on GitHub (Mar 3, 2018): Ideally they'd even use the very same functions for valid, split and binary.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#1814
No description provided.