Note 2.11.1.
The following algorithm is so poor that it may be a stretch even to call it a hashing algorithm. That being said, it is being used as a tool to explain what hashes are.
github.com/pearcej/security-hash
docs.docker.com/get-docker/
www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701
bash
shell in the terminal on a custom Linux container, and type docker run -it ryantolboom/hash
. You should see your command followed by output similar to the following:
ryan@R90VJ3MK:/windir/c/Users/rxt1077/it230/docs$ docker run -it ryantolboom/hash root@vm-name:/
run
command interactively (-it
) as this container runs bash
by default.
md5sum
. Typically this is used to detect if a file has been tampered with. A website may provide links to download software as well as an MD5 hash of the files so that you know what you’ve downloaded is correct. Similarly a security system may keep md5sums (MD5 hashes) of certain critical files to determine if they have been tampered with by malware. Let’s practice taking the md5sum of the /etc/passwd
file. Note that root@vm-name:/#
is the prompt in the terminal, indicating that we are running as root on a container named vm-name
. Your will appear differently.
md5sum /etc/passwd
. You should see your command followed by output similar to the following:
root@vm-name:/# md5sum /etc/passwd 9911b793a6ca29ad14ab9cb40671c5d7 /etc/passwd
md5sum /etc/passwd
. The second line is the output of the command, which is the MD5 hash of the contents of the file /etc/passwd
. The output is in two parts separated by a space. The first part of the output line, namely 9911b793a6ca29ad14ab9cb40671c5d7
is the MD5 hash, the second part, namely /etc/passwd
is the file name.
/tmp/name.txt
by typing echo "<your_name>" >> /tmp/name.txt
which will appear as follows:
root@vm-name:/# echo "<your_name>" >> /tmp/name.txt
cat
command in Linux is used to display the contents of files, concatenate multiple files, and create new files, so you can see the contents of the new file by running: cat /tmp/name.txt
.
md5sum
of your first name which is stored in /tmp/name.txt
? (You can run the command md5sum /tmp/name.txt
to find out.)
/etc/shadow
file. Let’s print out the contents of that file to see how it looks. Type cat /etc/shadow
, and you should see your command followed by output similar to the following:
root@vm-name:/# cat /etc/shadow root:*:19219:0:99999:7::: daemon:*:19219:0:99999:7::: bin:*:19219:0:99999:7::: sys:*:19219:0:99999:7::: sync:*:19219:0:99999:7::: games:*:19219:0:99999:7::: man:*:19219:0:99999:7::: lp:*:19219:0:99999:7::: mail:*:19219:0:99999:7::: news:*:19219:0:99999:7::: uucp:*:19219:0:99999:7::: proxy:*:19219:0:99999:7::: www-data:*:19219:0:99999:7::: backup:*:19219:0:99999:7::: list:*:19219:0:99999:7::: irc:*:19219:0:99999:7::: gnats:*:19219:0:99999:7::: nobody:*:19219:0:99999:7::: _apt:*:19219:0:99999:7::: karl:$y$j9T$oR2ZofMTuH3dpEGbw6c/y.$TwfvHgCl4sIp0b28YTepJ3YVvl/3UyWKeLCmDV1tAd9:19255:0:99999:7:::
karl
user has a long hash immediately after their username.
www.openwall.com/john/
john <passwordfile>
in your terminal. You can also customize its behavior with options like --wordlist
to specify a custom wordlist for cracking. We will tell it to use the default wordlist to try and determine what the password is that matches karl’s hash in /etc/shadow
by running the command john --format=crypt --wordlist=/usr/share/john/password.lst /etc/shadow
. The --format=crypt
option tells John the Ripper to use the crypt format, which is the format used by the hashes in the shadow file. The --wordlist
option tells John to use the specified wordlist file, which is a list of common passwords. The last argument is the file containing the hashes, in this case /etc/shadow
. You should see your command followed by output similar to the following:
root@vm-name:/# john --format=crypt --wordlist=/usr/share/john/password.lst /etc/shadow Loaded 1 password hash (crypt, generic crypt(3) [?/64]) Press 'q' or Ctrl-C to abort, almost any other key for status <karl's password> (karl) 1g 0:00:00:01 100% 0.6211g/s 178.8p/s 178.8c/s 178.8C/s lacrosse..pumpkin Use the "--show" option to display all of the cracked passwords reliably Session completed
--show
command with the file: john --show /etc/shadow
/usr/share/john/password.lst
, you will quickly find that John the Ripper figures out karl’s password. John the Ripper can also run incrementally though all the possible character combinations, but it takes much longer. To help make these types of attacks more difficult, every hash in /etc/shadow
is built off of a random number. This number is called a salt and is stored with the hash. This means that instead of just trying one hash for each word in the wordlist, the hash cracker must try every possible salt for every word in the wordlist, slowing things down significantly. Modern hash crackers may use rainbow tablesen.wikipedia.org/wiki/Rainbow_table
crypt
to show that we have the actual password. This utility is already installed on your container. We will start by printing out just the line in /etc/shadow
that has karl’s info. The Linux grep
command is a powerful search tool. (The name is an acronym from Globally search for a Regular Expression and Print matches.) We will use the grep
command to limit out output to things that have karl
in them by typing cat /etc/shadow | grep karl
. You should see your command followed by output similar to the following:
root@vm-name:/# cat /etc/shadow | grep karl karl:$y$j9T$oR2ZofMTuH3dpEGbw6c/y.$TwfvHgCl4sIp0b28YTepJ3YVvl/3UyWKeLCmDV1tAd9:19255:0:99999:7:::
:
, are used as separators in the shadow file. The first part of the shadow line is the username, karl
.
$y$j9T$oR2ZofMTuH3dpEGbw6c/y.$TwfvHgCl4sIp0b28YTepJ3YVvl/3UyWKeLCmDV1tAd9
.
$
, is the version of the hashing algorithm being used, y
for yescrypt in our case.
j9T
for us.
oR2ZofMTuH3dpEGbw6c/y.
in between the third set of dollar signs is the salt.
TwfvHgCl4sIp0b28YTepJ3YVvl/3UyWKeLCmDV1tAd9
in between the fourth $
and the :
is the hash itself.
crypt
utility calls the system crypt
man7.org/linux/man-pages/man3/crypt.3.html
/etc/shadow
. If everything goes well, you should see hash output that matches what is in /etc/shadow
. To try this, type crypt <karl's password> '$y$j9T$oR2ZofMTuH3dpEGbw6c/y.'
into the terminal, replacing <karl's password>
with the actual password you cracked. You should see your command followed by output similar to the following:
root@vm-name:/# crypt <karl's password> '$y$j9T$oR2ZofMTuH3dpEGbw6c/y.' $y$j9T$oR2ZofMTuH3dpEGbw6c/y.$TwfvHgCl4sIp0b28YTepJ3YVvl/3UyWKeLCmDV1tAd9
crypt
command matches the hash in /etc/shadow