Video
The video for this chapter is not available yet.
Exam domains and objectives covered
Domain 3: Security Architecture and Engineering Main domain
- 3.7 Understand methods of cryptanalytic attacks
Domain 7: Security Operations
- 7.2 Conduct logging and monitoring activities
- 7.7 Operate and maintain detection and preventative measures
Domain 8: Software Development Security
- 8.2 Identify and apply security controls in software development ecosystems
- 8.3 Assess the effectiveness of software security
- 8.5 Define and apply secure coding guidelines and standards
Objectives are numbered as in the official ISC2® CISSP exam outline.
Learning objectives
By the end of this chapter you should be able to:
- Describe how viruses, worms, Trojans, logic bombs and other malware spread, hide and deliver payloads
- Explain ransomware, fileless malware and zero-day attacks, and how to reduce their impact
- Compare signature-based and behaviour-based detection, file integrity monitoring, EDR and UEBA
- Recognise application attacks such as buffer overflows, TOCTOU, backdoors, privilege escalation and rootkits
- Defend web applications against injection, XSS, request forgery, directory traversal and session hijacking
- Identify source-code weaknesses and apply secure coding and code integrity countermeasures
Key topics
- Virus propagation techniques
- Polymorphic and stealth viruses
- Worms and Trojans
- Logic bombs
- Ransomware
- Fileless malware
- Anti-malware, EDR and UEBA
- Buffer overflows
- TOCTOU
- Rootkits and privilege escalation
- SQL and command injection
- Cross-site scripting
- CSRF and SSRF
- Parameterised queries
- Code signing
Chapter notes
Chapter overview
The final chapter looks at the attacker’s toolkit: malicious code that spreads and hides, and attacks that exploit poorly written applications, especially on the web. Understanding how each attack works is the fastest route to choosing the right defence, whether that’s a detection tool, a secure coding practice or a process control. Real malware rarely fits neatly into one category, so focus on the behaviours.
Key concepts
Who writes malware
- Script kiddies run tools and kits written by others, with little understanding of how they work.
- Organised crime uses malware to steal money and identities at scale, for example banking Trojans that log keystrokes.
- Advanced persistent threats (APTs), often state-linked, write highly targeted malware and may use zero-day exploits that no vendor has patched.
Viruses
A virus has two parts: propagation (how it spreads) and a payload (what it does). It needs a host and usually some human action.
| Propagation technique | How it works |
|---|---|
| Master boot record / boot sector | Infects the code that loads the operating system, often via shared removable media; secure boot and TPM-backed measures help |
| File infector | Alters or replaces executables. A companion virus uses a similar file name so it runs in place of the real program |
| Macro | Abuses application scripting (such as VBA) in documents; blocking untrusted macros greatly reduced these |
| Service injection | Injects into trusted system processes to evade anti-malware; keep browsers and helper applications patched |
Techniques for evading detection:
- Multipartite: uses several propagation methods at once (for example, files and boot sector).
- Stealth: tampers with the operating system so scanners see a clean copy.
- Polymorphic: changes its own code with each infection so its signature keeps changing.
- Encrypted: encrypts its body with a different key each time; only a small decryption routine stays constant, and that routine is what scanners look for.
Hoaxes (fake virus warnings spread by email and social media) waste time and can trick people into harmful actions.
Other malicious code
- Logic bombs lie dormant until a trigger (a date, an event, an account being deleted). Often planted by insiders or contractors.
- Trojan horses look useful but carry a hidden payload. Variants include rogue anti-virus (fake security software that steals data or demands payment), remote access Trojans (RATs) that open backdoors for remote control, and cryptomalware that mines cryptocurrency with the victim’s resources.
- Botnets link infected machines under a botmaster’s control (see Chapter 17).
- Worms spread on their own, without human help. Landmark examples: the 1988 Internet (Morris) worm, which combined several Unix weaknesses and a password attack; Code Red (2001), which hit unpatched web servers even though a fix had existed for weeks; and Stuxnet (2010), which spread through zero-days and USB drives to sabotage specific industrial controllers. It showed malware could cause physical damage and serve as a weapon between states.
- Spyware watches activity and steals data such as credentials; adware pushes advertising. Both are potentially unwanted programs (PUPs), often installed with nominal consent. Compromised browser extensions are a common delivery route.
- Malicious scripts (PowerShell, Bash) automate attacker tasks such as privilege escalation and persistence. Fileless malware runs entirely in memory, often launched by a script from a phishing link, so tools that only watch the disk miss it.
Ransomware
Ransomware encrypts files on the system and attached drives with a key only the attacker holds, then demands payment. Many groups also steal data first and threaten to publish it (double extortion). Targets have moved from individuals to hospitals, councils and large firms.
- The best recovery control is tested, offline or immutable backups, with the ability to rebuild systems cleanly.
- Prevention: patching, least privilege, email and web filtering, application allow listing, EDR, segmentation and user awareness.
- Paying is an ethical dilemma and may be illegal where the attackers are under sanctions; authorities generally discourage it, and payment doesn’t guarantee recovery. Take legal advice before engaging.
Zero-days and defence in depth
A zero-day exploits a flaw before a fix exists. The window of vulnerability runs from discovery until patches and signatures are deployed, and slow patching stretches it further. Layer overlapping controls (patching, anti-malware, configuration management, application control, content filtering) so at least one is likely to catch an attack.
Detecting and preventing malware
- Signature-based anti-malware matches files against known patterns. It’s only as current as its definitions, so update frequently. When it finds something it disinfects, quarantines or, if policy demands, deletes the file.
- Heuristic (behaviour-based) detection watches for suspicious actions: privilege escalation, covering tracks, altering system files. Suspicious files can be detonated in a sandbox and, if they misbehave, blocked across the organisation.
- Modern tools cover worms, Trojans, rootkits, spyware and more, with central management of settings and alerts. If a new outbreak appears, check protection status directly with your vendor.
- File integrity monitoring keeps hashes of important files and alerts on unexpected changes (useful against defacement and tampering).
- Endpoint detection and response (EDR) analyses memory, file system and network activity on endpoints, isolates suspicious activity, uses threat intelligence and integrates with incident response. Delivered as a service, it’s managed detection and response (MDR).
- User and entity behaviour analytics (UEBA) profiles normal behaviour for each user and entity and flags deviations that may mean a compromised account or insider threat. UEBA focuses on the user; EDR focuses on the endpoint. Next-generation endpoint suites often bundle all of these.
- Malware now targets every platform, including macOS, Android™ and other mobile devices, not just Windows®.
Application attacks
- Buffer overflow: input longer than the space reserved for it spills into adjacent memory and can let an attacker run commands. Prevent it with bounds checking and input validation: reject values that are too long, of the wrong type or outside the expected range. Then patch promptly, since many overflows are fixed by vendor updates.
- Time-of-check to time-of-use (TOCTOU or TOC/TOU): a race condition in which an attacker swaps or alters a resource between the moment it’s checked and the moment it’s used. TOCTOU, other race conditions and communication disconnects are state attacks: they exploit timing and transitions between states.
- Backdoors: undocumented ways to bypass authentication, left by developers (deliberately or by accident) or planted by malware.
- Privilege escalation: moving from a normal account to administrator or root, often with a rootkit that exploits known operating system flaws and then hides the attacker’s presence. Consistent patching defeats most rootkits.
Injection attacks
Injection supplies code as input and tricks the application into running it or passing it on.
- SQL injection alters a database query, for example by adding a second query or an always-true condition, to read, change or delete data. Blind SQL injection works when results aren’t displayed: content-based blind injection compares responses to true and false conditions; timing-based blind injection uses deliberate delays to extract data piece by piece. Tools automate both.
- Code injection is the general class; others include LDAP, XML and DLL injection. XSS is code injection into web pages.
- Command injection passes attacker input to an operating system call, so an extra command (for example, one that deletes files) runs alongside the intended one.
Authorisation and web application attacks
- Insecure direct object reference (IDOR): changing an identifier in a URL or request reveals other people’s records because the application doesn’t re-check authorisation.
- Directory traversal: using
../sequences to climb out of the web root and read files such as password hashes. File inclusion goes further and executes a file, either local (LFI) or fetched from the attacker’s server (RFI), often to install a web shell that blends in with normal HTTPS traffic. - Cross-site scripting (XSS) injects script that runs in other users’ browsers. Reflected XSS bounces input back in a crafted link; stored (persistent) XSS saves the script on the server, for example in a forum post; DOM-based XSS manipulates the page within the browser. Defend with strict input validation and context-appropriate output encoding.
- Cross-site request forgery (CSRF/XSRF) abuses a site’s trust in a logged-in user’s browser to send unwanted commands, such as a funds transfer. Defend with anti-CSRF tokens and checks on request origin.
- Server-side request forgery (SSRF) tricks the server into fetching an attacker-chosen URL, exposing internal resources.
- Session hijacking takes over an authenticated session by stealing authentication details or cookies, or by sitting in the middle. Use anti-replay authentication, secure cookies and short session lifetimes.
The OWASP Top 10 and Proactive Controls are good starting points for testing and secure design.
Application security controls
- Input validation is the most important control. Allow listing (accept only input matching a defined pattern, such as an age of 0–123) beats block listing (reject known-bad input), which is reserved for free-text fields. Validate on the server. Watch for legitimate input (an apostrophe in O’Reilly) when blocking characters.
- Metacharacters (quotes, semicolons, ampersands, pipes and so on) have special meaning; escaping them makes them literal.
- Parameter pollution sends the same parameter twice, hoping the filter checks one value while the application uses the other.
- Web application firewalls (WAFs) inspect traffic at the application layer in front of web servers. They’re a valuable extra layer, not a substitute for secure code.
- Parameterised queries pass input as typed variables that can’t change the query’s structure. Stored procedures keep precompiled SQL on the database server and accept only arguments. Both stop SQL injection.
- Protecting stored data: data minimisation (don’t hold what you don’t need), tokenisation (replace identifiers via a protected lookup table) and salted hashing (irreversible, and resistant to rainbow tables).
Code security
- Code signing proves who published code and that it hasn’t changed since. It does not prove the code is safe: signed malware still verifies.
- Code reuse: third-party libraries and SDKs speed development but import their flaws; test outsourced and third-party code as rigorously as your own, and track dependencies.
- Software diversity: avoid single points of failure such as dependence on one codebase, binary or compiler.
- Code repositories provide version control, change auditing and reuse, and prevent dead code nobody owns.
- Integrity measurement: hash code at release and compare it with the approved version before deployment.
- Resilience: scale up (vertically, more resources per instance) or scale out (horizontally, more instances); elasticity adds and removes capacity automatically.
Source-code weaknesses
- Comments can hand attackers a map. Strip them from code that users can see, such as web scripts.
- Error handling: use structured handling (try/catch) for unexpected conditions, including absurdly large numbers that cause integer overflow. Show users minimal messages and log full details.
- Hard-coded credentials: maintenance backdoor accounts, or embedded keys for other services, are exposed the moment code leaks or is pushed to a public repository.
- Memory management: resource exhaustion, including memory leaks where an application never returns memory, can crash systems. Null pointer dereferencing can crash a program, leak debugging detail or even bypass controls.
- Risk analysis and mitigation (objective 8.3.2) means ranking these weaknesses by likelihood and impact, then fixing, mitigating or formally accepting each one.
Exam tips
- Viruses need a host or user action to spread; worms don’t.
- Parameterised queries are the primary defence against SQL injection.
- Input validation is the common thread in defending against buffer overflows, XSS and injection.
- Backups are the most effective control for recovering from ransomware.
- UEBA spots unusual behaviour, which is ideal for compromised accounts and insider threats.
- Patching is the standard answer for rootkits, known buffer overflows and worms like Code Red.
- Code signing answers “who wrote it and was it changed?”, not “is it safe?”.
Common traps
- XSS vs CSRF: XSS exploits the user’s trust in a site (script runs in the browser); CSRF exploits the site’s trust in the user’s browser (commands sent on the user’s behalf).
- CSRF vs SSRF: CSRF fools the user’s browser; SSRF fools the server.
- Polymorphic vs encrypted virus: polymorphic rewrites its code; encrypted hides its body behind a changing key but keeps a detectable decryption routine.
- Stealth vs rootkit: both hide; a rootkit’s main job is maintaining privileged, concealed access.
- Logic bomb vs Trojan: a logic bomb waits for a trigger; a Trojan disguises itself as something useful.
- Allow list vs block list input validation: allow listing is stronger; block listing is a fallback.
- Client-side vs server-side validation: client-side checks help usability but offer no security.
- Directory traversal vs file inclusion: traversal reads files; inclusion executes them.
- EDR vs UEBA: endpoint focus versus user focus.
- TOCTOU: the clue is a gap between checking something and using it.
Quick revision
- Malware authors: script kiddies, organised crime, APTs with zero-days.
- Virus propagation: boot sector/MBR, file infector (and companion), macro, service injection.
- Evasion: multipartite, stealth, polymorphic, encrypted.
- Logic bombs wait; Trojans disguise; RATs give remote control; worms self-propagate; spyware and adware are PUPs; fileless malware lives in memory.
- Ransomware encrypts and often steals; offline backups are the answer; paying may be unlawful.
- Detection: signatures plus heuristics, sandboxing, file integrity monitoring, EDR/MDR, UEBA.
- Application attacks: buffer overflow, TOCTOU, backdoors, privilege escalation, rootkits.
- Web attacks: SQL (including blind), command and other injection; IDOR; traversal and file inclusion; XSS; CSRF; SSRF; session hijacking.
- Controls: server-side allow-list validation, escaping, output encoding, WAF, parameterised queries, stored procedures, tokens.
- Code security: signing, dependency tracking, repositories, release hashes, no comments or secrets in exposed code, careful error and memory handling.
Key terms
| Term | Meaning |
|---|---|
| Payload | The harmful action malware carries out |
| Multipartite virus | A virus that spreads by more than one technique |
| Polymorphic virus | A virus that changes its code with each infection to evade signatures |
| Logic bomb | Malicious code that activates when a set condition occurs |
| Remote access Trojan | Malware disguised as legitimate software that gives an attacker remote control |
| Worm | Malware that copies itself across networks without human action |
| Fileless malware | Malware that runs in memory without writing files to disk |
| Ransomware | Malware that encrypts or steals data and demands payment |
| Window of vulnerability | The time between a flaw’s discovery and deployment of a fix |
| EDR | Endpoint tooling that detects, investigates and contains malicious activity |
| UEBA | Analytics that baseline user and entity behaviour and flag deviations |
| Buffer overflow | Writing beyond allocated memory, potentially enabling code execution |
| TOCTOU | A race condition exploiting the gap between checking and using a resource |
| Rootkit | Malware that gains and conceals privileged access |
| SQL injection | Manipulating database queries through crafted input |
| Insecure direct object reference | Accessing other records by changing an identifier the application fails to authorise |
| Cross-site scripting | Injecting script that runs in other users’ browsers |
| Cross-site request forgery | Causing a logged-in user’s browser to send unwanted requests |
| Parameterised query | A query whose input is bound as data and can’t alter the SQL structure |
| Code signing | Digitally signing code to prove its origin and integrity |
| Memory leak | An application failing to release memory it no longer needs |