[GH-ISSUE #1067] ASan error in base64_convert with --format=hmac-md5 #661

Closed
opened 2026-10-14 03:18:15 +07:00 by bsakaguchi · 9 comments
Owner

Originally created by @frank-dittrich on GitHub (Mar 3, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1067

64bit Linux

(bleeding-jumbo)run $ ./john --test=0 --format=hmac-md5 
Will run 8 OpenMP threads
Testing: HMAC-MD5 [password is key, MD5 128/128 AVX 12x]... (8xOMP) =================================================================
==9256== ERROR: AddressSanitizer: global-buffer-overflow on address 0x0000008db01f at pc 0x468ad2 bp 0x7fff098426f0 sp 0x7fff098426e0
READ of size 1 at 0x0000008db01f thread T0
    #0 0x468ad1 (/home/fd/git/JtR/run/john+0x468ad1)
    #1 0x613b41 (/home/fd/git/JtR/run/john+0x613b41)
    #2 0x7792f7 (/home/fd/git/JtR/run/john+0x7792f7)
    #3 0x7610a7 (/home/fd/git/JtR/run/john+0x7610a7)
    #4 0x763175 (/home/fd/git/JtR/run/john+0x763175)
    #5 0x78831d (/home/fd/git/JtR/run/john+0x78831d)
    #6 0x7898b9 (/home/fd/git/JtR/run/john+0x7898b9)
    #7 0x3bc2621d64 (/usr/lib64/libc-2.18.so+0x21d64)
    #8 0x4066b4 (/home/fd/git/JtR/run/john+0x4066b4)
0x0000008db01f is located 1 bytes to the left of global variable '*.LC18 (hmacMD5_fmt_plug.c)' (0x8db020) of size 8
  '*.LC18 (hmacMD5_fmt_plug.c)' is ascii string 'hashcat'
0x0000008db01f is located 31 bytes to the right of global variable '*.LC17 (hmacMD5_fmt_plug.c)' (0x8dafa0) of size 96
  '*.LC17 (hmacMD5_fmt_plug.c)' is ascii string '$cram_md5$PG5vLXJlcGx5QGhhc2hjYXQubmV0Pg==$dXNlciA0NGVhZmQyMmZlNzY2NzBmNmIyODc5MDgxYTdmNWY3MQ=='
Shadow bytes around the buggy address:
  0x0000801135b0: 00 00 00 00 02 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x0000801135c0: 00 00 00 00 00 05 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x0000801135d0: f9 f9 f9 f9 00 00 00 00 00 06 f9 f9 f9 f9 f9 f9
  0x0000801135e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 03 f9 f9
  0x0000801135f0: f9 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00
=>0x000080113600: f9 f9 f9[f9]00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x000080113610: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080113620: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080113630: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080113640: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080113650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:     fa
  Heap righ redzone:     fb
  Freed Heap region:     fd
  Stack left redzone:    f1
  Stack mid redzone:     f2
  Stack right redzone:   f3
  Stack partial redzone: f4
  Stack after return:    f5
  Stack use after scope: f8
  Global redzone:        f9
  Global init order:     f6
  Poisoned by user:      f7
  ASan internal:         fe
==9256== ABORTING
(bleeding-jumbo)run $ ./asan_symbolize.py 
    #0 0x468ad1 (/home/fd/git/JtR/run/john+0x468ad1)
    #1 0x613b41 (/home/fd/git/JtR/run/john+0x613b41)
    #2 0x7792f7 (/home/fd/git/JtR/run/john+0x7792f7)
    #3 0x7610a7 (/home/fd/git/JtR/run/john+0x7610a7)
    #4 0x763175 (/home/fd/git/JtR/run/john+0x763175)
    #5 0x78831d (/home/fd/git/JtR/run/john+0x78831d)
    #6 0x7898b9 (/home/fd/git/JtR/run/john+0x7898b9)
    #7 0x3bc2621d64 (/usr/lib64/libc-2.18.so+0x21d64)
    #8 0x4066b4 (/home/fd/git/JtR/run/john+0x4066b4)
llvm-symbolizer: for the -functions option: 'short' is invalid value for boolean argument! Try 0 or 1
    #0 0x468ad1 in base64_convert /home/fd/git/JtR/src/base64_convert.c:852
    #1 0x613b41 in prepare /home/fd/git/JtR/src/hmacMD5_fmt_plug.c:163
    #2 0x7792f7 in fmt_self_test_body /home/fd/git/JtR/src/formats.c:320
    #3 0x7610a7 in benchmark_format /home/fd/git/JtR/src/bench.c:240
    #4 0x763175 in benchmark_all /home/fd/git/JtR/src/bench.c:639
    #5 0x78831d in john_run /home/fd/git/JtR/src/john.c:1309
    #6 0x7898b9 in main /home/fd/git/JtR/src/john.c:1687
    #7 0x3bc2621d64 in ?? ??:0
    #8 0x4066b4 in _start ??:?

Built with --enable-asan --enable-memdbg-ex (and with --enable-rexgen, but I doubt that this matters).

Originally created by @frank-dittrich on GitHub (Mar 3, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1067 64bit Linux ``` (bleeding-jumbo)run $ ./john --test=0 --format=hmac-md5 Will run 8 OpenMP threads Testing: HMAC-MD5 [password is key, MD5 128/128 AVX 12x]... (8xOMP) ================================================================= ==9256== ERROR: AddressSanitizer: global-buffer-overflow on address 0x0000008db01f at pc 0x468ad2 bp 0x7fff098426f0 sp 0x7fff098426e0 READ of size 1 at 0x0000008db01f thread T0 #0 0x468ad1 (/home/fd/git/JtR/run/john+0x468ad1) #1 0x613b41 (/home/fd/git/JtR/run/john+0x613b41) #2 0x7792f7 (/home/fd/git/JtR/run/john+0x7792f7) #3 0x7610a7 (/home/fd/git/JtR/run/john+0x7610a7) #4 0x763175 (/home/fd/git/JtR/run/john+0x763175) #5 0x78831d (/home/fd/git/JtR/run/john+0x78831d) #6 0x7898b9 (/home/fd/git/JtR/run/john+0x7898b9) #7 0x3bc2621d64 (/usr/lib64/libc-2.18.so+0x21d64) #8 0x4066b4 (/home/fd/git/JtR/run/john+0x4066b4) 0x0000008db01f is located 1 bytes to the left of global variable '*.LC18 (hmacMD5_fmt_plug.c)' (0x8db020) of size 8 '*.LC18 (hmacMD5_fmt_plug.c)' is ascii string 'hashcat' 0x0000008db01f is located 31 bytes to the right of global variable '*.LC17 (hmacMD5_fmt_plug.c)' (0x8dafa0) of size 96 '*.LC17 (hmacMD5_fmt_plug.c)' is ascii string '$cram_md5$PG5vLXJlcGx5QGhhc2hjYXQubmV0Pg==$dXNlciA0NGVhZmQyMmZlNzY2NzBmNmIyODc5MDgxYTdmNWY3MQ==' Shadow bytes around the buggy address: 0x0000801135b0: 00 00 00 00 02 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 0x0000801135c0: 00 00 00 00 00 05 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 0x0000801135d0: f9 f9 f9 f9 00 00 00 00 00 06 f9 f9 f9 f9 f9 f9 0x0000801135e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 03 f9 f9 0x0000801135f0: f9 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00 =>0x000080113600: f9 f9 f9[f9]00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 0x000080113610: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x000080113620: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x000080113630: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x000080113640: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x000080113650: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Heap righ redzone: fb Freed Heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack partial redzone: f4 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 ASan internal: fe ==9256== ABORTING (bleeding-jumbo)run $ ./asan_symbolize.py #0 0x468ad1 (/home/fd/git/JtR/run/john+0x468ad1) #1 0x613b41 (/home/fd/git/JtR/run/john+0x613b41) #2 0x7792f7 (/home/fd/git/JtR/run/john+0x7792f7) #3 0x7610a7 (/home/fd/git/JtR/run/john+0x7610a7) #4 0x763175 (/home/fd/git/JtR/run/john+0x763175) #5 0x78831d (/home/fd/git/JtR/run/john+0x78831d) #6 0x7898b9 (/home/fd/git/JtR/run/john+0x7898b9) #7 0x3bc2621d64 (/usr/lib64/libc-2.18.so+0x21d64) #8 0x4066b4 (/home/fd/git/JtR/run/john+0x4066b4) llvm-symbolizer: for the -functions option: 'short' is invalid value for boolean argument! Try 0 or 1 #0 0x468ad1 in base64_convert /home/fd/git/JtR/src/base64_convert.c:852 #1 0x613b41 in prepare /home/fd/git/JtR/src/hmacMD5_fmt_plug.c:163 #2 0x7792f7 in fmt_self_test_body /home/fd/git/JtR/src/formats.c:320 #3 0x7610a7 in benchmark_format /home/fd/git/JtR/src/bench.c:240 #4 0x763175 in benchmark_all /home/fd/git/JtR/src/bench.c:639 #5 0x78831d in john_run /home/fd/git/JtR/src/john.c:1309 #6 0x7898b9 in main /home/fd/git/JtR/src/john.c:1687 #7 0x3bc2621d64 in ?? ??:0 #8 0x4066b4 in _start ??:? ``` Built with `--enable-asan --enable-memdbg-ex` (and with --enable-rexgen, but I doubt that this matters).
bsakaguchi 2026-10-14 03:18:15 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

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

That's a bug and the correct fix is this

diff --git a/src/hmacMD5_fmt_plug.c b/src/hmacMD5_fmt_plug.c
index 3cfadb1..cb41a65 100644
--- a/src/hmacMD5_fmt_plug.c
+++ b/src/hmacMD5_fmt_plug.c
@@ -160,7 +160,8 @@ static char *prepare(char *split_fields[10], struct fmt_main *self)
                                     flg_Base64_MIME_TRAIL_EQ);
                o += len;
                *o++ = '#';
-               len = base64_convert(++d, e_b64_mime, strlen(p),
+               d++;
+               len = base64_convert(d, e_b64_mime, strlen(d),
                                     o, e_b64_raw,
                                     sizeof(out) - len - 2,
                                     flg_Base64_MIME_TRAIL_EQ);

However @jfoug the above fails self-test. To make it work I need to give strlen(d) + 1 as input length which is obviously not correct! Is this a bug in base64_convert() or do I misunderstand something?

<!-- gh-comment-id:76940118 --> @magnumripper commented on GitHub (Mar 3, 2015): That's a bug and the correct fix is this ``` patch diff --git a/src/hmacMD5_fmt_plug.c b/src/hmacMD5_fmt_plug.c index 3cfadb1..cb41a65 100644 --- a/src/hmacMD5_fmt_plug.c +++ b/src/hmacMD5_fmt_plug.c @@ -160,7 +160,8 @@ static char *prepare(char *split_fields[10], struct fmt_main *self) flg_Base64_MIME_TRAIL_EQ); o += len; *o++ = '#'; - len = base64_convert(++d, e_b64_mime, strlen(p), + d++; + len = base64_convert(d, e_b64_mime, strlen(d), o, e_b64_raw, sizeof(out) - len - 2, flg_Base64_MIME_TRAIL_EQ); ``` However @jfoug the above fails self-test. To make it work I need to give `strlen(d) + 1` as input length which is obviously not correct! Is this a bug in base64_convert() or do I misunderstand something?
Author
Owner

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

I committed the fix with +1 in 914cc05. But it looks very strange to me so I'm not closing yet.

<!-- gh-comment-id:76941939 --> @magnumripper commented on GitHub (Mar 3, 2015): I committed the fix with +1 in 914cc05. But it looks very strange to me so I'm not closing yet.
Author
Owner

@frank-dittrich commented on GitHub (Mar 3, 2015):

Apparently, this commit also causes TS to fail for dynaimic_31 and dynamic_2001.

<!-- gh-comment-id:76950785 --> @frank-dittrich commented on GitHub (Mar 3, 2015): Apparently, this commit also causes TS to fail for dynaimic_31 and dynamic_2001.
Author
Owner

@jfoug commented on GitHub (Mar 3, 2015):

This is an easy fix. The later memmove is not copying the null byte (you only copy 0x20 bytes, not 0x21), so the length of the hash is too long. Copy the null and the problem goes away. I will commit and @frank-dittrich can check if there are failures, BUT there should be no interaction, I think.

<!-- gh-comment-id:76952956 --> @jfoug commented on GitHub (Mar 3, 2015): This is an easy fix. The later memmove is not copying the null byte (you only copy 0x20 bytes, not 0x21), so the length of the hash is too long. Copy the null and the problem goes away. I will commit and @frank-dittrich can check if there are failures, BUT there should be no interaction, I think.
Author
Owner

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

I still think the notion of strlen(d) + 1 as "length of input to use" has got to be flawed. I have a buffer (of any length, but in this case 53 bytes) with 52 characters that I want to convert. Why do I have to ask for 53?

<!-- gh-comment-id:76961314 --> @magnumripper commented on GitHub (Mar 3, 2015): I still think the notion of `strlen(d) + 1` as "length of input to use" has got to be flawed. I have a buffer (of any length, but in this case 53 bytes) with 52 characters that I want to convert. Why do I have to ask for 53?
Author
Owner

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

Oh, now I get it (after reviewing 9ff7aa0). LOL I'm stupid.

<!-- gh-comment-id:76961722 --> @magnumripper commented on GitHub (Mar 3, 2015): Oh, now I get it (after reviewing 9ff7aa0). LOL I'm stupid.
Author
Owner

@jfoug commented on GitHub (Mar 3, 2015):

The problem was len was a 'longer' value (I think) so the null byte was copied before. Now we return proper length.

Now, there MAY be a problem in base-64 convert, where the length returned is wrong, if the code hits a null byte less than length of string. I will investigate this.

However, after your fix, and 9ff7aa0, I think 'this' bug is squashed.

<!-- gh-comment-id:76984546 --> @jfoug commented on GitHub (Mar 3, 2015): The problem was len was a 'longer' value (I think) so the null byte was copied before. Now we return proper length. Now, there MAY be a problem in base-64 convert, where the length returned is wrong, if the code hits a null byte less than length of string. I will investigate this. However, after your fix, and 9ff7aa0, I think 'this' bug is squashed.
Author
Owner

@jfoug commented on GitHub (Mar 3, 2015):

Ok, I added a quick-dirty function, and yes, there are problems:

$ ../run/base64conv.exe -l
len=37  data = user 44eafd22fe76670f6b2879081a7f5f71
len=40  data = user 44eafd22fe76670f6b2879081a7f5f71
len=40  data = user 44eafd22fe76670f6b2879081a7f5f71
len=41  data = user 44eafd22fe76670f6b2879081a7f5f71
len=45  data = user 44eafd22fe76670f6b2879081a7f5f71
len=37  data = user 44eafd22fe76670f6b2879081a7f5f71
len=40  data = user 44eafd22fe76670f6b2879081a7f5f71
len=40  data = user 44eafd22fe76670f6b2879081a7f5f71
len=41  data = user 44eafd22fe76670f6b2879081a7f5f71
len=45  data = user 44eafd22fe76670f6b2879081a7f5f71

I pass same data (actually code from the XSHA512 code.I then do strlen(p) and then other calls with strlen(p)+xx You can see the length returned is not right.

<!-- gh-comment-id:76998004 --> @jfoug commented on GitHub (Mar 3, 2015): Ok, I added a quick-dirty function, and yes, there are problems: ``` $ ../run/base64conv.exe -l len=37 data = user 44eafd22fe76670f6b2879081a7f5f71 len=40 data = user 44eafd22fe76670f6b2879081a7f5f71 len=40 data = user 44eafd22fe76670f6b2879081a7f5f71 len=41 data = user 44eafd22fe76670f6b2879081a7f5f71 len=45 data = user 44eafd22fe76670f6b2879081a7f5f71 len=37 data = user 44eafd22fe76670f6b2879081a7f5f71 len=40 data = user 44eafd22fe76670f6b2879081a7f5f71 len=40 data = user 44eafd22fe76670f6b2879081a7f5f71 len=41 data = user 44eafd22fe76670f6b2879081a7f5f71 len=45 data = user 44eafd22fe76670f6b2879081a7f5f71 ``` I pass same data (actually code from the XSHA512 code.I then do strlen(p) and then other calls with strlen(p)+xx You can see the length returned is not right.
Author
Owner

@jfoug commented on GitHub (Mar 3, 2015):

I have done some fixing in base64_conv code.Now the len=37 is returned for all of the above conversions, and added that quick/dirty function to the base64conv program if a -l switch (length) is used.

<!-- gh-comment-id:77001329 --> @jfoug commented on GitHub (Mar 3, 2015): I have done some fixing in base64_conv code.Now the len=37 is returned for all of the above conversions, and added that quick/dirty function to the base64conv program if a -l switch (length) is used.
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#661
No description provided.