📝 Asymmetric encryption as a Security Tool (11 MCQs)
Public and Private Key Cryptography
Asymmetric encryption uses a mathematically related public and private key pair. The public key can be distributed, while the private key must remain protected. Operating systems and network protocols use asymmetric cryptography for secure key establishment, digital signatures, and identity verification. It reduces the need to share one secret in advance but requires trustworthy public-key validation.
Why Two Key Roles Simplify Secure Communication
Symmetric encryption requires communicating parties to share a secret securely before protected communication. Asymmetric cryptography allows a public key to be shared openly, addressing part of this distribution problem. However, users must verify that a public key belongs to the intended entity, and public-key operations are generally more computationally expensive.
Public Key Encryption and Private Key Decryption
For confidentiality, a sender encrypts data using the recipient's public key, and the corresponding private key decrypts it. Digital signatures use a different operation: the signer creates a signature with a private key, and others verify it using the public key. Real protocols commonly combine asymmetric and symmetric methods.
Example of Securely Sending a Session Key
A client obtains a verified public key for a server and uses an authenticated key-establishment protocol to agree on a session secret. Both parties then use symmetric encryption for bulk data. This hybrid arrangement combines public-key establishment with the efficiency of symmetric encryption.
Identity Verification and Computational Trade-Offs
Asymmetric cryptography supports digital signatures, certificates, and secure key establishment. Its performance cost makes it less suitable for encrypting large data streams directly. Compromised private keys undermine identity and confidentiality, while unverified public keys permit impersonation. Certificate validation, key protection, and suitable algorithms are therefore critical.
Misconceptions About Asymmetric Encryption
'The public key must be kept secret' reverses its purpose; it is intended for distribution. 'A private key decrypts every message encrypted with any public key' is false because the keys must form the corresponding pair. 'Asymmetric encryption is always faster than symmetric encryption' ignores its higher computational cost.
Exam Focus: Key Pairs, Signatures and Hybrid Systems
Trace confidentiality using a recipient's public and private keys, then distinguish it from digital signing. Identify which key creates and verifies a signature. Questions may ask why protocols combine asymmetric key establishment with symmetric session encryption and why public-key certificates are needed to establish identity.
Key Terms of Asymmetric Encryption
- Public key - Key distributed for encryption or verification.
- Private key - Secret key controlled by its owner.
- Key pair - Mathematically related public and private keys.
- Digital signature - Verifiable proof of message authenticity.
- Certificate - Binds a public key to an identity.
📝 All Asymmetric encryption as a Security Tool MCQs
Q1. What is a buffer overflow in the context of stack memory?
📖 Explanation: A buffer overflow happens when more data is written to a stack-allocated buffer than it can hold, causing the excess to overwrite neighboring memory such as saved registers or the return address. Option B describes this precisely. Option A confuses reading with writing, Option C refers to encryption unrelated to memory safety, and Option D describes compression, which is unrelated to overflow. Understanding this basic definition is essential for recognizing why attackers can hijack execution flow.
Q2. Why do attackers often prepend a series of NOP instructions (a NOP sled) before their shellcode in an overflow exploit?
📖 Explanation: A NOP sled consists of many no‑operation instructions () placed before the malicious code. If the overwritten return address lands anywhere within the sled, execution will slide forward until it reaches the real shellcode, improving reliability despite minor address miscalculations. Option C captures this purpose. Option A misstates the goal, Option B is about alignment not reliability, and Option D exaggerates the effect on debugging; NOPs mainly aid landing accuracy.
Q3. A program copies user input from argv[1] into a local array buffer[64] using strcpy without bounds checking. Which step is most critical for an attacker to gain control of execution?
📖 Explanation: When strcpy copies unchecked data, the attacker can write past buffer[64] and reach the saved return address stored just above it on the stack. Overwriting this address with the location of injected shellcode redirects execution when the function returns. Option B directly targets the return address, which is the decisive control point. Overwriting the frame pointer (A) may cause a crash but not necessarily control flow; NOPs (C) aid landing but require the address overwrite first; modifying PATH ( D) does not affect the stack layout.
Q4. How does the saved frame pointer relate to the return address in a typical stack frame?
📖 Explanation: In a conventional stack frame, the saved frame pointer ( or ) is pushed first, followed by the saved return address. Consequently, the return address resides at a higher memory address (closer to the top of the stack) than the saved frame pointer. Option C correctly describes this ordering. Option A is false because they are distinct entries; Option B reverses the relationship; Option D incorrectly places them in the heap, which is unrelated to stack‑based overflow attacks.
Q5. If a buffer holds 64 bytes and an attacker needs to overwrite a 4‑byte return address located 72 bytes from the start of the buffer, how many NOP bytes must the attacker prepend to a 20‑byte shellcode to reach the return address?
📖 Explanation: The distance from the buffer start to the return address is 72 bytes. Subtract the 20‑byte shellcode gives 52 bytes needed for filler. Since the attacker also wants a NOP sled, the remaining space after the shellcode is 52 − 20 = 32 bytes. However, only the bytes before the shellcode count as NOPs; the attacker places the return address after the NOP sled, so the NOP count equals 72 − 64 = 8 bytes. Option B (12) is the correct calculation when accounting for the 4‑byte saved frame pointer preceding the return address, yielding 12 NOPs.
Q6. Which mitigation technique directly protects the saved return address from being overwritten by a buffer overflow?
📖 Explanation: Stack canaries are special guard values placed between local buffers and control data like the saved return address. Before a function returns, the program checks whether the canary was altered; if it was, the program aborts, preventing the overwritten return address from being used. Option C describes this protection. ASLR (A) randomizes memory locations but does not stop overwriting; DEP (B) marks pages non‑executable but does not protect the address itself; PIE (D) makes code position‑independent, which helps with ASLR but does not guard the stack.
Q7. A vulnerable function uses strcpy(buf, input) where buf is 48 bytes long. The attacker discovers that the saved return address is 56 bytes from the start of buf. What offset (in bytes) must the attacker use to reach the return address?
📖 Explanation: The offset equals the number of bytes from the beginning of buf to the saved return address. Since the return address resides 56 bytes away, the attacker must supply 56 bytes of data before the overwritten address. Therefore, the correct offset is 56 bytes, matching option B. Option A gives the size of buf but not the distance to the return address; Option C and D add extra bytes beyond the needed offset, which would overshoot and likely cause a crash.
Q8. How does Address Space Layout Randomization (ASLR) reduce the reliability of a buffer‑overflow exploit that uses a fixed return‑address value?
📖 Explanation: ASLR randomizes the base address of memory regions such as the stack, heap, and libraries each time a program runs. Because the attacker’s payload relies on a known address (e.g., the start of the shellcode), the randomization makes that address differ across executions, causing the exploit to fail unless the attacker can guess or leak the address. Option B captures this effect. Option A is unrelated to address randomization, Option C incorrectly claims NOP sleds are disabled, and Option D misrepresents ASLR’s function.
Q9. When constructing a payload to execute /bin/sh after a stack overflow, which component must be placed at the overwritten return address?
📖 Explanation: The overwritten return address determines where execution resumes after the vulnerable function returns. To launch a shell, the attacker places the address that points directly to the injected /bin/sh shellcode at this location, causing the processor to jump to the malicious code. Option B is therefore correct. Option A would call printf instead of the shell, Option C (a NOP) would not transfer control, and Option D (buffer size) is irrelevant to the control‑flow redirection.
Q10. What is the primary difference between a code‑injection attack and a return‑to‑libc (RET2LIBC) attack?
📖 Explanation: In a code‑injection attack, the attacker writes custom shellcode into a writable region and then redirects execution to it. In a return‑to‑libc (RET2LIBC) attack, the attacker does not inject new code; instead, they overwrite the return address with the address of an existing library function (e.g., system) and supply appropriate arguments. Option B correctly describes this distinction. Option A reverses the roles, Option C incorrectly asserts both need DEP disabled, and Option D misstates the NOP requirement, which varies with the technique.
Q11. If a system employs a non‑executable stack but the attacker cannot overwrite the return address, which alternative technique could still allow execution of malicious code?
📖 Explanation: When the stack is marked non‑executable, traditional shellcode on the stack cannot run. However, heap spraying places malicious code in the heap, which may be executable, allowing the attacker to redirect execution there. Option A (heap spraying) is thus viable. Return‑oriented programming (B) still needs a writable, executable region for gadgets; Format string exploits (C) target different vulnerabilities; SQL injection (D) is unrelated to binary exploitation. Hence, heap spraying is the appropriate fallback.