[GH-ISSUE #2889] 7z2john.pl treats CRC as a signed value #1831

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

Originally created by @kholia on GitHub (Nov 15, 2017).
Original GitHub issue: https://github.com/openwall/john/issues/2889

See https://github.com/hashcat/hashcat/issues/1450 for details.

hash.txt <- sample hash to demonstrate the problem.

The following incorrect patch enables loading and cracking of this hash with JtR,

diff --git a/src/7z_fmt_plug.c b/src/7z_fmt_plug.c
index feab12c..903778f 100644
--- a/src/7z_fmt_plug.c
+++ b/src/7z_fmt_plug.c
@@ -247,8 +247,6 @@ static int valid(char *ciphertext, struct fmt_main *self)
                goto err;
        if ((p = strtokm(NULL, "$")) == NULL) /* crc */
                goto err;
-       if (!isdecu(p))
-               goto err;
        if ((p = strtokm(NULL, "$")) == NULL) /* data length */
                goto err;
        if (!isdec(p))

If we change -914293439 (CRC field) to unsigned int 3380673857, then the hash is cracked just fine without any changes.

The actual issue seems to be in 7z2john.pl (and upstream too I believe). The $hash_buf = sprintf line uses the %i format specifier. I believe that we should be using the %u format specifier for the CRC field. We need to treat the CRC value as an unsigned integer value.

CC'ing @philsmd for his advice.

Code in question,

  $hash_buf = sprintf ("%s:%s%i\$%i\$%i\$%s\$%i\$%s\$%i\$%i\$%i\$%s",
    ...
    unpack ("H*", $iv_buf),
    $crc,
    $data_len,
    $unpack_size,
    unpack ("H*", $data)
  )
Originally created by @kholia on GitHub (Nov 15, 2017). Original GitHub issue: https://github.com/openwall/john/issues/2889 See https://github.com/hashcat/hashcat/issues/1450 for details. [hash.txt](https://github.com/magnumripper/JohnTheRipper/files/1475738/hash.txt) <- sample hash to demonstrate the problem. The following incorrect patch enables loading and cracking of this hash with JtR, ``` diff --git a/src/7z_fmt_plug.c b/src/7z_fmt_plug.c index feab12c..903778f 100644 --- a/src/7z_fmt_plug.c +++ b/src/7z_fmt_plug.c @@ -247,8 +247,6 @@ static int valid(char *ciphertext, struct fmt_main *self) goto err; if ((p = strtokm(NULL, "$")) == NULL) /* crc */ goto err; - if (!isdecu(p)) - goto err; if ((p = strtokm(NULL, "$")) == NULL) /* data length */ goto err; if (!isdec(p)) ``` If we change `-914293439` (CRC field) to unsigned int `3380673857`, then the hash is cracked just fine without any changes. The actual issue seems to be in `7z2john.pl` (and upstream too I believe). The `$hash_buf = sprintf` line uses the `%i` format specifier. I believe that we should be using the `%u` format specifier for the CRC field. We need to treat the CRC value as an unsigned integer value. CC'ing @philsmd for his advice. Code in question, ``` $hash_buf = sprintf ("%s:%s%i\$%i\$%i\$%s\$%i\$%s\$%i\$%i\$%i\$%s", ... unpack ("H*", $iv_buf), $crc, $data_len, $unpack_size, unpack ("H*", $data) ) ```
bsakaguchi 2026-10-15 04:26:15 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

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

Here is a slightly better approach if we want to support "negative" CRC values.

$ git diff
diff --git a/src/7z_fmt_plug.c b/src/7z_fmt_plug.c
index feab12c..7ebfdc8 100644
--- a/src/7z_fmt_plug.c
+++ b/src/7z_fmt_plug.c
@@ -247,7 +247,7 @@ static int valid(char *ciphertext, struct fmt_main *self)
                goto err;
        if ((p = strtokm(NULL, "$")) == NULL) /* crc */
                goto err;
-       if (!isdecu(p))
+       if (!isdecu(p) && !isdec_negok(p))
                goto err;
        if ((p = strtokm(NULL, "$")) == NULL) /* data length */
                goto err;
<!-- gh-comment-id:344893673 --> @kholia commented on GitHub (Nov 16, 2017): Here is a slightly better approach if we want to support "negative" CRC values. ``` $ git diff diff --git a/src/7z_fmt_plug.c b/src/7z_fmt_plug.c index feab12c..7ebfdc8 100644 --- a/src/7z_fmt_plug.c +++ b/src/7z_fmt_plug.c @@ -247,7 +247,7 @@ static int valid(char *ciphertext, struct fmt_main *self) goto err; if ((p = strtokm(NULL, "$")) == NULL) /* crc */ goto err; - if (!isdecu(p)) + if (!isdecu(p) && !isdec_negok(p)) goto err; if ((p = strtokm(NULL, "$")) == NULL) /* data length */ goto err; ```
Author
Owner

@philsmd commented on GitHub (Nov 16, 2017):

Hey,
thanks for the report.

I also noticed this "problem" within the hashcat's issue you linked above, but it didn't really made any difference for hashcat (hashcat parsed it correctly anyways).

I agree that this is not really expected behaviour and therefore I pushed this fix for 7z2hashcat:
github.com/philsmd/7z2hashcat@9d37dc9edc

We shouldn't use signed integers at all within the hash format for 7zip, I replaced all of them.

Thanks again. I think this issue can be closed too whenever you update 7z2john to the newest version.

<!-- gh-comment-id:344905909 --> @philsmd commented on GitHub (Nov 16, 2017): Hey, thanks for the report. I also noticed this "problem" within the hashcat's issue you linked above, but it didn't really made any difference for hashcat (hashcat parsed it correctly anyways). I agree that this is not really expected behaviour and therefore I pushed this fix for 7z2hashcat: https://github.com/philsmd/7z2hashcat/commit/9d37dc9edc1137a67d21ccb35d52729bb258ffa4 We shouldn't use signed integers at all within the hash format for 7zip, I replaced all of them. Thanks again. I think this issue can be closed too whenever you update 7z2john to the newest version.
Author
Owner

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

Thanks @philsmd. I will backport this change very soon.

<!-- gh-comment-id:344914995 --> @kholia commented on GitHub (Nov 16, 2017): Thanks @philsmd. I will backport this change very soon.
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#1831
No description provided.