mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #732] Remove Authen::Passphrase from pass_gen.pl #375
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#375
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 @jfoug on GitHub (Sep 4, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/732
These are the hashes used. I would love to remove dependancies on Authen::Passphrase
Authen::Passphrase::EggdropBlowfish; (commented out for now)
Gone: Authen::Passphrase::BlowfishCrypt;
Gone: Authen::Passphrase::LANManager; (quite a bit harder, than NT hash)
Gone: Authen::Passphrase::NTHash; md4(encode("UTF-16LE", $pwd)); (pretty easy one).
Gone: Authen::Passphrase::PHPass;
Gone: Authen::Passphrase::MD5Crypt;
Gone: Authen::Passphrase::DESCrypt; (using Crypt::DesCrypt_XS which is what Authen::Passphrase also had as a dependancy. Even does BSDI properly, including password folding.).
Gone: Authen::Passphrase::BigCrypt;
I think MD5Crypt is already gone, since Authen::Passprase::MD5Crypt did not do apr1, and the code I did was 2.5x faster than the authen code anyway.
I will simply update this issue each time I remove another hash, until they are all gone.
I still have a dependency on Crypt::UnixCrypt_XS Authen::Passprase also had this dependency, and I am almost certain this was to get BSDI working. The standard 'crypt' perl function 'could' do DesCrypt and BigCrypt, BUT only if crypt(1) program was installed on the system. There is a Crypt::UnixCrypt, but it would only handle DesCrypt and BigCrypt (not BSDI). It was pure-perl and about 6k times slower than UnixCrypt_XS. I will be leaving the Crypt::UnixCrypt_XS as a dependency, since no additional dependency was actually 'added'.
@magnumripper commented on GitHub (Sep 4, 2014):
A problem with this is the more we do ourselves, the more we need a test suite for pass_gen.pl 😃
@jfoug commented on GitHub (Sep 4, 2014):
lol. I do not quite agree, but yes, I have to make sure I do it right. Combination of looking at data, and running with john (and the TS), allow knowing that the coding is right. It really is not that hard.
I am trying to remove the really BIG dependencies. Authens does build better than it used to, but is still big. The PBKDF2 is a HUGE build. I think CryptX would be another good one to drop (has the Haval, functions, etc). I would like to get to where we just pull in MD* SHA* CBC, EBC, DES, etc. The hashing functions and pass_gen does the rest. That would be ideal in my oppion, and we will never get there, but I want to pick off the best of the low hanging fruit, trying to get there.
I had to make functions for most of these so far. NT was trivial (just md4 of an encoded string). LM took some work (converting 7 bytes into 8 bytes was ugly, but I did it). PhPass was pretty easy. MD5 was already gone, because Authen never had the apr1 hash.
DESCrypt should not be hard. BigCrypt is just DESCrypt, 2 indepentant limbs (I think), just like LM is 2 limbs. If there are any I will have problems with, that may be the blow fish crap. But time will tell.
@jfoug commented on GitHub (Sep 4, 2014):
Here is my 7 byte into 8 byte function. Can you think of a better way to do this (or is there something within the DES where we can pass in a packed 7 byte and have the DES object do this for us)
This does work, and seems fast enough.
@magnumripper commented on GitHub (Sep 4, 2014):
At any rate dropping these dependancies is a good thing. It took me a good while to get pass_gen.pl working on a fresh Ubuntu default install...
@jfoug commented on GitHub (Sep 4, 2014):
That's what tstall was put in there to help with, since we hide the problem since using the require.
But yes, I want to lose some of the dependencies
@jfoug commented on GitHub (Sep 5, 2014):
All that is left is the blowfish hashes.
@jfoug commented on GitHub (Sep 5, 2014):
There is another DES key builder already there, and is as ugly (or worse), than mine.
setup_des_key() and expand_7bit_to_8bit() do the same thing. I bet the setup_des_key() is probably an order of magnitude faster than my bit array method. If so, I will drop mine, and simply use the existing setup_des_key to do the work for LM.
1Mb setup_des_key() took 9s
1Mb expand_7bit_to_8bit() took 35s
I will drop my code.
@jfoug commented on GitHub (Sep 5, 2014):
I have these all done. The eggdrop bf, I do not have done. I have simply commented it out for now. I am working on a FRESH cygwin system, installing Perl mods one at a time to get a list. Here is where is dependent to do a -tstall now:
Digest::MD4
Crypt::UnixCrypt_XS
Crypt::DES
Crypt::Eksblowfish
Crypt::RC4
Crypt::CBC
Crypt::ECB
String::CRC32
Digest::GOST
Crypt::Digest (this is a HUGE one, but the ONLY place I have found that has all of the RipeMD hashes)
Digest::Haval256
Digest::Whirlpool
Digest::Tiger
So, I have been able to drop Authen::Passphrase and all of the PBKDF2 (Crypt::PBKDF2 and Crypt::OpenSSL::PBKDF2). These also were HUGE installs, so we have dropped 3 very large perl mods, but still have a very big one. I think this is the best I can do, without writing my own RipeMD pure perl code.
I think now that I have this done, I will install a brand new cygwin, and install everything other than Crypt::Digest, commenting out all of the Ripemd functions. I want to make sure there is no extra modules that get installed with Crypt::Digest, and that there is no 'better' way to instll the ripemd stuff.
@jfoug commented on GitHub (Sep 5, 2014):
I found Crypt::Digest::RIPEMD128 and Crypt::Digest::RIPEMD160 in the 'install' to CryptX (Crypt::Digest). I will see if I can install these by themselves, BUT I think these will trigger CryptX to be installed. Also, I have to see if I can 'use' these by themselves. Currently for the ripemd's I do this:
Crypt::Digest::digest_data("RIPEMDxxx", $pass) (or digest_data_hex, or digest_data_base64). So it is the Crypt::Digest doing the work (the CryptX). I have to figure out 1. if I can install these by themselves, and 2, if I can properly access them.
Time for another clean install :)
@jfoug commented on GitHub (Sep 5, 2014):
Just did fresh cygwin and installed ALL of the modules except the Crypt::Digest. When I commented out the ripemd stuff, things ran all the way through.
I tried to install Crypt::Digest::RIPEMD128 and it simply installs the full CryptX suite (which is HUGE).
So I think that is the only monster I have not been able to removed. I now to use the lower level Ripemd* functions, and not the higher level Crypt::Digest::digest("RIPEMDxxx", $s) but I still am not able to install a single module.
It has been a fun experiment, but I think I have picked all the low hanging fruit at this time.
@magnumripper commented on GitHub (Sep 6, 2014):
I can't remember, but do we have a command for "read plaintext(s) and output hash(es) for each format we can do" or something like that? That would be great for testing pass_gen.pl pre and post your changes in one go (just diffing the bulk outputs).
I'm mostly concerned about handling UTF-8 vs. raw. In fact, iirc some of the libs we used was retarded enough to always assume ISO-8859-1 so the output was wrong - and we made some workaround. I expect your code will be less stupid, but we may have some workarounds still in there that needs to be removed. Things like that.
@jfoug commented on GitHub (Sep 6, 2014):
That would be good feature to add, but rand salt, user names, etc would make compares hard.
@magnumripper commented on GitHub (Sep 7, 2014):
I believe you can seed rand() with a constant, so we get "same randomness" each time. Could be another option :)
@jfoug commented on GitHub (Sep 7, 2014):
Cud write my own rand. Then I can control it. I like the -genall switch idea. I might do that, putting I into a prior version so we can regression test easily.
@jfoug commented on GitHub (Sep 7, 2014):
I have added -genall and -rgenall They are basically the same, but -genall calls srand(). These will run each word through all hashes. Works pretty good. There 'could' be some encoding issues still, I am not sure. There is a 'hidden_cp' variable. I had to set it.
@jfoug commented on GitHub (Sep 7, 2014):
I will run this with a few words on the version prior to my main changes, then use it to regression test.
@jfoug commented on GitHub (Sep 7, 2014):
No go. Many of the formats had a param that was something like randbits=>12 Now I compute those hashes myself, not using the authen. So my rand generator gets different results :(( since it is called a different number of times.
@magnumripper commented on GitHub (Sep 7, 2014):
Doh. But this functionality can be useful in the future anyway.
@jfoug commented on GitHub (Sep 7, 2014):
Agreed, it's useful.
@jfoug commented on GitHub (Sep 8, 2014):
I was able to get this working. Now, we have 100% match. NOTE, this check was done after my pbkdf2 changes, but that code was solid.
28f7e92Now the authen removal regression tests. I will run the regression tests on a larger wordlist, but once I get that done, I will check that in.
Now, except for the HUGE dependency of CryptX to get RipeMDxxx working, our dependencies are on Crypt:* and Digest* functions, the core hash functions (and CBC, ECB).
@jfoug commented on GitHub (Sep 8, 2014):
I also got bfegg working, but I simply took the code from authen::passphrase. Just took one 'special' base-64 generation function, and the magic value that gets encrypted. Easy once you know the 'key', lol.
I used these words, and still, 100% equal on -nrgenall
1
12
123
1234
12345
123456
1234567
12345678
123456789
1234567890
a1234567890
ab1234567890
abc1234567890
abcd1234567890
Aabcd1234567890
AZabcd1234567890
AZXabcd1234567890
AZXQabcd1234567890
!AZXQabcd1234567890
!@AZXQabcd1234567890
!@#AZXQabcd1234567890
!@#{AZXQabcd1234567890
!@#{.AZXQabcd1234567890
!@#{.<AZXQabcd1234567890
!@#{.<?AZXQabcd1234567890
!@#{.<?/AZXQabcd1234567890
!@#{.<?/=AZXQabcd1234567890
That's good enough. I am checking in my dependency removal code.
@jfoug commented on GitHub (Sep 8, 2014):
Authen:Passphrase dependency removal:
a7fc67e@magnumripper commented on GitHub (Sep 8, 2014):
Excellent. I'll do some regression tests using 8-bit stuff just for peace of mind.
@jfoug commented on GitHub (Sep 8, 2014):
I have not done any tests 8-bit. It may have other problems, so beware.
I would recommend to use the -nrgenall (at least at first). That one will srand each times it generates a new rand string (so they all start with srand(666) ) That way, if something gets off on one format, it will get back in line on the next. Once you get a good run from -nrgenall, then try with -genall
I am pretty comfortable that my code is pretty good. One thing I think we need to test, is some VERY long words. There could be issues there (especially in the bf code). I will test when I get home.
@magnumripper commented on GitHub (Sep 8, 2014):
First problem. This works fine with the older code:
DEScrypt works fine, it dies when trying to do LM.
I was more worried about NT but that one seems to work correctly.
@jfoug commented on GitHub (Sep 8, 2014):
Works on cygwin. I will test out ubuntu 64 bit (intel). Works on my ubuntu also. Looks like it is that 'wonderful' appl3 product you have there, lol.
@magnumripper commented on GitHub (Sep 8, 2014):
Same thing, other encoding,
same problem.
@jfoug commented on GitHub (Sep 8, 2014):
Works for me. Here are the 2 hashes created:
test:u1-LM:1:c75669625ee3d86faad3b435b51404ee:1:0:M�LLER::
test2:u1-LM:1:c75669625ee3d86faad3b435b51404ee:1:0:MüLLER::
test2 was made using iconv -t cp1252 This was on Ubuntu-64 bit VM in virtual-box.
@jfoug commented on GitHub (Sep 8, 2014):
Try to update your Crypt::DES from cpan. Line47 of my DES.pm is in the middle of a comment, so it certainly is a different version than you are running.
@magnumripper commented on GitHub (Sep 8, 2014):
My Crypt::DES was no older than about a year (and from CPAN, not Apple) but I'm doing a full cpan upgrade now. It will take a while...
@jfoug commented on GitHub (Sep 8, 2014):
Could it be the setup_des_key() within pass_gen.pl. You wrote that, I simply use it. It uses a lot of chr(ord....) calls.
@jfoug commented on GitHub (Sep 8, 2014):
Are you not able to simply do a:
cpan
install Crypt::DES
?
That should not be a full cpan upgrade.
@magnumripper commented on GitHub (Sep 8, 2014):
Line 47 was this
$self->{'ks'} = Crypt::DES::expand_key(shift);Yeah, in hindsight I should have upgraded Crypt::DES only 😢
@magnumripper commented on GitHub (Sep 8, 2014):
Upgrade did not help. Not sure what happens, I'll dig into it later.
@magnumripper commented on GitHub (Sep 8, 2014):
Hmm wait a minute... what perl version are you running? I'm running 5.16 for whatever reason. I think I know what might be happening under the hood.
@jfoug commented on GitHub (Sep 8, 2014):
5.18.2 on Ubuntu 5.14.2 on cygwin. It works properly on both perl's.
@magnumripper commented on GitHub (Sep 8, 2014):
Well they are wrong. The ü is not uppercased, for a starter. I see the problem, I'm on it. It was even worse before
a7fc67e(Authen::Passphrase::LANManager assumes ISO-8859-1 which is never correct IRL) but now we have chance to do it properly.Not sure why my perl bugged out harder, but it was a good thing.
@magnumripper commented on GitHub (Sep 8, 2014):
Fixed in
aef7f2f.The problem is when we use
-utf8or-codepage=we get our password strings internally represented in (some) Unicode format. To output a correct LM hash we need to convert it to CP850 or some other OEM codepage.Current LM code now works correctly in these cases:
-utf8as long as it can be encoded in CP850-codepage=CPxxxUsing 8-bit non-OEM codepage input with a corresponding
-codepage=CPxxxxwill technically give correct hashes, they will be "what you asked for". They will just not resemble any real Windows hash.I also had to fix raw SHA1. The fix is logical: Without it [and when using
-codepageor-utf8], we are hashing Perl's internal binary representation of the string, whatever it is. The really scaring thing is that only SHA1 needed the fix... all of them should. This indicates all other Digest:: modules are buggy. Or maybe they are specified that way and SHA1 is buggy?@magnumripper commented on GitHub (Sep 8, 2014):
Here is a correct (and known so) LM hash for 'müller'
@jfoug commented on GitHub (Sep 9, 2014):
JtR does not crack this, on my machine. The file I created has the 2 byte value for the u (in lower case). I tried with -enc=utf-8 and all sorts of other ways. Simply does not find it.
Also, on output (shown last pw tested), the u is lower case version.
@jfoug commented on GitHub (Sep 9, 2014):
Nope, it does crack it (hard to do though)
./john -w=pw in -encod=utf-8 -targe=cp850
Target encoding: CP850
Loaded 1 password hash (LM [DES 256/256 XOP])
Press 'q' or Ctrl-C to abort, almost any other key for status
M▒LLER (u0-LM)
1g 0:00:00:00 DONE (2014-09-09 07:30) 1000g/s 2000p/s 2000c/s 2000C/s M▒LLER
Use the "--show" option to display all of the cracked passwords reliably
Session completed
Glad I did not create a PEBCAK issue for this, lol.
@magnumripper commented on GitHub (Sep 9, 2014):
Yeah it's tricky because, well, it IS tricky :-) But if you un-comment the recommended encoding options in john.conf, it "just works" with no encoding options supplied.
It really is tricky, many moving parts involved. No wonder most CPAN developers end up doing the wrong thing. I now see more need for conversions like the one I added for raw-sha1 (the digest modules typically assume 8859-1 so we need to use something else, eg. CP850, to detect the problem when testing) but I will try to implement it a level higher instead of adding that conversion to every format.
@jfoug commented on GitHub (Sep 9, 2014):
They are not the same. Can you look at des_setup_key() function. To me, it looks busted:
$ ./x.pl
setup_des_key: fffffffffffffffe
expand_7bit_to_8bit: fefefefefefefefe
@jfoug commented on GitHub (Sep 9, 2014):
It 'may' be the same, since the bottom bit 'is' thrown away (I think), merging the top 7 bits of each byte into the final 56 byte key. So even though the keys are not binary compatible, they end up possibly being the same, since the bits that matter, are in the same slots.
I am going to create some more test cases, and change the & to be 254 for all values in setup_des_key. I think that change should show if they are the same or not.
@jfoug commented on GitHub (Sep 9, 2014):
This setup_des_key is fully compatible, and makes the input buffers exactly like they are 'supposed' to be (same as my expand_7bit_to_8bit() function does) .
Magnum, do you have ANY problem with this change:
@jfoug commented on GitHub (Sep 9, 2014):
Will this code have problems if in -utf-8 mode ? Is the chr() function going to give us utf8 characters??
@magnumripper commented on GitHub (Sep 9, 2014):
If it works I have no problems with it. When I did the original perl code I just ported it from the NTLMv1 format:
Actually I did wonder yesterday how it could work without that very
& 254but it sure did.UTF-8 is no different to
--codepage=iso-8859-1or anything else with 8-bit input. If there is a problem with internal string representation, I'll solve it in the caller so as long as raw mode (no-utf8nor-codepageoption) works fine with 8-bit, all is fine.@jfoug commented on GitHub (Sep 13, 2014):
Would it help to simply put this into it's own function? Something like:
If those 2 functions were built, would that be enough to 'leverage' to use within the formats that need this? NOTE, if utf-8 is set, and the thing will not encode, I STILL set $s to $_[0], If not, then the generation scripts I have to jtrts will fail. It may be that we want to make a special command line switch (undocumented) that allows pass_gen to output 'something' for jtrts generation scripts (which would set the command line param), but for 'normal' usage, the pass_gen.pl would die instead on the garbage word.
But if these 2 function primitives are enough to do what you are wanting, then I will get them put into code, and used by the LANman function.
NOTE, functions were written on the fly here in github, so they may not be syntax correct or even correct at all, but you should be able to get the point of them.
@jfoug commented on GitHub (Sep 13, 2014):
I am adding another function also
and now rawsha1 will look like this:
@magnumripper commented on GitHub (Sep 13, 2014):
I see little use for the
ms_word_encode()functions. We need the UC version in lanman but that's the only application I know of. But there's no harm in moving it to a function.Also, instead of calling
word_encode()in almost every format I was thinking of doing it in the outerwhile <STDIN>loop(s), always populating a global$pw_string(perl string in its internal Unicode-aware format, as read from file or stdin) that few formats use, while$_[0]is always the output ofword_encode().After that, the NT format should use
encode("UTF-16LE", $pw_string)and raw-sha1 (and almost all other formats) should simply use$_[0]as they always did. Formats that do uppercasing and such things must use$pw_stringfor proper non-ASCII operation.Instead of global
$pw_stringwe could send it as$_[1]instead but I don't mind a global in this case.@magnumripper commented on GitHub (Sep 13, 2014):
Besides this, there are lots of existing places in pass_gen.pl where you should
s/print/print STDERR/. I'm not touching it right now since you are working on it (btw feel free to implement what I wrote above - or I'll do it in a couple of days or later)@jfoug commented on GitHub (Sep 14, 2014):
I think I have a quick 'check' for this. See what you think.
What do you think here? will this flush out the problem formats, IYHO ?
@jfoug commented on GitHub (Sep 14, 2014):
I am still having issues with testing this, in a CP. Here is a input file. Note the first 2 hashes were made with pass_gen.pl with unicode input. One was with $1, the other with $0. I then edited the file, putting in \x9A which is the right character for the code page. However, I can NOT find that hash in JtR. Can you provide help here, OR do we still have bugs somewhere, or even a bug in JtR's encode handling code.
@jfoug commented on GitHub (Sep 14, 2014):
I am done with pass_gen.pl for a while. I do not understand how to get the encoding stuff right, so I will leave that for you to hammer out.
@magnumripper commented on GitHub (Sep 14, 2014):
I will have a look at it. Any function taking Perl's internal binary representation of a [Unicode] string and passing to a hash function is bound to result in undefined behavior. So no function should use the raw string. We can use it because we want to do something like uppercasing, but then we would call
word_encode()on the result of that before hashing.@magnumripper commented on GitHub (Sep 15, 2014):
c2de395fixes a bug in that try-catch thingy. You can't test$@for defined, it's always defined.5a694bcffixes nearly all formats for using --encoding or --utf8. There are some problem with dynamic, I'll leave them to you because I couldn't follow it (at least not right now). You probably need to pass on$_[1]through the subs so it ends up reachable at some proper place - but you still need$_[0]for printing. So a call to a sub should use an argument of@_instead of$_[0]. Just like I did to DES here:@magnumripper commented on GitHub (Sep 15, 2014):
BTW I have absolutely no idea what
$arg_hidden_cpis supposed to do. I suspect it's a flawed solution to some problem I'm not aware of. I just didn't touch it. No Microsoft format uses ISO-8859-1 so that is a weird default. Perhaps CP1252 would be a bit better but maybe the best solution is something similar toms_word_encodebut using the ANSI [SIC] formats CP1250, CP1251, CP1252 and CP1253? That's just a guess.