[GH-ISSUE #2575] Add support for other mscash2 format (used by metasploit) #1690

Closed
opened 2026-10-15 04:22:31 +07:00 by bsakaguchi · 13 comments
Owner

Originally created by @Rogdham on GitHub (Jun 14, 2017).
Original GitHub issue: https://github.com/openwall/john/issues/2575

The cachedump module of metasploit returns mscash2 hash in the following form:

january:$DCC2$#january#26b5495b21f9ad58255d99b5e117abe2:domain.local:DOMAIN

(password is verylongpassword)

This format is not properly recognised by john. Although there is no iteration value, it should be using the default number (10240) just as it is the case in the following form (correctly recognised by john):

january:$DCC2$january#26b5495b21f9ad58255d99b5e117abe2:domain.local:DOMAIN

Notice that there is no # between $DCC2$ and january.

It think that adding a case just like this one should solve this issue, but I don't know the codebase well enough to be sure.

Steps to reproduce

$ echo 'january:$DCC2$#january#26b5495b21f9ad58255d99b5e117abe2:domain.local:DOMAIN' > cachedump.txt
$ echo 'verylongpassword' > password.txt
$ john cachedump.txt --format=mscash2 --wordlist=password.txt

The lines above should recover the pasword.

System configuration

Using latest bleeding-jumbo version from git:
John the Ripper 1.8.0-jumbo-1-5697-gea2f5a909+ OMP [linux-gnu 64-bit AVX2-ac]

Originally created by @Rogdham on GitHub (Jun 14, 2017). Original GitHub issue: https://github.com/openwall/john/issues/2575 The [cachedump module of metasploit](https://github.com/rapid7/metasploit-framework/blob/master/modules/post/windows/gather/cachedump.rb#L171) returns mscash2 hash in the following form: `january:$DCC2$#january#26b5495b21f9ad58255d99b5e117abe2:domain.local:DOMAIN` _(password is `verylongpassword`)_ This format is not properly recognised by john. Although there is no iteration value, it should be using the default number (10240) just as it is the case in the following form (correctly recognised by john): `january:$DCC2$january#26b5495b21f9ad58255d99b5e117abe2:domain.local:DOMAIN` _Notice that there is no `#` between `$DCC2$` and `january`._ It think that adding a case just like [this one](https://github.com/magnumripper/JohnTheRipper/blob/49a55dfdd3795d601f04076ed71e653bc43935b9/src/mscash_common_plug.c#L360) should solve this issue, but I don't know the codebase well enough to be sure. ### Steps to reproduce ``` $ echo 'january:$DCC2$#january#26b5495b21f9ad58255d99b5e117abe2:domain.local:DOMAIN' > cachedump.txt $ echo 'verylongpassword' > password.txt $ john cachedump.txt --format=mscash2 --wordlist=password.txt ``` The lines above should recover the pasword. ### System configuration Using latest bleeding-jumbo version from git: `John the Ripper 1.8.0-jumbo-1-5697-gea2f5a909+ OMP [linux-gnu 64-bit AVX2-ac]`
bsakaguchi 2026-10-15 04:22:31 +07:00
Author
Owner

@kholia commented on GitHub (Jun 15, 2017):

@magnumripper The following patch adds support for such hashes,

diff --git a/src/mscash_common_plug.c b/src/mscash_common_plug.c
index fbc2121..a6af781 100644
--- a/src/mscash_common_plug.c
+++ b/src/mscash_common_plug.c
@@ -221,6 +221,7 @@ struct fmt_tests mscash2_common_tests[] = {
        // Non-standard iterations count
        {"$DCC2$10000#Twelve_chars#54236c670e185043c8016006c001e982", "magnum"},
        {"$DCC2$january#26b5495b21f9ad58255d99b5e117abe2", "verylongpassword" },
+       {"$DCC2$#january#26b5495b21f9ad58255d99b5e117abe2", "verylongpassword"},  // metasploit cachedump format
        {"$DCC2$february#469375e08b5770b989aa2f0d371195ff", "(##)(&#*%%" },
        {"$DCC2$john-the-ripper#495c800a038d11e55fafc001eb689d1d", "batman#$@#1991" },
        {"$DCC2$#59137848828d14b1fca295a5032b52a1", "a" }, //Empty Salt
@@ -368,6 +369,19 @@ char *mscash2_common_prepare(char *split_fields[10], struct fmt_main *self)
                MEM_FREE(cp);
                return split_fields[1];
        }
+       // make $DCC2$#salt#hash format hashes into $DCC2$10240#salt#hash (insert 10240 into the line)
+       if (!strncmp(split_fields[1], FORMAT_TAG2, FORMAT_TAG2_LEN) &&
+           strstr(split_fields[1], "$DCC2$") + 6 == strchr(split_fields[1], '#')) {
+               cp = mem_alloc(strlen(split_fields[1]) + 6);
+               sprintf(cp, "%s10240%s", FORMAT_TAG2, &(split_fields[1][6]));
+               if (mscash2_common_valid(cp, 128, self)) {
+                       char *cipher = str_alloc_copy(cp);
+                       MEM_FREE(cp);
+                       return cipher;
+               }
+               MEM_FREE(cp);
+               return split_fields[1];
+       }
        if (!split_fields[0])
                return split_fields[1];

Does it look correct?

<!-- gh-comment-id:308627957 --> @kholia commented on GitHub (Jun 15, 2017): @magnumripper The following patch adds support for such hashes, ``` diff --git a/src/mscash_common_plug.c b/src/mscash_common_plug.c index fbc2121..a6af781 100644 --- a/src/mscash_common_plug.c +++ b/src/mscash_common_plug.c @@ -221,6 +221,7 @@ struct fmt_tests mscash2_common_tests[] = { // Non-standard iterations count {"$DCC2$10000#Twelve_chars#54236c670e185043c8016006c001e982", "magnum"}, {"$DCC2$january#26b5495b21f9ad58255d99b5e117abe2", "verylongpassword" }, + {"$DCC2$#january#26b5495b21f9ad58255d99b5e117abe2", "verylongpassword"}, // metasploit cachedump format {"$DCC2$february#469375e08b5770b989aa2f0d371195ff", "(##)(&#*%%" }, {"$DCC2$john-the-ripper#495c800a038d11e55fafc001eb689d1d", "batman#$@#1991" }, {"$DCC2$#59137848828d14b1fca295a5032b52a1", "a" }, //Empty Salt @@ -368,6 +369,19 @@ char *mscash2_common_prepare(char *split_fields[10], struct fmt_main *self) MEM_FREE(cp); return split_fields[1]; } + // make $DCC2$#salt#hash format hashes into $DCC2$10240#salt#hash (insert 10240 into the line) + if (!strncmp(split_fields[1], FORMAT_TAG2, FORMAT_TAG2_LEN) && + strstr(split_fields[1], "$DCC2$") + 6 == strchr(split_fields[1], '#')) { + cp = mem_alloc(strlen(split_fields[1]) + 6); + sprintf(cp, "%s10240%s", FORMAT_TAG2, &(split_fields[1][6])); + if (mscash2_common_valid(cp, 128, self)) { + char *cipher = str_alloc_copy(cp); + MEM_FREE(cp); + return cipher; + } + MEM_FREE(cp); + return split_fields[1]; + } if (!split_fields[0]) return split_fields[1]; ``` Does it look correct?
Author
Owner

@frank-dittrich commented on GitHub (Jun 15, 2017):

        {"$DCC2$january#26b5495b21f9ad58255d99b5e117abe2", "verylongpassword" },
+       {"$DCC2$#january#26b5495b21f9ad58255d99b5e117abe2", "verylongpassword"},  // metasploit cachedump format

What if #january is used as a salt in our current implementation?

May be we replaced $# with $ some time in the past, to get rid of the unnecessary #.?
If metasploit uses $# here, we should as well, and add a comment.
(Or metasploit can be changed.)

<!-- gh-comment-id:308632983 --> @frank-dittrich commented on GitHub (Jun 15, 2017): ``` {"$DCC2$january#26b5495b21f9ad58255d99b5e117abe2", "verylongpassword" }, + {"$DCC2$#january#26b5495b21f9ad58255d99b5e117abe2", "verylongpassword"}, // metasploit cachedump format ``` What if `#january` is used as a salt in our current implementation? May be we replaced `$#` with `$` some time in the past, to get rid of the unnecessary `#`.? If metasploit uses `$#` here, we should as well, and add a comment. (Or metasploit can be changed.)
Author
Owner

@Rogdham commented on GitHub (Jun 15, 2017):

Does it look correct?

I don't know enough all mscash2 formats to know for sure, but I can confirm that @kholia's patch allows to crack the hash output by metasploit.

(Or metasploit can be changed.)

I've open a bug report.

However, I think that is would be better if john does crack this format because there will always be people running older versions of metasploit, plus the format may be used in other tools as well.

<!-- gh-comment-id:308639570 --> @Rogdham commented on GitHub (Jun 15, 2017): > Does it look correct? I don't know enough all mscash2 formats to know for sure, but I can confirm that @kholia's patch allows to crack the hash output by metasploit. > (Or metasploit can be changed.) I've open [a bug report](https://github.com/rapid7/metasploit-framework/issues/8560). However, I think that is would be better if john does crack this format because there will always be people running older versions of metasploit, plus the format may be used in other tools as well.
Author
Owner

@jfoug commented on GitHub (Jun 15, 2017):

What if a '#' char is used ANYWHERE in the salt?? I think we need to find the 32 byte hex string that is appended by the '#' char and the salt preceeds that. However, @frank-dittrich is right, even doing that, we will not be able to handle a salt that starts with a # char, once we take this route. It would almost be better to make a pre-processing tool for these hashes, that convert them INTO johns canonical format, and not handle these natively. Knowledge that the '#' starting a salt will render john unusable might be used, by intelligent people.

As was also listed, metasploit should not have made up their own hash format...... but used the existing defacto format.

Just saying.

<!-- gh-comment-id:308715936 --> @jfoug commented on GitHub (Jun 15, 2017): What if a '#' char is used ANYWHERE in the salt?? I think we need to find the 32 byte hex string that is appended by the '#' char and the salt preceeds that. However, @frank-dittrich is right, even doing that, we will not be able to handle a salt that starts with a # char, once we take this route. It would almost be better to make a pre-processing tool for these hashes, that convert them INTO johns canonical format, and not handle these natively. Knowledge that the '#' starting a salt will render john unusable might be used, by intelligent people. As was also listed, metasploit should not have made up their own hash format...... but used the existing defacto format. Just saying.
Author
Owner

@Rogdham commented on GitHub (Jun 15, 2017):

Just to be sure that I understand things correctly:

  • currently, the hash $DCC2$#january#26b5495b21f9ad58255d99b5e117abe2 is understood by john as 10240 iterations with salt #january
  • you point out that if we modify that behaviour as 10240 iterations with salt january, we will not be able to crack hash with salt starting with #

Assuming the above is true, could we not just use the following hash for #january as salt : $DCC2$10240##january#26b5495b21f9ad58255d99b5e117abe2 (i.e. double #) ?

If so, it is just a matter of what should be the default understanding of the $DCC2$#january#26b5495b21f9ad58255d99b5e117abe2 format. In that case, I am not sure. metasploit is using that format (i.e. meaning january as salt), what tools use the same format with the other meaning (i.e. #january as salt)?

<!-- gh-comment-id:308724426 --> @Rogdham commented on GitHub (Jun 15, 2017): Just to be sure that I understand things correctly: * currently, the hash `$DCC2$#january#26b5495b21f9ad58255d99b5e117abe2` is understood by john as 10240 iterations with salt `#january` * you point out that if we modify that behaviour as 10240 iterations with salt `january`, we will not be able to crack hash with salt starting with `#` Assuming the above is true, could we not just use the following hash for `#january` as salt : `$DCC2$10240##january#26b5495b21f9ad58255d99b5e117abe2` (i.e. double `#`) ? If so, it is just a matter of what should be the default understanding of the `$DCC2$#january#26b5495b21f9ad58255d99b5e117abe2` format. In that case, I am not sure. metasploit is using that format (i.e. meaning `january` as salt), what tools use the same format with the other meaning (i.e. `#january` as salt)?
Author
Owner

@frank-dittrich commented on GitHub (Jun 15, 2017):

What is hashcat using? I think, if metasploit and hashcat use the same layout, john should be adjusted, and the need for the extra # should be documented.

<!-- gh-comment-id:308725262 --> @frank-dittrich commented on GitHub (Jun 15, 2017): What is hashcat using? I think, if metasploit and hashcat use the same layout, john should be adjusted, and the need for the extra # should be documented.
Author
Owner

@Rogdham commented on GitHub (Jun 15, 2017):

I was also thinking: what is the current way to mean 20480 iterations with salt #january?

<!-- gh-comment-id:308725835 --> @Rogdham commented on GitHub (Jun 15, 2017): I was also thinking: what is the current way to mean 20480 iterations with salt `#january`?
Author
Owner

@magnumripper commented on GitHub (Jun 16, 2017):

As was also listed, metasploit should not have made up their own hash format...... but used the existing defacto format.

Definitely agreed. Our mscash2 format pre-dates the whole metasploit project AFAIK. I vote for not working around their mistakes unless we are really forced to.

I was also thinking: what is the current way to mean 20480 iterations with salt #january?

That would be $DCC2$20480##januari#c6758e5be7fc943d00b97972a8a97620. We find the last # searching backwards from end. We should add a test vector for this case.

<!-- gh-comment-id:308945038 --> @magnumripper commented on GitHub (Jun 16, 2017): > As was also listed, metasploit should not have made up their own hash format...... but used the existing defacto format. Definitely agreed. Our mscash2 format pre-dates the whole metasploit project AFAIK. I vote for **not** working around their mistakes unless we are really forced to. > I was also thinking: what is the current way to mean 20480 iterations with salt #january? That would be `$DCC2$20480##januari#c6758e5be7fc943d00b97972a8a97620`. We find the last `#` searching backwards from end. We should add a test vector for this case.
Author
Owner

@Rogdham commented on GitHub (Jun 16, 2017):

As was also listed, metasploit should not have made up their own hash format...... but used the existing defacto format.
Definitely agreed. Our mscash2 format pre-dates the whole metasploit project AFAIK. I vote for not working around their mistakes unless we are really forced to.

My point was that if john can add metasploit's format without having any side effect, then that format could just be added. However, if that would break anything, I would be ok with just closing that issue.

As far as I understand this, it would break the current behaviour when no iteration count is specified, and the salt starts with a # (note that this hash would be still crackable by re-formatting it, see below). @magnumripper: could you confirm and do you think that this case is a dealbreaker?

I was also thinking: what is the current way to mean 20480 iterations with salt #january?
That would be $DCC2$20480##januari#c6758e5be7fc943d00b97972a8a97620. We find the last # searching backwards from end. We should add a test vector for this case.

Ok, makes sense. In that case, $DCC2$10240##january#26b5495b21f9ad58255d99b5e117abe2 should work to handle salts starting with # (in answer of the part of @jfoug's comment above).

<!-- gh-comment-id:308954381 --> @Rogdham commented on GitHub (Jun 16, 2017): > As was also listed, metasploit should not have made up their own hash format...... but used the existing defacto format. > Definitely agreed. Our mscash2 format pre-dates the whole metasploit project AFAIK. I vote for not working around their mistakes unless we are really forced to. My point was that if john can add metasploit's format without having any side effect, then that format could just be added. However, if that would break anything, I would be ok with just closing that issue. As far as I understand this, it would break the current behaviour when no iteration count is specified, and the salt starts with a `#` (note that this hash would be still crackable by re-formatting it, see below). @magnumripper: could you confirm and do you think that this case is a dealbreaker? > I was also thinking: what is the current way to mean 20480 iterations with salt #january? > That would be $DCC2$20480##januari#c6758e5be7fc943d00b97972a8a97620. We find the last # searching backwards from end. We should add a test vector for this case. Ok, makes sense. In that case, `$DCC2$10240##january#26b5495b21f9ad58255d99b5e117abe2` should work to handle salts starting with `#` (in answer of the part of @jfoug's comment above).
Author
Owner

@magnumripper commented on GitHub (Jun 16, 2017):

We find the last # searching backwards from end. We should add a test vector for this case.

There were actually bugs in some code paths. All should be fixed now (test vectors are added)

My point was that if john can add metasploit's format without having any side effect, then that format could just be added.

Absolutely. I looked into that but unfortunately it would break things. AFAIK we have always parsed $DCC2$#january#26b5495b21f9ad58255d99b5e117abe2 as a salt of #january. Metasploit needs to fix their code. BTW in your issue there (https://github.com/rapid7/metasploit-framework/issues/8560) you should point out to them that the current format isn't correct and never was. That is, not listing iteration count is supported (albeit stupid) but then it has to be written as $DCC2$january#26b5495b21f9ad58255d99b5e117abe2 without the extra #.

BTW hashcat does parse the current Metasploit hash correctly but OTOH hashcat doesn't support a salt including # at all (which is a bug IMHO).

Bottom line is we're not going to add a workaround for this case, so I'm closing. But feel free to comment further or challenge my opinions 😉

<!-- gh-comment-id:309011263 --> @magnumripper commented on GitHub (Jun 16, 2017): > We find the last # searching backwards from end. We should add a test vector for this case. There were actually bugs in some code paths. All should be fixed now (test vectors are added) > My point was that if john can add metasploit's format without having any side effect, then that format could just be added. Absolutely. I looked into that but unfortunately it would break things. AFAIK we have always parsed `$DCC2$#january#26b5495b21f9ad58255d99b5e117abe2` as a salt of `#january`. Metasploit needs to fix their code. BTW in your issue there (https://github.com/rapid7/metasploit-framework/issues/8560) you should point out to them that the current format isn't correct and never was. That is, not listing iteration count *is* supported (albeit stupid) but then it has to be written as `$DCC2$january#26b5495b21f9ad58255d99b5e117abe2` without the extra `#`. BTW hashcat does parse the current Metasploit hash correctly but OTOH hashcat doesn't support a salt including `#` at all (which is a bug IMHO). Bottom line is we're not going to add a workaround for this case, so I'm closing. But feel free to comment further or challenge my opinions 😉
Author
Owner

@frank-dittrich commented on GitHub (Jun 16, 2017):

@magnumripper Did you check our git history?
May be we used the extra # in the past, metasploit and hashcat copied it from us, and then we dropped it.

<!-- gh-comment-id:309011841 --> @frank-dittrich commented on GitHub (Jun 16, 2017): @magnumripper Did you check our git history? May be we used the extra # in the past, metasploit and hashcat copied it from us, and then we dropped it.
Author
Owner

@Rogdham commented on GitHub (Jun 16, 2017):

Ok, I will go back to metasploit to make sure that they output correct hashes.

Many thanks to all of you for the time you took looking at this issue! 👍

<!-- gh-comment-id:309031697 --> @Rogdham commented on GitHub (Jun 16, 2017): Ok, I will go back to metasploit to make sure that they output correct hashes. Many thanks to all of you for the time you took looking at this issue! :+1:
Author
Owner

@magnumripper commented on GitHub (Jun 16, 2017):

@magnumripper Did you check our git history? May be we used the extra # in the past, metasploit and hashcat copied it from us, and then we dropped it.

I didn't bother but it doesn't matter. The format they use aren't shown in any sample nor documented anywhere. It's got to be a mistake.

<!-- gh-comment-id:309065797 --> @magnumripper commented on GitHub (Jun 16, 2017): > @magnumripper Did you check our git history? May be we used the extra # in the past, metasploit and hashcat copied it from us, and then we dropped it. I didn't bother but it doesn't matter. The format they use aren't shown in any sample nor documented anywhere. It's got to be a mistake.
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#1690
No description provided.