Course contentsShow
← Software Engineering
Lesson 1044 of 1,93332. Security EngineeringFree lesson

A03: Injection

How untrusted data sent to interpreters can execute unintended commands or access data.

A03: Injection

You'll learn: How attackers can hijack commands by sneaking malicious instructions into data your application processes.

The Core Problem

Injection vulnerabilities occur when an application sends untrusted user input directly to an interpreter (like a database, operating system shell, or XML parser) without proper validation or escaping. The interpreter can't distinguish between your intended commands and the attacker's malicious additions.

Think of it like giving someone a form letter to fill in: "Dear _____, please send me _____." If they write "Santa, please send me a bicycle. Also, send $1000 to my account," they've "injected" extra instructions you never intended.

Common Injection Types

SQL Injection is the most notorious. If you build a query like:

SELECT * FROM users WHERE username = 'INPUT_HERE'

An attacker entering admin' OR '1'='1 creates:

SELECT * FROM users WHERE username = 'admin' OR '1'='1'

This always returns true, potentially bypassing authentication.

Command Injection happens when you pass user input to system commands:

ping USER_INPUT

Input like google.com; rm -rf / executes destructive commands.

Why It's Dangerous

Injection can lead to:

  • Data breaches (reading sensitive records)
  • Data manipulation (updating or deleting data)
  • System compromise (executing arbitrary code)
  • Authentication bypass

Prevention Basics

  1. Use parameterized queries/prepared statements (separates code from data)
  2. Validate and sanitize all user input
  3. Apply principle of least privilege (limit interpreter permissions)
  4. Avoid passing user input to interpreters when possible

Key Takeaway: Injection attacks exploit the blurred line between data and commands—always treat user input as untrusted data, never as executable code, and use proper safeguards when passing it to interpreters.