[GH-ISSUE #673] PHPS format problem with \x24 ('$') in $HEX$ #325

Closed
opened 2026-10-14 03:01:25 +07:00 by bsakaguchi · 7 comments
Owner

Originally created by @frank-dittrich on GitHub (Jun 26, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/673

(bleeding-jumbo)run $ catPHPS.hashes 
bash: catPHPS.hashes: command not found
(bleeding-jumbo)run $ cat PHPS.hashes 
$PHPS$433925$5d756853cd63acee76e6dcd6d3728447
$PHPS$73616c$aba22b2ceb7c841473c03962b145feb3
$PHPS$247824$ad14afbbf0e16d4ad8c8985263a3d051

(bleeding-jumbo)run $ ./john PHPS.hashes PHPS.pw
Loaded 3 password hashes with 3 different salts (PHPS [md5(md5($p).$s) 128/128 AVX 480x4x3])
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
test             (?)
welcome          (?)
password         (?)
3g 0:00:00:00 DONE 2/3 (2014-06-26 15:07) 300.0g/s 614400p/s 1843Kc/s 1843KC/s 123456..Open
Use the "--show" option to display all of the cracked passwords reliably
Session completed
(bleeding-jumbo)run $ ./john --show PHPS.hashes 
?:welcome
?:password

2 password hashes cracked, 1 left
(bleeding-jumbo)run $ ./john --show=LEFT PHPS.hashes > PHPS.left

2 password hashes cracked, 1 left

(bleeding-jumbo)run $ cat PHPS.left 
?:$dynamic_6$ad14afbbf0e16d4ad8c8985263a3d051$$x$

(bleeding-jumbo)run $ ./john PHPS.left PHPS.pw
Warning: detected hash type "dynamic_6", but the string is also recognized as "PHPS"
Use the "--format=PHPS" option to force loading these as that type instead
Loaded 1 password hash (dynamic_6 [md5(md5($p).$s) 128/128 AVX 480x4x3])
No password hashes left to crack (see FAQ)
(bleeding-jumbo)run $ ./john PHPS.left --format=PHPS PHPS.pw
Loaded 1 password hash (PHPS [md5(md5($p).$s) 128/128 AVX 480x4x3])
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
test             (?)
(bleeding-jumbo)run $ ./john PHPS.hashes --format=PHPS PHPS.pw
Loaded 3 password hashes with 3 different salts (PHPS [md5(md5($p).$s) 128/128 AVX 480x4x3])
Remaining 1 password hash
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
test             (?)
1g 0:00:00:00 DONE 2/3 (2014-06-26 15:12) 100.0g/s 614400p/s 614400c/s 614400C/s 123456..Open
Use the "--show" option to display all of the cracked passwords reliably
Session completed

(bleeding-jumbo)run $ sort john.pot |uniq -c
      1 $dynamic_6$5d756853cd63acee76e6dcd6d3728447$C9%:welcome
      1 $dynamic_6$aba22b2ceb7c841473c03962b145feb3$sal:password
      5 $dynamic_6$ad14afbbf0e16d4ad8c8985263a3d051$HEX$247824:test
Originally created by @frank-dittrich on GitHub (Jun 26, 2014). Original GitHub issue: https://github.com/openwall/john/issues/673 ``` (bleeding-jumbo)run $ catPHPS.hashes bash: catPHPS.hashes: command not found (bleeding-jumbo)run $ cat PHPS.hashes $PHPS$433925$5d756853cd63acee76e6dcd6d3728447 $PHPS$73616c$aba22b2ceb7c841473c03962b145feb3 $PHPS$247824$ad14afbbf0e16d4ad8c8985263a3d051 (bleeding-jumbo)run $ ./john PHPS.hashes PHPS.pw Loaded 3 password hashes with 3 different salts (PHPS [md5(md5($p).$s) 128/128 AVX 480x4x3]) Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status test (?) welcome (?) password (?) 3g 0:00:00:00 DONE 2/3 (2014-06-26 15:07) 300.0g/s 614400p/s 1843Kc/s 1843KC/s 123456..Open Use the "--show" option to display all of the cracked passwords reliably Session completed (bleeding-jumbo)run $ ./john --show PHPS.hashes ?:welcome ?:password 2 password hashes cracked, 1 left (bleeding-jumbo)run $ ./john --show=LEFT PHPS.hashes > PHPS.left 2 password hashes cracked, 1 left (bleeding-jumbo)run $ cat PHPS.left ?:$dynamic_6$ad14afbbf0e16d4ad8c8985263a3d051$$x$ (bleeding-jumbo)run $ ./john PHPS.left PHPS.pw Warning: detected hash type "dynamic_6", but the string is also recognized as "PHPS" Use the "--format=PHPS" option to force loading these as that type instead Loaded 1 password hash (dynamic_6 [md5(md5($p).$s) 128/128 AVX 480x4x3]) No password hashes left to crack (see FAQ) (bleeding-jumbo)run $ ./john PHPS.left --format=PHPS PHPS.pw Loaded 1 password hash (PHPS [md5(md5($p).$s) 128/128 AVX 480x4x3]) Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status test (?) (bleeding-jumbo)run $ ./john PHPS.hashes --format=PHPS PHPS.pw Loaded 3 password hashes with 3 different salts (PHPS [md5(md5($p).$s) 128/128 AVX 480x4x3]) Remaining 1 password hash Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status test (?) 1g 0:00:00:00 DONE 2/3 (2014-06-26 15:12) 100.0g/s 614400p/s 614400c/s 614400C/s 123456..Open Use the "--show" option to display all of the cracked passwords reliably Session completed (bleeding-jumbo)run $ sort john.pot |uniq -c 1 $dynamic_6$5d756853cd63acee76e6dcd6d3728447$C9%:welcome 1 $dynamic_6$aba22b2ceb7c841473c03962b145feb3$sal:password 5 $dynamic_6$ad14afbbf0e16d4ad8c8985263a3d051$HEX$247824:test ```
Author
Owner

@jfoug commented on GitHub (Jun 26, 2014):

I tried this with no problems, ,BUT i put -w= in front of the PSPS.pw

I do see a bug, in that I have 3 elements in my .pot file, but the --show=left only sees 2 of them, and dumps out the test one with x. I think I will add '$' to the chars deemed 'bad' in loader, and see if this problem goes away.

<!-- gh-comment-id:47227710 --> @jfoug commented on GitHub (Jun 26, 2014): I tried this with no problems, ,BUT i put -w= in front of the PSPS.pw I do see a bug, in that I have 3 elements in my .pot file, but the --show=left only sees 2 of them, and dumps out the test one with $x$. I think I will add '$' to the chars deemed 'bad' in loader, and see if this problem goes away.
Author
Owner

@jfoug commented on GitHub (Jun 26, 2014):

I believe this fixes the issue, BUT since I never use --show (or --show=left), I am not sure what real side effects this will have, so I am not committing it.

diff --git a/src/loader.c b/src/loader.c
index d2d1c03..3636be4 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -825,10 +825,17 @@ static void ldr_load_pot_line(struct db_main *db, char *line)
        void *binary;
        int hash;
        struct db_password *current;
+       char *flds[10] = {0,0,0,0,0,0,0,0,0,0};

        ciphertext = ldr_get_field(&line, db->options->field_sep_char);
+
        if (format->methods.valid(ciphertext, format) != 1) return;

+       // without this prepare, we have problems not dropping off dynamic formats which had to use
+       // the $HEX$ for the salt, when stored in the .pot file.
+       flds[1] = ciphertext;
+       ciphertext = format->methods.prepare(flds, format);
+
        ciphertext = format->methods.split(ciphertext, 0, format);
        binary = format->methods.binary(ciphertext);
        hash = db->password_hash_func(binary);

I think magnum mentioned something about prepare not being called here. Well, it looks like there are side effects.

<!-- gh-comment-id:47229618 --> @jfoug commented on GitHub (Jun 26, 2014): I believe this fixes the issue, BUT since I never use --show (or --show=left), I am not sure what real side effects this will have, so I am not committing it. ``` diff --git a/src/loader.c b/src/loader.c index d2d1c03..3636be4 100644 --- a/src/loader.c +++ b/src/loader.c @@ -825,10 +825,17 @@ static void ldr_load_pot_line(struct db_main *db, char *line) void *binary; int hash; struct db_password *current; + char *flds[10] = {0,0,0,0,0,0,0,0,0,0}; ciphertext = ldr_get_field(&line, db->options->field_sep_char); + if (format->methods.valid(ciphertext, format) != 1) return; + // without this prepare, we have problems not dropping off dynamic formats which had to use + // the $HEX$ for the salt, when stored in the .pot file. + flds[1] = ciphertext; + ciphertext = format->methods.prepare(flds, format); + ciphertext = format->methods.split(ciphertext, 0, format); binary = format->methods.binary(ciphertext); hash = db->password_hash_func(binary); ``` I think magnum mentioned something about prepare not being called here. Well, it looks like there are side effects.
Author
Owner

@magnumripper commented on GitHub (Jun 26, 2014):

I think prepare() is called when loading your input file, but not when loading the pot file. It might even be that cracked hash removal (when loading) behaves differently than --show. I haven't had time to follow all code yet but I think prepare is not called in either of those cases.

<!-- gh-comment-id:47266052 --> @magnumripper commented on GitHub (Jun 26, 2014): I think prepare() is called when loading your input file, but not when loading the pot file. It might even be that cracked hash removal (when loading) behaves differently than --show. I haven't had time to follow all code yet but I _think_ prepare is not called in either of those cases.
Author
Owner

@jfoug commented on GitHub (Jun 27, 2014):

Without the patch I list above, when I run phps with this input file, it finds 1 password every time after the initial run finding 3. The one it finds every time is the 'test' password. What this shows, is without that prepare patch, any dynamic found, that are stored as HEX in the .pot file, will never be removed from input. They will always show up in a --show=LEFT They will always be re-run when continuing a run, etc.

I am going to put this call to prepare, after the valid, I am not 100% sure of this, but the .pot file is the most likely place where multiple hash types are located. Pretty much all hashes getting to the .pot file were written as cannonical tagged hashes.

<!-- gh-comment-id:47337030 --> @jfoug commented on GitHub (Jun 27, 2014): Without the patch I list above, when I run phps with this input file, it finds 1 password every time after the initial run finding 3. The one it finds every time is the 'test' password. What this shows, is without that prepare patch, any dynamic found, that are stored as $HEX$ in the .pot file, will never be removed from input. They will always show up in a --show=LEFT They will always be re-run when continuing a run, etc. I am going to put this call to prepare, after the valid, I am not 100% sure of this, but the .pot file is the most likely place where multiple hash types are located. Pretty much all hashes getting to the .pot file were written as cannonical tagged hashes.
Author
Owner

@jfoug commented on GitHub (Jun 27, 2014):

Put this f89acf9 prepare in there. All testing done, things work the way they worked in the past, but the HEX also properly are handled. NOTE, I do not use --show or --show=left features at all, so my testing may be lacking.

But this PHPS issue listed here, is handled properly.

<!-- gh-comment-id:47341338 --> @jfoug commented on GitHub (Jun 27, 2014): Put this f89acf9 prepare in there. All testing done, things work the way they worked in the past, but the $HEX$ also properly are handled. NOTE, I do not use --show or --show=left features at all, so my testing may be lacking. But this PHPS issue listed here, is handled properly.
Author
Owner

@frank-dittrich commented on GitHub (Jun 27, 2014):

You culd argue that the problem is caused by:

  1. PHPS being a thin format with a fallback to dynamic.
  2. dynamic doing some things in prepare() which could as well be done in split()
    Hint:
    If you call prepare with the ciphertext being the only field that is filled, then definitely you could do the same things in split.
    A less intrusive change could be: move the logic you put into loader.c into PHPS's split() function instead.
<!-- gh-comment-id:47344450 --> @frank-dittrich commented on GitHub (Jun 27, 2014): You culd argue that the problem is caused by: 1. PHPS being a thin format with a fallback to dynamic. 2. dynamic doing some things in prepare() which could as well be done in split() Hint: If you call prepare with the ciphertext being the only field that is filled, then definitely you could do the same things in split. A less intrusive change could be: move the logic you put into loader.c into PHPS's split() function instead.
Author
Owner

@jfoug commented on GitHub (Jun 27, 2014):

7c671a5 rolls back f89acf9 and adds logic to thin dyna formats, so they call the dynamic split function from within their split functions.

NOTE, net-md5 and net-sha1 do not call dyna split (or prepare, etc). They are not thin formats, but 'hybrid'. I am not sure how to work around thier issues. If they use dyna to find a hash, then they will store with HEX in the .pot. We should test them, to make SURE they are working right. I can not see how they would be working right.

<!-- gh-comment-id:47352480 --> @jfoug commented on GitHub (Jun 27, 2014): 7c671a5 rolls back f89acf9 and adds logic to thin dyna formats, so they call the dynamic split function from within their split functions. NOTE, net-md5 and net-sha1 do not call dyna split (or prepare, etc). They are not thin formats, but 'hybrid'. I am not sure how to work around thier issues. If they use dyna to find a hash, then they will store with $HEX$ in the .pot. We should test them, to make SURE they are working right. I can not see how they would be working right.
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#325
No description provided.