LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-10-2010, 05:01 AM   #1
m4rtin
Member
 
Registered: Sep 2007
Posts: 261

Rep: Reputation: 16
reverse engineer crypt(3) hash


I have generated a password hash using mkpasswd under Linux(mkpasswd utility uses crypt(3) C library function, which uses DES as a default if I'm correct). The hash of my password is hGHG8kqTlGTfQ. Is it possible to reverse engineer this hash back to my password?

How can this password hash be useful? I mean every time I generate a hash with the same password, the hash is different. For example all those hashes are generated with the same password: hGHG8kqTlGTfQ, TZB86wpkAMv3w, .VUzeoahYE2xU

All explanations are most welcome
 
Old 02-10-2010, 06:00 AM   #2
ozanbaba
Member
 
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 778

Rep: Reputation: 135Reputation: 135
well man page says it creates random passwords automatically. so they are randomly created passwords.


and hash functions are completely deterministic so you can't get two diffirent hash from same data unless
there's some thing with implantation, function or both.
 
0 members found this post helpful.
Old 02-10-2010, 10:41 AM   #3
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
As per the crypt(3) man page about DES:
Code:
...
       salt is a two-character string chosen from the set [a–zA–Z0–9./].  This
       string  is used to perturb the algorithm in one of 4096 different ways.
...
The returned value points to the encrypted password, a series
       of 13 printable ASCII characters (the first  two  characters  represent
       the salt itself).
...
Here are the hashes of your password, with the salt in bold type:
Code:
hGHG8kqTlGTfQ, TZB86wpkAMv3w, .VUzeoahYE2xU
To summarize, you have three different hashes of the same password because the salts are different. To answer another of your questions, hashes in general are a one-way mechanism: you cannot retrieve your password from a hash. Your can infer this from the fact that there is only a finite number of hashes of a given type (DES, MD5, etc) but a (theoretically) infinite number of passwords. DES has further limitations on the password length as explained in the man page.
 
1 members found this post helpful.
Old 02-10-2010, 04:52 PM   #4
ozanbaba
Member
 
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 778

Rep: Reputation: 135Reputation: 135
that's not hash, that's not hash at all. hash functions are deterministic and they are created to give the same outcome at any time and at any computer. this is important aspect of hash functions.

however randomly created salt is regularly used in encrypting anything. and still mypasswd man pages says it creates passwords " mkpasswd - generate new password, optionally apply it to a user". using DES to create them randomly is simple way to do that.
 
Old 02-10-2010, 08:25 PM   #5
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Quote:
I mean every time I generate a hash with the same password, the hash is different.
ozanbaba, we may be discussing different things. i was only talking about password hashing (which is how i understood the statement above), not password generation, which i think is what you were talking about. if the question is one about password generation, then m4rtin should ignore my post.
 
Old 02-10-2010, 11:43 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Basically, what we've got is the same (clear-text) passwd being hashed 3 times, each time with a different salt, as pointed out above.
The result is 3 different hashes, stored with the (relevant) leading salt so that the OS can re-create the hash by taking the same salt and hashing it with the clear-text passwd.
In Unix, its always done this way; the system does not even attempt to reverse the process ie it compares the stored result with the generated hash at each login attempt.
 
Old 02-11-2010, 05:19 AM   #7
Web31337
Member
 
Registered: Sep 2009
Location: Russia
Distribution: Gentoo, LFS
Posts: 399
Blog Entries: 71

Rep: Reputation: 65
Code:
$ mkpasswd 1
CDtwLvTx6ySYc
$ mkpasswd 1
IpI5s.JwGI7A6
$ mkpasswd 1 Ip
IpI5s.JwGI7A6
It expects 2-byte salt, which is 2 first bytes of newly generated hash.
Read help and mans carefully.
This is a rough shell code describing the simple way in which password can be verified.
Code:
STOREDPW=IpI5s.JwGI7A6
echo -n 'Please enter the password: '
read USERPW
SALT=`echo $STOREDPW | head -c 2`
USERPW=`mkpasswd $USERPW $SALT`
if [ $USERPW = $STOREDPW ]; then
	echo Password verified.
	exit 0
fi
echo Password verification failed.
exit 1
 
Old 02-11-2010, 05:28 AM   #8
eaglek1
LQ Newbie
 
Registered: Jan 2009
Posts: 5

Rep: Reputation: 2
if for instance you want to hash the password 'qwerty' with mkpasswd several times, you will have different hashes every time. Because of the salt, as was previously stated.

If for some instance you want to generate the same hash twice for the same password you need to force the salt for a value of your choice.
Something like this:

$> mkpasswd -S 10 , and then put 'qwerty'
you will always get '10KzyU/2omSCM'

You can see that the first 2 letters are the salt of your choice.

Just another hint, you can choose other methods of encryption like md5, sha-256, sha-512 just by using the -m parameter.


just h@ck1ng f0r fun!
eaglek1
 
Old 02-11-2010, 08:31 AM   #9
ozanbaba
Member
 
Registered: May 2003
Location: İzmir
Distribution: Slackware64 15.0 Multilib
Posts: 778

Rep: Reputation: 135Reputation: 135
Quote:
Originally Posted by Berhanie View Post
ozanbaba, we may be discussing different things. i was only talking about password hashing (which is how i understood the statement above), not password generation, which i think is what you were talking about. if the question is one about password generation, then m4rtin should ignore my post.
hashing is completely different thing from what you are discussing. you are both discussing encryption which is what crypt does. one can use it to create a random password or encrypt a password.
 
Old 02-14-2010, 05:30 PM   #10
m4rtin
Member
 
Registered: Sep 2007
Posts: 261

Original Poster
Rep: Reputation: 16
Thanks you all for discussion! Now I understand, how mkpasswd utility works(+ hashing and salting).

PS Web31337, nice script, but is there a possibility to hide sdtin appearing to terminal window when user is typing in USERPW?
 
Old 02-14-2010, 05:50 PM   #11
cantab
Member
 
Registered: Oct 2009
Location: England
Distribution: Kubuntu, Ubuntu, Debian, Proxmox.
Posts: 553

Rep: Reputation: 115Reputation: 115
Quote:
Originally Posted by m4rtin View Post
The hash of my password is hGHG8kqTlGTfQ. Is it possible to reverse engineer this hash back to my password?
Only by brute force - trying all possible passwords until a match is obtained. The 'salting' described serves to increase the difficulty of such a brute-force search, by requiring the attacker to run crypt on each password 4096 times, once for each possible salt.

The brute force search can - and usually will - be limited by considering only lowercase, or by using a dictionary search, or other methods that assume the password chosen is not fully random.

The nature of a hash function is such that multiple passwords could lead to the same hash. Any of these passwords could be used to log in. Which one is 'correct' can be inferred as it will be the one with a sensible length and possibly a pattern. Of course, that only matters if you've used the password elsewhere, which you're not supposed to do - but almost everyone does.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How To Reverse Engineer A Motherboard BIOS LXer Syndicated Linux News 0 02-06-2010 02:20 PM
USB experiment board driver. Reverse engineer? TheBrick Programming 1 08-23-2006 08:18 AM
Reverse engineer classes to diagrams in php ??? ALInux Programming 1 12-28-2005 05:19 AM
Trying to reverse engineer our network :) 8webguy8 Linux - Networking 12 03-17-2004 08:46 AM
How can you reverse engineer a small C program OrganicX Programming 1 01-30-2004 08:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration