Faculty.cs.nku.edu



CIT 480: Securing Computer SystemsLab #17: Symmetric CryptographyName: _____________________1: Lab PreparationsThis lab can be completed on any Linux machine that has OpenSSL 1.0.1 or later installed. You can do this lab on an NKU Linux PC or server or on your Kali VM. In this lab, we will use the OpenSSL package to experiment with encryption and decryption using symmetric encryption algorithms. While OpenSSL is a library for providing Transport Layer Security (TLS), the project also provides a command line tool that provides access to all of the encryption algorithms contained in the library.Verify that the version of OpenSSL is 1.0.1 or later.$ openssl versionExamine the list of encryption algorithms provided by OpenSSL. Lower case names followed by an ASCII arrow (=>) are aliases for the longer upper case names on the right side of the arrow.$ openssl list -cipher-algorithmsHow many ciphers, including aliases, are supported by this version of OpenSSL? Provide both the command line you used for counting ciphers and the number below.26670647700ReferencesThe command man openssl will provide short descriptions of how the command works. See the OpenSSL command HOWTO at to obtain more details.2: Encryption and Decryption with PasswordsIn the cryptography basics lab, we used OpenSSL to encrypt using a password. OpenSSL converts the password into a key of the appropriate length for the specified cipher. While this usage is convenient, it is subject to password guessing attacks, as we'll demonstrate in this section. We'll use the Ubuntu Linux legal notice in /etc/passwd as our plaintext in this section.2.1: Encrypt a text file using the Advanced Encryption Standard (AES) 128-bit version using the openssl command. Use whatever password you want to use for encryption, but remember it as you will need it for later questions in the pare the sizes and types of the resulting files. It will quickly become obvious that the encrypted file is stored in a binary format, not as ASCII text, so we will need to use commands like xxd and strings to investigate the ciphertext rather than just using cat. Describe how the original and encrypted files differ in your own words. Are there any interesting strings in the ciphertext file?$ openssl aes-128-cbc -salt -in /etc/passwd -out ciphertext$ ls -l /etc/passwd ciphertext$ file /etc/passwd ciphertext$ xxd /etc/passwd$ xxd ciphertext$ strings -6 ciphertext26670666750 2.2: Decrypt the file, then compare the resulting plaintext with the original file using the diff command to verify that decryption worked correctly. If the diff command produces no output (and a return value of zero), then the files match. Any output indicates a discrepancy between the two files. Put the output of diff (if any) and the return value from diff (as stored in the $? shell variable) in the box below. $ openssl aes-128-cbc -d -salt -in ciphertext -out plaintext$ diff /etc/passwd plaintext$ echo $?266704826002.3: Guess the password of the file using the shell loop below, which simply tries each password in a file with openssl one by one. First, create a file named words.lst with the following contents:123456passwordfoobarfoobazAdd your password to the middle of the list. Do not make it the first item in the list. $ for PASSWORD in $(cat words.lst);do export PASSWORD echo; echo “Trying $PASSWORD”; echo if openssl aes-128-cbc -d -salt -in ciphertext -pass env:PASSWORD >/dev/null 2>&1 then echo 'Password for file:' $PASSWORD openssl aes-128-cbc -d -salt -in ciphertext -pass env:PASSWORD fidoneWhat was the output for the correct password (don’t include the decrypted file; just include the output of the code). What was the output for (one of the) incorrect passwords? left61595003: Encryption and Description with KeysIn this part of the lab, we will encrypt and decrypt by explicitly specifying the encryption key and initialization vector (IV), which will ensure that our stored data cannot be decrypted using a password guessing attack. Note that keys are only resistant to guessing attacks if they are random, so we will first learn how to generate random numbers with OpenSSL. The initialization vector is similar to a salt, so it must also be random, though it does not have to be kept secret like an encryption key.3.1: Generate an 8 byte (64 bit) random number and write it in hexadecimal notation in the box below.$ openssl rand –hex 8left107950 3.2: Generate the key and initialization vector, storing them in shell variables so that we can reuse them, then encrypt the file with them. Note that specifying options, like the key and initialization vector on the command line exposes them to other users on the same machine who run the ps command, so this technique should only be used when your threat model does not include local users. Include your key, initialization vector, and first 16 bytes of the ciphertext as listed by xxd in the box below.$ key=$(openssl rand –hex 16)$ echo $key$ iv=$(openssl rand –hex 16)$ echo $iv$ openssl aes-128-cbc -K $key -iv $iv -in /etc/passwd -out ciphertext$ xxd -l 16 ciphertext266707048503.3: Decrypt the file, then compare the plaintext output with the original file using the diff command to verify that decryption worked correctly. If the diff command produces no output, then the files match. Any output indicates a discrepancy between the two files. Put the output of diff (if any) and the return value from diff (as stored in the $? shell variable) in the box below.$ openssl aes-128-cbc -d -K $key -iv $iv -in ciphertext -out plaintext$ cat plaintext$ diff /etc/passwd plaintext$ echo $?266704381504: Block Cipher Operation ModesIn this section, we will examine why it is important to use secure block cipher modes like Cipher Block Chaining (CBC) instead of Electronic Code Book (ECB) mode. To experiment with this modes, we will need a bitmap image file, which can fetch via the web. If using a VM or Linux PC, download and verify the image as follows.$ wget $ eog penguin.bmpIf on kosh, download the image with$ wget remember that to view any images, you will need to transfer them to another computer via sftp.3.1: Encrypt the image using AES-128 once in CBC mode and once in ECB mode. Use the same password for both encryptions. Note that both passwords are the same size, but that the contents of the files differ even though both files are produced by encrypting the same plaintext with the same cipher and key. The differences arise from the use of different block cipher modes.The cmp command identifies differences in binary files, while xxd will let us view the differences. Write the output of all cmp and xxd commands in the box below.$ openssl aes-128-cbc -in penguin.bmp -out cipher.cbc$ openssl aes-128-ecb -in penguin.bmp -out cipher.ecb$ ls -l cipher.*$ cmp cipher.cbc cipher.ecb$ xxd -l 16 cipher.cbc$ xxd -l 16 cipher.ecbright666750 3.2: If we attempt to view our encrypted images directly, we receive an error about the file type.$ eog cipher.ecbThis error results because the file header, which identifies the filetype and provides metadata (such as the height and width of the image) that an image viewer needs, is encrypted and thus gibberish to the image viewer. To fix this problem, we will copy the 54-byte BMP header from the penguin image to a file, remove the first 54 bytes from the ciphertext files, then append the BMP header to both encrypted files. Once we have done that, we can view the images.$ dd if=penguin.bmp of=header bs=1 count=54$ dd if=cipher.cbc of=cipherbody.cbc bs=1 skip=54$ dd if=cipher.ecb of=cipherbody.ecb bs=1 skip=54$ cat header cipherbody.cbc >cbc.bmp$ cat header cipherbody.ecb >ecb.bmp$ eog ecb.bmp$ eog cbc.bmpDescribe the differences between the images in the box below, and describe why using ECB compared to CBC produced such results. Are you convinced that you need to use CBC for your ciphertext to be confidential?-19050609600 5: Submitting the LabBring a printed copy with your name on it to class on the class period after which this lab was assigned. Online students must submit the lab via Blackboard. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download