mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #2425] very bad (and decreasing) performance on mode "Single" in certain circumstances #1612
Labels
No labels
bug
core branch
documentation
enhancement
enhancement
fixed - pending verify
fuzz bug
good first issue
invalid
invalid
maintenance/cleanup
new cracking mode
new format
new tool
non-trivial
notes/external issues
portability
question
RFC / discussion
testing
WONTFIX
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openwall/john#1612
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @p4tpr0 on GitHub (Feb 12, 2017).
Original GitHub issue: https://github.com/openwall/john/issues/2425
Originally assigned to: @jfoug on GitHub.
I have a hash file where every line looks like this:
candidate:$dynamic_25$hash$salt
"candidate" is a very serious password candidate to test, with 50-60% success rate without even using mangling rules.
When using mode "single" on this big hash file with "SingleRetestGuessed = N" and no rules, I see a bad performance that decrease along the cracking session. Sample session:
The performance is good if none of the candidates matches its hash, or if each candidate matches its hash. The performance is very bad if the file is a mix of both cases.
How to reproduce:
Memory consumption is quite high also, but performance is my main concern here.
John build-info:
Version: 1.8.0.9-jumbo-1-bleeding
Build: freebsd10.3 64-bit AVX-ac
SIMD: AVX, interleaving: MD4:3 MD5:3 SHA1:1 SHA256:1 SHA512:1
$JOHN is ./
Format interface version: 14
Max. number of reported tunable costs: 3
Rec file version: REC4
Charset file version: CHR3
CHARSET_MIN: 1 (0x01)
CHARSET_MAX: 255 (0xff)
CHARSET_LENGTH: 24
SALT_HASH_SIZE: 1048576
Max. Markov mode level: 400
Max. Markov mode password length: 30
gcc version: 5.4.0
Crypto library: OpenSSL
OpenSSL library version: 020000000 (loaded: 01000113f)
LibreSSL 2.4.4 (loaded: OpenSSL 1.0.1s-freebsd 1 Mar 2016)
GMP library version: 5.1.3
File locking: fcntl()
fseek(): fseek
ftell(): ftell
fopen(): fopen
memmem(): System's
Full discussion on the mailing-list:
http://www.openwall.com/lists/john-users/2017/02/02/1
@jfoug commented on GitHub (Feb 14, 2017):
Note, this bug has nothing to do with the min-cracks == 64 in dynamic. But I am going to see if that can be reduced to 1, since that DOES impact memory greatly, but I think that reduction will also greatly impact single throughput, when normal single rules are used. Dyna has a LOT of overhead. Reducing it to 1 (or SIMD_COEF) will make other runs of single run at probably 10-20% of what they should.
I have done a bit of single stepping, and I have not found where this problem is located at. I will look more when I have more time.
@magnumripper commented on GitHub (Jan 8, 2018):
The min. keys per crypt should always be (SIMD_COEF * SIMD_PARA * THREADS) as far as I know. Bumping it to 64 doesn't make any sense to me.
@magnumripper commented on GitHub (Dec 19, 2018):
I believe recent changes to single mode should have fixed this issue (eg. by automagically limiting max. plaintext length down to 16 if needed), and/or added some warning for what's the cause (i.e. memory constraints).
@magnumripper commented on GitHub (Dec 20, 2018):
Now I'm instead pretty sure this is another symthom of #3417...
@jfoug commented on GitHub (Dec 23, 2018):
@p4tpr0 Please validate after these fixes: #3556 and #3547
Once validated on your end, please close this bug.
@p4tpr0 commented on GitHub (Jan 9, 2019):
Well, I guess I can conclude it's now worst than what it was when I've opened this issue:
code from 201702:
code as of today:
both compiled on FreeBSD 11.2-RELEASE:
At least on FreeBSD I can load my whole hash file (1M lines). Current code compiled on Ubuntu 16 LTS just wont load a file that large unless I provide 123 GB RAM:
I've managed to test with a 100K lines file + SingleMaxBufferSize set to 16GB, same performance decrease over time:
@magnumripper commented on GitHub (Jan 9, 2019):
How much real RAM does that FreeBSD gear have? And how much on the Ubuntu system? Are you sure they didn't start swapping? That would explain the whole problem. The warnings are new but the problem was always there: Single mode needs memory for a full batch of full-length plaintexts plus indeces and hash tables per salt, and a million salts are a lot.
@p4tpr0 commented on GitHub (Jan 10, 2019):
No swap: both machines have 32 GB RAM. FreeBSD box is used for many other things. It has about 5GB Free RAM, and process for current code takes less than 2GB RAM for 1M hashes:
On Ubuntu, most memory is free, and john has to be tuned to accept a 100K hashes file (SingleMaxBufferSize to 16GB). It consumes a lot more memory but won't swap:
@magnumripper commented on GitHub (Jan 11, 2019):
OK, I see now that FBSD machine doesn't use SIMD while the Ubuntu has AVX2 so 8x larger batch size (and that does sum up the 2 GB vs. 16 GB).
The problem is likely related to your disabling of rules. What if you try normal single rules, is performance figures better then? Are you not getting warnings about low number of candidates?
@p4tpr0 commented on GitHub (Jan 12, 2019):
On FreeBSD, code from 20190109:
no warning and same decreasing performance.
@magnumripper commented on GitHub (Jan 12, 2019):
Well the decrease is now moderate - from 2049K at best, to 1847K. That's no big deal, is it? Some rules process very fast, some fairly slow - this is completely normal. Your initial post showed a steady decrease from 5563 to 791, that's more alarming. Not to mention your last post is 500 times faster than that (note the K vs. no K)!
I really don't get why the p/s is not in sync with c/s in your last post though. @solardiz any clue?
@solardiz commented on GitHub (Jan 12, 2019):
I guess buffers for more salts fill up and are actually tested against those salts, which takes time and results in testing of more {candidate password, salt} combinations (thus, steady c/s and C/s), but does't result in more candidate passwords being introduced for testing against any salts (thus, decreasing p/s). In other words, initial p/s may have been "inflated" by testing those new candidate passwords against smaller subsets of salts only, which ceases to be the case the longer we run with
SingleRetestGuessedset (I don't know if it was set or not in this run - but I guess that it was?) At ~900k remaining salts and going at ~1.8M c/s, the target p/s is around 2, so even the ~80 p/s we see at the 9 minute mark is still heavily "inflated".@solardiz commented on GitHub (Jan 12, 2019):
On a related note, the hashing speeds of ~2M c/s seem very low for this format (even on one core, which I think it is). I'm surprised this was the case even in the AVX2 build. Where are we wasting so much CPU time?
Also, the "64/64" reporting is almost certainly wrong for a non-SIMD build here, because SHA-1 can't use more than 32 bits in that case. Should be "32/64". This is probably something for @jfoug to fix.
@solardiz commented on GitHub (Jan 12, 2019):
When running with
SingleRetestGuessedwe skip counting the firstsalt->keys->count_from_guessescandidates per salt towardsstatus.candsincrk_process_salt(). This is correct since this many guesses are presumed to have already been tried against another salt (and success there is why we're retrying them against other salts now), thus they are not new candidates.In other words, single mode tries to maximize the guess rate obtained early on, because we want to crack more passwords sooner rather than later. That's a feature, not a bug.
@jfoug commented on GitHub (Jan 13, 2019):
There may be a bug in the recursion code within single.c. Here is an interesting patch to monitor what is happening on the recursion level. For me, in my Fedora VM, I recurse ~65000 times, then it crashes. It is probably where the stack exceeds 1mb or something. My test data is RockYou data (250k lines, fed through pass_gen.pl to create the data). I am currently building data in dynamic_25 format, but I can not see how dynamic would play any part in this problem (other than it is probably a very heavy stack user itself).
Ok, when run, the recur_level simply increases, on this data, never decreases. It 'follows' the crack count. To me, this simply seems like an infinite recursion bug.
@magnumripper commented on GitHub (Jan 13, 2019):
Not sure why you used that strange diff format, I don't understand it. Anyway I did similar things some time ago and reach 5-6000 levels then it decreased again. I'm certain this isn't quite a bug, except perhaps there should be some safeguard against going too deep (@solardiz heads-up).
The "trigger" here is the unrealistic test data, it wouldn't happen IRL. What actually happens is that all buffers fill equally and then when the first one is full, crypt_all() gets called and we get a crack. Now that successful candidate is added to all other salts' list of words... however, as soon as it was added to the first of them, THAT buffer gets full, crypt_all is called, and we get yet another candidate that will be added to all salts. And when that is added to salt numero tres, THAT buffers gets full and so on. For 250K salts we will recurse until we smash the stack.
It will obviously cease to happen at all if you set
SingleRestestGuessed = N@p4tpr0 commented on GitHub (Jan 13, 2019):
This bug was triggered by real life data :)
Full context: https://www.patpro.net/blog/index.php/2017/04/09/3071-my-take-on-the-myspace-dump/
@jfoug commented on GitHub (Jan 13, 2019):
Ok, performed same test using mhac-sha1 (after fixing the format, which fails to have a salt-hash function). It crashed exactly the same manner, at about 65000 recursion depth, stack overflowed.
@jfoug commented on GitHub (Jan 13, 2019):
Partly agree. This 'test' data is unrealistic, as in every user name is a password. However, as @p4tpr0 shows, it does not keep this issue under control.
it does.
I have always strongly disliked the re-test guessed aspect, of single mode. It does nothing but significantly slow things down. Yes, it may increase crack rate a 'tiny' bit, BUT it increases crack time, often by orders of magnitude.
Now, for 'core' john, that may be the best that can be done. It does not have ability to perform things like -loopback= which performs much better. But for jumbo, having single mode re-insert cracks back into the single stream is not a good thing (IMHO).
That being said, yes, we need to figure out SOME way to protect ourselves, making sure that recursion DOES complete, and also DOES NOT go too deep.
NOTE, there is also a memory leak, right after the recursive call. The keys data value MUST be MEM_FREE called. I have tested this (ASAN build), and it is 100% a memory leak.
@jfoug commented on GitHub (Jan 13, 2019):
This is the first time I have read https://www.patpro.net/blog/index.php/2017/04/09/3071-my-take-on-the-myspace-dump/ (btw, nice writeup @p4tpr0, heh).
The data seen there is 'very' similar to the worst case senario (which is the input file I created with pass_gen.pl which lists the exact password in gecos). So @magnumripper, you can not flippantly deem the trigger data as 'unrealistic'.
Now, if @p4tpr0 had simply removed the comment on the the
#SingleRestestGuessed = Nline in john.conf, the entire file would have been testable in 1 run, and probably would have succeeded much faster than the 87 minutes he lists in the write up.So I still state, that this is NOT unrealistic data. What I find to be most 'unrealistic' is the default behavior of re-injecting cracks back into the single wordspace. What is happening here, is we have taken the wonderful tool of single (which ONLY deals with a tiny subset of data, SPECIFIC to a hash), and now treats it in wordlist manner, splashing words across the board, blindly to all hashes, which really is against the concept of single.
@solardiz commented on GitHub (Jan 13, 2019):
I liked the
SingleRestestGuessedbehavior very much when I worked on this code in 1990s - attacking not too many salts, and having fairly infrequent guesses. I would know those have already been tested against all salts, saving me time on manual "re-cracking". But I agree it's often unsuitable these days, and I don't mind changing the default in jumbo. Since it will differ from core, maybe we need to print a "Note: ..." each time single mode is used, listing the current setting and a brief explanation there. Maybe that "Note: ..." should be printed the first time single mode cracks a password (so it's not printed when there are no single mode cracks and thus the setting doesn't matter).We could also introduce a hard-coded limit on the recursion (e.g., 10000?), and print a "Warning: ..." when it's reached saying that some guesses won't be re-tested against all salts because of that limit. Maybe even switch to the
SingleRestestGuessed = Nbehavior in that case since the user wouldn't be able to rely on that feature anyway.There's no memory leak (at least not in core) - we
MEM_FREEentire key buffers (not individual keys) as the recursion unwinds.@jfoug commented on GitHub (Jan 13, 2019):
here is the code (with a comment added about the memory leak), from current jumbo. This IS a memory leak. I have validated it by running a small file generated by pass_gen, so that it completed fully. Leaks were listed. I inserted the mem_free, leaks gone (but still found exactly same resultant .pot file). ASAN is a fantastic tool,
@solardiz commented on GitHub (Jan 13, 2019):
You're right, I missed the
return 1. This memory leak is also present in core. I'll fix it there along with the next round of fixes, but jumbo doesn't have to wait on me. Thanks!@jfoug commented on GitHub (Jan 13, 2019):
Digging deeper into the code, yes, it is a memory leak, but only a cleanup leak (I think). single_add_key() only returns 1 if single_process_buffer() (the function we are in), returns 1. The only way single_process_buffer() returns 1 is if the crack_process_salt() returns 1 which ONLY happens, when we are done (i.e when the quit command from whatever instance is unwinding the john process).
SO, even though these do show up as leaks, I think they are only leaks because we are exiting. It is not like they were leaks in continual run code. It is just not proper post run memory cleanup.
@jfoug commented on GitHub (Jan 13, 2019):
I believe the easiest 'fix', is to simply put sanity checking in there. Like @solardiz listed, some large (but not impossible value) for recursion level. Then once that level is hit, we emit a warning, and no longer enter the retest_guessed block. So something like
In this manner, we protect the process from stack overflow when dealing with large and highly crackable 'single-mode' working sets of data, allow the retest_guessed to function (whether default, or by demand if not default), AND it also prints a warning telling the user that there may be some missed cracks, but that they can be found easily by rerunning john using the -loop= mode of input.
Then to deal with recursion_level, simply increment the recursion_level variable at start of single_process_buffer(), and decrement it at every point where single_process_buffer() exits, just like I did in the diff @magnum complained about, lol. Sorry @magnumripper, i can read both context (-c) or unified (-u) diffs. I will try and not use the context in the future.
@magnumripper commented on GitHub (Jan 14, 2019):
So you assume the problem you saw was indeed the recursion we are discussing now. What's your reason for assuming that? I'm not saying it can't be, I just don't assume so myself.
@magnumripper commented on GitHub (Jan 14, 2019):
Well I can read it, but it takes me twice as long 😄
@magnumripper commented on GitHub (Jan 14, 2019):
I disagree. Sometimes it does no good, sometimes it does wonders. When using single mode with large keys_per_crypt formats as recently improved, we really need a lot of candidates and it will NOT slow things down. When using it in staged tests with password in gecos field and a KPC of 1, obviously it will look like it's the worst idea ever. But IRL it isn't, that test is just flawed.
@magnumripper commented on GitHub (Jan 14, 2019):
Either way we change the default or not, we should probably add an option
--single-retest-guessed(or possibly--single-no-retest-guessedif we do change the default, or perhaps simply--single-retest-guessed=BOOL).@frank-dittrich commented on GitHub (Jan 14, 2019):
@p4tpr0
IMHO, real life data wouldn't have most of the passwords equal to user name or at least based on user name plus some well defined mangling rules.
With your data set, it doesn't make sense to retry one guessed password on all other salts during single mode.
So you should have used the already mentioned
option.
Please do, and report the results of that test.
Frank
@jfoug commented on GitHub (Jan 14, 2019):
Well, i used diff a LONG time, with the context mode, and got very comfortable with it. Only recently (within last 5 years or so), much to do with git, have I started working with the unified diff output format.
I used to use patch a lot. It worked well with the context version of diffs.
So the muscle memory of
diff -C 3 xxx yyyis simply hard for this old dog to unlearn, lol.@jfoug commented on GitHub (Jan 14, 2019):
@frank-dittrich
When running in that mode, the test from Myspace dump (or 'fake' data generated with pass_gen.pl), will not cause stack recursion problems. The fake generated data from pass_gen.pl is really the worst case situation for this issue, where every hash is cracked by the password in a gecos field.
Well, here you may be wrong. It 'should' not happen, however as we have seen time and time again, people implement this type of algorithms very poorly. Thus the 'smart' pen tester will find and exploit these. Having a quality tool such as john, throwing stack overflow cores when run on these 'worst case' situations is not good. This also happened around the AM dump. There was a serious implementation flaw, which allowed a tremendously good single mode. But the AM bcrypt was SO heavy, that it was near impossible to see any stack crash there, since it would simply take a LONG time.
I have no problem AT ALL, with keeping retest-guessed true by default, even though I think it really is a different 'concept' than single, and for salted hashes, especially when working with a LARGE set of them, can have runtime significantly extended.
It is not as big a deal with working with a set of data with 100 salts. There you crack a word, and it gets 'added' to the building data of 100 salts. BUT when dealing with 1 million salts, each time you crack a word, you now insert that into 1 million salts.
The biggest thing I will be working on (and would LIKE to hear some critique prior to starting this work), is to add a new john.conf setting (max-single-recursion-depth). I would say default that at 10k, but since it is in the .conf file, it can be extended if the user chooses. Then, within single, it is very simple to add a couple lines of code and count the depth of recursion during runtime. Then if that max is hit, we simply do not recurse (we may stop, or simply stop until the level drops). There will be a warning message dumped out stating why, stating which parts of the documentation to go to to see how to work around this.
Then within the docs, it would be a good time to educate on the SingleRetestGuessed = N flag. It may (almost certainly IS) something which this user, with this dataset may actually WANT to use anyway
@p4tpr0 commented on GitHub (Jan 14, 2019):
@frank-dittrich
You are absolutely right. My John config from feb. 2017 used that settings (see first post), but I've failed to report it into the config file for current John. I've corrected that mistake and made a new test:
test data file is generated as described in first post (with random mangling to get about 38% candidates that won't match password).
@jfoug commented on GitHub (Jan 16, 2019):
I am not 100% sure this is the entire issue. I also see decreasing performance over time. I will be looking into this. There may be no error, but I am working on this, so if I find something, i will correct what I find.
@frank-dittrich commented on GitHub (Jan 16, 2019):
When most hashes are cracked immediately, such a warning will not be noticed by any user, because it disappears too fast.
(You would have to print that warning when the session ends or when it is interrupted by the user.)
I wouldn't mind if we change the default in jumbo to
SingleRetestGuessed = N, but this should be properly documented.We could add a warning about that new default behaviour (for jumbo) at the start of a session, before any input file is processed. That way, the user has a chance to see the warning.
(The user should be able to suppress this warning by adjusting config file setting.)
@jfoug commented on GitHub (Jan 16, 2019):
@frank-dittrich it may be that the default does not need changed (it really ONLY needs to be changed if we want it to be). What needs to happen, is that john needs to PROTECT itself.
As for printing the warning, yep, it is likely something not well seen. BUT it could 'also' be printed at graceful exit (end of data, the kill file shows up, or ^c signal is caught). So what we would need to do here, is setup some 'on exit, do this' logic to printf the warning again.
@magnumripper commented on GitHub (Jan 16, 2019):
True. I need to think about this over night.