Software Vulnerabilities (Injection, XSS, Buffer Overflow)

Context: Information Security and Cryptography Β· concrete software weaknesses attackers exploit Β· catalogued at CWE (cwe.mitre.org); the common root is unchecked input

Quick Revision

  • 🎯 Objective: four classic vulnerabilities β€” buffer overflow, command injection, XSS, SQL injection βž” each lets attacker input become executed code/commands.
  • ⚑ Key Constraint: the shared root cause is missing input sanitisation (+ running with excessive privileges) β€” the single defence theme across all four.

πŸ“ The four vulnerabilities

  • Buffer overflow βž” input larger than the buffer overwrites the return address in the activation record (cf. subroutine return); a crafted payload redirects execution to injected code (e.g. execve("myshell")). Countermeasures: stack canary, address-space layout randomisation (ASLR).
  • Command injection βž” user input is passed into a shell command and executed; runs with the host program’s privileges (root β‡’ full compromise).
  • Cross-site scripting (XSS) βž” attacker injects a script that runs in the victim’s browser with the visited domain’s rights (same-origin trust abused); stored XSS persists on the server and can steal session tokens.
  • SQL injection βž” input is concatenated into an SQL statement so it executes extra commands (the β€œBobby Tables” '); DROP TABLE Students;--); can escalate to wider system compromise.

πŸ”§ Minimal example (command injection)

int main(char* argc, char** argv) {
  char cmd[CMD_MAX] = "/usr/bin/cat ";
  strcat(cmd, argv[1]);   // argv[1] is NOT sanitised
  system(cmd);            // runs the whole string in a shell
}

Exploit: argument ;rm -rf / β†’ cat fails, then rm -rf / runs β€” as root, it wipes the root partition.

πŸ›‘οΈ Defences

  • Sanitise/validate input βž” the common thread; reject or escape dangerous characters.
  • Use safe interfaces βž” parameterised queries / stored procedures (SQLi), output encoding (XSS β€” see the OWASP cheat sheets), avoid system() with user data (command injection). Helps but does not guarantee safety.
  • Least privilege βž” don’t run services as root; limits the blast radius when a vuln is hit.

⚠️ Common Mistakes

  • πŸ’‘ Sanitisation reduces, not eliminates βž” predefined interfaces β€œcan prevent … but do not guarantee” β€” defence in depth (least privilege, ASLR/canaries) still matters.
  • πŸ’‘ XSS abuses trust, not a server bug alone βž” the browser runs the script because it appears to come from the trusted domain β€” the injection point is often stored user content.

🧠 Active Recall