Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hash-audit

License Perl CLI Platform

Filesystem integrity and provenance tracker using cryptographic hashes. Creates, verifies, and compares file manifests for compliance, security monitoring, and deployment verification.

Problem It Solves

Detecting unauthorized filesystem changes is critical for:

  • Security monitoring: Was the web root modified?
  • Compliance audits: Can you prove files haven't changed?
  • Deployment verification: Does production match the release?
  • Backup validation: Is the backup complete and uncorrupted?

hash-audit creates SHA-256 manifests and verifies them against current filesystem state.

How It Works

Create Manifest                    Verify Later
─────────────────                  ───────────────────
/var/www/                          /var/www/
├── index.html  ──┐                ├── index.html     ✓ hash matches
├── app.js      ──┼──► manifest    ├── app.js         ✗ MODIFIED
├── config.json ──┘    (JSON)      ├── config.json    ✓ hash matches
                                   ├── backdoor.php   ✗ EXTRA (not in manifest)
                                   └── (styles.css)   ✗ MISSING

Installation

cd hash-audit
perl -Ilib bin/hash-audit --help

Usage

Create Manifest

# Create manifest for directory
hash-audit /var/www > www.manifest.json
hash-audit -o www.json /var/www

# Include permissions and mtimes
hash-audit --perms --mtime -o full.json /app

# Ignore patterns
hash-audit -i '.git' -i '*.log' -i 'node_modules' /project

Verify Against Manifest

# Verify current state against baseline
hash-audit --verify www.json /var/www

# Quick check in scripts
if hash-audit -q --verify manifest.json /app; then
    echo "Integrity OK"
else
    echo "ALERT: Files modified!"
fi

Compare Manifests

# See what changed between two points in time
hash-audit --compare v1.json --compare v2.json

# Track deployment changes
hash-audit -o before.json /app
deploy_new_version
hash-audit -o after.json /app
hash-audit --compare before.json --compare after.json

Output Formats

JSON (default)

{
  "version": 1,
  "generated": 1704067200,
  "root": "/var/www",
  "algorithm": "sha256",
  "files": {
    "index.html": {
      "type": "file",
      "size": 1234,
      "hash": "abc123..."
    }
  }
}

Text (sha256sum compatible)

abc123...  index.html
def456...  app.js

Perl API

use HashAudit;

my $auditor = HashAudit->new(
    include_perms   => 1,
    include_mtime   => 1,
    ignore_patterns => ['.git', '*.tmp'],
);

# Create manifest
my $result = $auditor->create_manifest('/var/www');
die $result->{error} unless $result->{success};

# Save for later
$auditor->save_manifest($result->{manifest}, 'baseline.json');

# Later: verify
my $loaded = $auditor->load_manifest('baseline.json');
my $verify = $auditor->verify_manifest($loaded->{manifest}, '/var/www');

if ($verify->{valid}) {
    print "All files verified\n";
} else {
    for my $v (@{$verify->{violations}}) {
        print "$v->{type}: $v->{path}\n";
    }
}

Options

Option Description
-c, --create Create manifest (default mode)
-v, --verify=FILE Verify against manifest
-C, --compare=FILE Compare manifests (use twice)
-o, --output=FILE Write to file
-f, --format=FMT Output format: json, text
-p, --perms Include permissions
-m, --mtime Include modification times
-H, --hidden Include hidden files
-L, --follow-symlinks Follow symbolic links
-i, --ignore=PAT Ignore pattern (repeatable)
--verbose Show progress
-q, --quiet Minimal output

Exit Codes

Code Meaning
0 Success / verification passed / manifests identical
1 Verification failed / manifests differ
2 Error

Violation Types

Type Meaning
MISSING File in manifest not found on disk
EXTRA File on disk not in manifest
MODIFIED File hash doesn't match
SIZE File size changed
TYPE Entry type changed (file → directory)
ERROR Could not read file

Synthetic Test Data

Generate test directories for validation:

# Create baseline directory with 50 files
bin/generate-test-data --files 50 --output baseline

# Create baseline + modified version
bin/generate-test-data --files 30 -m 5 -a 3 -D 2

# Create manifest and verify
hash-audit -o baseline.json baseline
hash-audit --verify baseline.json baseline-modified

Running Tests

prove -l t/

Use Cases

Security Monitoring

# After incident: check for unauthorized changes
hash-audit --verify baseline.json /var/www | grep -E "MODIFIED|EXTRA"

# Cron job for continuous monitoring
0 * * * * hash-audit -q --verify /etc/baseline.json /etc || alert "Config changed!"

Deployment Verification

# Verify deployment matches release
hash-audit --verify release-v2.3.json /app
echo "Deployment verified: exit code $?"

Compliance Auditing

# Create auditable baseline
hash-audit --perms --mtime -o audit-$(date +%Y%m%d).json /data

# Prove files unchanged since baseline
hash-audit --verify audit-20240101.json /data

Backup Validation

# Before backup
hash-audit -o pre-backup.json /important

# After restore
hash-audit --verify pre-backup.json /restored

Design Decisions

  1. SHA-256: Industry standard, collision-resistant
  2. JSON manifests: Human-readable, easily parsed
  3. Streaming hashes: Files hashed without loading into memory
  4. No external deps: Uses only core Perl modules
  5. Deterministic output: Same input always produces same manifest

See Also

  • sha256sum - Hash individual files
  • AIDE - Advanced intrusion detection
  • Tripwire - File integrity checker

Author

Ed Bates — TECHBLIP LLC

License

Licensed under the Apache License, Version 2.0.

About

Filesystem integrity and provenance tracker using cryptographic hashes

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages