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
Buffer overflow, command injection, XSS and SQL injection look unrelated β what do they share?
Answer
- Short answer: all four arise from treating untrusted input as trusted β unchecked input crosses a boundary and becomes executed code (machine code, a shell command, browser script, or SQL).
- Why: Input sanitisation + least privilege β validating/escaping input and dropping privileges cuts every one of them; the damage scales with the privileges of the exploited process (root β total compromise).