[GH-ISSUE #2117] Add generic helper methods for handling large non-hash data #1415

Closed
opened 2026-10-15 04:16:07 +07:00 by bsakaguchi · 85 comments
Owner

Originally created by @kholia on GitHub (Apr 15, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2117

Currently each format (e.g. LUKS) has its own hacks for handling large amount (> LINE_BUFFER-SIZE) of non-hash data.

Adding such hacks for new formats (e.g. gpg2john) requires duplicated code, and time.

It would be nice to have a unified way of handling large amount of non-inlinable non-hash data.

  • read any arbitrary line length from input files.
  • read any arbitrary line length from .pot files.
  • set LINE_BUFFER_SIZE back to 0x400 to match core
  • reduce .pot file writing to LINE_BUFFER_SIZE (truncating hash). This truncation will have a hash of the full source, and the binary() appended for later comparison needs.
  • make sure -show works in all cases
  • make sure -show=left works in all cases, including that for LONG sources, it shows the full source
  • adjust ALL formats which can have longer than 0x400 sources to validate and binary properly on truncated hash. (which formats???)
  • Fix any problems in other code due to reduction in LINE_BUFFER_SIZE (keepass seem to be the only one)
  • make sure that a hash with dyna salt would work (????)
  • make sure that a hash that does not store it's source works (or if we run with memory reduction switches)
  • make sure that .pot line entries which are > than LINE_BUFFER_SIZE (i.e. older cracks) still work properly.
  • change other *2john so that they build inline files (or at least can). zip2john is one I know of. There are others. (listed below)
  • luks (these ARE longer than 1024 bytes) I patched listconf.c to not cut field 15 to 256 bytes
  • agilekeychain (NOTE, opencl and cuda and *2john should also be handled prior to setting ANY checkmark)
  • cloudkeychain
  • dmg
  • fde
  • gpg
  • keepass
  • keestore
  • krb5tgs
  • odf
  • openbsd-softraid
  • PEM
  • pfx
  • pkzip
  • putty
  • ssh2
  • sshng
  • strip
  • sxc
  • true crypt (all types)
  • zip2
  • The next 'may' have some hashes longer than 1024. I am not sure but we need to check each one, then check them off.
  • bitcoin
  • blockchain
  • efs
  • encfs
  • ike
  • iwork
  • keychain
  • krb5
  • kwallet
  • pdf
  • rsvp
  • 7z
  • vdi (aes-xts256)
  • vtp
  • wpapsk
  • handle any hashes with 0 byte binaries ??
  • perform all tests including jtrts.pl since it cracks, then re-tests from .pot file, so this IS a good test.
Originally created by @kholia on GitHub (Apr 15, 2016). Original GitHub issue: https://github.com/openwall/john/issues/2117 Currently each format (e.g. LUKS) has its own hacks for handling large amount (> LINE_BUFFER-SIZE) of non-hash data. Adding such hacks for new formats (e.g. gpg2john) requires duplicated code, and time. It would be nice to have a unified way of handling large amount of non-inlinable non-hash data. - [x] read any arbitrary line length from input files. - [x] read any arbitrary line length from .pot files. - [x] set LINE_BUFFER_SIZE back to 0x400 to match core - [x] reduce .pot file writing to LINE_BUFFER_SIZE (truncating hash). This truncation will have a hash of the full source, and the binary() appended for later comparison needs. - [x] make sure -show works in all cases - [x] make sure -show=left works in all cases, including that for LONG sources, it shows the full source - [x] adjust ALL formats which can have longer than 0x400 sources to validate and binary properly on truncated hash. (which formats???) - [x] Fix any problems in other code due to reduction in LINE_BUFFER_SIZE (keepass seem to be the only one) - [x] make sure that a hash with dyna salt would work (????) - [x] make sure that a hash that does not store it's source works (or if we run with memory reduction switches) - [x] make sure that .pot line entries which are > than LINE_BUFFER_SIZE (i.e. older cracks) still work properly. - [x] change other *2john so that they build inline files (or at least can). zip2john is one I know of. There are others. (listed below) - [x] luks (these ARE longer than 1024 bytes) I patched listconf.c to not cut field 15 to 256 bytes - [x] agilekeychain (NOTE, opencl and cuda and *2john should also be handled prior to setting ANY checkmark) - [x] cloudkeychain - [x] dmg - [x] fde - [x] gpg - [x] keepass - [x] keestore - [x] krb5tgs - [x] odf - [x] openbsd-softraid - [x] PEM - [x] pfx - [x] pkzip - [x] putty - [x] ssh2 - [x] sshng - [x] strip - [x] sxc - [x] true crypt (all types) - [x] zip2 - [x] The next 'may' have some hashes longer than 1024. I am not sure but we need to check each one, then check them off. - [x] bitcoin - [x] blockchain - [x] efs - [x] encfs - [x] ike - [x] iwork - [x] keychain - [x] krb5 - [x] kwallet - [x] pdf - [x] rsvp - [x] 7z - [x] vdi (aes-xts256) - [x] vtp - [x] wpapsk - [x] handle any hashes with 0 byte binaries ?? - [ ] perform all tests including jtrts.pl since it cracks, then re-tests from .pot file, so this IS a good test.
bsakaguchi 2026-10-15 04:16:07 +07:00
Author
Owner
<!-- gh-comment-id:210281723 --> @kholia commented on GitHub (Apr 15, 2016): https://github.com/magnumripper/JohnTheRipper/blob/bleeding-jumbo/src/gpg2john.c#L948 https://github.com/magnumripper/JohnTheRipper/blob/bleeding-jumbo/src/luks2john.c#L190 See these links for more details.
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

How about this (note just talking something out, am not looking to put code to this yet) Have a line format like:

$JTR_BIGLINE$length_in_decimal \n
whatever line data is needed. (line length is length_in_decimal)

That way within loader, it could be written smart enough to see the JTR_BIGLINE, and the next line would be loaded 'extra long'. It would allow for binary data, or anything really. It would not use the fgetl() function, but simply do an fread (or read if we are not using stdio FILE object). Same thing could be in a .pot file, or the input file.

Or maybe we do something like

$JTR_BIGLINE$length_in_decimal$md5_hash_hex \n
real_line_data

This is mostly to get data between a *2john and john itself (I think).

<!-- gh-comment-id:214590957 --> @jfoug commented on GitHub (Apr 26, 2016): How about this (note just talking something out, am not looking to put code to this yet) Have a line format like: $JTR_BIGLINE$length_in_decimal \n whatever line data is needed. (line length is length_in_decimal) That way within loader, it could be written smart enough to see the JTR_BIGLINE, and the next line would be loaded 'extra long'. It would allow for binary data, or anything really. It would not use the fgetl() function, but simply do an fread (or read if we are not using stdio FILE object). Same thing could be in a .pot file, or the input file. Or maybe we do something like $JTR_BIGLINE$length_in_decimal$md5_hash_hex \n real_line_data This is mostly to get data between a *2john and john itself (I think).
Author
Owner

@kholia commented on GitHub (Apr 26, 2016):

Yes, this is mostly to get data between a *2john tool and john itself.

How is this 'extra long' line (after the newline) encoded? Is it hex-encoded?

By doing this we will get rid of the really ugly hacks which are currently present in many formats (e.g. LUKS).

<!-- gh-comment-id:214688502 --> @kholia commented on GitHub (Apr 26, 2016): Yes, this is mostly to get data between a *2john tool and john itself. How is this 'extra long' line (after the newline) encoded? Is it hex-encoded? By doing this we will get rid of the really ugly hacks which are currently present in many formats (e.g. LUKS).
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

I am not sure the encoding of the next line should be specified (or matter). It would be loaded by loader just like any line, but it would not be limited by the line length field.

Note, I have not looked at code, so this may be a total non-starter. Just thinking out loud currently. There likely will have to be many other things changed along the way. We 'may' have to build a long line structure vs just a char * for this also, so that there would be knowledge to other parts of john to just how long the data is. Or we could force hex/base64 encoding if the data is binary, to keep things in NULL terminated C string format.

<!-- gh-comment-id:214694376 --> @jfoug commented on GitHub (Apr 26, 2016): I am not sure the encoding of the next line should be specified (or matter). It would be loaded by loader just like any line, but it would not be limited by the line length field. Note, I have not looked at code, so this may be a total non-starter. Just thinking out loud currently. There likely will have to be many other things changed along the way. We 'may' have to build a long line structure vs just a char \* for this also, so that there would be knowledge to other parts of john to just how long the data is. Or we could force hex/base64 encoding if the data is binary, to keep things in NULL terminated C string format.
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

pkzip (zip?) also does something like this, where it encodes the name of the .zip file into the input string. Then if that file is not found, we can not crack the zip.

<!-- gh-comment-id:214694682 --> @jfoug commented on GitHub (Apr 26, 2016): pkzip (zip?) also does something like this, where it encodes the name of the .zip file into the input string. Then if that file is not found, we can not crack the zip.
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

is 4gb going to do it? I certainly HOPE so, since we are now loading this into memory. If not, then we have to also look at some other method. One that loads, the other that does something like memory mapped file.

Actually mem_mapped file might be best best always ???

<!-- gh-comment-id:214767985 --> @jfoug commented on GitHub (Apr 26, 2016): is 4gb going to do it? I certainly HOPE so, since we are now loading this into memory. If not, then we have to also look at some other method. One that loads, the other that does something like memory mapped file. Actually mem_mapped file might be best best always ???
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

Very quick n dirty 'test'

--- src/loader.c    Mon Jan 19 16:26:32 1970
+++ src/loader.c    Mon Jan 19 16:26:32 1970
@@ -101,7 +101,7 @@
 {
    struct stat file_stat;
    FILE *file;
-   char line_buf[LINE_BUFFER_SIZE], *line;
+   char line_buf[LINE_BUFFER_SIZE], *line, *ex_size_line=NULL;
    int warn_enc;

    warn_enc = john_main_process && (options.target_enc != ASCII) &&
@@ -124,6 +124,13 @@
    dyna_salt_init(db->format);
    while (fgets(line_buf, sizeof(line_buf), file)) {
        line = skip_bom(line_buf);
+       if (!strncmp(line, "$JTR_BIG_LINE$", 14)) {
+           unsigned len;  // NOTE, max size 4gb.
+           sscanf(line, "$JTR_BIG_LINE$%u\n", &len);
+           ex_size_line = mem_alloc(len);
+           fread(ex_size_line, 1, len, file);
+           line = ex_size_line;
+       }

        if (warn_enc) {
            char *u8check;
@@ -151,6 +158,8 @@
            }
        }
        process_line(db, line);
+       if (ex_size_line)
+           MEM_FREE(ex_size_line);
        check_abort(0);
    }
    if (name == options.activepot)
@@ -845,7 +854,7 @@
 {
    struct list_main *words;
    struct  list_entry *tmp;
-   int i, start_cnt, til, max_per, max, words_for_this, digit_trim;
+   int i, start_cnt, max_per, max, words_for_this, digit_trim;
    char *pos, *word;
    char Buf[128];

@@ -903,7 +912,6 @@
        DeNum(Buf, tmp->data, digit_trim);
        while (*Buf == 0 && i < start_cnt) {
            ++i;
-           ++til;
            tmp = tmp->next;
            DeNum(Buf, tmp->data, digit_trim);
        }
@@ -1200,9 +1208,12 @@

    bench_running++;
    while (current->ciphertext) {
-       char line[LINE_BUFFER_SIZE];
+       char *ex_len_line = NULL, _line[LINE_BUFFER_SIZE], *line = _line;
        int i, pos = 0;
-
+       if (strlen(current->ciphertext) > LINE_BUFFER_SIZE-200) {
+           ex_len_line = mem_alloc(strlen(current->ciphertext)+300);
+           line = ex_len_line;
+       }
        if (!current->fields[0])
            current->fields[0] = "?";
        if (!current->fields[1])
@@ -1215,6 +1226,7 @@

        ldr_load_pw_line(testdb, line);
        current++;
+       MEM_FREE(ex_len_line);
    }
    bench_running--;

--- C:/projects/phpbb/johnripper/john-1.7.9/bleed64/src/logger.c    Tue Feb 23 15:50:29 2016
+++ C:/projects/phpbb/johnripper/john-1.7.9/bleed0/src/logger.c Tue Apr 26 10:58:54 2016
@@ -411,6 +411,23 @@
                                      "%s%c%s\n", ciphertext,
                                      field_sep, store_plain);
            if (count1 > 0) pot.ptr += count1;
+       } else {
+           if (options.secure) {
+               secret = components(store_plain, len);
+               pot.ptr += (int)sprintf(pot.ptr, "$JTR_BIG_LINE$%u\n", strlen(ciphertext) + 1 + strlen(secret) + 1);
+           } else
+               pot.ptr += (int)sprintf(pot.ptr, "$JTR_BIG_LINE$%u\n", strlen(ciphertext) + 1 + strlen(store_plain) + 1);
+
+           // since we do not know the size, we flush, then write the actual line to the .pot file.
+           log_file_flush(&pot);
+           log_file_flush(&log);
+           write(pot.fd, ciphertext, strlen(ciphertext));
+           write(pot.fd, &field_sep, 1);
+           if (options.secure)
+               write(pot.fd, secret, strlen(secret));
+           else
+               write(pot.fd, store_plain, strlen(store_plain));
+           write(pot.fd, "\n", 1);
        }
    }

Then I created a file with the 2 'test' hashes.

line 1 is "$JTR_BIG_LINE$86581\n" then the next line is the hash. Line 3 is "$JTR_BIG_LINE$171914" then the 4th is the longer hash.

This runs through loader.c and valid within LUKS works.

NOTE, within params.h, I also changed to this for this test: #define LINE_BUFFER_SIZE 0x400

I also think we would need to dump out .pot files using this type logic (not only in the *2john). I am still VERY early in testing, I just wanted to toss out some findings. In the end, this may be pretty easy to add. The one KILLER would be any .pot files made prior to any change like this. But I guess a script to 'fix' any extra long .pot lines would be acceptable, if we need that.

But getting the LINE_BUFFER_SIZE down to something reasonable does make sense, especially since we have several of these buffers ON THE STACK!

<!-- gh-comment-id:214777141 --> @jfoug commented on GitHub (Apr 26, 2016): Very quick n dirty 'test' ``` diff --- src/loader.c Mon Jan 19 16:26:32 1970 +++ src/loader.c Mon Jan 19 16:26:32 1970 @@ -101,7 +101,7 @@ { struct stat file_stat; FILE *file; - char line_buf[LINE_BUFFER_SIZE], *line; + char line_buf[LINE_BUFFER_SIZE], *line, *ex_size_line=NULL; int warn_enc; warn_enc = john_main_process && (options.target_enc != ASCII) && @@ -124,6 +124,13 @@ dyna_salt_init(db->format); while (fgets(line_buf, sizeof(line_buf), file)) { line = skip_bom(line_buf); + if (!strncmp(line, "$JTR_BIG_LINE$", 14)) { + unsigned len; // NOTE, max size 4gb. + sscanf(line, "$JTR_BIG_LINE$%u\n", &len); + ex_size_line = mem_alloc(len); + fread(ex_size_line, 1, len, file); + line = ex_size_line; + } if (warn_enc) { char *u8check; @@ -151,6 +158,8 @@ } } process_line(db, line); + if (ex_size_line) + MEM_FREE(ex_size_line); check_abort(0); } if (name == options.activepot) @@ -845,7 +854,7 @@ { struct list_main *words; struct list_entry *tmp; - int i, start_cnt, til, max_per, max, words_for_this, digit_trim; + int i, start_cnt, max_per, max, words_for_this, digit_trim; char *pos, *word; char Buf[128]; @@ -903,7 +912,6 @@ DeNum(Buf, tmp->data, digit_trim); while (*Buf == 0 && i < start_cnt) { ++i; - ++til; tmp = tmp->next; DeNum(Buf, tmp->data, digit_trim); } @@ -1200,9 +1208,12 @@ bench_running++; while (current->ciphertext) { - char line[LINE_BUFFER_SIZE]; + char *ex_len_line = NULL, _line[LINE_BUFFER_SIZE], *line = _line; int i, pos = 0; - + if (strlen(current->ciphertext) > LINE_BUFFER_SIZE-200) { + ex_len_line = mem_alloc(strlen(current->ciphertext)+300); + line = ex_len_line; + } if (!current->fields[0]) current->fields[0] = "?"; if (!current->fields[1]) @@ -1215,6 +1226,7 @@ ldr_load_pw_line(testdb, line); current++; + MEM_FREE(ex_len_line); } bench_running--; ``` ``` diff --- C:/projects/phpbb/johnripper/john-1.7.9/bleed64/src/logger.c Tue Feb 23 15:50:29 2016 +++ C:/projects/phpbb/johnripper/john-1.7.9/bleed0/src/logger.c Tue Apr 26 10:58:54 2016 @@ -411,6 +411,23 @@ "%s%c%s\n", ciphertext, field_sep, store_plain); if (count1 > 0) pot.ptr += count1; + } else { + if (options.secure) { + secret = components(store_plain, len); + pot.ptr += (int)sprintf(pot.ptr, "$JTR_BIG_LINE$%u\n", strlen(ciphertext) + 1 + strlen(secret) + 1); + } else + pot.ptr += (int)sprintf(pot.ptr, "$JTR_BIG_LINE$%u\n", strlen(ciphertext) + 1 + strlen(store_plain) + 1); + + // since we do not know the size, we flush, then write the actual line to the .pot file. + log_file_flush(&pot); + log_file_flush(&log); + write(pot.fd, ciphertext, strlen(ciphertext)); + write(pot.fd, &field_sep, 1); + if (options.secure) + write(pot.fd, secret, strlen(secret)); + else + write(pot.fd, store_plain, strlen(store_plain)); + write(pot.fd, "\n", 1); } } ``` Then I created a file with the 2 'test' hashes. line 1 is "$JTR_BIG_LINE$86581\n" then the next line is the hash. Line 3 is "$JTR_BIG_LINE$171914" then the 4th is the longer hash. This runs through loader.c and valid within LUKS works. NOTE, within params.h, I also changed to this for this test: #define LINE_BUFFER_SIZE 0x400 I also think we would need to dump out .pot files using this type logic (not only in the *2john). I am still VERY early in testing, I just wanted to toss out some findings. In the end, this may be pretty easy to add. The one KILLER would be any .pot files made prior to any change like this. But I guess a script to 'fix' any extra long .pot lines would be acceptable, if we need that. But getting the LINE_BUFFER_SIZE down to something reasonable does make sense, especially since we have several of these buffers ON THE STACK!
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

WOOP!!

WARNING, LUKS format hash representation will change in future releases,
see doc/README.LUKS
Press 'q' or Ctrl-C to abort, almost any other key for status
2g 0:00:00:05 DONE (2016-04-26 10:21) 0.3685g/s 0.3685p/s 0.7370c/s 0.7370C/s openwall..!@#$%^&*
Use the "--show" option to display all of the cracked passwords reliably
Session completed
At Program Exit
MemDbg_Validate level 0 checking Passed
Loaded 2 password hashes with 2 different salts (LUKS [PBKDF2-SHA1 128/128 SSE4.1 4x])
!@#$%^&*         (user_test1)
openwall         (admin)
Press any key to continue . . .

This was also under the very lame VC compiler (which is a nightmare for LUKS). I also added user names, : several extra : and the GECOS used for the passwords. LUKS is so slow, that I created a word file with the 2 passwords, since I did not want to wait for single to find them

However, the .pot file contains these HUGE line. I will see how it now 'works', but I expect a crash.

<!-- gh-comment-id:214781392 --> @jfoug commented on GitHub (Apr 26, 2016): WOOP!! ``` WARNING, LUKS format hash representation will change in future releases, see doc/README.LUKS Press 'q' or Ctrl-C to abort, almost any other key for status 2g 0:00:00:05 DONE (2016-04-26 10:21) 0.3685g/s 0.3685p/s 0.7370c/s 0.7370C/s openwall..!@#$%^&* Use the "--show" option to display all of the cracked passwords reliably Session completed At Program Exit MemDbg_Validate level 0 checking Passed Loaded 2 password hashes with 2 different salts (LUKS [PBKDF2-SHA1 128/128 SSE4.1 4x]) !@#$%^&* (user_test1) openwall (admin) Press any key to continue . . . ``` This was also under the very lame VC compiler (which is a nightmare for LUKS). I also added user names, : several extra : and the GECOS used for the passwords. LUKS is so slow, that I created a word file with the 2 passwords, since I did not want to wait for single to find them However, the .pot file contains these HUGE line. I will see how it now 'works', but I expect a crash.
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

I will make a quick branch with these changes, and we can see whatever else is needed (or drop it for some other methods).

<!-- gh-comment-id:214794646 --> @jfoug commented on GitHub (Apr 26, 2016): I will make a quick branch with these changes, and we can see whatever else is needed (or drop it for some other methods).
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

Have a look for yourself.

I really think this POC could stand up (with a bit more searching). I have trimmed max line len down to 0x400 in this POC. All hashes with length > that would need to use the long line (2 line) format.

https://github.com/magnumripper/JohnTheRipper/tree/generic-big-hash-helper

<!-- gh-comment-id:214813760 --> @jfoug commented on GitHub (Apr 26, 2016): Have a look for yourself. I really think this POC could stand up (with a bit more searching). I have trimmed max line len down to 0x400 in this POC. All hashes with length > that would need to use the long line (2 line) format. https://github.com/magnumripper/JohnTheRipper/tree/generic-big-hash-helper
Author
Owner

@magnumripper commented on GitHub (Apr 26, 2016):

I didn't read all of this thoroughly, I just wanted to throw in that I'd prefer us to start supporting arbitrarily long lines without any special tag. Ditching all non-inlining (file references) in *2john tools would be great IMO.

Also, I believe a RAR file can exceed 2 or even 4 GB although we could opt to just not support it if it gets too troublesome.

FWIW I do like memmap (for certain things).

<!-- gh-comment-id:214823369 --> @magnumripper commented on GitHub (Apr 26, 2016): I didn't read all of this thoroughly, I just wanted to throw in that I'd prefer us to start supporting arbitrarily long lines without any special tag. Ditching all non-inlining (file references) in *2john tools would be great IMO. Also, I believe a RAR file can exceed 2 or even 4 GB although we could opt to just not support it if it gets too troublesome. FWIW I do like memmap (for certain things).
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

We certainly could move in that direction. At least this POC flushes out exactly WHAT we have to do to get there.

Biggest thing is that fgets call might need to be replaced with something.

We 'could' do something like (note written off the cuff, so DO NOT comment about stupid syntax/logic errors, lol)

char *fgetll(char *buf, int buf_len, FILE *in) {
    int len;
    char *cp, *cp2;
    if (!fgets(buf, buf_len, in)) return NULL;
    len = strlen(buf);
    if (buf[len-1] == '\n') return buf;
    cp = buf;
    while (1) {
        cp2 = cp;
        cp = mem_alloc(len+60000);
        strcpy(cp, cp2);
        if (cp2 != buf) MEM_FREE(cp2);
        if (!fgets(&cp[len], 60000, in)) return cp; /* return we read some data. I think we get an EOF if there is no trailing \n on the last line */
        len = strlen(buf);
        if (buf[len-1] == '\n') return cp;
    }
}

Then the caller of jtr_long_fgets() would have to check that if the pointer does not point to whatever buffer was passed in, that the caller MUST call MEM_FREE on the returned pointer. Also, the caller should use the pointer, and NOT the 'buffer'.

But we can work towards that goal. Right now, this POC just helps find any problem spots. I expect to have issues in -show and or -show=left, and possibly numerous other places.

This is ONLY for input files / pot files. NOT for wordlist files, etc.

Right now, a couple spots in loader, and a little change to logger is all that appears to be needed to get this to work, with a tiny line_buffer_size, yet with huge input buffers.

<!-- gh-comment-id:214839985 --> @jfoug commented on GitHub (Apr 26, 2016): We certainly could move in that direction. At least this POC flushes out exactly WHAT we have to do to get there. Biggest thing is that fgets call might need to be replaced with something. We 'could' do something like (note written off the cuff, so DO NOT comment about stupid syntax/logic errors, lol) ``` C char *fgetll(char *buf, int buf_len, FILE *in) { int len; char *cp, *cp2; if (!fgets(buf, buf_len, in)) return NULL; len = strlen(buf); if (buf[len-1] == '\n') return buf; cp = buf; while (1) { cp2 = cp; cp = mem_alloc(len+60000); strcpy(cp, cp2); if (cp2 != buf) MEM_FREE(cp2); if (!fgets(&cp[len], 60000, in)) return cp; /* return we read some data. I think we get an EOF if there is no trailing \n on the last line */ len = strlen(buf); if (buf[len-1] == '\n') return cp; } } ``` Then the caller of jtr_long_fgets() would have to check that if the pointer does not point to whatever buffer was passed in, that the caller MUST call MEM_FREE on the returned pointer. Also, the caller should use the pointer, and NOT the 'buffer'. But we can work towards that goal. Right now, this POC just helps find any problem spots. I expect to have issues in -show and or -show=left, and possibly numerous other places. This is ONLY for input files / pot files. NOT for wordlist files, etc. Right now, a couple spots in loader, and a little change to logger is all that appears to be needed to get this to work, with a tiny line_buffer_size, yet with huge input buffers.
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

Please look at code after this commit: 75ebd61

This should handle any length line, but line_buffer_len is set to 0x400

There is still problems with --show command (looks close, but I am not getting line endings). But it stores properly in .pot files, later detects that the hash was cracked, etc. That is GOOD looking stuff.

I just made a fgetll() function. That one is based on fgetl() but the ll version does not stop at the size of the buffer. However, it WILL allocate a larger buffer that the caller must delete or leak memory.

<!-- gh-comment-id:214865822 --> @jfoug commented on GitHub (Apr 26, 2016): Please look at code after this commit: 75ebd61 This should handle any length line, but line_buffer_len is set to 0x400 There is still problems with --show command (looks close, but I am not getting line endings). But it stores properly in .pot files, later detects that the hash was cracked, etc. That is GOOD looking stuff. I just made a fgetll() function. That one is based on fgetl() but the ll version does not stop at the size of the buffer. However, it WILL allocate a larger buffer that the caller must delete or leak memory.
Author
Owner

@magnumripper commented on GitHub (Apr 26, 2016):

I guess mmap would be hard to use because it will be read-only: We can't overwrite \n with null and so on. It would work with "pascal strings".

<!-- gh-comment-id:214873973 --> @magnumripper commented on GitHub (Apr 26, 2016): I guess mmap would be hard to use because it will be read-only: We can't overwrite \n with null and so on. It would work with "pascal strings".
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

Right now, the code is still semi POC (since it is SO hard on memory possibly). BUT things are looking pretty good, AFAICT

@kholia since you are the one that wanted this, can you see if this does what you were wanting? I would hate to continue pursuing this, IF it is not going to solve the problem you needed it for.

<!-- gh-comment-id:214875917 --> @jfoug commented on GitHub (Apr 26, 2016): Right now, the code is still semi POC (since it is SO hard on memory possibly). BUT things are looking pretty good, AFAICT @kholia since you are the one that wanted this, can you see if this does what you were wanting? I would hate to continue pursuing this, IF it is not going to solve the problem you needed it for.
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

This is now PR #2126 Needs to be talked about a bit, and make sure everything works, but I think it is pretty well on the way there.

It would be nice to have the data windowed through, only loading in parts as they are needed, BUT that may require changes to code all over the place.

<!-- gh-comment-id:214878644 --> @jfoug commented on GitHub (Apr 26, 2016): This is now PR #2126 Needs to be talked about a bit, and make sure everything works, but I think it is pretty well on the way there. It would be nice to have the data windowed through, only loading in parts as they are needed, BUT that may require changes to code all over the place.
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

Having Travis issues on full tests. I have to meet someone for beers in a few minutes, but we are going to have nasty weather later tonite (tornados?) so I will figure this out later tonite.

<!-- gh-comment-id:214884164 --> @jfoug commented on GitHub (Apr 26, 2016): Having Travis issues on full tests. I have to meet someone for beers in a few minutes, but we are going to have nasty weather later tonite (tornados?) so I will figure this out later tonite.
Author
Owner

@jfoug commented on GitHub (Apr 26, 2016):

keepass seems to be the only format which puked with the reduction of LINE_BUFFER_SIZE. I fixed it (hack by just putting the 0x30000 back). But now with a smaller line buffer, we may want to see about adjusting this one properly.

<!-- gh-comment-id:214890834 --> @jfoug commented on GitHub (Apr 26, 2016): keepass seems to be the only format which puked with the reduction of LINE_BUFFER_SIZE. I fixed it (hack by just putting the 0x30000 back). But now with a smaller line buffer, we may want to see about adjusting this one properly.
Author
Owner

@magnumripper commented on GitHub (Apr 26, 2016):

You should probably verify that loading of eg. 25, 50 or even 100 million raw hashes didn't get significantly slower (or even starts failing).

<!-- gh-comment-id:214912447 --> @magnumripper commented on GitHub (Apr 26, 2016): You should probably verify that loading of eg. 25, 50 or even 100 _million_ raw hashes didn't get significantly slower (or even starts failing).
Author
Owner

@jfoug commented on GitHub (Apr 27, 2016):

Good test: This is results from my terribly slow laptop, on cygwin.

input lines original john loader big-hash-line enhanced
1M 3s 3s
5M 16s 17s
25M 95s 89s

So I see little difference. John has SO much overhead in our overly 'deep' valid functions, that fileIO is a small part of the whole thing (shame).

Lines were made with:

./perl -e '{for($i=0;$i<1000000;++$i){print '1' x 40 , "\n";}}' > 1

Then I catted the file to get 5m and 25m. The hash was raw-sha1 Timing was counted by hand (no watch), and stopped as soon as I saw 'Loaded X password hashes....'

I added this to each file, just to make sure something was cracked:

echo -n password | sha1sum | cut -b 1-40 >> 1

<!-- gh-comment-id:214930163 --> @jfoug commented on GitHub (Apr 27, 2016): Good test: This is results from my terribly slow laptop, on cygwin. | input lines | original john loader | big-hash-line enhanced | | --- | --- | --- | | 1M | 3s | 3s | | 5M | 16s | 17s | | 25M | 95s | 89s | So I see little difference. John has SO much overhead in our overly 'deep' valid functions, that fileIO is a small part of the whole thing (shame). Lines were made with: ./perl -e '{for($i=0;$i<1000000;++$i){print '1' x 40 , "\n";}}' > 1 Then I catted the file to get 5m and 25m. The hash was raw-sha1 Timing was counted by hand (no watch), and stopped as soon as I saw 'Loaded X password hashes....' I added this to each file, just to make sure something was cracked: echo -n password | sha1sum | cut -b 1-40 >> 1
Author
Owner

@jfoug commented on GitHub (Apr 27, 2016):

I hope others look at this. I think this would be nice to get added. This seems much better than the original fixed size and fgets calls

<!-- gh-comment-id:214935678 --> @jfoug commented on GitHub (Apr 27, 2016): I hope others look at this. I think this would be nice to get added. This seems much better than the original fixed size and fgets calls
Author
Owner

@magnumripper commented on GitHub (Apr 27, 2016):

Just from looking at the code (logger.c new branch), I believe you are writing to the pot/log files without locking. That would be a horrific bug.

<!-- gh-comment-id:214986552 --> @magnumripper commented on GitHub (Apr 27, 2016): Just from looking at the code (logger.c new branch), I believe you are writing to the pot/log files without locking. That would be a horrific bug.
Author
Owner

@kholia commented on GitHub (Apr 27, 2016):

Thanks for working on this @jfoug. I will try to fix luks2john.c so that it no longer generates non-inlined hashes.

<!-- gh-comment-id:215050787 --> @kholia commented on GitHub (Apr 27, 2016): Thanks for working on this @jfoug. I will try to fix `luks2john.c` so that it no longer generates non-inlined hashes.
Author
Owner

@jfoug commented on GitHub (Apr 27, 2016):

It may also be good to NOT store these monster lines in the .pot file. I will have to think a bit more about this, but I am pretty sure it can be done. NOTE, it will require some work on a few formats in their valid and binary functions. What I think we can do is for these extra long ones, we chop off the first part of the source (at a fixed point), append a '$' and append the binary representation in hex.) Then the hashes that can have HUGE lines, we have to modify valid to spot this, and modify binary to also spot this. Or we change the format interface again, to add some helper function(s) like pot_source() or something, so the format is in control. If pot_source() was defined as having to reduce the hash string to fit within LINE_BUFFER_SIZE, then the hack done in logger where I am doing direct non-buffered writes can go away.

But putting even a handful of > gb lines into the .pot file is silly, just so we can later not load them, when they probably will never be run again.......

We may also want to bump up LINE_BUFFER_SIZE a bit. I drastically cut it down, but I bet 0x1000 is a better 'max' normal size. 1K is 'ok', but I think 4K is really what it should be set at.

<!-- gh-comment-id:215071765 --> @jfoug commented on GitHub (Apr 27, 2016): It may also be good to NOT store these monster lines in the .pot file. I will have to think a bit more about this, but I am pretty sure it can be done. NOTE, it will require some work on a few formats in their valid and binary functions. What I think we can do is for these extra long ones, we chop off the first part of the source (at a fixed point), append a '$' and append the binary representation in hex.) Then the hashes that can have HUGE lines, we have to modify valid to spot this, and modify binary to also spot this. Or we change the format interface again, to add some helper function(s) like pot_source() or something, so the format is in control. If pot_source() was defined as having to reduce the hash string to fit within LINE_BUFFER_SIZE, then the hack done in logger where I am doing direct non-buffered writes can go away. But putting even a handful of > gb lines into the .pot file is silly, just so we can later not load them, when they probably will never be run again....... We may also want to bump up LINE_BUFFER_SIZE a bit. I drastically cut it down, but I bet 0x1000 is a better 'max' normal size. 1K is 'ok', but I think 4K is really what it should be set at.
Author
Owner

@jfoug commented on GitHub (Apr 27, 2016):

I have made changes. 9317ced b79361e

  1. line length bumped to 4k (0x1000)
  2. any line > than 4k, will be written to the .pot file by truncating to 1k, adding a $ and the binary.
  3. the logging no longer has to do an out of normal write (since again all lines to the .pot file are under max line length).
  4. some length checking in logger.c was minimized, by allocating the buffer with some extra slack space, that is large enough to not have to care about these 'pre' write checks.

Things are working fine. -show works fine. Rerun removes the duplicates. The .pot file is just fine.

<!-- gh-comment-id:215226480 --> @jfoug commented on GitHub (Apr 27, 2016): I have made changes. 9317ced b79361e 1. line length bumped to 4k (0x1000) 2. any line > than 4k, will be written to the .pot file by truncating to 1k, adding a $ and the binary. 3. the logging no longer has to do an out of normal write (since again all lines to the .pot file are under max line length). 4. some length checking in logger.c was minimized, by allocating the buffer with some extra slack space, that is large enough to not have to care about these 'pre' write checks. Things are working fine. -show works fine. Rerun removes the duplicates. The .pot file is just fine.
Author
Owner

@magnumripper commented on GitHub (Apr 28, 2016):

FWIW I liked 0x400 (1 KB) because that's what core uses.

Using a truncated binary is a terrible idea because it can and will cause false positives from dupes in some cases. However we could add a hash representing the binary blob (eg. SHA256(data)). Something like:

original:
login:$tag$salt$stuff$huge_portion_of_data::

pot entry:
$tag$salt$stuff$<sha256(huge_portion_of_data)>:cleartext
<!-- gh-comment-id:215339724 --> @magnumripper commented on GitHub (Apr 28, 2016): FWIW I liked 0x400 (1 KB) because that's what core uses. Using a truncated binary is a terrible idea because it can and **will** cause false positives from dupes in some cases. However we could add a hash representing the binary blob (eg. SHA256(data)). Something like: ``` original: login:$tag$salt$stuff$huge_portion_of_data:: pot entry: $tag$salt$stuff$<sha256(huge_portion_of_data)>:cleartext ```
Author
Owner

@magnumripper commented on GitHub (Apr 28, 2016):

Perhaps marked with a tag to tell loader & co. about it

pot entry:
$tag$salt$stuff$BLOBHASH$<sha256(huge_portion_of_data)>:cleartext

(where BLOBHASH$ is that literal string)

<!-- gh-comment-id:215340183 --> @magnumripper commented on GitHub (Apr 28, 2016): Perhaps marked with a tag to tell loader & co. about it ``` pot entry: $tag$salt$stuff$BLOBHASH$<sha256(huge_portion_of_data)>:cleartext ``` (where `BLOBHASH$` is that literal string)
Author
Owner

@jfoug commented on GitHub (Apr 28, 2016):

I thought of adding a hash of the original also. I would have to find the locations it was used. I may still have to lob on the binary of the data.

But I can easily set the max buffer back to 1k, and chop the blob smaller, adding a hash, and the binary.

So I would see:

input
[login:]$tag$salt$stuff$stuff2$...$binary$...$biggest_blob::

pot
$tag$salt$stuff$stu$BLOBHASH$<md5 of full source>$SOURCEBINARY$<binary() in hex>:cleartext

The reason I go with md5, is because it is shorter, allowing more of the original source line to be there (the source is what anyone searching for matched data (outside of john's -show) will be able to use to match. Md5 will NOT have any collisions. Just because there are 'methods' to find duplicates, does not mean you will ever find a pair ITW.

So I would create a function in loader that would be passed in the original source, binary, and length of binary, and a max_len buffer, and would produce the string that was 0x400 minus a few bytes long, and that would be the .pot (or .log?) entry. There should be no ambiguity upon reload. There is the md5 for a strcmp, and the binary for a memcmp / hash of the binary.

<!-- gh-comment-id:215410339 --> @jfoug commented on GitHub (Apr 28, 2016): I thought of adding a hash of the original also. I would have to find the locations it was used. I may still have to lob on the binary of the data. But I can easily set the max buffer back to 1k, and chop the blob smaller, adding a hash, and the binary. So I would see: ``` input [login:]$tag$salt$stuff$stuff2$...$binary$...$biggest_blob:: pot $tag$salt$stuff$stu$BLOBHASH$<md5 of full source>$SOURCEBINARY$<binary() in hex>:cleartext ``` The reason I go with md5, is because it is shorter, allowing more of the original source line to be there (the source is what anyone searching for matched data (outside of john's -show) will be able to use to match. Md5 will NOT have any collisions. Just because there are 'methods' to find duplicates, does not mean you will ever find a pair ITW. So I would create a function in loader that would be passed in the original source, binary, and length of binary, and a max_len buffer, and would produce the string that was 0x400 minus a few bytes long, and that would be the .pot (or .log?) entry. There should be no ambiguity upon reload. There is the md5 for a strcmp, and the binary for a memcmp / hash of the binary.
Author
Owner

@jfoug commented on GitHub (Apr 28, 2016):

But this was also why I put this in a branch. I knew this was going to be a big undertaking, with strange twists coming from all directions. The shorten of .pot lines is one such twist. That should have been done long ago.

The one thing that MUST still be handled, is making sure that .pot lines > 0x400 ARE handled properly (i.e. lines prior existing, that are not truncated).

I have added a todo list in the original post, so we can track progress. If you think of other things that need to be there, whether logic or testing, please add them to that list, so that we can validate when progress is complete.

<!-- gh-comment-id:215420798 --> @jfoug commented on GitHub (Apr 28, 2016): But this was also why I put this in a branch. I knew this was going to be a big undertaking, with strange twists coming from all directions. The shorten of .pot lines is one such twist. That should have been done long ago. The one thing that MUST still be handled, is making sure that .pot lines > 0x400 ARE handled properly (i.e. lines prior existing, that are not truncated). I have added a todo list in the original post, so we can track progress. If you think of other things that need to be there, whether logic or testing, please add them to that list, so that we can validate when progress is complete.
Author
Owner

@jfoug commented on GitHub (Apr 28, 2016):

6b32938 adds an MD5 for the full source, and this is used for compares. There are also easy to spot tags for the source and binary. Helper functions for ALL of this were added as ldr_*() functions.

This is a much better method, than the original POC of simple truncation and then strcmp of that fixed string.

There is still one area where we do a fixed length truncation data build. That is in ldr_cracked_hash() function. In that function, if we have a source that is >= the length, then it will get hashes only up to a certain shorter length. We can not 'know' the amount of valid hash here, since we do not know the particulars about hash type, unless we are doing a single hash. So the easy way is to simply hash a fixed length that is shorter than any format would cut down for it's binary and the md5 of the full hash. We will have to watch this POT_BUFFER_CT_TRIM_SIZE as we add more 'long' source formats, to make sure we do not have a binary that is too long. Once we get all hashes in, then we can document the longest, and set this POT_BUFFER_CT_TRIM_SIZE to be closer to the threshold.

<!-- gh-comment-id:215514187 --> @jfoug commented on GitHub (Apr 28, 2016): 6b32938 adds an MD5 for the full source, and this is used for compares. There are also easy to spot tags for the source and binary. Helper functions for ALL of this were added as ldr_*() functions. This is a much better method, than the original POC of simple truncation and then strcmp of that fixed string. There is still one area where we do a fixed length truncation data build. That is in ldr_cracked_hash() function. In that function, if we have a source that is >= the length, then it will get hashes only up to a certain shorter length. We can not 'know' the amount of valid hash here, since we do not know the particulars about hash type, unless we are doing a single hash. So the easy way is to simply hash a fixed length that is shorter than any format would cut down for it's binary and the md5 of the full hash. We will have to watch this POT_BUFFER_CT_TRIM_SIZE as we add more 'long' source formats, to make sure we do not have a binary that is too long. Once we get all hashes in, then we can document the longest, and set this POT_BUFFER_CT_TRIM_SIZE to be closer to the threshold.
Author
Owner

@jfoug commented on GitHub (Apr 28, 2016):

I have added check-off-boxes for all hashes that ARE over 1k, and many that 'may' allow for > 1k lines. For this task, we should make sure all of these formats have their valid (and possibly binary) able to handle chopped .pot lines (both cpu and GPU), AND we should also look at all of these *2john routines.

<!-- gh-comment-id:215522893 --> @jfoug commented on GitHub (Apr 28, 2016): I have added check-off-boxes for all hashes that ARE over 1k, and many that 'may' allow for > 1k lines. For this task, we should make sure all of these formats have their valid (and possibly binary) able to handle chopped .pot lines (both cpu and GPU), AND we should also look at all of these *2john routines.
Author
Owner

@jfoug commented on GitHub (Apr 28, 2016):

@magnumripper and @kholia

should we remove the inline threshold values in the *2john and just always inline ???? It would make things easier, AND have fewer problems for end users having to keep those files around in exacting locations.

<!-- gh-comment-id:215529278 --> @jfoug commented on GitHub (Apr 28, 2016): @magnumripper and @kholia should we remove the inline threshold values in the *2john and just always inline ???? It would make things easier, AND have fewer problems for end users having to keep those files around in exacting locations.
Author
Owner

@jfoug commented on GitHub (Apr 28, 2016):

We probably can not remove the 'external' stuff from the formats, but we could talk about it. It would be nice to remove that also. But older input files, .pot entries, etc are the concern here.

<!-- gh-comment-id:215531860 --> @jfoug commented on GitHub (Apr 28, 2016): We probably can not remove the 'external' stuff from the formats, but we could talk about it. It would be nice to remove that also. But older input files, .pot entries, etc are the concern here.
Author
Owner

@jfoug commented on GitHub (Apr 29, 2016):

This should handle a lot of formats (I think all of these are known to have > 1k source lines. There may still be more.

4f92365

The *2john files still need to be looked at.

<!-- gh-comment-id:215615608 --> @jfoug commented on GitHub (Apr 29, 2016): This should handle a lot of formats (I think all of these are known to have > 1k source lines. There may still be more. 4f92365 The *2john files still need to be looked at.
Author
Owner

@magnumripper commented on GitHub (Apr 29, 2016):

I had the idea we'd do the hashing in *2john, definitely not in loader. We'd always inline, and always put a hash before the inlined data, and (for ALL formats that do this) always put a BLOBHASH$ tag before that hash.

So the input file would have the hash AND the full blob, while the pot entry would have the exact same data bar the inlined blob.

This also means we are back at your original idea (if we want) to only use fgetsll() when we see the BLOBHASH$ tag.

Finally, the formats can opt to verify that the hash is correct for provided blob.

<!-- gh-comment-id:215653168 --> @magnumripper commented on GitHub (Apr 29, 2016): I had the idea we'd do the hashing in *2john, definitely not in loader. We'd always inline, and always put a hash before the inlined data, and (for ALL formats that do this) always put a `BLOBHASH$` tag before that hash. So the **input** file would have the hash AND the full blob, while the **pot** entry would have the exact same data bar the inlined blob. This also means we are back at your original idea (if we want) to only use fgetsll() when we see the `BLOBHASH$` tag. Finally, the formats can opt to verify that the hash is correct for provided blob.
Author
Owner

@magnumripper commented on GitHub (Apr 29, 2016):

We probably can not remove the 'external' stuff from the formats, but we could talk about it. It would be nice to remove that also. But older input files, .pot entries, etc are the concern here.

I vote for ditching backwards compatibility in this case. The 0x30000 limit was one of the worst ideas in Jumbo history.

<!-- gh-comment-id:215654075 --> @magnumripper commented on GitHub (Apr 29, 2016): > We probably can not remove the 'external' stuff from the formats, but we could talk about it. It would be nice to remove that also. But older input files, .pot entries, etc are the concern here. I vote for ditching backwards compatibility in this case. The 0x30000 limit was one of the worst ideas in Jumbo history.
Author
Owner

@magnumripper commented on GitHub (Apr 29, 2016):

Oh, and another thing: All formats that do this, should use Base64 for the big blob. Using hex format to inline a 300 MB file will produce 600 MB. We have helper functions already so there's no need to be lazy.

<!-- gh-comment-id:215654374 --> @magnumripper commented on GitHub (Apr 29, 2016): Oh, and another thing: **All** formats that do this, should use Base64 for the big blob. Using hex format to inline a 300 MB file will produce 600 MB. We have helper functions already so there's no need to be lazy.
Author
Owner

@kholia commented on GitHub (Apr 29, 2016):

I agree too about breaking backwards compatibility in this particular case.

<!-- gh-comment-id:215654471 --> @kholia commented on GitHub (Apr 29, 2016): I agree too about breaking backwards compatibility in this particular case.
Author
Owner

@jfoug commented on GitHub (Apr 29, 2016):

I think making a sweeping change to precompute this data within the *2john is a Bad Idea (tm) overall. Changing the signature of all of those formats??, Yuk.

Right now, the signature is computed using a function 'called' ldr_*() but it is ONLY done within logger.c and done when a crack is found, prior to writing to the .pot file. Thus (especially for these HUGE hashes), it is done almost never. The code is clean, works well, and has minimal impact. Yes, we may want to take some time, and remove the logic for the 'externally owned' data files, and put everything inline. But that change has to be done no matter what.

Please actually LOOK at what was done, and how it actually works. Yes, we certainly can when we get time, convert all big blobs into base-64, and do it one by one. But that is ONLY a change in the *2john and *_fmt_plug.c file pair, and is much easier to control.

I think breaking backward compatibility in this case is a good thing (btw). It allows us to NOT have to always look over our shoulders for that crap. Most of the time, if someone has cracked something like that in the past, they are not re-running the input again. It would simply end up being either .pot file lines that match nothing, or would be handled by the extra long line reading from fgetll()

<!-- gh-comment-id:215839587 --> @jfoug commented on GitHub (Apr 29, 2016): I think making a sweeping change to precompute this data within the *2john is a Bad Idea (tm) overall. Changing the signature of all of those formats??, Yuk. Right now, the signature is computed using a function 'called' ldr_*() but it is ONLY done within logger.c and done when a crack is found, prior to writing to the .pot file. Thus (especially for these HUGE hashes), it is done almost never. The code is clean, works well, and has minimal impact. Yes, we may want to take some time, and remove the logic for the 'externally owned' data files, and put everything inline. But that change has to be done no matter what. Please actually LOOK at what was done, and how it actually works. Yes, we certainly can when we get time, convert all big blobs into base-64, and do it one by one. But that is ONLY a change in the *2john and *_fmt_plug.c file pair, and is much easier to control. I think breaking backward compatibility in this case is a good thing (btw). It allows us to NOT have to always look over our shoulders for that crap. Most of the time, if someone has cracked something like that in the past, they are not re-running the input again. It would simply end up being either .pot file lines that match nothing, or would be handled by the extra long line reading from fgetll()
Author
Owner

@jfoug commented on GitHub (Apr 29, 2016):

Those 3 functions were put into loader, more as 'library' functions (well the external ones were), so that it could be done as simplified and controlled code. It does no mean they are run for every loader input. Well, one is, (the static one). It is a replacement for strcmp only. The others are just there, so that all the code is kept local, and controlled on the actual format of the strings read and written to the .pot file.

<!-- gh-comment-id:215840511 --> @jfoug commented on GitHub (Apr 29, 2016): Those 3 functions were put into loader, more as 'library' functions (well the external ones were), so that it could be done as simplified and controlled code. It does no mean they are run for every loader input. Well, one is, (the static one). It is a replacement for strcmp only. The others are just there, so that all the code is kept local, and controlled on the actual format of the strings read and written to the .pot file.
Author
Owner

@magnumripper commented on GitHub (Apr 29, 2016):

I think making a sweeping change to precompute this data within the *2john is a Bad Idea (tm) overall. Changing the signature of all of those formats??, Yuk.

I can't see your point at all. These changes are a major signature change already, and not backwards compatible at all: We are going from referencing an actual (eg.) RAR file name/path, to inlining it - so why not prepend the hash already?

If the input file doesn't have the hash, how can we handle --show in a good way?

Also, I have some other things in mind like Johnny the GUI and other things. They'll have a hard time keeping up with this functionality if we don't give them this hash (and BLOBHASH$ tag) as anchor.

<!-- gh-comment-id:215909289 --> @magnumripper commented on GitHub (Apr 29, 2016): > I think making a sweeping change to precompute this data within the *2john is a Bad Idea (tm) overall. Changing the signature of all of those formats??, Yuk. I can't see your point at all. These changes are a major signature change already, and not backwards compatible at all: We are going from referencing an actual (eg.) RAR file name/path, to inlining it - so why not prepend the hash already? If the input file doesn't have the hash, how can we handle --show in a good way? Also, I have some other things in mind like Johnny the GUI and other things. They'll have a hard time keeping up with this functionality if we don't give them this hash (and `BLOBHASH$` tag) as anchor.
Author
Owner

@jfoug commented on GitHub (May 2, 2016):

Are we going to define this order? If so, then how about 👍
$tag$SOURCE_HASH$md5_hash$SOURCE_BIN$binary()_$0|1$ ... original hash with inlined blob... The 0 or 1 would be for truncated vs non-truncated. This will be used within valid. If it is 0 (truncated), and in pot_load, then the tag is all that is used for validation. It is assumed that since we are reading from the .pot file, that it is valid.

The problem with this, is now the generation code has to build the whole line in memory (or later re-read it from a file) to be able to back generate the source hash, AND to rebuild the binary. Also the binary data would also have to be set to empty and then filled in later, once the line was ready, AND the *2john will need the logic for the binary() function to be able to properly generate this (if it is not provided). If done that way, then we could use a NULL binary section as the key to whether this was a full length hash line or a truncated one. If it is filled out (and we are in .pot reading mode), then we know it is truncated. This would eliminate the full/truncated flag.

All of this is doable, but this is a lot of work, and lots of one-off. I guess we have the work and one-off for each *2john since we are taking the the file reference signature, and changing it to inlining. But building this type change can also be tricky. I will start to work on this, and see how it goes. kind of a shame, since it was done and fully working already, but I do see your point, about some of the tools like johnny. All in all, it should not be all that hard. Mostly get it done once, and then cookie cutter code from then on.

This also might not be a bad time to TRASH all the * separators in some of the signature lines once and for all. Get to using $ across the board for these.

Sorry if this comment wandered. I have been on little sleep the last 4 or 5 days. Waiting in the airline club now. I have not been a traveler for a couple decades now, and sort of forgot about the nice perks like this (but not traveling is a perk I also like). Here with one of my cousins husbands, and waiting for my flight. I will get on to see how this can be completed during the week.

<!-- gh-comment-id:216169244 --> @jfoug commented on GitHub (May 2, 2016): Are we going to define this order? If so, then how about :+1: `$tag$SOURCE_HASH$md5_hash$SOURCE_BIN$binary()_$0|1$ ... original hash with inlined blob...` The 0 or 1 would be for truncated vs non-truncated. This will be used within valid. If it is 0 (truncated), and in pot_load, then the tag is all that is used for validation. It is assumed that since we are reading from the .pot file, that it is valid. The problem with this, is now the generation code has to build the whole line in memory (or later re-read it from a file) to be able to back generate the source hash, AND to rebuild the binary. Also the binary data would also have to be set to empty and then filled in later, once the line was ready, AND the *2john will need the logic for the binary() function to be able to properly generate this (if it is not provided). If done that way, then we could use a NULL binary section as the key to whether this was a full length hash line or a truncated one. If it is filled out (and we are in .pot reading mode), then we know it is truncated. This would eliminate the full/truncated flag. All of this is doable, but this is a lot of work, and lots of one-off. I guess we have the work and one-off for each *2john since we are taking the the file reference signature, and changing it to inlining. But building this type change can also be tricky. I will start to work on this, and see how it goes. kind of a shame, since it was done and fully working already, but I do see your point, about some of the tools like johnny. All in all, it should not be all that hard. Mostly get it done once, and then cookie cutter code from then on. This also might not be a bad time to TRASH all the \* separators in some of the signature lines once and for all. Get to using $ across the board for these. Sorry if this comment wandered. I have been on little sleep the last 4 or 5 days. Waiting in the airline club now. I have not been a traveler for a couple decades now, and sort of forgot about the nice perks like this (but not traveling is a perk I also like). Here with one of my cousins husbands, and waiting for my flight. I will get on to see how this can be completed during the week.
Author
Owner

@kholia commented on GitHub (May 2, 2016):

We now have luks2john.py (Python port) in bleeding-jumbo, and it should be easier to change / test than the old C code.

The new code always generates inlined hashes, and surprisingly the old bleeding-jumbo format code cracks the inlined hashes just fine.

<!-- gh-comment-id:216242863 --> @kholia commented on GitHub (May 2, 2016): We now have `luks2john.py` (Python port) in bleeding-jumbo, and it should be easier to change / test than the old C code. The new code always generates inlined hashes, and surprisingly the old bleeding-jumbo format code cracks the inlined hashes just fine.
Author
Owner

@magnumripper commented on GitHub (May 2, 2016):

Are we going to define this order? If so, then how about 👍
$tag$SOURCE_HASH$md5_hash$SOURCE_BIN$binary()_$0|1$ ... original hash with inlined blob...
The 0 or 1 would be for truncated vs non-truncated. This will be used within valid. If it is 0 (truncated), and in pot_load, then the tag is all that is used for validation. It is assumed that since we are reading from the .pot file, that it is valid.

Is the 0/1 flag needed at all? An input file would always have the complete line (hash followed by Base64-blob), while a pot line would always end right after the hash of the blob (specifically, it would NOT contain a truncated blob because that would just be a waste of space). I see no need for that flag. Perhaps you're addressing the fact loader.c's functions are generic so we don't really know whether we're loading a pot file or an input file? But we should be able to use ldr_in_pot for that.

<!-- gh-comment-id:216303382 --> @magnumripper commented on GitHub (May 2, 2016): > Are we going to define this order? If so, then how about :+1: > `$tag$SOURCE_HASH$md5_hash$SOURCE_BIN$binary()_$0|1$ ... original hash with inlined blob...` > The 0 or 1 would be for truncated vs non-truncated. This will be used within valid. If it is 0 (truncated), and in pot_load, then the tag is all that is used for validation. It is assumed that since we are reading from the .pot file, that it is valid. Is the 0/1 flag needed at all? An input file would always have the complete line (hash followed by Base64-blob), while a pot line would always end right after the hash of the blob (specifically, it would NOT contain a _truncated blob_ because that would just be a waste of space). I see no need for that flag. Perhaps you're addressing the fact loader.c's functions are generic so we don't really know whether we're loading a pot file or an input file? But we should be able to use `ldr_in_pot` for that.
Author
Owner

@magnumripper commented on GitHub (May 2, 2016):

We're not talking about a very large number of formats, I think.

$ git grep -l MAX_INLINE_SIZE *.c
keepass2john.c
luks2john.c  (just got obsolete in favor of python version)
rar2john.c
zip2john.c

...but there may be a few more written in Python.

<!-- gh-comment-id:216304399 --> @magnumripper commented on GitHub (May 2, 2016): We're not talking about a very large number of formats, I think. ``` $ git grep -l MAX_INLINE_SIZE *.c keepass2john.c luks2john.c (just got obsolete in favor of python version) rar2john.c zip2john.c ``` ...but there may be a few more written in Python.
Author
Owner

@jfoug commented on GitHub (May 2, 2016):

I never did look into the *2johns yet. The only fmt that had issues was keepass (or something like that). That format got a hack, to simply keep the buffer the same size. We need to revisit that one and fix it correctly.
As for the 0/1 logic, it was to keep thing generic in loader. There are hashes which 'may' have lines > buf_size, but some may not. I guess we could always trunc them. I figured we could put null 'placeholder' bytes in the binary section so that that field would server to tell us if we have the full hash, or only part of it. When we have only part, valid does very little (vvalidates the tag mostly), and then binary() has the data direcctly available. Some formats work out of box (with my first code), since binary was the last field. So if a format did cp = strrchr($s)+1; binary=hex2bin(cp), then those formats required no changes. However, now, the binary will have to search for the binary tag if loading from .pot file. It may also be possible to remove the need for binary. I think it's only needed to generate a hash. but without it, the code will not find the already cracked .pot record.

<!-- gh-comment-id:216356830 --> @jfoug commented on GitHub (May 2, 2016): I never did look into the *2johns yet. The only fmt that had issues was keepass (or something like that). That format got a hack, to simply keep the buffer the same size. We need to revisit that one and fix it correctly. As for the 0/1 logic, it was to keep thing generic in loader. There are hashes which 'may' have lines > buf_size, but some may not. I guess we could always trunc them. I figured we could put null 'placeholder' bytes in the binary section so that that field would server to tell us if we have the full hash, or only part of it. When we have only part, valid does very little (vvalidates the tag mostly), and then binary() has the data direcctly available. Some formats work out of box (with my first code), since binary was the last field. So if a format did cp = strrchr($s)+1; binary=hex2bin(cp), then those formats required no changes. However, now, the binary will have to search for the binary tag if loading from .pot file. It may also be possible to remove the need for binary. I think it's only needed to generate a hash. but without it, the code will not find the already cracked .pot record.
Author
Owner

@jfoug commented on GitHub (May 2, 2016):

But now with source_hash being a 'unique' field up front (both in full data and in .pot lines), we really do not need to store anything more in .pot file than those computed data. As far as that goes, we would not even need to put the source_binary into the source line, UNTIL we crack it. At that time, we have binary() function to generate the data, so getting it jammed into the .pot file record is trivial.

I was putting 'lots' of source line into the .pot reccord, to try to get something searchable outside of john for finding cracked lines. But if the *2john builds the hash, then it will always be there, and be a great key, and the only thing needed for these formats to find that crack line by hand (or script).

<!-- gh-comment-id:216357625 --> @jfoug commented on GitHub (May 2, 2016): But now with $source_hash$ being a 'unique' field up front (both in full data and in .pot lines), we really do not need to store anything more in .pot file than those computed data. As far as that goes, we would not even need to put the $source_binary$ into the source line, UNTIL we crack it. At that time, we have binary() function to generate the data, so getting it jammed into the .pot file record is trivial. I was putting 'lots' of source line into the .pot reccord, to try to get something searchable outside of john for finding cracked lines. But if the *2john builds the hash, then it will always be there, and be a great key, and the only thing needed for these formats to find that crack line by hand (or script).
Author
Owner

@magnumripper commented on GitHub (May 2, 2016):

I'm just dry running these ideas in my head so far. The easiest way to "fool" the current logic and self-tests might be to strip the binary [ie. the big blob] in split(), after allocating a buffer for it and reading it into the buffer. So the return from split() would always be with the blob-hash but without the blob - ready for pot use.

In get_salt() and/or get_binary(), we'd associate that buffer with the corresponding salt and/or binary (eg. by means of the blob-hash).

But that would be a bit of a mis-use of split()... I wonder if @solardiz has any ideas or opinions?

<!-- gh-comment-id:216376715 --> @magnumripper commented on GitHub (May 2, 2016): I'm just dry running these ideas in my head so far. The easiest way to "fool" the current logic and self-tests might be to strip the binary [ie. the big blob] in split(), after allocating a buffer for it and reading it into the buffer. So the return from split() would always be with the blob-hash but without the blob - ready for pot use. In get_salt() and/or get_binary(), we'd associate that buffer with the corresponding salt and/or binary (eg. by means of the blob-hash). But that would be a bit of a mis-use of split()... I wonder if @solardiz has any ideas or opinions?
Author
Owner

@jfoug commented on GitHub (May 3, 2016):

@magnumripper how do you think we should proceed on this? The hashed shorter line length .pot entries is almost a 2nd task, on top of 'generic' helper functions for the format input lines.

But even though it is 2 issues, they really to tie together. It would be very sad to get large line reading/writing to simply fill up .pot files with monster data, to only shortly after convert things over to shortened hashed .pot entries.

I might start working on a 'true' generic package, which we would also need ported over to python, since people seem to like that language for some reason. This lib will be the tools needed for both the *2john tools, AND used as common code which now is in the loader.c file. I will start on that first, then on some *2john so that we have input, then on to loader/logger within john to actually use them.

<!-- gh-comment-id:216596891 --> @jfoug commented on GitHub (May 3, 2016): @magnumripper how do you think we should proceed on this? The hashed shorter line length .pot entries is almost a 2nd task, on top of 'generic' helper functions for the format input lines. But even though it is 2 issues, they really to tie together. It would be very sad to get large line reading/writing to simply fill up .pot files with monster data, to only shortly after convert things over to shortened hashed .pot entries. I might start working on a 'true' generic package, which we would also need ported over to python, since people seem to like that language for some reason. This lib will be the tools needed for both the *2john tools, AND used as common code which now is in the loader.c file. I will start on that first, then on some *2john so that we have input, then on to loader/logger within john to actually use them.
Author
Owner

@jfoug commented on GitHub (May 3, 2016):

@magnumripper how about something like this (for the *2john files):

typedef struct PU_CTX_t {
    FILE *out;
    MD5_CTX md5;
    char Tag[128];
    int taglen;
    long starting_offset;
} PU_CTX;


int pu_start_line(PU_CTX *ctx, const char *tag, FILE *fp);
int pu_fprintf(PU_CTX, const char *, ...);
int pu_complete_line(PU_CTX *ctx);

Then the *2john would do:

PU_CTX ctx;
pu_start_line(&ctx, "rar", fp);
pu_fprintf(&ctx, "$%s", raw_to_hex(next_field));
....
pu_complete_line(&ctx);

So the start would grab the ftell location, write the tag followed by the source hash placeholder: $rar$SOURCE_HASH$00000000000000000000000000000000$ Then the fprints would be used to write data, along with these would md5 the data. Finally the complete would seek back to the place holder, and write the md5 of the data, so there is a UNIQUE search string which would match up between .pot and input source line.

How does that look for a generic 'write only' interface? I still would need to handle the read side of things for within loader and logger.

<!-- gh-comment-id:216641126 --> @jfoug commented on GitHub (May 3, 2016): @magnumripper how about something like this (for the *2john files): ``` C typedef struct PU_CTX_t { FILE *out; MD5_CTX md5; char Tag[128]; int taglen; long starting_offset; } PU_CTX; int pu_start_line(PU_CTX *ctx, const char *tag, FILE *fp); int pu_fprintf(PU_CTX, const char *, ...); int pu_complete_line(PU_CTX *ctx); ``` Then the *2john would do: ``` C PU_CTX ctx; pu_start_line(&ctx, "rar", fp); pu_fprintf(&ctx, "$%s", raw_to_hex(next_field)); .... pu_complete_line(&ctx); ``` So the start would grab the ftell location, write the tag followed by the source hash placeholder: `$rar$SOURCE_HASH$00000000000000000000000000000000$` Then the fprints would be used to write data, along with these would md5 the data. Finally the complete would seek back to the place holder, and write the md5 of the data, so there is a UNIQUE search string which would match up between .pot and input source line. How does that look for a generic 'write only' interface? I still would need to handle the read side of things for within loader and logger.
Author
Owner

@magnumripper commented on GitHub (May 3, 2016):

@magnumripper how do you think we should proceed on this? The hashed shorter line length .pot entries is almost a 2nd task

Not sure. If I had time I'd start experimenting with the RAR $RAR3$*1* formats. I'd start with rar2john, then adapt the formats, then loader - and finally test/fix problems until it looks good. This is complex enough that it's a good idea to move slowly though. I think we are close to a good solution now.

I think we should always put the blobhash + blob last. The current syntax is this:

$RAR3$*1*hex(salt)*hex(crc)*PACK_SIZE*UNP_SIZE*1*hex(blob)*method

We should scrap the last *1* (inline flag, not needed anymore) and move the last field (method) to before the blobhash and blob. So it'd end up like this:

$RAR3$*2*hex(salt)*hex(crc)*PACK_SIZE*UNP_SIZE*method*hex(blobhash)*base64(blob)

And corresponding pot entry

$RAR3$*2*hex(salt)*hex(crc)*PACK_SIZE*UNP_SIZE*method*hex(blobhash)

I can see a reason not to change the * to $ in this case: We want the $RAR3$*0* format (which doesn't need or use any blob at all) to remain unaltered or we'll break compatibiliy with hashcat.

@magnumripper how about something like this (for the *2john files):

Yeah something like that should be a good thing. Because of what I just said though, we might want to add a delimiter argument (* for RAR) to the functions.

<!-- gh-comment-id:216677999 --> @magnumripper commented on GitHub (May 3, 2016): > @magnumripper how do you think we should proceed on this? The hashed shorter line length .pot entries is almost a 2nd task Not sure. If I had time I'd start experimenting with the RAR `$RAR3$*1*` formats. I'd start with rar2john, then adapt the formats, then loader - and finally test/fix problems until it looks good. This is complex enough that it's a good idea to move slowly though. I think we are close to a good solution now. I think we should always put the blobhash + blob last. The current syntax is this: ``` $RAR3$*1*hex(salt)*hex(crc)*PACK_SIZE*UNP_SIZE*1*hex(blob)*method ``` We should scrap the last `*1*` (inline flag, not needed anymore) and move the last field (method) to before the blobhash and blob. So it'd end up like this: ``` $RAR3$*2*hex(salt)*hex(crc)*PACK_SIZE*UNP_SIZE*method*hex(blobhash)*base64(blob) ``` And corresponding pot entry ``` $RAR3$*2*hex(salt)*hex(crc)*PACK_SIZE*UNP_SIZE*method*hex(blobhash) ``` I can see a reason not to change the `*` to `$` in this case: We want the `$RAR3$*0*` format (which doesn't need or use any blob at all) to remain unaltered or we'll break compatibiliy with hashcat. > @magnumripper how about something like this (for the *2john files): Yeah something like that should be a good thing. Because of what I just said though, we might want to add a delimiter argument (`*` for RAR) to the functions.
Author
Owner

@magnumripper commented on GitHub (May 3, 2016):

BTW we might want to drop support for $RAR3$*1* and use $RAR3$*2* for this new syntax. We could print a suggestion to re-run rar2john in case we're fed a $RAR3$*1* input file.

$RAR3$*0* is -hp mode (also supported by hashcat) - should not be changed at all!
$RAR3$*1* is old-style -p mode syntax (sometimes inlined) which we cease to support
$RAR3$*2* is new-style -p mode syntax (always inlined but only hash in pot) that we add now

<!-- gh-comment-id:216678792 --> @magnumripper commented on GitHub (May 3, 2016): BTW we might want to drop support for `$RAR3$*1*` and use `$RAR3$*2*` for this new syntax. We could print a suggestion to re-run rar2john in case we're fed a `$RAR3$*1*` input file. `$RAR3$*0*` is -hp mode (also supported by hashcat) - should not be changed at all! `$RAR3$*1*` is old-style -p mode syntax (sometimes inlined) which we cease to support `$RAR3$*2*` is new-style -p mode syntax (always inlined but only hash in pot) that we add now
Author
Owner

@magnumripper commented on GitHub (May 3, 2016):

@jfoug I think you have in mind to replace nearly all fields with the hash. While that would work, I think it has several downsides. I recommend only the Base64 blob be left out of pot entries, nothing else. And the blobhash should be MD5(blob), nothing else. This relieves loader.c from most of the action and also makes it very easy for a format to verify that an input file's blob is intact.

I'm pretty sure if we're going this path, no new logic or support is needed from loader.c (apart from generic support for reading arbitrarily long lines) and we need NO special tag like BLOBHASH or SOURCE_HASH at all.

Hmm on second thought maybe the last statement is wrong. I think loader sometimes just do a strcmp(pot_line, input_line) and this will fail. So maybe we do need a BLOBHASH tag telling loader to limit that strcmp to the length of the pot line.

Hmm on third thought, no... if we use split() as I suggested earlier, this problem vanishes! I think this can ALL be done in rar2john + rar_fmt as long as loader handles long lines.

Hopefully I'll be able to show what I mean in a separate topic branch within 12h or so.

<!-- gh-comment-id:216685487 --> @magnumripper commented on GitHub (May 3, 2016): @jfoug I think you have in mind to replace nearly all fields with the hash. While that would work, I think it has several downsides. I recommend only the Base64 blob be left out of pot entries, nothing else. And the blobhash should be MD5(blob), nothing else. This relieves loader.c from most of the action and also makes it very easy for a format to verify that an input file's blob is intact. I'm pretty sure if we're going this path, no new logic or support is needed from loader.c (apart from generic support for reading arbitrarily long lines) and we need NO special tag like `BLOBHASH` or `SOURCE_HASH` at all. Hmm on second thought maybe the last statement is wrong. I think loader sometimes just do a strcmp(pot_line, input_line) and this will fail. So maybe we do need a `BLOBHASH` tag telling loader to limit that strcmp to the length of the pot line. Hmm on third thought, no... if we use split() as I suggested earlier, this problem vanishes! I think this can ALL be done in rar2john + rar_fmt as long as loader handles long lines. Hopefully I'll be able to show what I mean in a separate topic branch within 12h or so.
Author
Owner

@jfoug commented on GitHub (May 4, 2016):

@jfoug I think you have in mind to replace nearly all fields with the hash. While that would work, I think it has several downsides. I recommend only the Base64 blob be left out of pot entries,

No, what I have in mind is to make this 'generic' There is NO SUCH THING as a base64 blob. If the format/*2john do that, then by all means they will. ALL this generic code will do is to wrap logic on top of fprintf type logic. Nothing more, nothing less. But the *2john and fmt will be in charge of their strings.

NOTE, this is done with a var_args function. Thus that function does not care what the *2john does.

<!-- gh-comment-id:216703077 --> @jfoug commented on GitHub (May 4, 2016): > @jfoug I think you have in mind to replace nearly all fields with the hash. While that would work, I think it has several downsides. I recommend only the Base64 blob be left out of pot entries, No, what I have in mind is to make this 'generic' There is NO SUCH THING as a base64 blob. If the format/*2john do that, then by all means they will. ALL this generic code will do is to wrap logic on top of fprintf type logic. Nothing more, nothing less. But the *2john and fmt will be in charge of their strings. NOTE, this is done with a var_args function. Thus that function does not care what the *2john does.
Author
Owner

@magnumripper commented on GitHub (May 4, 2016):

Yeah but if I construct the RAR3 line using your pu_start_line(), pu_fprintf() and pu_complete_line() functions, it will MD5 all of the line. At least that's how I understood it. Then again I guess I could do things like

printf("$RAR3$*2*this and that*foo*bar*"); // normal printf's to build most of the line
pu_start_line(&ctx, "", stdout);
for (...)
    pu_fprintf(&ctx, "%s", raw_to_base64(chunk)); // only use the shared function for the blob
pu_complete_line(&ctx);

BTW I do not think we need that *fp pointer. All tools write to stdout.

<!-- gh-comment-id:216704945 --> @magnumripper commented on GitHub (May 4, 2016): Yeah but if I construct the RAR3 line using your pu_start_line(), pu_fprintf() and pu_complete_line() functions, it will MD5 all of the line. At least that's how I understood it. Then again I guess I could do things like ``` c printf("$RAR3$*2*this and that*foo*bar*"); // normal printf's to build most of the line pu_start_line(&ctx, "", stdout); for (...) pu_fprintf(&ctx, "%s", raw_to_base64(chunk)); // only use the shared function for the blob pu_complete_line(&ctx); ``` BTW I do not think we need that `*fp` pointer. All tools write to stdout.
Author
Owner

@magnumripper commented on GitHub (May 4, 2016):

Oh BTW that function would not work correctly if used as I wrote above. It would MD5 the Base64. We need an MD5 of the actual binary.

For rar2john I'd rather just have a function like

int write_blob(FILE *fp, off_t offset, size_t size, char delim);

Then I could

printf("$RAR3$*2*this and that*foo*bar*"); // normal printf's to build most of the line
write_blob(fp, pos, file_header_unp_size, '*'); // adds the blob-hash and the actual blob encoded in Base64 using * as delimiter.
<!-- gh-comment-id:216706635 --> @magnumripper commented on GitHub (May 4, 2016): Oh BTW that function would not work correctly if used as I wrote above. It would MD5 the Base64. We need an MD5 of the actual binary. For rar2john I'd rather just have a function like ``` c int write_blob(FILE *fp, off_t offset, size_t size, char delim); ``` Then I could ``` c printf("$RAR3$*2*this and that*foo*bar*"); // normal printf's to build most of the line write_blob(fp, pos, file_header_unp_size, '*'); // adds the blob-hash and the actual blob encoded in Base64 using * as delimiter. ```
Author
Owner

@jfoug commented on GitHub (May 4, 2016):

Ok, this is the code I am working with.

typedef struct PU_CTX_t {
    MD5_CTX md5;
    char Tag[128];
    int taglen;
} PU_CTX;

/* these are for the *2john mostly (writing functions)        */
/* these use a CTX to track the data, accumulate the md5, etc */
int pu_start_line(PU_CTX *ctx, const char *tag);
int pu_fprintf(PU_CTX *ctx, const char *fmt, ...);
int pu_complete_line(PU_CTX *ctx);

/* these are used in john's loader.c and logger.c */
int pu_isa_pot_source(const char *ciphertext);
int pu_pot_source_cmp(const char *pot_entry, const char *full_source);
const char *pu_pot_source(const char *full_source,
                           char buffer[LINE_BUFFER_SIZE+1],
                           void *bin, int blen);

The signatures for 'full' hash will be

$tag_thiscan be whatever and does not even need dollar wrapping$normal_hash_stuff$SOURCE_HASH$taglen_hex$md5_of_entire_source

Then in the .pot file it will be:

$tag$SOURCE_HASH$md5_of_entire_source$BINARY$binary()_in_hex

So we can keep 'any' format that the *2john wants, we are simply appending the source_hash md5 AND the length of the tag (which can be ANYTHING. So the tag can be rar3 or $rar3$0$ or whatever the format wants. That tag WILL get put into the .pot file, when we crack. Then the source MD5 and binary will make sure that a FULL hash and a truncated .pot file hash match. Also, the md5 hash can be used by any ancillary tool to find t hings in the .pot file, if they need to scan for cracks OUTSIDE of using john's -show function (I do that all the time, and I am sure there are MANY others).

<!-- gh-comment-id:216730992 --> @jfoug commented on GitHub (May 4, 2016): Ok, this is the code I am working with. ``` C typedef struct PU_CTX_t { MD5_CTX md5; char Tag[128]; int taglen; } PU_CTX; /* these are for the *2john mostly (writing functions) */ /* these use a CTX to track the data, accumulate the md5, etc */ int pu_start_line(PU_CTX *ctx, const char *tag); int pu_fprintf(PU_CTX *ctx, const char *fmt, ...); int pu_complete_line(PU_CTX *ctx); /* these are used in john's loader.c and logger.c */ int pu_isa_pot_source(const char *ciphertext); int pu_pot_source_cmp(const char *pot_entry, const char *full_source); const char *pu_pot_source(const char *full_source, char buffer[LINE_BUFFER_SIZE+1], void *bin, int blen); ``` The signatures for 'full' hash will be ``` $tag_thiscan be whatever and does not even need dollar wrapping$normal_hash_stuff$SOURCE_HASH$taglen_hex$md5_of_entire_source ``` Then in the .pot file it will be: ``` $tag$SOURCE_HASH$md5_of_entire_source$BINARY$binary()_in_hex ``` So we can keep 'any' format that the *2john wants, we are simply appending the source_hash md5 AND the length of the tag (which can be ANYTHING. So the tag can be $rar3$ or $rar3$0$ or whatever the format wants. That tag WILL get put into the .pot file, when we crack. Then the source MD5 and binary will make sure that a FULL hash and a truncated .pot file hash match. Also, the md5 hash can be used by any ancillary tool to find t hings in the .pot file, if they need to scan for cracks OUTSIDE of using john's -show function (I do that all the time, and I am sure there are MANY others).
Author
Owner

@magnumripper commented on GitHub (May 4, 2016):

Your version is founded on new/special handling in several parts of core. If my ideas end up flying IRL, that's not needed. Pot sync and --show would just work, with current known-good code. Any introduced bug would be isolated to affected formats (eg. rar).

The one and only core change really needed is the support you already wrote for handling arbitrarily long lines.

<!-- gh-comment-id:216742519 --> @magnumripper commented on GitHub (May 4, 2016): Your version is founded on new/special handling in several parts of core. If my ideas end up flying IRL, that's not needed. Pot sync and --show would just work, with current known-good code. Any introduced bug would be isolated to affected formats (eg. rar). The one and only core change really needed is the support you already wrote for handling arbitrarily long lines.
Author
Owner

@magnumripper commented on GitHub (May 9, 2016):

Your version is founded on new/special handling in several parts of core. If my ideas end up flying IRL, that's not needed.

My bad @jfoug, you're code is a winner and I was too focused on rar and the likes, that may point to external files. My "way" of attacking it would have been superior had it been done in 2011... but it wasn't! Given our current legacy I can't see any way of attacking this other than complete your topic branch.

I'm still testing. There's a LOT to test now.

<!-- gh-comment-id:217958653 --> @magnumripper commented on GitHub (May 9, 2016): > Your version is founded on new/special handling in several parts of core. If my ideas end up flying IRL, that's not needed. My bad @jfoug, you're code is a winner and I was too focused on rar and the likes, that may point to external files. My "way" of attacking it would have been superior **had it been done in 2011**... but it wasn't! Given our current legacy I can't see any way of attacking this other than complete your topic branch. I'm still testing. There's a LOT to test now.
Author
Owner

@jfoug commented on GitHub (May 10, 2016):

There is still a ton of testing, in the code which I started on. Hacks galor. BUT it is a way of handing this in a semi generic manner.

The reason I left a large chunk of data (in the .pot file), and appended the hash to the end, was so that there was the best possible chance of having something 'unique' that could be searched upon, to find the hashes outside of john. There is always the case where a hash could NOT be found at all

However, I do think your method of doing this (having the *2john) build the hash, does have merits, as then for that hash, the ENTIRE data stored in the .pot file is the tag, the hash and the binary. That actually should of be done with no changes to the internal format (other than valid/binary), and only changing the *2john. Possibly, we can start down that path also, and slowly wean ourselves off of the need for logger/loader to cut/compute_hash, and move that logic out to the *2john. Once we get 'most' of them done, then we can work on the few hashes that still have to use the logger/loader hashing, and figure them out. Figuring out 10 or so stragglers is much easier than 80ish that we currently have.

But for the hashes which have no *2john, BUT are over 1k, I could find no other way around this, short of storing the huge data in the .pot file, and THEN we have the issue of having to write data outside of the lock, or come up with other hacks to handle that longer line. Now, we certainly could also make the slack end of buffer size 0x30000, so that we never have to worry about the slack part, but I think we just need to flatten out the warts the best we can within what I have started on. I know it is ugly, but I did spend a lot of heads down time, and found (and worked around) numerous issues.

Yes, if we would NEVER have increased buffer size to 0x30000, then we would have more options. BUT even though it does not sound all that bad, we are screwed.

Part of the problem is there are things which are > 1k, and are ITW real hashes, not some *2john thing. That kbr5_something is one of them (iirc) where we have a raw hash that does not even have a tag, that is > 1k.

<!-- gh-comment-id:218060715 --> @jfoug commented on GitHub (May 10, 2016): There is still a ton of testing, in the code which I started on. Hacks galor. BUT it is a way of handing this in a semi generic manner. The reason I left a large chunk of data (in the .pot file), and appended the hash to the end, was so that there was the best possible chance of having something 'unique' that could be searched upon, to find the hashes outside of john. There is always the case where a hash could NOT be found at all However, I do think your method of doing this (having the *2john) build the hash, does have merits, as then for that hash, the ENTIRE data stored in the .pot file is the tag, the hash and the binary. That actually should of be done with no changes to the internal format (other than valid/binary), and only changing the *2john. Possibly, we can start down that path also, and slowly wean ourselves off of the need for logger/loader to cut/compute_hash, and move that logic out to the *2john. Once we get 'most' of them done, then we can work on the few hashes that still have to use the logger/loader hashing, and figure them out. Figuring out 10 or so stragglers is much easier than 80ish that we currently have. But for the hashes which have no *2john, BUT are over 1k, I could find no other way around this, short of storing the huge data in the .pot file, and THEN we have the issue of having to write data outside of the lock, or come up with other hacks to handle that longer line. Now, we certainly could also make the slack end of buffer size 0x30000, so that we never have to worry about the slack part, but I think we just need to flatten out the warts the best we can within what I have started on. I know it is ugly, but I did spend a lot of heads down time, and found (and worked around) numerous issues. Yes, if we would NEVER have increased buffer size to 0x30000, then we would have more options. BUT even though it does not sound all that bad, we are screwed. Part of the problem is there are things which are > 1k, and are ITW real hashes, not some *2john thing. That kbr5_something is one of them (iirc) where we have a raw hash that does not even have a tag, that is > 1k.
Author
Owner

@jfoug commented on GitHub (May 10, 2016):

Note, I will be gone a couple weeks. Do not take my silent-ness to mean anything. Gonna do a 2 week, no destination ride. Probably put 4 to 6k miles on the bike, and hit a lot of south central, and western US locations. I will be on the road in about 36 hours.

<!-- gh-comment-id:218061336 --> @jfoug commented on GitHub (May 10, 2016): Note, I will be gone a couple weeks. Do not take my silent-ness to mean anything. Gonna do a 2 week, no destination ride. Probably put 4 to 6k miles on the bike, and hit a lot of south central, and western US locations. I will be on the road in about 36 hours.
Author
Owner

@magnumripper commented on GitHub (May 10, 2016):

Cool, ride safe and ATGATT.

I'll continue testing this. Yes, we certainly have the option to do the split() thing as well as this generic stuff. I'll try that out too.

<!-- gh-comment-id:218064281 --> @magnumripper commented on GitHub (May 10, 2016): Cool, ride safe and ATGATT. I'll continue testing this. Yes, we certainly have the option to do the split() thing _as well as_ this generic stuff. I'll try that out too.
Author
Owner

@magnumripper commented on GitHub (Jun 2, 2016):

#2130 is merged now! I fixed a few more issues and then decided we won't ever find more issues until we actually merge.

<!-- gh-comment-id:223370334 --> @magnumripper commented on GitHub (Jun 2, 2016): #2130 is merged now! I fixed a few more issues and then decided we won't ever find more issues until we actually merge.
Author
Owner

@jfoug commented on GitHub (Jun 10, 2016):

Good that this is merged. Yes, we may still need to polish it a bit, but getting these to be proper inlines sure helps things out, especially to NOT put multi megabyte (or gigabyte) blobs into the .pot file.

<!-- gh-comment-id:225261049 --> @jfoug commented on GitHub (Jun 10, 2016): Good that this is merged. Yes, we may still need to polish it a bit, but getting these to be proper inlines sure helps things out, especially to NOT put multi megabyte (or gigabyte) blobs into the .pot file.
Author
Owner

@magnumripper commented on GitHub (Jun 15, 2016):

46a6c50 fixed issues with pot-syncing truncated ciphertexts. I thought I had that tested but given the problem I think it never worked 😎 Easy fix though.

<!-- gh-comment-id:226255833 --> @magnumripper commented on GitHub (Jun 15, 2016): 46a6c50 fixed issues with pot-syncing truncated ciphertexts. I thought I had that tested but given the problem I think it never worked 😎 Easy fix though.
Author
Owner

@jfoug commented on GitHub (Jul 13, 2016):

Is this 'feature enhancement' now considered complete? We did it differently than was first proposed, but I 'think' we have it fully running now (correct?)

Or do we still have lots of 'cleanup' to do to remove the older hack stuff.

<!-- gh-comment-id:232397285 --> @jfoug commented on GitHub (Jul 13, 2016): Is this 'feature enhancement' now considered complete? We did it differently than was first proposed, but I 'think' we have it fully running now (correct?) Or do we still have lots of 'cleanup' to do to remove the older hack stuff.
Author
Owner

@jfoug commented on GitHub (Jul 13, 2016):

@magnumripper your new method will not remove duplicates. What we are comparing is the binary from the full hash, vs an MD5 of the original hash string. 2 totally different things.

That was why I was calling binary() at .pot time, and putting that out there.

<!-- gh-comment-id:232466461 --> @jfoug commented on GitHub (Jul 13, 2016): @magnumripper your new method will not remove duplicates. What we are comparing is the binary from the full hash, vs an MD5 of the original hash string. 2 totally different things. That was why I was calling binary() at .pot time, and putting that out there.
Author
Owner

@jfoug commented on GitHub (Jul 13, 2016):

Ok, we NEED to have SOURCE_HASH AND BIN_HASH BIN_HASH is the return from binary() of the format, where the 'real' hash is. We HAVE to have the binary value, to be able to remove duplicates. The code we have today removes .pot lines (I think), if binary() is 0 bytes long. BUT something like luks (which does have a binary), will NOT work right.

<!-- gh-comment-id:232468271 --> @jfoug commented on GitHub (Jul 13, 2016): Ok, we NEED to have $SOURCE_HASH$ AND $BIN_HASH$ $BIN_HASH$ is the return from binary() of the format, where the 'real' hash is. We HAVE to have the binary value, to be able to remove duplicates. The code we have today removes .pot lines (I think), if binary() is 0 bytes long. BUT something like luks (which does have a binary), will NOT work right.
Author
Owner

@jfoug commented on GitHub (Jul 13, 2016):

Ok, for LUKS. The first block is how our code writes a .pot file today. It fails to remove the hash and re-cracks it. The 2nd one has $bin_value appended, and it does properly .pot remove.

$luks$1$592$4c554b53babe000161657300000000000000000000000000000000000000000000000000000000006362632d65737369763a73686132353600000000000000000000000000000000736861310000000000000000000000000000000000000000000000000000000000000408000000104f386b50df3fcd9132589a934851faaff16709ff628ed0b628b0d7151b3600c0b3f95d8404a8b35fdf5dd6b6ff10f4c352fde11900010b1762663664393836622d633836352d343261622d616534662d6165313336633938383735360000000000ac71f3000430f5d9c39e349b48d7cf1771d9c152840b389a4353ff186436ec75cc397529ed40260000000800000fa00000dead0000000000000000000000000000000000000000000000000000000000000000000000000000008800000fa00000dead0000000000000000000000000000000000000000000000000000000000000000000000000000010800000fa00000dead0000000000000000000000000000000000000000000000000000000000000000000000000000018800000fa00000dead0000000000000000000000000000000$SOURCE_HASH$5fd6a096972d1a65afa21f2781ed7fe9:!@#$%^&*
$luks$1$592$4c554b53babe000161657300000000000000000000000000000000000000000000000000000000006362632d65737369763a73686132353600000000000000000000000000000000736861310000000000000000000000000000000000000000000000000000000000000408000000104f386b50df3fcd9132589a934851faaff16709ff628ed0b628b0d7151b3600c0b3f95d8404a8b35fdf5dd6b6ff10f4c352fde11900010b1762663664393836622d633836352d343261622d616534662d6165313336633938383735360000000000ac71f3000430f5d9c39e349b48d7cf1771d9c152840b389a4353ff186436ec75cc397529ed40260000000800000fa00000dead0000000000000000000000000000000000000000000000000000000000000000000000000000008800000fa00000dead0000000000000000000000000000000000000000000000000000000000000000000000000000010800000fa00000dead000000000000000000000000000000000000000000000000000000000000000000000000000001$SOURCE_HASH$5fd6a096972d1a65afa21f2781ed7fe9$4f386b50df3fcd9132589a934851faaff16709ff:!@#$%^&*!@#$%^&*

For luks, this happens to work with an unmodified binary() function, since $_hex_binary_value is the last thing on a valid luks hash line. BUT we may need to do a strrchr(ct, '$') in other formats binary functions, IF we detect this is a .pot line with the $SOURCE_HASH

@magnumripper what do you see about what I have just found??

<!-- gh-comment-id:232468986 --> @jfoug commented on GitHub (Jul 13, 2016): Ok, for LUKS. The first block is how our code writes a .pot file today. It fails to remove the hash and re-cracks it. The 2nd one has $bin_value appended, and it does properly .pot remove. ``` $luks$1$592$4c554b53babe000161657300000000000000000000000000000000000000000000000000000000006362632d65737369763a73686132353600000000000000000000000000000000736861310000000000000000000000000000000000000000000000000000000000000408000000104f386b50df3fcd9132589a934851faaff16709ff628ed0b628b0d7151b3600c0b3f95d8404a8b35fdf5dd6b6ff10f4c352fde11900010b1762663664393836622d633836352d343261622d616534662d6165313336633938383735360000000000ac71f3000430f5d9c39e349b48d7cf1771d9c152840b389a4353ff186436ec75cc397529ed40260000000800000fa00000dead0000000000000000000000000000000000000000000000000000000000000000000000000000008800000fa00000dead0000000000000000000000000000000000000000000000000000000000000000000000000000010800000fa00000dead0000000000000000000000000000000000000000000000000000000000000000000000000000018800000fa00000dead0000000000000000000000000000000$SOURCE_HASH$5fd6a096972d1a65afa21f2781ed7fe9:!@#$%^&* ``` ``` $luks$1$592$4c554b53babe000161657300000000000000000000000000000000000000000000000000000000006362632d65737369763a73686132353600000000000000000000000000000000736861310000000000000000000000000000000000000000000000000000000000000408000000104f386b50df3fcd9132589a934851faaff16709ff628ed0b628b0d7151b3600c0b3f95d8404a8b35fdf5dd6b6ff10f4c352fde11900010b1762663664393836622d633836352d343261622d616534662d6165313336633938383735360000000000ac71f3000430f5d9c39e349b48d7cf1771d9c152840b389a4353ff186436ec75cc397529ed40260000000800000fa00000dead0000000000000000000000000000000000000000000000000000000000000000000000000000008800000fa00000dead0000000000000000000000000000000000000000000000000000000000000000000000000000010800000fa00000dead000000000000000000000000000000000000000000000000000000000000000000000000000001$SOURCE_HASH$5fd6a096972d1a65afa21f2781ed7fe9$4f386b50df3fcd9132589a934851faaff16709ff:!@#$%^&*!@#$%^&* ``` For luks, this happens to work with an unmodified binary() function, since $_hex_binary_value is the last thing on a valid luks hash line. BUT we may need to do a strrchr(ct, '$') in other formats binary functions, IF we detect this is a .pot line with the $SOURCE_HASH @magnumripper what do you see about what I have just found??
Author
Owner

@jfoug commented on GitHub (Jul 13, 2016):

Made some simple changes, and now luks (and likely others with a binary) work. But I am seeing strangeness on -show and -show=left:

$ ../run/john in2 -w=in1
WARNING, LUKS format hash representation will change in future releases,
see doc/README.LUKS
Using default input encoding: UTF-8
Loaded 1 password hash (LUKS [PBKDF2-SHA1 128/128 AVX 4x])
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
!@#$%^&*         (?)
1g 0:00:00:00 DONE (2016-07-13 15:26) 6.410g/s 6.410p/s 6.410c/s 6.410C/s !@#$%^&*
Use the "--show" option to display all of the cracked passwords reliably
Session completed

$ ../run/john in2 -w=in1
WARNING, LUKS format hash representation will change in future releases,
see doc/README.LUKS
Using default input encoding: UTF-8
Loaded 1 password hash (LUKS [PBKDF2-SHA1 128/128 AVX 4x])
No password hashes left to crack (see FAQ)

$ ../run/john in2 -show=left
WARNING, LUKS format hash representation will change in future releases,
see doc/README.LUKS

1 password hash cracked, 0 left

$ ../run/john in2 -show
WARNING, LUKS format hash representation will change in future releases,
see doc/README.LUKS
0 password hashes cracked, 1 left

I have not checked anything in yet, (but easily could), the changes are pretty trivial. What I have done is to simply append a '$' and any possible binary() result to the .pot line. we can easily modify formats binary() if we need to. luks did not require any changes to binary(). But now the -show and -show=left are having issues

$ git diff cracker.c loader.[ch]
diff --git a/src/cracker.c b/src/cracker.c
index 356d1ff..27197da 100644
--- a/src/cracker.c
+++ b/src/cracker.c
@@ -403,7 +403,7 @@ static int crk_process_guess(struct db_salt *salt, struct db_password *pw,
                else
                        ct = ldr_pot_source(
                                crk_methods.source(pw->source, pw->binary),
-                               buffer);
+                               crk_db->format, buffer);
                log_guess(crk_db->options->flags & DB_LOGIN ? replogin : "?",
                          crk_db->options->flags & DB_LOGIN ? repuid : "",
                          (char*)ct,
diff --git a/src/loader.c b/src/loader.c
index 0f6dbdf..1d521f4 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -101,7 +101,7 @@ static char *skip_bom(char *string)
  * will now get 'trimmed' when put into the .pot file. Here is the trimming
  * method:
  *    input:    $hashtype$abcdefghijk..........qrstuvwxzy$something$else
- *    pot:      $hashtype$abcdefghijk.......$SOURCE_HASH$<md5 of full hash>
+ *    pot:      $hashtype$abcdefghijk.......$SOURCE_HASH$<md5 of full hash>$<hex of binary()
  * this way we can fully compare this .pot record (against the full input line)
  */
 int ldr_pot_source_cmp(const char *pot_entry, const char *full_source) {
@@ -133,11 +133,11 @@ int ldr_pot_source_cmp(const char *pot_entry, const char *full_source) {
  * line with a hash tacked on. However, it will always be shorter or equal
  * to (LINE_BUFFER_SIZE - PLAINTEXT_BUFFER_SIZE)
  */
-const char *ldr_pot_source(const char *full_source,
+const char *ldr_pot_source(const char *full_source, struct fmt_main *fmt,
                            char buffer[LINE_BUFFER_SIZE + 1])
 {
        MD5_CTX ctx;
-       int len;
+       int len, bin_len;
        char *p = buffer;
        unsigned char mbuf[16];

@@ -149,8 +149,11 @@ const char *ldr_pot_source(const char *full_source,
         * but that has a hash of the full source
         */

+       /* compute binary length */
+       bin_len = fmt->params.binary_size;
+
        /* 13=len sig1, 32=len hash */
-       len = MAX_CIPHERTEXT_SIZE - 13 - 32;
+       len = MAX_CIPHERTEXT_SIZE - 13 - 32 - 1 - (bin_len<<1);
        memcpy(p, full_source, len);
        p += len;
        memcpy(p, "$SOURCE_HASH$", 13);
@@ -160,6 +163,11 @@ const char *ldr_pot_source(const char *full_source,
        MD5_Final(mbuf, &ctx);
        base64_convert(mbuf, e_b64_raw, 16, p, e_b64_hex, 33, 0, 0);
        p += 32;
+       *p++ = '$';
+       if (bin_len) {
+               base64_convert(fmt->methods.binary((char*)full_source), e_b64_raw, bin_len, p, e_b64_hex, (bin_len<<1)+1, 0, 0);
+               p += bin_len<<1;
+       }
        *p = 0;
        return buffer;
 }
diff --git a/src/loader.h b/src/loader.h
index 356baf8..6f462b3 100644
--- a/src/loader.h
+++ b/src/loader.h
@@ -324,7 +324,7 @@ extern int ldr_pot_source_cmp(const char *pot_entry, const char *full_source);
  * This returns the line to write to a .pot file. It may be shorter than the
  * original source (with some extra tags added).
  */
-extern const char *ldr_pot_source(const char *full_source,
+extern const char *ldr_pot_source(const char *full_source, struct fmt_main *fmt,
                                   char buffer[LINE_BUFFER_SIZE+1]);

 /*
<!-- gh-comment-id:232477340 --> @jfoug commented on GitHub (Jul 13, 2016): Made some simple changes, and now luks (and likely others with a binary) work. But I am seeing strangeness on -show and -show=left: ``` $ ../run/john in2 -w=in1 WARNING, LUKS format hash representation will change in future releases, see doc/README.LUKS Using default input encoding: UTF-8 Loaded 1 password hash (LUKS [PBKDF2-SHA1 128/128 AVX 4x]) Will run 8 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status !@#$%^&* (?) 1g 0:00:00:00 DONE (2016-07-13 15:26) 6.410g/s 6.410p/s 6.410c/s 6.410C/s !@#$%^&* Use the "--show" option to display all of the cracked passwords reliably Session completed $ ../run/john in2 -w=in1 WARNING, LUKS format hash representation will change in future releases, see doc/README.LUKS Using default input encoding: UTF-8 Loaded 1 password hash (LUKS [PBKDF2-SHA1 128/128 AVX 4x]) No password hashes left to crack (see FAQ) $ ../run/john in2 -show=left WARNING, LUKS format hash representation will change in future releases, see doc/README.LUKS 1 password hash cracked, 0 left $ ../run/john in2 -show WARNING, LUKS format hash representation will change in future releases, see doc/README.LUKS 0 password hashes cracked, 1 left ``` I have not checked anything in yet, (but easily could), the changes are pretty trivial. What I have done is to simply append a '$' and any possible binary() result to the .pot line. we can easily modify formats binary() if we need to. luks did not require any changes to binary(). But now the -show and -show=left are having issues ``` diff $ git diff cracker.c loader.[ch] diff --git a/src/cracker.c b/src/cracker.c index 356d1ff..27197da 100644 --- a/src/cracker.c +++ b/src/cracker.c @@ -403,7 +403,7 @@ static int crk_process_guess(struct db_salt *salt, struct db_password *pw, else ct = ldr_pot_source( crk_methods.source(pw->source, pw->binary), - buffer); + crk_db->format, buffer); log_guess(crk_db->options->flags & DB_LOGIN ? replogin : "?", crk_db->options->flags & DB_LOGIN ? repuid : "", (char*)ct, diff --git a/src/loader.c b/src/loader.c index 0f6dbdf..1d521f4 100644 --- a/src/loader.c +++ b/src/loader.c @@ -101,7 +101,7 @@ static char *skip_bom(char *string) * will now get 'trimmed' when put into the .pot file. Here is the trimming * method: * input: $hashtype$abcdefghijk..........qrstuvwxzy$something$else - * pot: $hashtype$abcdefghijk.......$SOURCE_HASH$<md5 of full hash> + * pot: $hashtype$abcdefghijk.......$SOURCE_HASH$<md5 of full hash>$<hex of binary() * this way we can fully compare this .pot record (against the full input line) */ int ldr_pot_source_cmp(const char *pot_entry, const char *full_source) { @@ -133,11 +133,11 @@ int ldr_pot_source_cmp(const char *pot_entry, const char *full_source) { * line with a hash tacked on. However, it will always be shorter or equal * to (LINE_BUFFER_SIZE - PLAINTEXT_BUFFER_SIZE) */ -const char *ldr_pot_source(const char *full_source, +const char *ldr_pot_source(const char *full_source, struct fmt_main *fmt, char buffer[LINE_BUFFER_SIZE + 1]) { MD5_CTX ctx; - int len; + int len, bin_len; char *p = buffer; unsigned char mbuf[16]; @@ -149,8 +149,11 @@ const char *ldr_pot_source(const char *full_source, * but that has a hash of the full source */ + /* compute binary length */ + bin_len = fmt->params.binary_size; + /* 13=len sig1, 32=len hash */ - len = MAX_CIPHERTEXT_SIZE - 13 - 32; + len = MAX_CIPHERTEXT_SIZE - 13 - 32 - 1 - (bin_len<<1); memcpy(p, full_source, len); p += len; memcpy(p, "$SOURCE_HASH$", 13); @@ -160,6 +163,11 @@ const char *ldr_pot_source(const char *full_source, MD5_Final(mbuf, &ctx); base64_convert(mbuf, e_b64_raw, 16, p, e_b64_hex, 33, 0, 0); p += 32; + *p++ = '$'; + if (bin_len) { + base64_convert(fmt->methods.binary((char*)full_source), e_b64_raw, bin_len, p, e_b64_hex, (bin_len<<1)+1, 0, 0); + p += bin_len<<1; + } *p = 0; return buffer; } diff --git a/src/loader.h b/src/loader.h index 356baf8..6f462b3 100644 --- a/src/loader.h +++ b/src/loader.h @@ -324,7 +324,7 @@ extern int ldr_pot_source_cmp(const char *pot_entry, const char *full_source); * This returns the line to write to a .pot file. It may be shorter than the * original source (with some extra tags added). */ -extern const char *ldr_pot_source(const char *full_source, +extern const char *ldr_pot_source(const char *full_source, struct fmt_main *fmt, char buffer[LINE_BUFFER_SIZE+1]); /* ```
Author
Owner

@jfoug commented on GitHub (Jul 13, 2016):

If I roll back my recent changes, then -show and -show=left both show 0 crack 1 left for this LUKS crack. So I will dig into both of those functions. Well, in my VC build it works, grrr. I will look at this next week after I get back from my Colorado trip.

<!-- gh-comment-id:232487054 --> @jfoug commented on GitHub (Jul 13, 2016): If I roll back my recent changes, then -show and -show=left both show 0 crack 1 left for this LUKS crack. So I will dig into both of those functions. Well, in my VC build it works, grrr. I will look at this next week after I get back from my Colorado trip.
Author
Owner

@magnumripper commented on GitHub (Jul 16, 2016):

Ok, we NEED to have SOURCE_HASH AND BIN_HASH

I think not. We may have a bug and/or we may have to rewrite something a little but we do not need BIN_HASH.

<!-- gh-comment-id:233135906 --> @magnumripper commented on GitHub (Jul 16, 2016): > Ok, we NEED to have $SOURCE_HASH$ AND $BIN_HASH$ I think not. We may have a bug and/or we may have to rewrite something a little but we do not need BIN_HASH.
Author
Owner

@jfoug commented on GitHub (Jul 18, 2016):

BIN_HASH is required for -show for any format that has a non-zero binary length.

<!-- gh-comment-id:233408633 --> @jfoug commented on GitHub (Jul 18, 2016): $BIN_HASH$ is required for -show for any format that has a non-zero binary length.
Author
Owner

@jfoug commented on GitHub (Jul 18, 2016):

I withdraw this bin_hash request, and think it is not needed. I am not sure why it was having problems, but I can not replicate the problem now. Well, not quite (-show and -show=left are working however).

$ ../run/john in2 -w=pw
WARNING, LUKS format hash representation will change in future releases,
see doc/README.LUKS
Using default input encoding: UTF-8
Loaded 1 password hash (LUKS [PBKDF2-SHA1 128/128 AVX 4x])
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
!@#$%^&*         (?)
1g 0:00:00:00 DONE (2016-07-18 17:04) 8.000g/s 24.00p/s 24.00c/s 24.00C/s testing123
Use the "--show" option to display all of the cracked passwords reliably
Session completed

$ ../run/john in2 -w=pw
WARNING, LUKS format hash representation will change in future releases,
see doc/README.LUKS
Using default input encoding: UTF-8
Loaded 1 password hash (LUKS [PBKDF2-SHA1 128/128 AVX 4x])
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
!@#$%^&*         (?)
1g 0:00:00:00 DONE (2016-07-18 17:04) 8.000g/s 24.00p/s 24.00c/s 24.00C/s testing123
Use the "--show" option to display all of the cracked passwords reliably
Session completed

$ ../run/john in2 -w=pw
WARNING, LUKS format hash representation will change in future releases,
see doc/README.LUKS
Using default input encoding: UTF-8
Loaded 1 password hash (LUKS [PBKDF2-SHA1 128/128 AVX 4x])
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
!@#$%^&*         (?)
1g 0:00:00:00 DONE (2016-07-18 17:04) 8.000g/s 24.00p/s 24.00c/s 24.00C/s testing123
Use the "--show" option to display all of the cracked passwords reliably
Session completed
<!-- gh-comment-id:233473900 --> @jfoug commented on GitHub (Jul 18, 2016): I withdraw this bin_hash request, and think it is not needed. I am not sure why it was having problems, but I can not replicate the problem now. Well, not quite (-show and -show=left are working however). ``` $ ../run/john in2 -w=pw WARNING, LUKS format hash representation will change in future releases, see doc/README.LUKS Using default input encoding: UTF-8 Loaded 1 password hash (LUKS [PBKDF2-SHA1 128/128 AVX 4x]) Will run 8 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status !@#$%^&* (?) 1g 0:00:00:00 DONE (2016-07-18 17:04) 8.000g/s 24.00p/s 24.00c/s 24.00C/s testing123 Use the "--show" option to display all of the cracked passwords reliably Session completed $ ../run/john in2 -w=pw WARNING, LUKS format hash representation will change in future releases, see doc/README.LUKS Using default input encoding: UTF-8 Loaded 1 password hash (LUKS [PBKDF2-SHA1 128/128 AVX 4x]) Will run 8 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status !@#$%^&* (?) 1g 0:00:00:00 DONE (2016-07-18 17:04) 8.000g/s 24.00p/s 24.00c/s 24.00C/s testing123 Use the "--show" option to display all of the cracked passwords reliably Session completed $ ../run/john in2 -w=pw WARNING, LUKS format hash representation will change in future releases, see doc/README.LUKS Using default input encoding: UTF-8 Loaded 1 password hash (LUKS [PBKDF2-SHA1 128/128 AVX 4x]) Will run 8 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status !@#$%^&* (?) 1g 0:00:00:00 DONE (2016-07-18 17:04) 8.000g/s 24.00p/s 24.00c/s 24.00C/s testing123 Use the "--show" option to display all of the cracked passwords reliably Session completed ```
Author
Owner

@jfoug commented on GitHub (Jul 25, 2016):

NOTE, it appears that MANY formats now are not removing currently found hashes.

I am not 100% sure, but I think it is due to this change (possibly this change not being complete).

<!-- gh-comment-id:235102213 --> @jfoug commented on GitHub (Jul 25, 2016): NOTE, it appears that MANY formats now are not removing currently found hashes. I am not 100% sure, but I think it is due to this change (possibly this change not being complete).
Author
Owner

@jfoug commented on GitHub (Jul 26, 2016):

These formats do NOT remove already found salts. (I found others I had to look at, but only these 2 are problems).

krb5_tgs_fmt_plug.c
pfx_ng_fmt_plug.c

<!-- gh-comment-id:235140950 --> @jfoug commented on GitHub (Jul 26, 2016): These formats do NOT remove already found salts. (I found others I had to look at, but only these 2 are problems). krb5_tgs_fmt_plug.c pfx_ng_fmt_plug.c
Author
Owner

@jfoug commented on GitHub (Jul 26, 2016):

0350a1c fixes the problem with pfx_ng format (the only with with BINARY_SIZE != 0) I simply also tack on BIN_HASH and the hex return from fmt->methods.binary(ct) to the end of the hash string (reducing the starting size appropriately). This fixes the already cracked removal bug.

I still have to find problem in krb5_tgs, BUT it may not be due to the trimmed hash (even though that format does trim).

<!-- gh-comment-id:235368159 --> @jfoug commented on GitHub (Jul 26, 2016): 0350a1c fixes the problem with pfx_ng format (the only with with BINARY_SIZE != 0) I simply also tack on $BIN_HASH$ and the hex return from fmt->methods.binary(ct) to the end of the hash string (reducing the starting size appropriately). This fixes the already cracked removal bug. I still have to find problem in krb5_tgs, BUT it may not be due to the trimmed hash (even though that format does trim).
Author
Owner

@magnumripper commented on GitHub (Jul 28, 2016):

You keep reverting to BIN_HASH and I maintain the idea this is NOT the canonical solution. But it will do for now.

<!-- gh-comment-id:235820868 --> @magnumripper commented on GitHub (Jul 28, 2016): You keep reverting to BIN_HASH and I maintain the idea this is NOT the canonical solution. But it will do for now.
Author
Owner

@jfoug commented on GitHub (Jul 28, 2016):

It HAS to be there, or salts will not be removed from the .pot file. Trust me on that one. The only format which has a binary>0 is pfx-ng That was actually the one I started on, and that is why I thought BIN_HASH was going to be needed. BUT it is only needed when there is a binary_len > 0 and a non fmt_default_binary_hash() method defined.

It is now ONLY added, when the format has a binary. pfx-ng is the only one at this time. It is all due to how loader works, since it is loading binaries. But with the chopped hashes, we can not use the 'normal' binary() method without providing help.

<!-- gh-comment-id:235822270 --> @jfoug commented on GitHub (Jul 28, 2016): It HAS to be there, or salts will not be removed from the .pot file. Trust me on that one. The only format which has a binary>0 is pfx-ng That was actually the one I started on, and that is why I thought $BIN_HASH$ was going to be needed. BUT it is only needed when there is a binary_len > 0 and a non fmt_default_binary_hash() method defined. It is now ONLY added, when the format has a binary. pfx-ng is the only one at this time. It is all due to how loader works, since it is loading binaries. But with the chopped hashes, we can not use the 'normal' binary() method without providing help.
Author
Owner

@magnumripper commented on GitHub (Jul 28, 2016):

I trust you fully. I'm not saying it was working prior to your fix - what I am saying is this is a bug that can be fixed in some other way. I will have a look at this exact case later.

I do realize your solution may be the best one (or least intrusive) after all, and when done this way (only when needed) it does look a lot better than the version we had some time ago. We'll see.

<!-- gh-comment-id:235901508 --> @magnumripper commented on GitHub (Jul 28, 2016): I trust you fully. I'm not saying it was working prior to your fix - what I am saying is this is a bug that can be fixed in some other way. I will have a look at this exact case later. I **do** realize your solution may be the best one (or least intrusive) after all, and when done this way (only when needed) it does look a lot better than the version we had some time ago. We'll see.
Author
Owner

@jfoug commented on GitHub (Jul 28, 2016):

I agree with having this field 'optional'. For most formats, where we use a cracked[] array, and binary_length=0 (and no bin_hash), this added field would have been worthless. And right now, I think this is the only format (pfx-ng), where we trim that has a binary. Most of our trims simply use encrypt/decrypt calls into a large data blob, and do not have any binary() possibility.

<!-- gh-comment-id:235951382 --> @jfoug commented on GitHub (Jul 28, 2016): I agree with having this field 'optional'. For most formats, where we use a cracked[] array, and binary_length=0 (and no bin_hash), this added field would have been worthless. And right now, I think this is the only format (pfx-ng), where we trim that has a binary. Most of our trims simply use encrypt/decrypt calls into a large data blob, and do not have any binary() possibility.
Author
Owner

@jfoug commented on GitHub (Aug 2, 2016):

Note, we 'could' check for chopped pots automatically, with a format change.

We could add a optional (NULL or char*) field, that is the signature field (or even an array of signatures), then within loader, during .pot load, we could to a strncmp of the line (even before split/prepare, since this is from the .pot file), and if it returns 0 for the compare, then call ldr_isa_pot_source() right from within the loader code, and know up front that this is a valid line from that hash. Then we do not have to add any logic to any formats.

<!-- gh-comment-id:236897879 --> @jfoug commented on GitHub (Aug 2, 2016): Note, we 'could' check for chopped pots automatically, with a format change. We could add a optional (NULL or char*) field, that is the signature field (or even an array of signatures), then within loader, during .pot load, we could to a strncmp of the line (even before split/prepare, since this is from the .pot file), and if it returns 0 for the compare, then call ldr_isa_pot_source() right from within the loader code, and know up front that this is a valid line from that hash. Then we do not have to add any logic to any formats.
Author
Owner

@magnumripper commented on GitHub (Aug 18, 2016):

I think potcheck.pl wrapped this one up

<!-- gh-comment-id:240884721 --> @magnumripper commented on GitHub (Aug 18, 2016): I think potcheck.pl wrapped this one up
Author
Owner

@magnumripper commented on GitHub (Aug 22, 2016):

@jfoug I reverted the BIN_HASH stuff (yet again) in 977a4130 and committed an alternate fix in 7870117f. I really really believe BIN_HASH is the wrong answer to ANY problem we might encounter.

<!-- gh-comment-id:241444944 --> @magnumripper commented on GitHub (Aug 22, 2016): @jfoug I reverted the BIN_HASH stuff (yet again) in 977a4130 and committed an alternate fix in 7870117f. I really _really_ believe BIN_HASH is the wrong answer to ANY problem we might encounter.
Author
Owner

@magnumripper commented on GitHub (Sep 1, 2016):

3ae959806, 694c93eff

<!-- gh-comment-id:244205065 --> @magnumripper commented on GitHub (Sep 1, 2016): 3ae959806, 694c93eff
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#1415
No description provided.