🎓 BookMCQ
← Back to 15. Security

📝 Firewalls in operating system security (14 MCQs)

Filtering Network Traffic at System Boundaries

A firewall is a security control that monitors and filters network traffic according to defined rules. Operating systems may include host-based firewalls that restrict incoming and outgoing connections for individual devices. Network firewalls protect broader network boundaries. Rules can consider addresses, ports, protocols, connection state, and application identity to allow or block communication.

Why Network Services Need Controlled Exposure

Every listening service creates a potential communication path into a system. Unrestricted traffic may expose vulnerable services or permit unauthorised connections. Firewalls reduce this exposure by limiting communication to approved services and sources, but they cannot correct vulnerabilities within permitted applications or prevent every attack originating through allowed traffic.

Rule Evaluation and Stateful Connection Tracking

A firewall examines packets or connection metadata against its configured rules. Stateless filtering evaluates individual packets using fields such as source address, destination port, and protocol. Stateful filtering tracks connection state and can allow return traffic belonging to an established connection without treating every packet as an independent new request.

Example of Restricting a Server Port

A server must accept HTTPS connections on TCP port 443 but should not expose its remote administration service to the public internet. The firewall permits approved web traffic and restricts administrative access to a trusted management network. Unauthorised connection attempts to the protected service are blocked or logged.

Traffic Control Benefits and Firewall Limitations

Firewalls reduce attack surface, enforce network segmentation, and help control unwanted communication. Incorrect rules can block legitimate services or expose sensitive ports. They cannot reliably detect every malicious action within encrypted or permitted traffic, nor do they replace endpoint protection, patching, authentication, and intrusion detection.

Misconceptions About Firewall Protection

'A firewall stops every type of malware' is false because malware can arrive through files or allowed connections. 'Blocking incoming traffic also blocks every outgoing threat' ignores outbound communication. 'A stateful firewall decrypts all encrypted traffic automatically' is incorrect because inspection of encrypted content requires additional capabilities and configuration.

Exam Focus: Firewall Rules and Packet Filtering

Interpret rules using source, destination, protocol, port, and connection state. Distinguish stateless packet filtering from stateful inspection and host-based from network firewalls. Given a connection scenario, determine whether traffic is permitted, and explain why firewall rules must be combined with endpoint security and regular configuration reviews.

Key Terms of Firewall Security

  • Firewall - Filters network traffic using security rules.
  • Packet filtering - Evaluates individual packets against rules.
  • Stateful inspection - Tracks connection state during filtering.
  • Inbound traffic - Data entering a protected system.
  • Outbound traffic - Data leaving a protected system.
3
Easy
6
Medium
5
Hard

📝 All Firewalls in operating system security MCQs

Q1. A Linux administrator wants to enable the NX (non‑executable) feature for all processes. Which command sequence will correctly activate it on a typical modern distribution?

A.echo \1\ > /proc/sys/kernel/randomize_va_space; sysctl -w vm.mmap_min_addr=65536
B.sysctl -w vm.nr_hugepages=0; echo \0\ > /proc/sys/kernel/execve_blacklist ✅
C.sysctl -w vm.mmap_min_addr=0; echo \1\ > /proc/sys/kernel/exec_prot
D.sysctl -w kernel.exec-shield=1; echo \1\ > /proc/sys/kernel/exec_prot
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The correct sequence is option B because modern Linux systems use the sysctl variable vm.mmap_min_addr to set the lowest allowable memory address for mappings, and enabling exec‑shield (or the equivalent exec_prot flag) turns on the NX bit for pages. Option A changes address randomization but does not enable NX. Option C sets the minimum address to zero, which disables protection. Option D mixes unrelated settings and does not guarantee NX activation. Enabling NX stops execution of injected stack code, strengthening system security.

Q2. What does the NX (non‑executable) bit in a page‑table entry signify?

A.The page can be written but not read
B.The page can be read but not written
C.The page can be read and written but not executed ✅
D.The page is inaccessible to all accesses
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Option C is correct because the NX bit marks a memory page as non‑executable, allowing read/write operations while preventing the CPU from fetching instructions from that page. Option A describes a write‑only restriction, which does not exist in typical page tables. Option B suggests a read‑only page, which is unrelated to execution protection. Option D would make the page completely inaccessible, which would cause a segmentation fault for any access. Understanding NX is essential for mitigating buffer‑overflow attacks.

Q3. A legacy x86 application suffers a stack‑based buffer overflow. The system has NX disabled. Which outcome is most likely when the overwritten return address points to the injected shellcode on the stack?

A.The injected code will execute, giving the attacker control ✅
B.The CPU will raise a page‑fault and abort the program
C.The operating system will automatically quarantine the process
D.The overflow will be silently ignored and the program will continue normally
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: When NX is disabled, the stack pages are executable, so the CPU will fetch and run the injected shellcode, allowing the attacker to hijack control flow (option A). Option B would occur only if NX were enabled, causing a protection fault. Option C describes a host‑based intrusion‑prevention system that is not guaranteed. Option D is unrealistic because a buffer overflow that overwrites the return address changes program flow, not normal execution.

Q4. Why are UNIX‑like multi‑user operating systems generally less vulnerable to traditional viruses compared with desktop PCs?

A.They encrypt all executable files by default
B.File permissions restrict write access to system binaries ✅
C.They run only interpreted scripts, not compiled code
D.They automatically delete any unknown program on execution
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The primary reason is option B: UNIX‑like systems enforce strict file‑permission bits that prevent ordinary users from modifying system binaries, limiting a virus’s ability to overwrite trusted executables. Option A is false; encryption is not default. Option C is inaccurate because compiled binaries are common. Option D describes a behavior not present in typical UNIX kernels. By protecting executable files, the OS reduces the impact of self‑replicating code.

Q5. Which operating system first shipped with built‑in support for the NX (or DEP) feature?

A.Windows Vista
B.Windows XP SP2 ✅
C.Windows 7
D.Windows Server 2003
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: Windows XP Service Pack 2 introduced support for the Data Execution Prevention (DEP) feature, which maps to the hardware NX bit on compatible CPUs. Vista and later versions continued support, but XP SP2 was the first to include it. Windows 7 and Server 2003 added DEP later, making option B the correct historical answer.

Q6. A developer writes a function that could be exploited by a stack‑based overflow. Which CPU feature should be relied on to automatically stop execution if the return address points to code on the stack?

A.Address Space Layout Randomization (ASLR)
B.Control Flow Guard (CFG)
C.NX (non‑executable) bit ✅
D.Supervisor Mode Execution Protection (SMEP)
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The NX bit (option C) directly prevents execution of instructions located on pages marked non‑executable, such as the stack, causing a fault when the CPU tries to run injected code. ASLR (option A) randomizes addresses but does not block execution. CFG (option B) is a software mitigation that validates indirect calls, not a hardware execution‑restriction. SMEP (option D) protects kernel memory from user‑mode code, unrelated to stack execution in user space.

Q7. How does marking a memory page as non‑executable mitigate the risk of a buffer‑overflow attack?

A.It forces the attacker to use return‑oriented programming instead of shellcode ✅
B.It prevents the CPU from fetching instructions from that page, causing a fault if overflowed code tries to run
C.It encrypts the page so the attacker cannot read its contents
D.It moves the page to a separate address space inaccessible to the process
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Option A is correct because a non‑executable (NX) page stops the CPU from executing any injected shellcode; an attacker must then resort to return‑oriented programming (ROP), which is considerably harder to craft. Option B describes a fault but does not explain the shift to ROP. Option C is false; NX does not encrypt data. Option D mischaracterizes page protection, as the page remains in the same address space but is simply non‑executable. This hardware protection raises the bar for successful exploits.

Q8. In a page‑table entry, the NX bit is set to 1. What will happen when a process attempts to execute an instruction at virtual address 0xBFFFF00xBFFFF0 located on that page?

A.The instruction will execute normally because the bit only affects writes
B.The CPU will raise a protection fault and terminate the process ✅
C.The operating system will swap the page out before execution
D.The address will be remapped to a executable region automatically
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: When the NX bit is 1, the page is marked non‑executable, so any attempt to fetch an instruction at 0xBFFFF00xBFFFF0 triggers a protection fault; the OS typically terminates the offending process (option B). Option D is incorrect because the OS does not silently remap pages to executable status. Option A misstates the effect of NX, which concerns execution, not writes. Option C describes swapping behavior unrelated to execution protection.

Q9. What is the relationship between the hardware NX feature and the software DEP (Data Execution Prevention) mechanism?

A.NX is a software layer that enables DEP on compatible CPUs
B.DEP is the hardware implementation, while NX is a Windows‑specific term
C.NX provides the underlying CPU capability that DEP leverages to enforce non‑executable pages ✅
D.They are unrelated; DEP protects data, NX protects code
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Option C correctly identifies that NX is the hardware flag in page tables, and DEP is the operating‑system policy that uses this flag to mark pages as non‑executable. Option A reverses the relationship. Option B incorrectly claims DEP is hardware. Option D mischaracterizes both mechanisms, as both target execution of malicious code rather than data protection alone.

Q10. An organization wants to stop email‑borne viruses that attach malicious executables. Which mitigation strategy is most effective?

A.Deploy a network‑level firewall that blocks all SMTP traffic
B.Configure the mail server to quarantine attachments with executable extensions
C.Install host‑based antivirus that scans incoming emails in real time ✅
D.Require users to use only web‑based email clients
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: Real‑time host‑based antivirus (option C) scans and disinfects attachments before they reach the user, directly targeting malicious executables. Option B relies on the server to quarantine, but sophisticated threats can evade simple extension checks. Option A blocks all email, which is impractical. Option D does not address the underlying risk of malicious attachments. Effective virus control combines scanning with user education, making option C the best choice.

Q11. Why do multi‑user operating systems with strict executable‑file protections limit the impact of viruses?

A.Because they prevent any process from creating new files
B.Because only the kernel can execute code, and it is immune to viruses
C.Because file‑system permissions stop ordinary users from overwriting trusted binaries ✅
D.Because they automatically roll back any changes made by unknown programs
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The core reason is option C: file‑system permission bits prevent non‑privileged users from modifying system binaries, so a virus cannot replace trusted executables with malicious versions. Option A is too broad; processes can still create files in user directories. Option B is inaccurate; user‑space programs can still run. Option D describes a version‑control feature not inherent to most OS kernels.

Q12. A firewall is configured to block inbound traffic on TCP port 80. What is the immediate effect on a web server behind this firewall?

A.The server can still receive HTTP requests from the Internet
B.All incoming HTTP requests are dropped, preventing external users from accessing the site ✅
C.Outgoing HTTP responses are also blocked, causing the server to lose connectivity
D.The firewall will redirect traffic to HTTPS automatically
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Blocking inbound TCP port 80 (option B) stops external clients from establishing HTTP connections to the server, effectively making the web service inaccessible from the Internet. Option A is false because the port is blocked. Option C misinterprets inbound filtering; outgoing responses are allowed once a connection is established. Option D would require a separate redirection rule, not a simple block.

Q13. How does network‑level firewalling complement host‑based NX protection in defending against code‑execution attacks?

A.Firewalls encrypt all traffic, making injected code unreadable
B.Firewalls can drop packets that contain shellcode, while NX stops execution of any code that still reaches memory ✅
C.Firewalls replace vulnerable binaries with patched versions, while NX prevents stack overflows
D.Firewalls enforce user authentication, which NX enforces at the CPU level
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: Option B correctly explains that firewalls can filter out malicious payloads (e.g., dropping packets that contain known exploit signatures), reducing the chance that malicious code reaches a host, while NX provides a hardware safeguard that prevents execution even if some code slips through. Option A confuses encryption with filtering. Option C describes patch management, not firewalling. Option D mixes authentication concepts unrelated to code execution.

Q14. A security engineer must allow employees to browse the web but prevent remote exploitation of a stack overflow in the browser. Which rule set best meets this requirement?

A.Allow outbound TCP 80/443, block all inbound traffic, enable NX on hosts
B.Allow inbound TCP 80/443, block outbound traffic, disable NX to improve performance
C.Allow inbound TCP 80/443, enable DEP on the firewall, and require VPN for all traffic ✅
D.Allow outbound TCP 80/443, enable host‑based NX, and add an intrusion‑prevention rule that drops traffic containing shellcode signatures
💡 Difficulty: hard | ✅ Correct: C

📖 Explanation: The optimal configuration is option C: permitting outbound web traffic (TCP 80/443) lets users browse, while the firewall’s intrusion‑prevention system (IPS) can inspect inbound packets for shellcode patterns and drop them, complementing host‑based NX that blocks execution of any remaining malicious code. Option A lacks the IPS component, leaving a gap. Option B reverses directionality and disables NX, increasing risk. Option D mixes host‑based NX with firewall rules but does not specify inspection for shellcode, making it less comprehensive than option C.

🔗 Related Topics (MCQs)