mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #2117] Add generic helper methods for handling large non-hash data #1415
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#1415
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 @kholia on GitHub (Apr 15, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2117
Currently each format (e.g. LUKS) has its own hacks for handling large amount (> LINE_BUFFER-SIZE) of non-hash data.
Adding such hacks for new formats (e.g. gpg2john) requires duplicated code, and time.
It would be nice to have a unified way of handling large amount of non-inlinable non-hash data.
@kholia commented on GitHub (Apr 15, 2016):
https://github.com/magnumripper/JohnTheRipper/blob/bleeding-jumbo/src/gpg2john.c#L948
https://github.com/magnumripper/JohnTheRipper/blob/bleeding-jumbo/src/luks2john.c#L190
See these links for more details.
@jfoug commented on GitHub (Apr 26, 2016):
How about this (note just talking something out, am not looking to put code to this yet) Have a line format like:
$JTR_BIGLINE$length_in_decimal \n
whatever line data is needed. (line length is length_in_decimal)
That way within loader, it could be written smart enough to see the JTR_BIGLINE, and the next line would be loaded 'extra long'. It would allow for binary data, or anything really. It would not use the fgetl() function, but simply do an fread (or read if we are not using stdio FILE object). Same thing could be in a .pot file, or the input file.
Or maybe we do something like
$JTR_BIGLINE$length_in_decimal$md5_hash_hex \n
real_line_data
This is mostly to get data between a *2john and john itself (I think).
@kholia commented on GitHub (Apr 26, 2016):
Yes, this is mostly to get data between a *2john tool and john itself.
How is this 'extra long' line (after the newline) encoded? Is it hex-encoded?
By doing this we will get rid of the really ugly hacks which are currently present in many formats (e.g. LUKS).
@jfoug commented on GitHub (Apr 26, 2016):
I am not sure the encoding of the next line should be specified (or matter). It would be loaded by loader just like any line, but it would not be limited by the line length field.
Note, I have not looked at code, so this may be a total non-starter. Just thinking out loud currently. There likely will have to be many other things changed along the way. We 'may' have to build a long line structure vs just a char * for this also, so that there would be knowledge to other parts of john to just how long the data is. Or we could force hex/base64 encoding if the data is binary, to keep things in NULL terminated C string format.
@jfoug commented on GitHub (Apr 26, 2016):
pkzip (zip?) also does something like this, where it encodes the name of the .zip file into the input string. Then if that file is not found, we can not crack the zip.
@jfoug commented on GitHub (Apr 26, 2016):
is 4gb going to do it? I certainly HOPE so, since we are now loading this into memory. If not, then we have to also look at some other method. One that loads, the other that does something like memory mapped file.
Actually mem_mapped file might be best best always ???
@jfoug commented on GitHub (Apr 26, 2016):
Very quick n dirty 'test'
Then I created a file with the 2 'test' hashes.
line 1 is "$JTR_BIG_LINE$86581\n" then the next line is the hash. Line 3 is "$JTR_BIG_LINE$171914" then the 4th is the longer hash.
This runs through loader.c and valid within LUKS works.
NOTE, within params.h, I also changed to this for this test: #define LINE_BUFFER_SIZE 0x400
I also think we would need to dump out .pot files using this type logic (not only in the *2john). I am still VERY early in testing, I just wanted to toss out some findings. In the end, this may be pretty easy to add. The one KILLER would be any .pot files made prior to any change like this. But I guess a script to 'fix' any extra long .pot lines would be acceptable, if we need that.
But getting the LINE_BUFFER_SIZE down to something reasonable does make sense, especially since we have several of these buffers ON THE STACK!
@jfoug commented on GitHub (Apr 26, 2016):
WOOP!!
This was also under the very lame VC compiler (which is a nightmare for LUKS). I also added user names, : several extra : and the GECOS used for the passwords. LUKS is so slow, that I created a word file with the 2 passwords, since I did not want to wait for single to find them
However, the .pot file contains these HUGE line. I will see how it now 'works', but I expect a crash.
@jfoug commented on GitHub (Apr 26, 2016):
I will make a quick branch with these changes, and we can see whatever else is needed (or drop it for some other methods).
@jfoug commented on GitHub (Apr 26, 2016):
Have a look for yourself.
I really think this POC could stand up (with a bit more searching). I have trimmed max line len down to 0x400 in this POC. All hashes with length > that would need to use the long line (2 line) format.
https://github.com/magnumripper/JohnTheRipper/tree/generic-big-hash-helper
@magnumripper commented on GitHub (Apr 26, 2016):
I didn't read all of this thoroughly, I just wanted to throw in that I'd prefer us to start supporting arbitrarily long lines without any special tag. Ditching all non-inlining (file references) in *2john tools would be great IMO.
Also, I believe a RAR file can exceed 2 or even 4 GB although we could opt to just not support it if it gets too troublesome.
FWIW I do like memmap (for certain things).
@jfoug commented on GitHub (Apr 26, 2016):
We certainly could move in that direction. At least this POC flushes out exactly WHAT we have to do to get there.
Biggest thing is that fgets call might need to be replaced with something.
We 'could' do something like (note written off the cuff, so DO NOT comment about stupid syntax/logic errors, lol)
Then the caller of jtr_long_fgets() would have to check that if the pointer does not point to whatever buffer was passed in, that the caller MUST call MEM_FREE on the returned pointer. Also, the caller should use the pointer, and NOT the 'buffer'.
But we can work towards that goal. Right now, this POC just helps find any problem spots. I expect to have issues in -show and or -show=left, and possibly numerous other places.
This is ONLY for input files / pot files. NOT for wordlist files, etc.
Right now, a couple spots in loader, and a little change to logger is all that appears to be needed to get this to work, with a tiny line_buffer_size, yet with huge input buffers.
@jfoug commented on GitHub (Apr 26, 2016):
Please look at code after this commit:
75ebd61This should handle any length line, but line_buffer_len is set to 0x400
There is still problems with --show command (looks close, but I am not getting line endings). But it stores properly in .pot files, later detects that the hash was cracked, etc. That is GOOD looking stuff.
I just made a fgetll() function. That one is based on fgetl() but the ll version does not stop at the size of the buffer. However, it WILL allocate a larger buffer that the caller must delete or leak memory.
@magnumripper commented on GitHub (Apr 26, 2016):
I guess mmap would be hard to use because it will be read-only: We can't overwrite \n with null and so on. It would work with "pascal strings".
@jfoug commented on GitHub (Apr 26, 2016):
Right now, the code is still semi POC (since it is SO hard on memory possibly). BUT things are looking pretty good, AFAICT
@kholia since you are the one that wanted this, can you see if this does what you were wanting? I would hate to continue pursuing this, IF it is not going to solve the problem you needed it for.
@jfoug commented on GitHub (Apr 26, 2016):
This is now PR #2126 Needs to be talked about a bit, and make sure everything works, but I think it is pretty well on the way there.
It would be nice to have the data windowed through, only loading in parts as they are needed, BUT that may require changes to code all over the place.
@jfoug commented on GitHub (Apr 26, 2016):
Having Travis issues on full tests. I have to meet someone for beers in a few minutes, but we are going to have nasty weather later tonite (tornados?) so I will figure this out later tonite.
@jfoug commented on GitHub (Apr 26, 2016):
keepass seems to be the only format which puked with the reduction of LINE_BUFFER_SIZE. I fixed it (hack by just putting the 0x30000 back). But now with a smaller line buffer, we may want to see about adjusting this one properly.
@magnumripper commented on GitHub (Apr 26, 2016):
You should probably verify that loading of eg. 25, 50 or even 100 million raw hashes didn't get significantly slower (or even starts failing).
@jfoug commented on GitHub (Apr 27, 2016):
Good test: This is results from my terribly slow laptop, on cygwin.
So I see little difference. John has SO much overhead in our overly 'deep' valid functions, that fileIO is a small part of the whole thing (shame).
Lines were made with:
./perl -e '{for($i=0;$i<1000000;++$i){print '1' x 40 , "\n";}}' > 1
Then I catted the file to get 5m and 25m. The hash was raw-sha1 Timing was counted by hand (no watch), and stopped as soon as I saw 'Loaded X password hashes....'
I added this to each file, just to make sure something was cracked:
echo -n password | sha1sum | cut -b 1-40 >> 1
@jfoug commented on GitHub (Apr 27, 2016):
I hope others look at this. I think this would be nice to get added. This seems much better than the original fixed size and fgets calls
@magnumripper commented on GitHub (Apr 27, 2016):
Just from looking at the code (logger.c new branch), I believe you are writing to the pot/log files without locking. That would be a horrific bug.
@kholia commented on GitHub (Apr 27, 2016):
Thanks for working on this @jfoug. I will try to fix
luks2john.cso that it no longer generates non-inlined hashes.@jfoug commented on GitHub (Apr 27, 2016):
It may also be good to NOT store these monster lines in the .pot file. I will have to think a bit more about this, but I am pretty sure it can be done. NOTE, it will require some work on a few formats in their valid and binary functions. What I think we can do is for these extra long ones, we chop off the first part of the source (at a fixed point), append a '$' and append the binary representation in hex.) Then the hashes that can have HUGE lines, we have to modify valid to spot this, and modify binary to also spot this. Or we change the format interface again, to add some helper function(s) like pot_source() or something, so the format is in control. If pot_source() was defined as having to reduce the hash string to fit within LINE_BUFFER_SIZE, then the hack done in logger where I am doing direct non-buffered writes can go away.
But putting even a handful of > gb lines into the .pot file is silly, just so we can later not load them, when they probably will never be run again.......
We may also want to bump up LINE_BUFFER_SIZE a bit. I drastically cut it down, but I bet 0x1000 is a better 'max' normal size. 1K is 'ok', but I think 4K is really what it should be set at.
@jfoug commented on GitHub (Apr 27, 2016):
I have made changes.
9317cedb79361eThings are working fine. -show works fine. Rerun removes the duplicates. The .pot file is just fine.
@magnumripper commented on GitHub (Apr 28, 2016):
FWIW I liked 0x400 (1 KB) because that's what core uses.
Using a truncated binary is a terrible idea because it can and will cause false positives from dupes in some cases. However we could add a hash representing the binary blob (eg. SHA256(data)). Something like:
@magnumripper commented on GitHub (Apr 28, 2016):
Perhaps marked with a tag to tell loader & co. about it
(where
BLOBHASH$is that literal string)@jfoug commented on GitHub (Apr 28, 2016):
I thought of adding a hash of the original also. I would have to find the locations it was used. I may still have to lob on the binary of the data.
But I can easily set the max buffer back to 1k, and chop the blob smaller, adding a hash, and the binary.
So I would see:
The reason I go with md5, is because it is shorter, allowing more of the original source line to be there (the source is what anyone searching for matched data (outside of john's -show) will be able to use to match. Md5 will NOT have any collisions. Just because there are 'methods' to find duplicates, does not mean you will ever find a pair ITW.
So I would create a function in loader that would be passed in the original source, binary, and length of binary, and a max_len buffer, and would produce the string that was 0x400 minus a few bytes long, and that would be the .pot (or .log?) entry. There should be no ambiguity upon reload. There is the md5 for a strcmp, and the binary for a memcmp / hash of the binary.
@jfoug commented on GitHub (Apr 28, 2016):
But this was also why I put this in a branch. I knew this was going to be a big undertaking, with strange twists coming from all directions. The shorten of .pot lines is one such twist. That should have been done long ago.
The one thing that MUST still be handled, is making sure that .pot lines > 0x400 ARE handled properly (i.e. lines prior existing, that are not truncated).
I have added a todo list in the original post, so we can track progress. If you think of other things that need to be there, whether logic or testing, please add them to that list, so that we can validate when progress is complete.
@jfoug commented on GitHub (Apr 28, 2016):
6b32938adds an MD5 for the full source, and this is used for compares. There are also easy to spot tags for the source and binary. Helper functions for ALL of this were added as ldr_*() functions.This is a much better method, than the original POC of simple truncation and then strcmp of that fixed string.
There is still one area where we do a fixed length truncation data build. That is in ldr_cracked_hash() function. In that function, if we have a source that is >= the length, then it will get hashes only up to a certain shorter length. We can not 'know' the amount of valid hash here, since we do not know the particulars about hash type, unless we are doing a single hash. So the easy way is to simply hash a fixed length that is shorter than any format would cut down for it's binary and the md5 of the full hash. We will have to watch this POT_BUFFER_CT_TRIM_SIZE as we add more 'long' source formats, to make sure we do not have a binary that is too long. Once we get all hashes in, then we can document the longest, and set this POT_BUFFER_CT_TRIM_SIZE to be closer to the threshold.
@jfoug commented on GitHub (Apr 28, 2016):
I have added check-off-boxes for all hashes that ARE over 1k, and many that 'may' allow for > 1k lines. For this task, we should make sure all of these formats have their valid (and possibly binary) able to handle chopped .pot lines (both cpu and GPU), AND we should also look at all of these *2john routines.
@jfoug commented on GitHub (Apr 28, 2016):
@magnumripper and @kholia
should we remove the inline threshold values in the *2john and just always inline ???? It would make things easier, AND have fewer problems for end users having to keep those files around in exacting locations.
@jfoug commented on GitHub (Apr 28, 2016):
We probably can not remove the 'external' stuff from the formats, but we could talk about it. It would be nice to remove that also. But older input files, .pot entries, etc are the concern here.
@jfoug commented on GitHub (Apr 29, 2016):
This should handle a lot of formats (I think all of these are known to have > 1k source lines. There may still be more.
4f92365The *2john files still need to be looked at.
@magnumripper commented on GitHub (Apr 29, 2016):
I had the idea we'd do the hashing in *2john, definitely not in loader. We'd always inline, and always put a hash before the inlined data, and (for ALL formats that do this) always put a
BLOBHASH$tag before that hash.So the input file would have the hash AND the full blob, while the pot entry would have the exact same data bar the inlined blob.
This also means we are back at your original idea (if we want) to only use fgetsll() when we see the
BLOBHASH$tag.Finally, the formats can opt to verify that the hash is correct for provided blob.
@magnumripper commented on GitHub (Apr 29, 2016):
I vote for ditching backwards compatibility in this case. The 0x30000 limit was one of the worst ideas in Jumbo history.
@magnumripper commented on GitHub (Apr 29, 2016):
Oh, and another thing: All formats that do this, should use Base64 for the big blob. Using hex format to inline a 300 MB file will produce 600 MB. We have helper functions already so there's no need to be lazy.
@kholia commented on GitHub (Apr 29, 2016):
I agree too about breaking backwards compatibility in this particular case.
@jfoug commented on GitHub (Apr 29, 2016):
I think making a sweeping change to precompute this data within the *2john is a Bad Idea (tm) overall. Changing the signature of all of those formats??, Yuk.
Right now, the signature is computed using a function 'called' ldr_*() but it is ONLY done within logger.c and done when a crack is found, prior to writing to the .pot file. Thus (especially for these HUGE hashes), it is done almost never. The code is clean, works well, and has minimal impact. Yes, we may want to take some time, and remove the logic for the 'externally owned' data files, and put everything inline. But that change has to be done no matter what.
Please actually LOOK at what was done, and how it actually works. Yes, we certainly can when we get time, convert all big blobs into base-64, and do it one by one. But that is ONLY a change in the *2john and *_fmt_plug.c file pair, and is much easier to control.
I think breaking backward compatibility in this case is a good thing (btw). It allows us to NOT have to always look over our shoulders for that crap. Most of the time, if someone has cracked something like that in the past, they are not re-running the input again. It would simply end up being either .pot file lines that match nothing, or would be handled by the extra long line reading from fgetll()
@jfoug commented on GitHub (Apr 29, 2016):
Those 3 functions were put into loader, more as 'library' functions (well the external ones were), so that it could be done as simplified and controlled code. It does no mean they are run for every loader input. Well, one is, (the static one). It is a replacement for strcmp only. The others are just there, so that all the code is kept local, and controlled on the actual format of the strings read and written to the .pot file.
@magnumripper commented on GitHub (Apr 29, 2016):
I can't see your point at all. These changes are a major signature change already, and not backwards compatible at all: We are going from referencing an actual (eg.) RAR file name/path, to inlining it - so why not prepend the hash already?
If the input file doesn't have the hash, how can we handle --show in a good way?
Also, I have some other things in mind like Johnny the GUI and other things. They'll have a hard time keeping up with this functionality if we don't give them this hash (and
BLOBHASH$tag) as anchor.@jfoug commented on GitHub (May 2, 2016):
Are we going to define this order? If so, then how about 👍
$tag$SOURCE_HASH$md5_hash$SOURCE_BIN$binary()_$0|1$ ... original hash with inlined blob...The 0 or 1 would be for truncated vs non-truncated. This will be used within valid. If it is 0 (truncated), and in pot_load, then the tag is all that is used for validation. It is assumed that since we are reading from the .pot file, that it is valid.The problem with this, is now the generation code has to build the whole line in memory (or later re-read it from a file) to be able to back generate the source hash, AND to rebuild the binary. Also the binary data would also have to be set to empty and then filled in later, once the line was ready, AND the *2john will need the logic for the binary() function to be able to properly generate this (if it is not provided). If done that way, then we could use a NULL binary section as the key to whether this was a full length hash line or a truncated one. If it is filled out (and we are in .pot reading mode), then we know it is truncated. This would eliminate the full/truncated flag.
All of this is doable, but this is a lot of work, and lots of one-off. I guess we have the work and one-off for each *2john since we are taking the the file reference signature, and changing it to inlining. But building this type change can also be tricky. I will start to work on this, and see how it goes. kind of a shame, since it was done and fully working already, but I do see your point, about some of the tools like johnny. All in all, it should not be all that hard. Mostly get it done once, and then cookie cutter code from then on.
This also might not be a bad time to TRASH all the * separators in some of the signature lines once and for all. Get to using $ across the board for these.
Sorry if this comment wandered. I have been on little sleep the last 4 or 5 days. Waiting in the airline club now. I have not been a traveler for a couple decades now, and sort of forgot about the nice perks like this (but not traveling is a perk I also like). Here with one of my cousins husbands, and waiting for my flight. I will get on to see how this can be completed during the week.
@kholia commented on GitHub (May 2, 2016):
We now have
luks2john.py(Python port) in bleeding-jumbo, and it should be easier to change / test than the old C code.The new code always generates inlined hashes, and surprisingly the old bleeding-jumbo format code cracks the inlined hashes just fine.
@magnumripper commented on GitHub (May 2, 2016):
Is the 0/1 flag needed at all? An input file would always have the complete line (hash followed by Base64-blob), while a pot line would always end right after the hash of the blob (specifically, it would NOT contain a truncated blob because that would just be a waste of space). I see no need for that flag. Perhaps you're addressing the fact loader.c's functions are generic so we don't really know whether we're loading a pot file or an input file? But we should be able to use
ldr_in_potfor that.@magnumripper commented on GitHub (May 2, 2016):
We're not talking about a very large number of formats, I think.
...but there may be a few more written in Python.
@jfoug commented on GitHub (May 2, 2016):
I never did look into the *2johns yet. The only fmt that had issues was keepass (or something like that). That format got a hack, to simply keep the buffer the same size. We need to revisit that one and fix it correctly.
As for the 0/1 logic, it was to keep thing generic in loader. There are hashes which 'may' have lines > buf_size, but some may not. I guess we could always trunc them. I figured we could put null 'placeholder' bytes in the binary section so that that field would server to tell us if we have the full hash, or only part of it. When we have only part, valid does very little (vvalidates the tag mostly), and then binary() has the data direcctly available. Some formats work out of box (with my first code), since binary was the last field. So if a format did cp = strrchr($s)+1; binary=hex2bin(cp), then those formats required no changes. However, now, the binary will have to search for the binary tag if loading from .pot file. It may also be possible to remove the need for binary. I think it's only needed to generate a hash. but without it, the code will not find the already cracked .pot record.
@jfoug commented on GitHub (May 2, 2016):
But now with
source_hashbeing a 'unique' field up front (both in full data and in .pot lines), we really do not need to store anything more in .pot file than those computed data. As far as that goes, we would not even need to put thesource_binaryinto the source line, UNTIL we crack it. At that time, we have binary() function to generate the data, so getting it jammed into the .pot file record is trivial.I was putting 'lots' of source line into the .pot reccord, to try to get something searchable outside of john for finding cracked lines. But if the *2john builds the hash, then it will always be there, and be a great key, and the only thing needed for these formats to find that crack line by hand (or script).
@magnumripper commented on GitHub (May 2, 2016):
I'm just dry running these ideas in my head so far. The easiest way to "fool" the current logic and self-tests might be to strip the binary [ie. the big blob] in split(), after allocating a buffer for it and reading it into the buffer. So the return from split() would always be with the blob-hash but without the blob - ready for pot use.
In get_salt() and/or get_binary(), we'd associate that buffer with the corresponding salt and/or binary (eg. by means of the blob-hash).
But that would be a bit of a mis-use of split()... I wonder if @solardiz has any ideas or opinions?
@jfoug commented on GitHub (May 3, 2016):
@magnumripper how do you think we should proceed on this? The hashed shorter line length .pot entries is almost a 2nd task, on top of 'generic' helper functions for the format input lines.
But even though it is 2 issues, they really to tie together. It would be very sad to get large line reading/writing to simply fill up .pot files with monster data, to only shortly after convert things over to shortened hashed .pot entries.
I might start working on a 'true' generic package, which we would also need ported over to python, since people seem to like that language for some reason. This lib will be the tools needed for both the *2john tools, AND used as common code which now is in the loader.c file. I will start on that first, then on some *2john so that we have input, then on to loader/logger within john to actually use them.
@jfoug commented on GitHub (May 3, 2016):
@magnumripper how about something like this (for the *2john files):
Then the *2john would do:
So the start would grab the ftell location, write the tag followed by the source hash placeholder:
$rar$SOURCE_HASH$00000000000000000000000000000000$Then the fprints would be used to write data, along with these would md5 the data. Finally the complete would seek back to the place holder, and write the md5 of the data, so there is a UNIQUE search string which would match up between .pot and input source line.How does that look for a generic 'write only' interface? I still would need to handle the read side of things for within loader and logger.
@magnumripper commented on GitHub (May 3, 2016):
Not sure. If I had time I'd start experimenting with the RAR
$RAR3$*1*formats. I'd start with rar2john, then adapt the formats, then loader - and finally test/fix problems until it looks good. This is complex enough that it's a good idea to move slowly though. I think we are close to a good solution now.I think we should always put the blobhash + blob last. The current syntax is this:
We should scrap the last
*1*(inline flag, not needed anymore) and move the last field (method) to before the blobhash and blob. So it'd end up like this:And corresponding pot entry
I can see a reason not to change the
*to$in this case: We want the$RAR3$*0*format (which doesn't need or use any blob at all) to remain unaltered or we'll break compatibiliy with hashcat.Yeah something like that should be a good thing. Because of what I just said though, we might want to add a delimiter argument (
*for RAR) to the functions.@magnumripper commented on GitHub (May 3, 2016):
BTW we might want to drop support for
$RAR3$*1*and use$RAR3$*2*for this new syntax. We could print a suggestion to re-run rar2john in case we're fed a$RAR3$*1*input file.$RAR3$*0*is -hp mode (also supported by hashcat) - should not be changed at all!$RAR3$*1*is old-style -p mode syntax (sometimes inlined) which we cease to support$RAR3$*2*is new-style -p mode syntax (always inlined but only hash in pot) that we add now@magnumripper commented on GitHub (May 3, 2016):
@jfoug I think you have in mind to replace nearly all fields with the hash. While that would work, I think it has several downsides. I recommend only the Base64 blob be left out of pot entries, nothing else. And the blobhash should be MD5(blob), nothing else. This relieves loader.c from most of the action and also makes it very easy for a format to verify that an input file's blob is intact.
I'm pretty sure if we're going this path, no new logic or support is needed from loader.c (apart from generic support for reading arbitrarily long lines) and we need NO special tag like
BLOBHASHorSOURCE_HASHat all.Hmm on second thought maybe the last statement is wrong. I think loader sometimes just do a strcmp(pot_line, input_line) and this will fail. So maybe we do need a
BLOBHASHtag telling loader to limit that strcmp to the length of the pot line.Hmm on third thought, no... if we use split() as I suggested earlier, this problem vanishes! I think this can ALL be done in rar2john + rar_fmt as long as loader handles long lines.
Hopefully I'll be able to show what I mean in a separate topic branch within 12h or so.
@jfoug commented on GitHub (May 4, 2016):
No, what I have in mind is to make this 'generic' There is NO SUCH THING as a base64 blob. If the format/*2john do that, then by all means they will. ALL this generic code will do is to wrap logic on top of fprintf type logic. Nothing more, nothing less. But the *2john and fmt will be in charge of their strings.
NOTE, this is done with a var_args function. Thus that function does not care what the *2john does.
@magnumripper commented on GitHub (May 4, 2016):
Yeah but if I construct the RAR3 line using your pu_start_line(), pu_fprintf() and pu_complete_line() functions, it will MD5 all of the line. At least that's how I understood it. Then again I guess I could do things like
BTW I do not think we need that
*fppointer. All tools write to stdout.@magnumripper commented on GitHub (May 4, 2016):
Oh BTW that function would not work correctly if used as I wrote above. It would MD5 the Base64. We need an MD5 of the actual binary.
For rar2john I'd rather just have a function like
Then I could
@jfoug commented on GitHub (May 4, 2016):
Ok, this is the code I am working with.
The signatures for 'full' hash will be
Then in the .pot file it will be:
So we can keep 'any' format that the *2john wants, we are simply appending the source_hash md5 AND the length of the tag (which can be ANYTHING. So the tag can be
rar3or $rar3$0$ or whatever the format wants. That tag WILL get put into the .pot file, when we crack. Then the source MD5 and binary will make sure that a FULL hash and a truncated .pot file hash match. Also, the md5 hash can be used by any ancillary tool to find t hings in the .pot file, if they need to scan for cracks OUTSIDE of using john's -show function (I do that all the time, and I am sure there are MANY others).@magnumripper commented on GitHub (May 4, 2016):
Your version is founded on new/special handling in several parts of core. If my ideas end up flying IRL, that's not needed. Pot sync and --show would just work, with current known-good code. Any introduced bug would be isolated to affected formats (eg. rar).
The one and only core change really needed is the support you already wrote for handling arbitrarily long lines.
@magnumripper commented on GitHub (May 9, 2016):
My bad @jfoug, you're code is a winner and I was too focused on rar and the likes, that may point to external files. My "way" of attacking it would have been superior had it been done in 2011... but it wasn't! Given our current legacy I can't see any way of attacking this other than complete your topic branch.
I'm still testing. There's a LOT to test now.
@jfoug commented on GitHub (May 10, 2016):
There is still a ton of testing, in the code which I started on. Hacks galor. BUT it is a way of handing this in a semi generic manner.
The reason I left a large chunk of data (in the .pot file), and appended the hash to the end, was so that there was the best possible chance of having something 'unique' that could be searched upon, to find the hashes outside of john. There is always the case where a hash could NOT be found at all
However, I do think your method of doing this (having the *2john) build the hash, does have merits, as then for that hash, the ENTIRE data stored in the .pot file is the tag, the hash and the binary. That actually should of be done with no changes to the internal format (other than valid/binary), and only changing the *2john. Possibly, we can start down that path also, and slowly wean ourselves off of the need for logger/loader to cut/compute_hash, and move that logic out to the *2john. Once we get 'most' of them done, then we can work on the few hashes that still have to use the logger/loader hashing, and figure them out. Figuring out 10 or so stragglers is much easier than 80ish that we currently have.
But for the hashes which have no *2john, BUT are over 1k, I could find no other way around this, short of storing the huge data in the .pot file, and THEN we have the issue of having to write data outside of the lock, or come up with other hacks to handle that longer line. Now, we certainly could also make the slack end of buffer size 0x30000, so that we never have to worry about the slack part, but I think we just need to flatten out the warts the best we can within what I have started on. I know it is ugly, but I did spend a lot of heads down time, and found (and worked around) numerous issues.
Yes, if we would NEVER have increased buffer size to 0x30000, then we would have more options. BUT even though it does not sound all that bad, we are screwed.
Part of the problem is there are things which are > 1k, and are ITW real hashes, not some *2john thing. That kbr5_something is one of them (iirc) where we have a raw hash that does not even have a tag, that is > 1k.
@jfoug commented on GitHub (May 10, 2016):
Note, I will be gone a couple weeks. Do not take my silent-ness to mean anything. Gonna do a 2 week, no destination ride. Probably put 4 to 6k miles on the bike, and hit a lot of south central, and western US locations. I will be on the road in about 36 hours.
@magnumripper commented on GitHub (May 10, 2016):
Cool, ride safe and ATGATT.
I'll continue testing this. Yes, we certainly have the option to do the split() thing as well as this generic stuff. I'll try that out too.
@magnumripper commented on GitHub (Jun 2, 2016):
#2130 is merged now! I fixed a few more issues and then decided we won't ever find more issues until we actually merge.
@jfoug commented on GitHub (Jun 10, 2016):
Good that this is merged. Yes, we may still need to polish it a bit, but getting these to be proper inlines sure helps things out, especially to NOT put multi megabyte (or gigabyte) blobs into the .pot file.
@magnumripper commented on GitHub (Jun 15, 2016):
46a6c50fixed issues with pot-syncing truncated ciphertexts. I thought I had that tested but given the problem I think it never worked 😎 Easy fix though.@jfoug commented on GitHub (Jul 13, 2016):
Is this 'feature enhancement' now considered complete? We did it differently than was first proposed, but I 'think' we have it fully running now (correct?)
Or do we still have lots of 'cleanup' to do to remove the older hack stuff.
@jfoug commented on GitHub (Jul 13, 2016):
@magnumripper your new method will not remove duplicates. What we are comparing is the binary from the full hash, vs an MD5 of the original hash string. 2 totally different things.
That was why I was calling binary() at .pot time, and putting that out there.
@jfoug commented on GitHub (Jul 13, 2016):
Ok, we NEED to have
SOURCE_HASHANDBIN_HASHBIN_HASHis the return from binary() of the format, where the 'real' hash is. We HAVE to have the binary value, to be able to remove duplicates. The code we have today removes .pot lines (I think), if binary() is 0 bytes long. BUT something like luks (which does have a binary), will NOT work right.@jfoug commented on GitHub (Jul 13, 2016):
Ok, for LUKS. The first block is how our code writes a .pot file today. It fails to remove the hash and re-cracks it. The 2nd one has $bin_value appended, and it does properly .pot remove.
For luks, this happens to work with an unmodified binary() function, since $_hex_binary_value is the last thing on a valid luks hash line. BUT we may need to do a strrchr(ct, '$') in other formats binary functions, IF we detect this is a .pot line with the $SOURCE_HASH
@magnumripper what do you see about what I have just found??
@jfoug commented on GitHub (Jul 13, 2016):
Made some simple changes, and now luks (and likely others with a binary) work. But I am seeing strangeness on -show and -show=left:
I have not checked anything in yet, (but easily could), the changes are pretty trivial. What I have done is to simply append a '$' and any possible binary() result to the .pot line. we can easily modify formats binary() if we need to. luks did not require any changes to binary(). But now the -show and -show=left are having issues
@jfoug commented on GitHub (Jul 13, 2016):
If I roll back my recent changes, then -show and -show=left both show 0 crack 1 left for this LUKS crack. So I will dig into both of those functions. Well, in my VC build it works, grrr. I will look at this next week after I get back from my Colorado trip.
@magnumripper commented on GitHub (Jul 16, 2016):
I think not. We may have a bug and/or we may have to rewrite something a little but we do not need BIN_HASH.
@jfoug commented on GitHub (Jul 18, 2016):
BIN_HASHis required for -show for any format that has a non-zero binary length.@jfoug commented on GitHub (Jul 18, 2016):
I withdraw this bin_hash request, and think it is not needed. I am not sure why it was having problems, but I can not replicate the problem now. Well, not quite (-show and -show=left are working however).
@jfoug commented on GitHub (Jul 25, 2016):
NOTE, it appears that MANY formats now are not removing currently found hashes.
I am not 100% sure, but I think it is due to this change (possibly this change not being complete).
@jfoug commented on GitHub (Jul 26, 2016):
These formats do NOT remove already found salts. (I found others I had to look at, but only these 2 are problems).
krb5_tgs_fmt_plug.c
pfx_ng_fmt_plug.c
@jfoug commented on GitHub (Jul 26, 2016):
0350a1cfixes the problem with pfx_ng format (the only with with BINARY_SIZE != 0) I simply also tack onBIN_HASHand the hex return from fmt->methods.binary(ct) to the end of the hash string (reducing the starting size appropriately). This fixes the already cracked removal bug.I still have to find problem in krb5_tgs, BUT it may not be due to the trimmed hash (even though that format does trim).
@magnumripper commented on GitHub (Jul 28, 2016):
You keep reverting to BIN_HASH and I maintain the idea this is NOT the canonical solution. But it will do for now.
@jfoug commented on GitHub (Jul 28, 2016):
It HAS to be there, or salts will not be removed from the .pot file. Trust me on that one. The only format which has a binary>0 is pfx-ng That was actually the one I started on, and that is why I thought
BIN_HASHwas going to be needed. BUT it is only needed when there is a binary_len > 0 and a non fmt_default_binary_hash() method defined.It is now ONLY added, when the format has a binary. pfx-ng is the only one at this time. It is all due to how loader works, since it is loading binaries. But with the chopped hashes, we can not use the 'normal' binary() method without providing help.
@magnumripper commented on GitHub (Jul 28, 2016):
I trust you fully. I'm not saying it was working prior to your fix - what I am saying is this is a bug that can be fixed in some other way. I will have a look at this exact case later.
I do realize your solution may be the best one (or least intrusive) after all, and when done this way (only when needed) it does look a lot better than the version we had some time ago. We'll see.
@jfoug commented on GitHub (Jul 28, 2016):
I agree with having this field 'optional'. For most formats, where we use a cracked[] array, and binary_length=0 (and no bin_hash), this added field would have been worthless. And right now, I think this is the only format (pfx-ng), where we trim that has a binary. Most of our trims simply use encrypt/decrypt calls into a large data blob, and do not have any binary() possibility.
@jfoug commented on GitHub (Aug 2, 2016):
Note, we 'could' check for chopped pots automatically, with a format change.
We could add a optional (NULL or char*) field, that is the signature field (or even an array of signatures), then within loader, during .pot load, we could to a strncmp of the line (even before split/prepare, since this is from the .pot file), and if it returns 0 for the compare, then call ldr_isa_pot_source() right from within the loader code, and know up front that this is a valid line from that hash. Then we do not have to add any logic to any formats.
@magnumripper commented on GitHub (Aug 18, 2016):
I think potcheck.pl wrapped this one up
@magnumripper commented on GitHub (Aug 22, 2016):
@jfoug I reverted the BIN_HASH stuff (yet again) in
977a4130and committed an alternate fix in7870117f. I really really believe BIN_HASH is the wrong answer to ANY problem we might encounter.@magnumripper commented on GitHub (Sep 1, 2016):
3ae959806,694c93eff