🎓 BookMCQ
← Back to 15. Security

📝 Cryptography as a Security Tool (10 MCQs)

Mathematical Protection of Digital Information

Cryptography applies mathematical algorithms and keys to protect information during storage, processing, and communication. Operating systems and network services use cryptographic mechanisms to support confidentiality, integrity, authentication, and non-repudiation. These mechanisms transform data into protected representations or produce verifiable values, allowing software to exchange information while reducing the risk of disclosure or undetected modification.

Why Security Requires More Than Access Permissions

Access controls cannot always prevent interception, copying, or modification when data travels across networks or resides on shared storage. Cryptography protects information even when communication channels or storage media are exposed. Its effectiveness depends on sound algorithms, secure key management, correct implementation, and protection of endpoint systems.

Algorithms, Keys and Cryptographic Operations

Encryption algorithms transform plaintext into ciphertext using a key, while decryption reverses the process with the appropriate key. Hash functions produce fixed-length digests, and digital signatures use asymmetric cryptography to support authenticity and integrity. Protocols combine these tools according to their security requirements rather than relying on one algorithm for every purpose.

Example of Protecting a Stored File

A user encrypts a sensitive file using a strong encryption algorithm and a protected key. An unauthorised person who obtains the file sees ciphertext rather than its readable contents. A user with the correct decryption key can recover the original data, provided the algorithm and key have not been compromised.

Security Benefits and Key Management Risks

Cryptography protects stored files, network sessions, credentials, and software updates. Weak keys, poor random number generation, obsolete algorithms, or exposed secrets can defeat otherwise sound designs. Encryption alone does not prove who sent data or detect every modification; integrity checks, authenticated encryption, digital signatures, and trusted key distribution address additional requirements.

Misconceptions About Cryptography

'Encryption and hashing are identical' is false because ordinary hashes are not designed for decryption. 'Using a strong algorithm guarantees secure communication' ignores weak keys and implementation flaws. 'A digital signature hides message contents' is incorrect because signatures provide authenticity and integrity, not confidentiality by themselves.

Exam Focus: Matching Cryptographic Tools to Goals

Distinguish encryption, hashing, digital signatures, and authentication by their purposes. Identify which keys are used in symmetric and asymmetric systems. Questions may ask how cryptography provides confidentiality or integrity, why key management matters, and why encryption without authentication may not prevent deliberate modification.

Key Terms of Cryptography

  • Plaintext - Original readable information.
  • Ciphertext - Data transformed by encryption.
  • Key - Secret or public cryptographic parameter.
  • Hash - Fixed-length digest of input data.
  • Digital signature - Cryptographic proof of authenticity and integrity.
2
Easy
5
Medium
3
Hard

📝 All Cryptography as a Security Tool MCQs

Q1. An attacker crafts input that overflows a buffer and overwrites the saved return address. Which step guarantees that execution jumps to the injected shellcode?

A.Overwrite the saved frame pointer
B.Overwrite the return address ✅
C.Place a NOP sled before the buffer
D.Increase the buffer size
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The correct answer is B because the return address tells the CPU where to continue after the function returns; overwriting it with the address of the shellcode redirects execution. Overwriting the frame pointer (A) only affects stack tracing, not the jump target. Adding a NOP sled (C) helps land in the shellcode but does not change the jump target itself. Increasing the buffer size (D) does not affect the overwritten address. In real attacks, the overwritten return address is the critical element that causes the malicious code to run.

Q2. A developer adds a random canary value before the return address to protect against overflow. Which mechanism best stops the attack?

A.Use of a NOP sled
B.Disabling the debugger
C.Inserting a random canary before the return address ✅
D.Removing the vulnerable buffer
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The correct answer is C; a stack canary is a known random value that, if altered by an overflow, alerts the program and aborts execution, preventing the malicious return address from taking effect. A NOP sled (A) merely aids landing in shellcode but does not detect corruption. Disabling the debugger (B) does not stop memory overwrites. Removing the buffer (D) would eliminate the vulnerability but is often impractical; the canary provides a targeted safeguard.

Q3. Which mitigation reduces the risk of a root‑privileged buffer overflow without requiring recompilation of the vulnerable program?

A.Enable address space layout randomization (ASLR) ✅
B.Increase the buffer size
C.Use static linking for all libraries
D.Turn off networking services
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: Enabling ASLR (A) randomizes the locations of stack, heap, and libraries, making it much harder for an attacker to guess the address of the injected shellcode or a useful library function, thus mitigating exploitation even when the binary cannot be rebuilt. Simply increasing the buffer size (B) does not address the overflow logic. Static linking (C) changes binary composition but does not hide addresses. Turning off networking (D) limits remote attacks but does not stop a local overflow from executing malicious code.

Q4. A program has a 64‑byte buffer, the return address is located 8 bytes after the buffer, and the attacker’s shellcode is 20 bytes long. How many NOP bytes must precede the shellcode to fill the buffer completely?

A.12
B.20
C.44 ✅
D.8
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The correct answer is C. The buffer holds 64 bytes; placing a 20‑byte shellcode at the start leaves 44 bytes to fill with NOPs (64 − 20 = 44). The extra 8 bytes after the buffer are used to overwrite the return address with the buffer’s address. Option A (12) and B (20) are too small, and D (8) refers to the space after the buffer, not the NOP sled needed inside it. Understanding this calculation is essential for constructing reliable exploits in real‑world attacks.

Q5. An attacker can only supply input via an environment variable, not via command‑line arguments. Which technique can still achieve code execution?

A.Return‑to‑libc attack ✅
B.Format‑string vulnerability
C.Stack pivot using setuid
D.Heap overflow
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: A return‑to‑libc attack (A) reuses existing library functions, such as system(), by pointing the overwritten return address to them, which works even when the attacker cannot inject raw shellcode via argv. A format‑string bug (B) requires a vulnerable printf‑style call, which is not given. A stack pivot using setuid (C) involves privilege changes but still needs a way to control the stack. A heap overflow (D) targets a different memory region and does not rely on environment variables. Return‑to‑libc is a practical method when direct code injection is limited.

Q6. Why does a buffer overflow pose a privilege‑escalation risk?

A.It allows reading private data
B.It can change the program’s control flow ✅
C.It encrypts the attacker’s payload
D.It improves program performance
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The correct answer is B because overwriting the return address or function pointer lets an attacker redirect execution to malicious code, potentially running with the program’s privileges. Simply reading memory (A) may expose data but does not grant execution rights. Encryption (C) is unrelated to overflow behavior, and performance improvements (D) are irrelevant. In practice, altering control flow is the core reason overflow bugs can lead to elevated privileges.

Q7. How does a NOP sled increase the reliability of a buffer‑overflow exploit?

A.It raises the chance of landing in the shellcode ✅
B.It slows down program execution
C.It blocks stack‑canary checks
D.It causes immediate segmentation faults
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: A NOP sled (A) consists of many no‑operation instructions placed before the shellcode, so even if the overwritten return address lands anywhere within the sled, execution will slide into the actual payload, improving success rates. Slowing execution (B) is a side effect but not the purpose. Blocking canaries (C) is unrelated; canaries detect overwrites regardless of NOPs. Causing segmentation faults (D) would defeat the exploit. Real‑world attackers rely on NOP sleds to tolerate imprecise address calculations.

Q8. Why do modern operating systems employ address space layout randomization (ASLR) to mitigate buffer overflows?

A.It randomizes stack addresses, making return‑address prediction difficult ✅
B.It increases the size of all buffers
C.It disables debugging tools
D.It encrypts executable code
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: The correct answer is A because ASLR randomizes the memory locations of the stack, heap, and libraries, so an attacker cannot reliably guess where their shellcode or useful functions reside, thwarting the overwritten return address technique. Simply increasing buffer sizes (B) does not prevent overwrites. Disabling debuggers (C) is unrelated to memory layout. Encrypting code (D) would hinder execution but is not the primary function of ASLR. In practice, ASLR adds a significant obstacle for exploit developers.

Q9. Why is simple input validation often insufficient against sophisticated overflow attacks?

A.Attackers can bypass validation using integer overflow ✅
B.Validation significantly slows program performance
C.Validation changes compiler optimizations
D.Validation only works on network packets
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: The correct answer is A because attackers may craft inputs that cause integer overflows, causing the validated length to be miscomputed and allowing more data to be written than expected, thereby bypassing naive checks. Performance impact (B) is a concern but not a security gap. Changing compiler behavior (C) is unrelated to runtime validation. Limiting validation to network packets (D) is a misconception; validation must be comprehensive. Real‑world attacks exploit such logic errors to achieve overflow despite apparent checks.

Q10. What is a \NOP sled\ in the context of exploiting a buffer overflow?

A.A sequence of no‑operation instructions used to increase the landing area for shellcode ✅
B.A cryptographic hash function
C.A limit on buffer size imposed by the compiler
D.A type of firewall rule
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: A NOP sled (A) is a series of instructions that do nothing, placed before malicious code so that an imprecise jump to any point in the sled will eventually slide into the payload, enhancing exploit reliability. It is not a hash (B), a compiler limit (C), or a firewall rule (D). Understanding the NOP sled concept helps students see how attackers compensate for uncertain address calculations in real attacks.

🔗 Related Topics (MCQs)