Integrity
Table of Contents
The "I" in the CIA Triad. Data and systems have not been modified, corrupted, or destroyed — either accidentally or maliciously. Integrity guarantees that what you receive is exactly what was sent, and that stored data reflects what was actually written.
The adversarial counterpart in the DAD Triad is Tampering.
Related: CIA Triad DAD Triad Confidentiality Availability Hashing Encryption
Technical Controls
Hashing
A cryptographic hash produces a fixed-length digest of data. Any modification to the data produces a completely different digest — the fundamental integrity verification mechanism.
# Generate and verify a file hash sha256sum file.iso > file.iso.sha256 sha256sum -c file.iso.sha256 # Python import hashlib digest = hashlib.sha256(b"data").hexdigest()
See Hashing for algorithm comparison and collision resistance.
HMAC — Hash-based Message Authentication Code
Combines a hash with a shared secret key. Verifies both integrity and authenticity — proves the data was produced by someone with the key and has not been altered in transit.
import hmac, hashlib key = b"shared-secret" data = b"message to sign" mac = hmac.new(key, data, hashlib.sha256).hexdigest() # Verify — use compare_digest to prevent timing attacks is_valid = hmac.compare_digest( hmac.new(key, received_data, hashlib.sha256).hexdigest(), received_mac )
Digital Signatures
Asymmetric-key integrity and authenticity — the sender signs with their private key; anyone with the public key can verify. Provides non-repudiation: the signer cannot later deny signing.
Signing: hash(data) → encrypt with private key → signature Verifying: decrypt signature with public key → compare hash
File Integrity Monitoring (FIM)
Baseline the hash of critical files; alert on changes. FIM is a core Wazuh capability — detects webshell drops, config changes, and binary tampering on endpoints.
Files typically monitored: /etc/passwd, /etc/shadow, /etc/sudoers /usr/bin/, /usr/sbin/ Web root (detect webshell drops)
Checksums
Weaker than cryptographic hashes — detect accidental corruption but not deliberate tampering (CRC32, Adler32). Suitable for error detection in storage/transmission, not security.
Integrity in Practice
| Layer | Mechanism |
|---|---|
| File system | Hash verification, FIM (Wazuh, Tripwire) |
| Data in transit | TLS + AEAD (AES-GCM includes integrity) |
| Data at rest | Signed backups, database checksums |
| Software | Code signing, package manager signature verification |
| Log files | Append-only storage, SIEM ingestion, tamper detection |
Tips
- HMAC is the correct primitive for API authentication tokens — not plain hashing, which can be forged by anyone
hmac.compare_digestis required for secure comparison — string equality operators short-circuit and leak timing information that can be used to forge MACs- Encryption alone does not guarantee integrity — non-AEAD modes (CBC without MAC) can be manipulated without the key; always use authenticated encryption
- FIM alerts on web roots are one of the highest-confidence indicators of a successful webshell upload