mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #2239] ASan errors in prepare(), split(), valid(), etc. in various formats (fuzzed input) #1495
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#1495
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 @frank-dittrich on GitHub (Aug 26, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2239
@frank-dittrich commented on GitHub (Aug 26, 2016):
Here's an ASan error for whirlpool (--format=whirlpool|whirlpool0|whirlpool1)
@frank-dittrich commented on GitHub (Aug 26, 2016):
Salted-SHA1 format:
@frank-dittrich commented on GitHub (Aug 26, 2016):
o3logon format:
@frank-dittrich commented on GitHub (Aug 26, 2016):
nsec3:
@frank-dittrich commented on GitHub (Aug 26, 2016):
krb5tgs format:
@frank-dittrich commented on GitHub (Aug 26, 2016):
KeePass:
@frank-dittrich commented on GitHub (Aug 26, 2016):
HMAC-MD5:
@jfoug commented on GitHub (Aug 26, 2016):
What is your build? fedora gcc ?
@frank-dittrich commented on GitHub (Aug 26, 2016):
Fedora 24, kernel 4.6.7-300.fc24.x86_64
@frank-dittrich commented on GitHub (Aug 26, 2016):
PEM format:
@jfoug commented on GitHub (Aug 26, 2016):
Damn off by 1 error in the _hexlen() function determining if there were any straggler bytes. But the fix simplifies the code making it easier to read. I took the end of buffer detect logic from the original code, (when the function returned an int) so it must have been wrong there also.
@jfoug commented on GitHub (Aug 26, 2016):
0b68c6ePlease check. All of these should be gone now.@jfoug commented on GitHub (Aug 26, 2016):
The last one (the PEM) may be a different crash. I will look at that one.
The PEM bug has been a bug in valid and the recent change simply forced it to the surface.
@frank-dittrich commented on GitHub (Aug 26, 2016):
These errors still exist after your hexlen() fix (I used the same files as in the comments above):
@jfoug commented on GitHub (Aug 26, 2016):
7f063dbis pem fix.I will look at others. NOTE, the pem bug was there all along. The more strict hexlen functions made it show up.
@jfoug commented on GitHub (Aug 26, 2016):
I think a lot of these have nothing to do with the hexlen?() changes, but you must have found a new method of really testing valid better ;)
@jfoug commented on GitHub (Aug 26, 2016):
I have all of these handled. Note, I am not sure about whirlpool. I could not replicate, but will check in what I have, and we can test more if needed.
@frank-dittrich commented on GitHub (Aug 26, 2016):
Still failing:
All the others are fixed. Thanks!
@jfoug commented on GitHub (Aug 26, 2016):
Oops, I missed that one. Let me get it. Did you still have an issue with whirlpool? I could not get it to fail.
@frank-dittrich commented on GitHub (Aug 26, 2016):
I have a fix for KeePass.
Whirlpool is OK now.
@jfoug commented on GitHub (Aug 26, 2016):
What method did you use to find these? Most of them are NOT new ones, but were latent waiting for proper bogus data.
@jfoug commented on GitHub (Aug 26, 2016):
Ok, check in keepass
@frank-dittrich commented on GitHub (Aug 26, 2016):
So far my keepass fix looks like this:
--test works, the fail_KeePass.pw doesn't contain any valid hashes.
But I think there's another error. There are 2 occurrences of
and I think it should be
if (res != 64 || strlen(p) != 64).Will change and repeat my tests.
After committing the changes, I'll describe my approach to find these bugs.
@jfoug commented on GitHub (Aug 26, 2016):
The problem with keypass is that there are no test vectors that excercise this. So I am not 100% sure about your 'fixes'.
The big problem I see, is there are the 'if' statements if (res == 1) { } where there is no else. Likely, it should fail if the if is not right, BUT we need to dig in to find out what the proper route is.
Your isdec is not safe. What if the value is 2 ?
@jfoug commented on GitHub (Aug 26, 2016):
The isdec is not really needed, since we test a specific value for the return. I think something like this is what is needed, BUT since I have no real test vectors, I can not say for sure:
@frank-dittrich commented on GitHub (Aug 26, 2016):
By adding isdec() I only wanted to avoid problems caused by undefined behaviour when calling atoi() with extra large integers...
@frank-dittrich commented on GitHub (Aug 26, 2016):
@jfoug If you think some of my changes are wrong or not good enough, please go ahead and adjust keepass.
Now that the other ASan errors are fixed, I'll try to find new errors in those formats that failed earlier.
@jfoug commented on GitHub (Aug 26, 2016):
This is isdec()
So it still calls atoi() AND sprintf. It is a pretty costly function. When we have the pointer, call atoi() in the valid, and then test for specific values, if the data is NOT the proper integer, then all is fine. The only possible issue would be testing for 0 (or -1), that 'might' be cause for issue, where a bogus value could give us one of those.
@jfoug commented on GitHub (Aug 26, 2016):
I still think in keepass we need to figure out what the PROPER thing to do is when those if(res==1) {} tests fail. I think that is the problem. Right now, the code just falls through, and happily returns 1.
@frank-dittrich commented on GitHub (Aug 26, 2016):
New o3logon format error:
@frank-dittrich commented on GitHub (Aug 26, 2016):
@jfoug You are right, valid() should fail for cases we don't handle. May be print a warning once per run?
@jfoug commented on GitHub (Aug 26, 2016):
I am just going to handle the else clauses, with a failure. The only issue I have is 'could' there be some version 2, or 3 ??? But I guess we will have to handle that when we can. We really should get some better data here for the ST values. @kholia do you know of any data that we could add to the ST strings for keepass?
@jfoug commented on GitHub (Aug 26, 2016):
Can you explain your method of finding these. Seems to hit a lot of formats. It looks like you pull fields off, but also possibly leave the delimiter trailing, etc. Looks like a damn good test.
@jfoug commented on GitHub (Aug 26, 2016):
It looks like many of these formats are 'newer'. Probably since the last time you and others fuzzed the hell out of the formats looking for asan problems. Some of these triggered with the new hexlen?() changes, but others were simply asan overflows and even actual SEGV cores waiting for the right bogus data to trip up the validation function.
@frank-dittrich commented on GitHub (Aug 26, 2016):
@jfoug basically I use 2 different strategies when fuzzing john formats.
The first is based on a "primitive fuzzer for john hashes" which Alexander Cherepanov published in john-dev mailing list in April, 2013.
Openwall still has his message, but without attachments:
http://openwall.com/lists/john-dev/2013/04/29/2
The ezmlm response I got when sending a mail to john-dev-help didn't list any command to retrieve all mailing list messages of a certain date, and I didn't want to retrieve header info of tons of message, just to learn the particular message number...
gmane.org seems to be down.
But marc.info still has that message:
https://marc.info/?l=john-dev&m=136719502025109&w=2
It includes the 2 attachments, fuzzer.sh and fuzz.pl.
The idea of fuzzer.sh was to search the source code for all sample hashes and store them in a file tests.pw. (Nowadays you have ./john --list=format-tests which can be used instead.)
A second step is then to apply some "mangling" steps to the hashes collected in tests.pw and create a file fuzzed.pw.
That "mangling" is done with fuzz.pl.
My version of fuzz.pl is almost unchanged, compared to Alexander's original code.
The diff is:
Some formats use '#' as a separator, so adding
'#'helped mangling the individual substrings in such hashes.formats.l contains the list of all formats that you want to fuzz.
If formats.l doesn't exist, fuzzer.sh creates it using
./john --list=format-details | cut -f 1.The fuzzed.pw file is tested against each format, formats with an exit code != 0 are stored in fails.l, together with the exit code.
Finally, for each format in fails.l, fuzzer.sh then tries to create a smaller sample file which still results in the same exit code.
Ideally, you should end up with a single "hash" which causes john to fail (segfault / ASan error, whatever).
(Sometimes you end up with a hash of length >= 10000. Then I just look at the hash and try to manually reduce the length of a certain substring, so that I can post a sample hash of reasonable length.)
For complex hashes with many separators, fuzz.pl will create many lines in fuzzed.pw.
So, testing each format against a fuzzed.pw out of all test hashes doesn't make much sense.
Instead, I slightly changed fuzzer.sh to skip generating tests.pw if it exists, to skip generating fuzzed.pw if it exists, skip generating formats.l if it exists.
I also added --session=fuzz --nolog --pot=fuzz.pot.
(The original version would write into john.pot and rm john.pot after each test. Not good.)
@jfoug commented on GitHub (Aug 26, 2016):
So, do you just think these were formats that never had gotten fuzzed up to now? (other than the issues caused by the off-by-one error in hexlen?() functions)
@frank-dittrich commented on GitHub (Aug 26, 2016):
Problems with that kind of fuzzing can occur if fuzz.pl mangled an iteration count field.
Then you might have several hashes with huge iteration counts, so that ./john --max-run-time=1 will not stop, and the process will be killed by the ulimit.
The original fuzzer.sh had
That was much too short for some formats, so I increased the value.
Nevertheless, when I think a certain format just "hangs" due to high iteration count, I just kill john.
For those formats, I will start
./john --testand look at the reported cost values.Then, I'll just repeat the exercise for those individual formats, but add a parameter --cost=-12000 to ./fuzzer.sh.
That parameter gets passed to john, so john will ignore (otherwise valid) hashes with unreasonably high iteration counts...
So, this is the command I run in the end:
The last lines indicate tests which I interrupted.
Minimizing samples for failed formats will look somewhat similar.
@frank-dittrich commented on GitHub (Aug 26, 2016):
The other approach I used in the past was american fuzzy lop https://github.com/mirrorer/afl
To find problems, you have to use an ASan build, even though afl doesn't recommend it.
(May be it would be better to test 32bit ASan builds, even on 64bit systems.)
To improve performance, I copy all the needed stuff into a tmpfs mounted on /run/user/1000, use --skip-self-tests and --nolog etc.
The files which afl generates often contain non-printable characters, so they have to be converted to base64 when creating a new issue on github.
afl could probably also be used to test some of the john symlinks.
@frank-dittrich commented on GitHub (Aug 26, 2016):
Yes, I think that most of the formats which had errors were relatively new (committed after the last systematic fuzzing) or were affected by some (buggy) core changes.
The original Raw-SHA1-AxCrypt format was moved to unused in January, 2016, because rawSHA1_fmt_plug.c was changed to support that format as well.
whirlpool is from 2013, not sure why there were new errors. (At least some of them don't appear to be related to the hexlen() changes.)
Salted-SHA1 is even older. Not sure what broke this format recently. I am sure I must have fuzzed this one in the past.
o3logon and nsec3 are new.
krb5_tgs_fmt_plug.c is from September, 2015. The last systematic fuzzing could have been earlier.
keepass_fmt_plug.c os older. hexlen() changes caused problems, but may be last time I didn't ignore the huge iteration counts using the --cost= option, and simply gave up fuzzing this format.
HMAC-MD5 is older, but had recent changes (
SOURCE_HASH).PEM is from October, 2015, and also had recent changes (
SOURCE_BIN).@frank-dittrich commented on GitHub (Aug 26, 2016):
@jfoug regarding the fuzzing, you asked more or less the same question in 2014:
https://github.com/magnumripper/JohnTheRipper/issues/894#issuecomment-66991582
And I answered it here:
https://github.com/magnumripper/JohnTheRipper/issues/894#issuecomment-66993517
@frank-dittrich commented on GitHub (Aug 26, 2016):
@jfoug BTW I only tested CPU formats. So may be similar tests are needed for GPU formats.
Not sure when I'll find the time to do this.