Macs Hash
Macs Hash
labtainer macs-hash
Note the terminal displays the paths to three files on your Linux host:
1) This lab manual
2) The lab report template
3) A spreadsheet that you will populate as part of the lab.
On most Linux systems, these are links that you can right click on and select “Open Link”. If you
chose to edit the lab report and/or spreadsheet on a different system, you are responsible
for copying the completed files back to the displayed path on your Linux system before
using “stoplab” to stop the lab for the last time.
Familiarize yourself with questions in the lab report template before you start.
In this lab, you will explore cryptographic hash functions and message authentication codes using
openssl, shasum, and a couple of home-grown scripts.
replacing:
ALGORITHM with one of the supported options
(i.e., 1, 224, 256, 384, 512, 512224, 512256).
FILENAME with the name of some file on your system.
shasum –a 1 foo.txt
Do the following:
4. Return to the terminal and generate the SHA256 digest of the file you just downloaded to
see if it matches the value contained in the SHA256.sdx file.
1 If you try to enter “man shasum”, then you will get the man page for a Perl command
instead of what you want, which is very confusing.
An explanation for why a change from ‘2’ to ‘3’ results in one bit being changed.
In the ASCII format, a ‘2’ is the number 50, while a ‘3’ is the number 51. The number 50
in binary is 00110010, while the number 51 in binary is 00110011; the only difference
in these two numbers is the right-most binary digit.
Record in item #2 of the report your observations of the differences between the
two digests of iou.txt.
7. Try a few more times to change iou.txt to see if you can get a new version of the file to
match the digest of the original version.
Record in item #3 of the report your experience with trying to get a different
message to match the digest of the original data.
Record in item #5 of your report the last four hex digits of the displayed digest.
2. You will next be using a script named collide1.sh. The collide1.sh script was
written to find random data that will hash to the same value as a given input file. Even
better, it will let you specify how much of the digest you want to try to match (all or part).
Execute the following command to find some random data that will hash such that the last
hex digit of its digest will match the last hex digit of the digest for declare.txt.
./collide1.sh declare.txt 1
In item #6 of the report, in the row for “Attempt 1”, enter the displayed number of
attempts it took to find a match on the last digit of the digest. Repeat the above
command nine more times to fill out the table.
3. Now execute the following command to try to match the last two hex digits of the digest
for declare.txt.
./collide1.sh declare.txt 2
In item #8 of the report, in the row for “Attempt 1”, enter the displayed number of
attempts it took to find a match on the last two digits of the digest. Repeat the above
command nine more times to fill out the table.
4. Now execute the following command to try to match the last three hex digits of the digest
for declare.txt.
./collide1.sh declare.txt 3
In item #9 of the report, in the row for “Attempt 1”, enter the displayed number of
attempts it took to find a match on the last three digits of the digest. Repeat the
above command nine more times to fill out the table.
5. Transfer the information from the three completed tables to the spreadsheet named
“Collide1.xlsx”. A predefined graph will show your average results compared against the
theoretical results.
Item #10 asks a follow-up question about the graph shown in the completed
spreadsheet.
./collide2.py
In item #11 of the report, in the row for “Attempt 1”, enter the displayed number of
attempts it took to find two random messages whose digests match on the last byte.
Repeat the above command nine more times to fill out the table.
man dgst
You would enter the following to create a SHA1-based HMAC using OpenSSL:
replacing:
KEY with any string of your choosing, as long as it does not have spaces. It appears that
this key is first hashed in some fashion to create the actual key.
FILENAME with the name of a file on your system
For example, to generate a SHA-1-based HMAC on a file named foo.txt (with a key of “mykey”),
you would do the following:
There are other hash functions available other than “-sha1”; see “man dgst” for more
information.
1. Use openssl as described above to create an HMAC for the file you created in Task 1.
2. Repeat the command with the same file but use a different key on the second try.
Record in item #13 of the report your observations about the HMAC outputs when
different keys are used on the same file.
3. Suppose you intercepted a transmission that included: 1) declare.txt (one of the files
in your home directory) and 2) its SHA1-based HMAC. The MAC tag you intercepted is:
HMAC-SHA1(declare.txt)= 986eb8a92e561f550a911352c8b2cf5fd0465342
Through some other means you find out that the key is only a single digit, i.e., one of the
following: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
Assume that you need to figure out the key (given the information learned above).
Try all possible keys to determine the key that was used to generate the above HMAC
value on the declare.txt file.
Submission
After finishing the lab, go to the terminal on your Linux system that was used to start the lab and
type:
stoplab macs-hash
If you modified the lab report or spreadsheet on a different system, you must copy those
completed files into the directory paths displayed when you started the lab, and you must do that
before typing “stoplab”. When you stop the lab, the system will display a path to the zipped lab
results on your Linux system. Provide that file to your instructor, e.g., via the Sakai site.
cp Copy a file.
cp source destination
This will copy the file with the “source” name to a copy with the
“destination” name. The “destination” can also include the path to another
directory.
clea Erase all the output on the current terminal and place the shell prompt at
r the top of the terminal.
less Display a page of a text file at a time in the terminal. (Also see more).
less file
To see another page press the space bar. To see one more line press the
Enter key. To quit at any time press ‘q’ to quit.
man Manual
man command
Displays the manual page for the given “command”. To see another page
press the space bar. To see one more line press the Enter key. To quit
before reaching the end of the file enter ‘q’.
more Display a page of a text file at a time in the terminal. (Also see less).
more file
To see another page press the space bar. To see one more line press the
Enter key. To quit at any time press ‘q’ to quit.