cs161 sp2021 mt1 Exam
cs161 sp2021 mt1 Exam
For questions with circular bubbles, you may select exactly one choice on Gradescope.
Unselected option
Only one selected option
For questions with square checkboxes, you may select one or more choices on Gradescope.
You can select
multiple squares
For questions with a large box, you need to write your answer in the text box on Gradescope.
There is an appendix at the end of this exam, containing descriptions of all C functions used on this exam.
You have 110 minutes, plus a 10-minute buffer for distractions or technical difficulties, for a total of 120
minutes. There are 7 questions of varying credit (150 points total).
The Gradescope answer sheet assignment has a time limit of 120 minutes. Do not click "Start Assignment"
until you’re ready to start the exam. The password to decrypt the PDF is at the top of the answer sheet.
The exam is open note. You can use an unlimited number of handwritten cheat sheets, but you must work
alone.
Clarifications will be posted at https://cs161.org/clarifications.
This is the end of Q1. Leave the remaining subparts of Q1 blank on Gradescope,
if there are any. Proceed to Q2 on your answer sheet.
Page 1 of 19
Q2 True/false (40 points)
Each true/false is worth 2 points.
Q2.1 T r u e or F a l s e: A bank vault is protected by a locked door, but thieves break into the vault by
entering the apartment upstairs and drilling a hole through the ceiling. This is an example of least
privilege.
True False
Q2.3 True or False: In general, we want our trusted computing base (TCB) to be as large as possible,
in order to ensure that all components of a software system are trusted components.
True False
Q2.4 True or False: A program with ASLR, stack canaries, and WˆX (also known as non-executable
pages, DEP, or the NX bit) enabled is still vulnerable to integer conversion vulnerabilities.
True False
Q2.5 T r u e or F a l s e: Format string vulnerabilities let us read values from memory, but not write to
memory.
True False
Q2.7 True or False: When W^X (also known as non-executable pages, DEP, or the NX bit) is enabled,
memory on the heap can be interpreted as code and executed.
True False
Q2.10 Tru e or F a l s e: One-time pad encryption and decryption can both be parallelized.
True False
Q2.11 True or False: If the secret key is randomly generated for each encryption, then even if nonces
are reused, AES-CTR mode is still IND-CPA secure.
True False
Q2.12 True or False: While using AES-CBC mode, an IV associated with a ciphertext should never be
revealed to an eavesdropper at any time.
True False
Q2.13 T r u e or F a l s e: While using AES-CTR mode, nonces associated with future ciphertexts can be
published ahead of time without breaking security.
True False
Q2.14 T r u e or F a l s e: A pseudorandom generator can be used to stretch an initial seed with k bits of
entropy to a longer output with 2k bits of entropy.
True False
Q2.15 True or False: Suppose p is a prime and g is a generator (just like in Diffie-Hellman). Given g a
(mod p), an attacker with unlimited computational resources cannot recover a.
True False
Q2.16 True or False: In practice, El Gamal encryption is usually used to encrypt random session keys,
not meaningful messages.
True False
Q2.18 T r u e or F a l s e: To solve a Bitcoin proof-of-work problem, a miner has to find a value whose
hash begins with many zeros.
True False
Q2.19 True or False: If you browse the Internet through Tor, all your communications are guaranteed
to be anonymous (no adversary can see who you’re communicating with).
Q2.20 True or False: The fastest computers today are capable of brute-forcing a 128-bit key in about
20 years.
True False
This is the end of Q2. Leave the remaining subparts of Q2 blank on Gradescope,
if there are any. Proceed to Q3 on your answer sheet.
Definitions of relevant C functions may be found on the last page of this exam.
Assume you are on a little-endian 32-bit x86 system. Assume that there is no compiler padding or saved
registers in all questions.
For this question, assume that no memory safety defenses are enabled.
Assume that you have set a breakpoint at line 2 in the program and stopped just before the call to
strncpy. Fill in the numbered blanks corresponding to the following entries in the stack diagram. Each
blank represents a variable or struct member and may represent more than one word. Higher-numbered
addresses are located at the top of the diagram.
Stack
RIP of main
SFP of main
(1a)
(1b)
(1c)
(1d)
(2a)
(2b)
(2c)
RIP of copy_buffers
SFP of copy_buffers
Q3.1 (3 points) Section 1:
(K)
(L)
Using GDB, you find that the address of the RIP of main is 0xfff7bf20. Construct an input that would
cause the vulnerable program to execute shellcode when provided to the program.
Q3.3 (5 points) The first part of your input should be some number of garbage bytes. How many bytes
of garbage do you need? Your answer should be an integer. Enter your answer in the text box on
Gradescope.
Q3.4 (5 points) The remainder of your input should be a series of bytes. What should these bytes be?
You may use the variable SHELLCODE as 30-byte shellcode byte sequence. Your answer should be an
expression in Python 2 syntax (just like Project 1). Enter your answer in the text box on Gradescope.
(B) Non-executable pages (also called DEP, W^X, and the NX bit)
(C) ASLR
(E)
(F)
This is the end of Q3. Leave the remaining subparts of Q3 blank on Gradescope,
if there are any. Proceed to Q4 on your answer sheet.
M0 M1 M2
IV IV IV
C0 C1 C2
Note that IV is the same for every block when encrypting a message. Assume IV is randomly
generated for each encrypted message. Is AES-ECB-IV IND-CPA secure?
(A) Yes, it is secure even if the attacker can predict future IVs, because it is no longer deterministic.
(B) Yes, but only if the attacker is unable to predict future IVs.
(C) No, because an attacker can still detect when the same block is encrypted twice.
(E)
(F)
For the following parts, consider this new AES scheme below.
AES-MULTI(K, M ) = E(K, IV ⊕ M1 ⊕ M2 ⊕ · · · ⊕ Mn ).
AES-MULTI splits the message M into blocks of the appropriate size matching the underlying block
cipher. It XORs all of the message blocks together, and then XORs this result with the IV. The result’s
size is one block, which is fed into the block cipher. The output of the block cipher is the ciphertext.
Q4.2 (3 points) Alice encrypts a message with AES-MULTI. Can Bob decrypt the message?
(G) Yes, Bob can always decrypt.
(I) Yes, but only if the message is more than one block long.
(K)
(L)
Q4.3 (3 points) Eve intercepts a ciphertext encrypted with AES-MULTI. Can Eve learn any information
about the plaintext?
(A) Yes, Eve can always learn something about the plaintext.
(C) Yes, but only if the message is more than one block long.
(D) No, Eve can never learn anything about the plaintext.
(E)
(F)
Alice and Bob are using AES-CFB with reused IVs. What values can an eavesdropper Eve learn?
Select all that apply.
This is the end of Q4. Leave the remaining subparts of Q4 blank on Gradescope,
if there are any. Proceed to Q5 on your answer sheet.
Q5.2 (3 points) Commitment: Alice generates a random secret key k and then encrypts her guess with
a secure block cipher: C(b) = E(k, b).
Verification: Alice reveals her guess and the key k. Bob decrypts the commitment and verifies that
it matches Alice’s guess, i.e. he checks that D(k, C(b)) = b.
Assume that encryption will automatically pad to the block size and decryption will unpad to the
orginal message.
Q5.4 (6 points) In this part, p is a publicly known, large prime number; g is a publicly known generator
modulo p; and a is another publicly known large number modulo p.
Commitment: Alice calculates C(b) = g a+b mod p.
Verification: Alice reveals her guess. Bob checks that C(b) = g a+b mod p.
If you answered that the scheme is hiding, write one sentence explaining why. If you answered
that the scheme is not hiding, write one sentence explaining how Bob can learn Alice’s guess.
Enter your answer in the text box on Gradescope.
This is the end of Q5. Leave the remaining subparts of Q5 blank on Gradescope,
if there are any. Proceed to Q6 on your answer sheet.
(E)
(F)
Q6.2 (3 points) For each user, the database stores (username, H(username) ⊕ password).
You can assume that the output of H is at least as long as the maximum password length.
(G) The attacker can determine all pairs of users who share the same password.
(K)
(L)
Q6.3 (3 points) For each user, the database stores (username, r, H(passwordkr)).
r is a random 1024-bit value selected when the user creates their account.
(A) The attacker can determine all pairs of users who share the same password.
(E)
(F)
Q6.4 (3 points) For each user, the database stores (username, AES-CBC(k, H(password))).
AES-CBC denotes AES-CBC mode encryption, with a random, unpredictable IV used for each
encryption. k is a secret key that the password database knows, but the attacker doesn’t know.
(G) The attacker can determine all pairs of users who share the same password.
(K)
(L)
Q6.5 (3 points) Because usernames are often unique to a website, some websites opt to salt the password
hash with the username rather than a random number. Consider storing (username,
H(passwordkusername)) for each user. Briefly describe one disadvantage of this scheme com-
pared to using random salts, i.e. storing (username, r, H(passwordkr)).
Enter your answer in the text box on Gradescope.
You realize that designing a secure password storage scheme can be hard and decide to think about
ways to let users log in without passwords.
Q6.6 (4 points) Which of the following protocols would allow you to verify a user’s identity? Assume
that you know the user’s public key, and the user’s private key has not been compromised. Select
all that apply.
(G) Encrypt a random value r with the user’s public key. The user tells you r.
(H) Give the user a random value r. The user signs r and sends you the signature.
(J) Perform Diffie-Hellman key exchange with the user to get a shared key k. The user tells you
k. (You can assume no MITM has tampered with the key exchange.)
(L)
Hobinrood uses a certificate hierarchy to validate users’ public keys. In the hierarchy, a trusted certificate
authority (CA) issues certificates to apps such as Hobinrood. Each app then issues certificates for its
trusted users.
Q6.7 (3 points) An attacker shows you a valid certificate for the attacker’s public key that appears to
be signed by Hobinrood and a valid certificate for Hobinrood signed by the trusted CA. You know
that Hobinrood would never issue a certificate to the attacker. What could the attacker have done
to accomplish this? Select all that apply.
(A) Stolen the CA’s private key (D) None of the above
This is the end of Q6. Leave the remaining subparts of Q6 blank on Gradescope,
if there are any. Proceed to Q7 on your answer sheet.
Definitions of relevant C functions may be found on the last page of this exam.
Assume you are on a little-endian 32-bit x86 system. Assume that there is no compiler padding or saved
registers in all questions.
For parts 1–3, assume that no memory safety defenses are enabled.
Q7.1 (3 points) Which of the following lines contains a memory safety vulnerability?
Q7.3 (3 points) Assume you did the previous part correctly. At what point will the instruction pointer
jump to the shellcode?
(A) Immediately after palindromify returns (D) Immediately after printf returns
For parts 4–7, assume that stack canaries are enabled, and all 4 bytes of the canary are random and
not null. Assume that gets will append a single null byte to your input.
Q7.4 (5 points) Which of the following values on the stack can we overwrite without writing to the
stack canary? Select all that apply.
Q7.5 (3 points) Suppose that we provide ABCDE as input to the program. When we enter the palindromify
function, what will be the initial value of j?
Q7.6 (5 points) Provide the first line of an input that will allow you to redirect execution of this program
to shellcode located at 0xbfff34d0. Write your answer in Python 2 syntax (just like Project 1).
Enter your answer in the text box on Gradescope.
Q7.8 (4 points) Assume the shellcode from the earlier parts resides in the stack section of memory.
Which of the following would we be able to do if stack canaries and ASLR were both in use? Select
all that apply.
(G) Leak the stack canary
(J) Redirect execution to the shellcode using the method from parts 6–7
(L)
This is the end of Q7. Leave the remaining subparts of Q7 blank on Gradescope,
if there are any. You have reached the end of the exam.
The strncmp() function compares the first (at most) n bytes of two
strings s1 and s2. It returns an integer less than, equal to, or
greater than zero if s1 is found, respectively, to be less than, to
match, or be greater than s2.
gets() reads a line from stdin into the buffer pointed to by s until
either a terminating newline or EOF, which it replaces with a null byte
('\0').
fgets() reads in at most one less than size characters from stream and
stores them into the buffer pointed to by s. Reading stops after an
EOF or a newline. If a newline is read, it is stored into the buffer.
A terminating null byte ('\0') is stored after the last character in
the buffer