🎓 BookMCQ
← Back to 15. Security

📝 Implementation of cryptography (12 MCQs)

Integrating Cryptographic Algorithms into System Software

Cryptographic implementation is the practical integration of algorithms, keys, protocols, and secure storage into software and operating system services. It covers how encryption, hashing, authentication, and signatures are performed while protecting secrets and validating data. Correct algorithm selection is only one requirement; implementation quality, random number generation, key handling, and protocol design determine real security.

Why Correct Algorithms Can Still Be Implemented Unsafely

A mathematically strong algorithm can be undermined by predictable keys, incorrect parameters, insecure modes, memory leaks, or flawed certificate validation. Software also faces timing and other side-channel risks. Cryptographic code must therefore be implemented and reviewed carefully, preferably using established libraries rather than custom-designed algorithms.

Library Calls, Randomness and Key Storage

An application calls a vetted cryptographic library to generate keys, encrypt data, compute digests, or verify signatures. Secure random number generators supply unpredictable values. Keys are stored using protected operating system facilities or hardware security modules where available. The implementation validates inputs, handles errors, and avoids exposing secrets through logs or memory.

Example of Authenticated File Encryption

An application encrypts a document using an authenticated encryption library with a fresh nonce and secret key. It stores the ciphertext and authentication tag. During decryption, the library verifies the tag before releasing plaintext. If the data has been modified or the key is incorrect, authentication fails and the plaintext is not accepted.

Side Channels, Compatibility and Secure Maintenance

Secure implementations protect against implementation flaws as well as mathematical attacks. Constant-time operations can reduce timing leakage, while tested libraries improve reliability. Poor upgrades or incompatible parameters can break access to stored data. Systems need algorithm agility, documented formats, key rotation, secure defaults, and regular cryptographic review.

Misconceptions About Cryptographic Implementation

'A standard algorithm guarantees a secure product' ignores implementation and key-management failures. 'Random-looking values are always cryptographically random' is false when generated by predictable sources. 'Successful decryption proves data integrity' is incorrect unless authentication or a separate integrity check is performed.

Exam Focus: Algorithms, Libraries and Secure Parameters

Distinguish algorithm design from its software implementation. Explain the roles of secure randomness, nonces, key storage, authenticated encryption, and certificate validation. Scenario questions may ask why custom cryptographic code is risky or how a library prevents modified ciphertext from being accepted as valid data.

Key Terms of Cryptographic Implementation

  • Cryptographic library - Tested software implementing security primitives.
  • Nonce - Value used once in a cryptographic operation.
  • Secure randomness - Unpredictable values for keys and nonces.
  • Side channel - Information leakage through implementation behaviour.
  • HSM - Hardware security module protecting keys.
2
Easy
6
Medium
4
Hard

📝 All Implementation of cryptography MCQs

Q1. A program allocates a char buffer[64] on the stack and copies user input using strcpy. Which of the following actions will cause the function to return to attacker‑controlled code?

A.Provide exactly 64 bytes
B.Provide 63 bytes
C.Provide 70 bytes ✅
D.Provide 0 bytes
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Providing more than the allocated 64 bytes forces strcpy to write past the end of the buffer. The extra bytes overwrite the saved frame pointer and then the return address. With 70 bytes the attacker reaches and replaces the return address, causing execution to jump to attacker‑controlled code. The other options either do not exceed the buffer or do not reach the return address, so the program returns normally.

Q2. Given a stack frame where buffer occupies bytes 0–79, the saved frame pointer occupies bytes 80–87, and the return address occupies bytes 88–95, how many bytes must the attacker write to reach the return address?

A.80
B.88 ✅
C.96
D.72
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The buffer occupies 80 bytes (0‑79). After the buffer, the next 8 bytes hold the saved frame pointer (80‑87). To overwrite the return address, the attacker must write through both regions, totaling 80 + 8 = 88 bytes. Writing only 80 bytes stops at the frame pointer, while 96 bytes would overshoot the return address. Therefore 88 bytes is the exact offset needed to control the return address.

Q3. An exploit includes a NOP sled of length N before the shellcode. Which of the following best describes the purpose of increasing N?

A.Decrease execution time
B.Ensure alignment
C.Raise probability of landing in shellcode ✅
D.Reduce memory usage
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: A NOP (No‑Operation) instruction does nothing and simply passes control to the next instruction. By placing many NOPs before the shellcode, the attacker creates a large target area so that even if the exact jump address is slightly off, execution will slide through the NOPs and eventually reach the shellcode. The other choices do not reflect the primary advantage of a longer NOP sled.

Q4. An exploit overwrites the return address with the address of buffer[0]. On a system that uses Address Space Layout Randomization (ASLR), why is this approach unreliable?

A.ASLR randomizes the stack base making the address unpredictable ✅
B.Buffer[0] is always executable
C.Return address cannot be changed
D.NOP sled prevents execution
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: ASLR randomizes the starting address of the stack each time a program runs. Because buffer[0] resides on the stack, its absolute address changes on each execution, so an attacker cannot reliably predict it in advance. Consequently, overwriting the return address with a fixed buffer[0] address will often point to an incorrect location, causing a crash. The other statements are either false or unrelated to the effect of ASLR.

Q5. A program employs a stack canary to detect buffer overflows. Which technique allows an attacker to still overwrite the return address without triggering the canary check?

A.Overwrite the canary with its original value ✅
B.Disable the canary at compile time
C.Use a format‑string vulnerability
D.Employ a return‑to‑libc attack
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: A stack canary is a known value placed between the buffer and the return address. The program verifies that the canary remains unchanged before returning. If an attacker can discover the canary value (e.g., via an information leak) and then write that exact value after overflowing the buffer, the check passes and the overwritten return address is used. Disabling the canary or using unrelated techniques does not bypass the canary check.

Q6. A web server runs with root privileges. An attacker injects shellcode that opens a reverse shell to the attacker’s machine. Which statement best describes the security impact of this exploit?

A.The attacker can only read files owned by the server user
B.The attacker gains the same privileges as the server process ✅
C.The attacker is limited to the network port used by the server
D.The exploit has no impact because the server validates input
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When a process runs with elevated (root) privileges, any code executed within that process inherits those privileges. Therefore, shellcode that establishes a reverse connection will execute with root rights, allowing the attacker to perform any action the server could, such as modifying system files, installing backdoors, or creating new privileged processes. The other options underestimate the privilege escalation effect.

Q7. Why are stack‑based buffer overflows considered especially dangerous in software security?

A.They corrupt heap metadata
B.They overwrite the function’s return address ✅
C.They increase program execution speed
D.They improve overall system security
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: A stack‑based buffer overflow occurs when data written beyond the bounds of a local buffer overwrites adjacent memory on the call stack. The most critical region directly after the buffer is the saved return address. Overwriting this address redirects execution to attacker‑chosen code, enabling arbitrary code execution. The other options either describe different memory areas or are unrelated to the primary danger.

Q8. How does a NOP sled enhance the reliability of a classic stack‑based shellcode exploit?

A.It encrypts the shellcode
B.It aligns the stack pointer
C.It provides a large landing zone for an imprecise jump ✅
D.It disables stack canaries
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: A NOP sled consists of consecutive No‑Operation instructions placed before the actual payload. When the exact jump address cannot be precisely determined, the processor will execute NOPs until it reaches the first non‑NOP instruction, which is the shellcode. This creates a forgiving region that increases the chance of successful execution even with slight address miscalculations. The other options do not describe the functional role of a NOP sled.

Q9. Why is using a debugger essential when developing a buffer‑overflow exploit that targets a specific return address?

A.Debuggers automatically generate shellcode ✅
B.They reveal the exact offset between the buffer and the return address
C.Debuggers bypass stack canaries
D.They encrypt the exploit payload
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: A debugger allows the attacker to inspect memory layout at runtime, view the contents of the stack, and step through function prologues. By observing where the buffer starts and where the saved return address resides, the attacker can calculate the precise number of bytes needed to overwrite the return address. This precision is crucial for a reliable exploit. The other statements are inaccurate regarding debugger capabilities.

Q10. In a return‑to‑libc attack, how does the technique differ from injecting custom shellcode on the stack?

A.It overwrites the stack pointer instead of the return address
B.It reuses existing library functions instead of executing new code ✅
C.It disables the operating system’s memory protection
D.It requires the attacker to write more bytes than a shellcode payload
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Return‑to‑libc attacks avoid placing new code on the stack by redirecting execution to already‑loaded library functions (e.g., system()), passing controlled arguments via the stack. This bypasses non‑executable stack protections because no new code is executed. The other options mischaracterize the method or describe unrelated effects.

Q11. Modern operating systems often enable a non‑executable (NX) stack. What is the primary effect of this protection on classic stack‑based buffer‑overflow attacks?

A.It randomizes the stack base address
B.It prevents execution of any code placed on the stack ✅
C.It increases the size of the stack
D.It removes the need for canaries
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: The NX (No‑Execute) bit marks memory pages as non‑executable, so even if an attacker successfully overwrites a return address to point to injected shellcode on the stack, the CPU will raise a protection fault and refuse to execute that code. This forces attackers to adopt alternative techniques such as return‑to‑libc or ROP. The other options describe different security mechanisms.

Q12. What does the acronym NOP stand for in assembly language?

A.Non‑Operational Procedure
B.No Operation
C.Network Optimized Protocol
D.Null Operand ✅
💡 Difficulty: medium | ✅ Correct: D

📖 Explanation: NOP stands for \No Operation

🔗 Related Topics (MCQs)