[GH-ISSUE #1300] Parameters that expect integer values: #826

Open
opened 2026-10-14 03:25:28 +07:00 by bsakaguchi · 4 comments
Owner

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

Originally assigned to: @solardiz on GitHub.

$ ./john --test=2--format=sunmd5
Will run 8 OpenMP threads
Benchmarking: descrypt, traditional crypt(3) [DES 128/128 AVX-16]... (8xOMP) DONE
Many salts: 15040K c/s real, 1888K c/s virtual
Only one salt:  11911K c/s real, 1498K c/s virtual

Benchmarking: bsdicrypt, BSDI crypt(3) ("_J9..", 725 iterations) [DES 128/128 AVX-16]... (8xOMP) DONE
Many salts: 467968 c/s real, 58605 c/s virtual
Only one salt:  399410 c/s real, 50333 c/s virtual

Benchmarking: md5crypt, crypt(3) $1$ [MD5 128/128 AVX 4x3]... (8xOMP) DONE
Raw:    116736 c/s real, 14619 c/s virtual

Benchmarking: bcrypt ("$2a$05", 32 iterations) [Blowfish 32/64 X2]... (8xOMP) ^CWait...
Session aborted

Accidentally, I forgot a space between --test=2 and --format=sunmd5, and got what I didn't intend.

I can reproduce on master, will post this to john-dev as well:

$ ./john --test=1--format=md5crypt
Benchmarking: descrypt, traditional crypt(3) [DES 128/128 AVX-16]... DONE
Many salts: 4476K c/s real, 4476K c/s virtual
Only one salt:  4596K c/s real, 4596K c/s virtual

Benchmarking: bsdicrypt, BSDI crypt(3) ("_J9..", 725 iterations) [DES 128/128 AVX-16]... DONE
Many salts: 172160 c/s real, 172160 c/s virtual
Only one salt:  167808 c/s real, 167808 c/s virtual

Benchmarking: md5crypt [MD5 32/64 X2]... DONE
Raw:    13086 c/s real, 13086 c/s virtual

Benchmarking: bcrypt ("$2a$05", 32 iterations) [Blowfish 32/64 X2]... ^CWait...
Session aborted
Originally created by @frank-dittrich on GitHub (May 11, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1300 Originally assigned to: @solardiz on GitHub. ``` $ ./john --test=2--format=sunmd5 Will run 8 OpenMP threads Benchmarking: descrypt, traditional crypt(3) [DES 128/128 AVX-16]... (8xOMP) DONE Many salts: 15040K c/s real, 1888K c/s virtual Only one salt: 11911K c/s real, 1498K c/s virtual Benchmarking: bsdicrypt, BSDI crypt(3) ("_J9..", 725 iterations) [DES 128/128 AVX-16]... (8xOMP) DONE Many salts: 467968 c/s real, 58605 c/s virtual Only one salt: 399410 c/s real, 50333 c/s virtual Benchmarking: md5crypt, crypt(3) $1$ [MD5 128/128 AVX 4x3]... (8xOMP) DONE Raw: 116736 c/s real, 14619 c/s virtual Benchmarking: bcrypt ("$2a$05", 32 iterations) [Blowfish 32/64 X2]... (8xOMP) ^CWait... Session aborted ``` Accidentally, I forgot a space between `--test=2` and `--format=sunmd5`, and got what I didn't intend. I can reproduce on master, will post this to john-dev as well: ``` $ ./john --test=1--format=md5crypt Benchmarking: descrypt, traditional crypt(3) [DES 128/128 AVX-16]... DONE Many salts: 4476K c/s real, 4476K c/s virtual Only one salt: 4596K c/s real, 4596K c/s virtual Benchmarking: bsdicrypt, BSDI crypt(3) ("_J9..", 725 iterations) [DES 128/128 AVX-16]... DONE Many salts: 172160 c/s real, 172160 c/s virtual Only one salt: 167808 c/s real, 167808 c/s virtual Benchmarking: md5crypt [MD5 32/64 X2]... DONE Raw: 13086 c/s real, 13086 c/s virtual Benchmarking: bcrypt ("$2a$05", 32 iterations) [Blowfish 32/64 X2]... ^CWait... Session aborted ```
Author
Owner

@frank-dittrich commented on GitHub (May 11, 2015):

As mentioned in http://openwall.com/lists/john-dev/2015/05/11/24. negative values shouldn't be allowed, either:

$ time ./john --test=-2 --format=descrypt
Benchmarking: descrypt, traditional crypt(3) [DES 128/128 AVX-16]...
^CWait...
Session aborted

real    0m38.544s
user    0m38.519s
sys    0m0.004s
<!-- gh-comment-id:101052842 --> @frank-dittrich commented on GitHub (May 11, 2015): As mentioned in http://openwall.com/lists/john-dev/2015/05/11/24. negative values shouldn't be allowed, either: ``` $ time ./john --test=-2 --format=descrypt Benchmarking: descrypt, traditional crypt(3) [DES 128/128 AVX-16]... ^CWait... Session aborted real 0m38.544s user 0m38.519s sys 0m0.004s ```
Author
Owner

@jfoug commented on GitHub (Jun 1, 2015):

Frank, the problem here is that what is used to parse these, is sscanf is used to parse, along with printf styled tokenized params. There is little more than this for context on how to parse.

So for --test we have this format: "%u" and this is the actual input that does the parse:

return sscanf(param, format, buffer) != 1;

So, sscanf with "%u" for 2xx is 2, and returns 1, so the code is 'happy'
also sscanf with "%u" for -2 is MAX_UINT-2 and the return is 1. So again the code is happy

I am not sure of what validation we can perform at all, without a total re-write of this logic. There 'might' be a way to do this to some extent, using a buffer, and sprintf, then comparing to see if original buffer and new buffer are the same, but it may be problematic. I can give that a shot and see.

<!-- gh-comment-id:107604127 --> @jfoug commented on GitHub (Jun 1, 2015): Frank, the problem here is that what is used to parse these, is sscanf is used to parse, along with printf styled tokenized params. There is little more than this for context on how to parse. So for --test we have this format: "%u" and this is the actual input that does the parse: return sscanf(param, format, buffer) != 1; So, sscanf with "%u" for 2xx is 2, and returns 1, so the code is 'happy' also sscanf with "%u" for -2 is MAX_UINT-2 and the return is 1. So again the code is happy I am not sure of what validation we can perform at all, without a total re-write of this logic. There 'might' be a way to do this to some extent, using a buffer, and sprintf, then comparing to see if original buffer and new buffer are the same, but it may be problematic. I can give that a shot and see.
Author
Owner

@magnumripper commented on GitHub (Jun 1, 2015):

This is core code, I suggest we just live with it as long as Solar doesn't change it. If he does, we might want to improve Jumbo-specific parsing too.

<!-- gh-comment-id:107611102 --> @magnumripper commented on GitHub (Jun 1, 2015): This is core code, I suggest we just live with it as long as Solar doesn't change it. If he does, we might want to improve Jumbo-specific parsing too.
Author
Owner

@jfoug commented on GitHub (Jun 1, 2015):

Here is a simple 'parse' improvement for signed and unsigned int's (which almost ALL % types are)

Since this is core code, I do agree with you, however.

--- src/getopt.c    Mon Jan 19 16:26:36 1970
+++ src/getopt.c    Mon Jan 19 16:26:36 1970
@@ -90,8 +90,20 @@
    if (format[0] == OPT_FMT_ADD_LIST_MULTI[0]) {
        list_add_multi(*(struct list_main **)buffer, param);
        return 0;
-   } else
-       return sscanf(param, format, buffer) != 1;
+   } else {
+       char tmp[32];
+       int ret;
+       ret = sscanf(param, format, buffer);
+       if (ret != 1) return 1;
+       if (!strcmp(format, "%u") ||
+           !strcmp(format, "%d"))
+       {
+           sprintf(tmp, format, *(unsigned**)buffer);
+           ret = strcmp(tmp, param);
+       }
+       return ret;
+       //return sscanf(param, format, buffer) != 1;
+   }
 }

 static int opt_process_one(struct opt_entry *list, opt_flags *flg, char *opt)
<!-- gh-comment-id:107622753 --> @jfoug commented on GitHub (Jun 1, 2015): Here is a simple 'parse' improvement for signed and unsigned int's (which almost ALL % types are) Since this is core code, I do agree with you, however. ``` patch --- src/getopt.c Mon Jan 19 16:26:36 1970 +++ src/getopt.c Mon Jan 19 16:26:36 1970 @@ -90,8 +90,20 @@ if (format[0] == OPT_FMT_ADD_LIST_MULTI[0]) { list_add_multi(*(struct list_main **)buffer, param); return 0; - } else - return sscanf(param, format, buffer) != 1; + } else { + char tmp[32]; + int ret; + ret = sscanf(param, format, buffer); + if (ret != 1) return 1; + if (!strcmp(format, "%u") || + !strcmp(format, "%d")) + { + sprintf(tmp, format, *(unsigned**)buffer); + ret = strcmp(tmp, param); + } + return ret; + //return sscanf(param, format, buffer) != 1; + } } static int opt_process_one(struct opt_entry *list, opt_flags *flg, char *opt) ```
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#826
No description provided.