







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








1 Ivy 2 1.1 Setup................. 2 1.2 Protocol................ 3 1.3 Capabilities.............. 4 1.4 Assignment.............. 4 1.5 Deliverables.............. 4 1.5.1 CS162............. 4
2 Keys 5 2.1 Setup................. 5 2.2 Theoretical Attack.......... 5 2.3 Assignment.............. 6 2.4 Deliverables.............. 6 2.5 Technical Details........... 6
3 Transcript 7 3.1 Setup................. 7 3.1.1 Challenge/Response Protocol 7 3.1.2 Signing Details........ 7 3.2 Assignment.............. 7 3.3 Deliverables.............. 8
4 Grades 9 4.1 Setup................. 9 4.1.1 Block Cipher Modes..... 9 4.1.2 Weaknesses of ECB..... 9 4.1.3 Database Layout....... 10 4.1.4 Academy Statistics...... 10 4.2 Assignment.............. 10
5 Padding 11 5.1 Setup................. 11 5.1.1 CBC Mode.......... 11 5.1.2 PKCS#7 Padding...... 11 5.1.3 The Leak........... 11 5.2 The Attack.............. 12 5.2.1 Recovering Intermediate State 12 5.2.2 Forging Multiple Blocks... 12 5.3 Assignment.............. 12 5.3.1 Technical Details....... 13 5.3.2 Stencil Code......... 13 5.4 Deliverables.............. 13
To become a fully-fledged crewmate on one of the top ships in space, potential candidates come from all across the galaxy to the Crewmate Academy to learn how to complete tasks from the best in the field. But the Academy’s been recently having some issues with some adversaries infiltrating their ranks—Impostors, if you will—and sometimes you don’t exactly know who you can trust. As a crewmate-in-training, perhaps it’s up to you to do some of your own investigation and see if you can learn anything about your classmates...
In this project, you will break the security of various cryptographic systems in the Crewmate Academy’s IT infrastructure. All problems in this project are self-contained, so you can complete them in any order.
CS166 students must complete the three problems in Part I: Ivy (Section 1), Keys (Section 2), and Transcript (Section 3). CS162 students must complete the three problems in Part I, along with an additional component for Ivy (Section 1), and the two problems in Part II: Grades (Section 4) and Padding (Section 5).
For all students, each problem is worth an equal portion of the overall credit for this project. For CS166, this means that each problem is worth 13 of the available credit, and for CS162, 15.
When you’re ready to submit, upload your files for each problem to their respectively named drop point on Gradescope. Do not upload them as a .zip file.
In this problem, you’ll try to steal the encryption key used by a wireless encryption protocol.
Your dorm at the Crewmate Academy is located on the famous “S.S.S. Ivy” spaceship. Each dorm room in the ship has a router that provides internet access to the crewmate residing inside. The design of the internet access on the S.S.S. Ivy has some oddities, though:
In order to make sure that crewmates cannot simply sniff this wireless traffic in order to snoop on their neighbors’ traffic, the wireless traffic is encrypted with a shared key, k. This shared key is known to the central hub and to all room routers. The network setup is illustrated in Figure 1.
Figure 1: Network configuration for the Ivy problem.
Snooping on your neighbors’ traffic sounds like your cup of tea—it’d certainly help you figure out if one of them was The Impostor. But, you’re also lazy. Stealing the router from the wall and tapping the internal circuitry to find the key sounds like too much work—it’d much easier if you can extract the key by breaking the cryptosystem (and much more covert than physically stealing the router).
Luckily for you, a quick web search for the router’s product name reveals a product spec sheet that describes the encryption protocol used—what a great find!
Given this setup, you’d like to be able to extract the key. You have a few tricks up your sleeve:
The binary at /course/cs1660/student/<your-login>/cryptography/ivy/router simulates your router. Given hex-encoded plaintexts on stdin, it prints corresponding ciphertexts to stdout in the format:
The first line of output corresponds to the ciphertext of the authentication packet that the router first sends to the hub. Your task is to recover the shared key, k, by interacting with this binary. We’ve also provided two utilities in the /course/cs1660/pub/cryptography/ivy/ directory which you might find helpful:
Your handin will consist of two files—KEY and README—along with any code you used in your attack. KEY should contain the recovered key on the first line, encoded in hex (do not include “0x” in front of the key), and nothing else. The KEY file is worth 70% of the problem credit. Your README should cover the following:
CS162 students must also write a sol.go, sol.rb, or sol.py program that, when given a path to an router binary, automatically performs your attack against that binary and prints the recovered key to stdout. Your program should have the following usage (where script-name is the name of your script or binary):
./script-name <path-to-router-binary>
Please also include instructions on how to compile and/or run your code in your README. For CS162 students, the sol.{go, rb, py} program is worth 40% of the credit for this problem, a correct KEY is worth 30%, and the README is worth 30%. CS162 students should upload their entire handin for the Ivy problem to the “Ivy (CS162)” drop point on Gradescope (do not upload anything to the “Ivy (CS166)” drop).
2 Keys
In this problem, you’ll try to break a block cipher encryption scheme that uses two encryption keys.
For a while, Crewmate Academy used a block cipher with a 24-bit key for all of its encryption needs— emails, crewmate task lists, and so on. However, as computers became more powerful, 24 bits was no longer enough—even a slow computer can perform 2^24 encryptions or decryptions in a reasonable amount of time.
Not wanting to redesign the cipher entirely, the Academy administrators had a clever idea: simply use two separate 24-bit keys. In order to encrypt a block, they would encrypt it first with the first key, and then encrypt the resulting ciphertext with the second key. To decrypt, they would decrypt with the second key, and then with the first. To see why this works, recall that a block cipher takes a fixed-length message m and a key k and produces a ciphertext c (and decryption is just the inverse of encryption):
Ek(m) = c [encryption] Dk(c) = m [decryption]
The Academy’s new system first creates a midway ciphertext, c′, by encrypting m with the first key, k 1 , and then produces the final ciphertext, c, by encrypting c′^ with the second key, k 2 :
Ek 1 (m) = c′^ −→ Ek 2 (c′) = c
In order to decrypt, the process is simply reversed:
Dk 2 (c) = c′^ −→ Dk 1 (c′) = m
The administrators figured that two 24-bit keys would be just as good as a single 48-bit key, since in order to encrypt or decrypt properly, an adversary would need to know the correct values for both keys. The number of possible pairs of 24-bit keys is 2^48 , so the administrators reasoned that in order to break the system, an adversary would have to just try all of the 2^48 possible pairs—the same as if the system had one 48-bit key, which would be way too long for a attacker with conventional hardware to brute-force.
Unfortunately, the Academy’s simple approach, while elegant, doesn’t work quite as well as they had hoped. Suppose that you were trying to break this scheme, and you were given a message, m, and a corresponding ciphertext, c. The simplest attack would be to try all 2^48 possible key pairs, and, for each, try encrypting m using that key pair, and seeing if the resulting ciphertext matched c.
However, imagine that, in addition to m and c, you also had c′—the midway ciphertext that’s the result of encrypting m only with the first of the two keys (or, alternatively, the result of decrypting c with the second of the two keys). In this way, you only would have to try 2^25 keys—almost as many tries as if the system had never added the second key! Here’s how:
Of course, you probably would never get access to the midway ciphertext used to compute a given plain- text/ciphertext pair. However, that doesn’t mean that the insight behind this attack is entirely worthless. Maybe you can use the idea to devise an attack that works even without the midway ciphertext?
3 Transcript
In this problem, you’ll exploit public key cryptography usage errors to forge your own transcript.
The Crewmate Academy website uses RSA public key cryptography to secure many of its operations. As a student at the Academy, two of these are relevant to you:
You’re applying for crewmate positions on higher-paying spaceships, and all of your applications require that you send a transcript. However, your grades aren’t quite what you like them to be. Luckily for you, the website designer made a critical mistake: the website uses the same RSA key pair for allowing users to verify the integrity of the website as it does for signing messages. This is a big no-no, and it just might let you forge your own transcript...
3.1.1 Challenge/Response Protocol
When a user connects to the website, the website provides a challenge/response protocol by which they can verify that the website they’re talking to is authentically the website of the Crewmate Academy.
In this protocol, the user generates a random nonce^2 , encrypts that nonce using the website’s public key, and sends the resulting ciphertext to the website. The website then decrypts the ciphertext with its private key and sends back the resulting plaintext. The user verifies that the plaintext matches their original nonce. If they match, it means that the website must be in possession of the private key corresponding to the public key.
3.1.2 Signing Details
When the website signs important documents (including transcripts), it does so by encrypting them with its RSA private key. Recipients of the document can then verify the signature by decrypting it with the server’s public key and verifying that the decrypted plaintext matches the document.
However, RSA cannot encrypt (or decrypt) plaintexts larger than the key, and RSA keys are only a few thousand bits long. To get around this, the document to be signed is first hashed, which produces a value small enough to be encrypted or decrypted in RSA (the Academy uses the SHA-256 hash for this purpose). Then, the website encrypts the hash with its private key. To verify the signature, one can decrypt the signature with the public key and check that the resulting plaintext matches the SHA-256 hash of the document.
The /course/cs1660/student/<your-login>/cryptography/transcript/challenge binary simulates the challenge/response protocol with the website. It accepts hex-encoded challenges on stdin and produces hex- encoded responses on stdout. Additionally, we’ve provided a JSON-encoded copy of the website’s public key in /course/cs1660/student/<your-login>/cryptography/transcript/server.pub.
(^2) In cryptography, a nonce is a “number used once”—in other words, a random value.
You may find the /bin/sha256sum program useful. Similarly, you may find these utilities in the /course/ cs1660/pub/cryptography/transcript directory helpful:
Your assignment is to produce two files: TRANSCRIPT (your forged transcript), and TRANSCRIPT.sign (the website’s signature that the TRANSCRIPT file is authentic). What you put in TRANSCRIPT is not important, so feel free to get creative there. However, it does need to be a plain text file (no PDFs, RTFs, etc).
Once you have a signature for your TRANSCRIPT, you should be able to verify the signature by using the verify binary in the /course/cs1660/pub/cryptography/transcript directory:
verify server.pub TRANSCRIPT $(cat TRANSCRIPT.sign)
Your handin should consist of three files: TRANSCRIPT, TRANSCRIPT.sign, and a README. Having a correct pair of TRANSCRIPT and TRANSCRIPT.sign files is worth 70% of the credit for this problem. Your README is worth 30% of the credit for this problem, and should cover the following:
4.1.3 Database Layout
After asking some of the crewmates about the new database system, you’ve learned that each plaintext database record consists of a five-digit staff ID (randomly chosen from { 1 ,... , 99999 } and represented with leading zeroes, if necessary), and a course grade (one of {A, B, C, N }) associated with that crewmate:
id:01234, grd:A
It happens that the ID part of the line (“id:01234”) is eight bytes long, as is the grade part (from the comma to the newline: “, grd:A\n”). Eight bytes is also the block length of the cipher that’s being used—what a coincidence! This means that the ciphertext blocks of the encrypted database are laid out like this:
4.1.4 Academy Statistics
Thanks to statistics that the Crewmate Academy must report due to intergalactic law, you also know:
We’ve provided an encrypted copy of the grade database at /course/cs1660/student/<your-login> /cryptography/grades/grades.enc. Using your knowledge of the database layout and Academy statis- tics, your task is to write a README containing answers and justifications to the following questions:
You should also turn in any code you used to analyze the data—please include a brief explanation of what your code does and how to run your code in your README.
5 Padding
In this problem, you’ll exploit a seemingly minor information leak to compromise an entire system.
At the same time you published your findings regarding the grade database, the Academy’s administrators were developing a system for emailing out crewmate grades. Vowing to never make the ECB mistake again, the administrators set out to find an alternative block cipher mode for use in the email system. They decided on Cipher Block Chaining (CBC) mode—and, for good measure, switched to using a block cipher with 16-byte blocks.
5.1.1 CBC Mode
CBC mode XORs each plaintext block with the previous ciphertext block, then encrypts the resulting block with the cipher. In this mode, any change in a plaintext block affects the ciphertext of all following blocks since the encryption of a given block depends on all preceding blocks. This makes statistical attacks much more difficult. Figure 3 illustrates CBC encryption:
Cipher Block Chaining (CBC) mode encryption
block cipher Key encryption
Ciphertext
Plaintext
block cipher Key encryption
Ciphertext
Plaintext
block cipher Key encryption
Ciphertext
Plaintext
Initialization Vector (IV)
Figure 3: Encryption in CBC mode. Source: https://en.wikipedia.org/wiki/Block_cipher_mode.
An issue with any fixed-length block cipher is that the plaintext’s length may not be a multiple of the block size. To fix this, we can add extra data to the end of the plaintext (called padding) until its length is a multiple of the block size. In designing the email system, the owner’s chose PKCS#7 padding.
5.1.2 PKCS#7 Padding
In PKCS#7, plaintexts are padded with bytes whose values encode the length of the padding. If one byte of padding is used, that byte’s value is 1; if two bytes are used, those bytes’ values are each 2, and so on:
01 02 02 03 03 03 04 04 04 04 (and so on)
Also, if a plaintext’s length is already a multiple of the block size, we add an entire block of padding. Since the email system’s cipher uses 16-byte blocks, a plaintext whose length is a multiple of 16 bytes would be padded with 16 bytes, each with the value 0x16.
5.1.3 The Leak
When decrypting a ciphertext, the email system performs the following steps:
ciphertext whose plaintext is “help” will cause the server to respond with a help menu—you can use that menu to figure out what to do next. (Sending the help command should only require a single ciphertext block, so this should allow you to test your solution to recovering a single ciphertext block’s intermediate state even if you haven’t yet figured out how to forge multi-block messages.)
5.3.1 Technical Details
5.3.2 Stencil Code
The /course/cs1660/pub/cryptography/padding directory contains stencil code for your attack in multiple languages—Go, Ruby, and Python 3. You can choose the one that you’re most comfortable with. The stencil code implements command-line argument validation and sets up the necessary networking code to send data to and read data from the padding server.
Your handin should consist of three files: a GRADES file, a README, and a Go, Ruby, or Python 3 script named sol.go, sol.rb, or sol.py. The GRADES file should contain the exact contents of the grades report (what this means will be obvious once you’ve extracted the grades). A correct GRADES file is worth 20% of the credit for this problem.
Your README is worth 30% of the credit. In addition to instructions on how to compile and/or run your solution code, it should cover the following:
The sol.{go, rb, py} script is worth 50% of the credit for this problem. Your program should have the following usage (where script-name is the name of your script or compiled binary):
./script-name
When run, your program should connect to the email server at the given host and port, perform your attack in order to send the given command, and print the server’s response as a result of executing command. In order to get full credit for your script, your script must be capable of sending any arbitrary command to the server (not just those that the server explicitly describes).