debsums

debsums

One-liner: Debian/Ubuntu package integrity verification tool that detects file tampering by comparing installed files against their MD5 checksums stored in package metadata.

🎯 What Is It?

debsums is a Linux utility for verifying the integrity of installed Debian/Ubuntu packages by checking if system files have been modified, corrupted, or replaced since installation.

Purpose: Detect:

Install:

sudo apt install debsums

πŸ”¬ How It Works

MD5 Checksum Verification

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Package    β”‚       β”‚  Installed File β”‚
β”‚   Database   β”‚       β”‚  (e.g., /bin/ls)β”‚
β”‚              β”‚       β”‚                 β”‚
β”‚ MD5: abc123  β”‚ ───── β”‚  Calculate MD5  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚                       β”‚
        β”‚                       β”œβ”€ abc123 βœ“ MATCH
        └───────────────────────┼─ def456 βœ— TAMPERED

Basic Usage

Check All Packages

# Verify all installed packages (noisy, shows missing docs)
sudo debsums

# Silent mode - only show errors
sudo debsums -s

# Check configuration files only
sudo debsums -a

# Check only altered files (excludes missing files)
sudo debsums -e -s

Check Specific Package

# Verify openssh-server
sudo debsums openssh-server

# Verify sudo package (from writeup)
sudo debsums sudo
debsums: changed file /etc/sudoers (from sudo package)

Detect Modified Binaries

# Check critical system binaries
sudo debsums coreutils
sudo debsums bash
sudo debsums systemd

# Check if /bin/ls has been replaced (rootkit indicator)
sudo debsums -e coreutils | grep '/bin/ls'

πŸ›‘οΈ Detection & Prevention

How to Detect Tampering (from writeup)

Find Modified Configuration Files

# From writeup Task 6
sudo debsums -e -s
debsums: changed file /etc/sudoers (from sudo package)

# This revealed attacker modified sudo configuration

Investigate Specific File

# Compare file hash manually
md5sum /etc/sudoers

# Check what was changed
sudo cat /etc/sudoers
# Found: www-data ALL=(ALL) NOPASSWD: /usr/bin/python3

Detect Rootkit Binaries

# Check if core utilities were replaced
sudo debsums -s coreutils bash util-linux

# Example output if rootkit present:
debsums: changed file /bin/ls (from coreutils package)
debsums: changed file /bin/ps (from procps package)

Integration with Forensic Workflow

# Step 1: Baseline check on clean system
sudo debsums > /var/log/debsums_baseline.txt

# Step 2: During incident response
sudo debsums -e -s > /var/log/debsums_current.txt

# Step 3: Compare results
diff /var/log/debsums_baseline.txt /var/log/debsums_current.txt

# Step 4: Investigate changed files
sudo stat /etc/sudoers
sudo cat /etc/sudoers

Limitations

πŸ“Š Attack Detection Examples

Scenario 1: Modified /etc/sudoers (from writeup)

Context: Attacker gained www-data web shell access, modified sudoers for privilege escalation

Detection:

sudo debsums -e -s
debsums: changed file /etc/sudoers (from sudo package)

# Investigate
sudo tail /etc/sudoers
www-data ALL=(ALL) NOPASSWD: /usr/bin/python3
# ⚠️ BACKDOOR: www-data can sudo python3 without password!

Remediation:

# Restore original
sudo apt install --reinstall sudo

# Verify integrity
sudo debsums sudo

Scenario 2: Rootkit Detection

Binary Replacement:

# Attacker replaces /bin/ls to hide files
sudo debsums coreutils
debsums: changed file /bin/ls (from coreutils package)

# Restore clean binary
sudo apt install --reinstall coreutils

Scenario 3: Proactive Monitoring

Daily Integrity Check:

# Cronjob: /etc/cron.daily/debsums-check
#!/bin/bash
CHANGES=$(debsums -e -s 2>&1)
if [ -n "$CHANGES" ]; then
  echo "$CHANGES" | mail -s "ALERT: File integrity violations" soc@company.com
fi

🎀 Interview Angles

Common Questions

STAR Story

Situation: Security alert triggered for suspicious sudo activity on production web server. Required quick determination if system files were compromised.
Task: Verify integrity of critical system files and identify unauthorized modifications without taking server offline.
Action: Ran debsums -e -s to check all packages for changes. Tool flagged /etc/sudoers as modified. Inspected file and found unauthorized entry: www-data ALL=(ALL) NOPASSWD: /usr/bin/python3, allowing web user to execute Python with root privileges. Checked timestamps with stat, confirmed modification during attack window. Used debsums to verify core binaries (coreutils, bash) were cleanβ€”no rootkit.
Result: Identified privilege escalation backdoor without false positives from legitimate config changes. Reinstalled sudo package (apt install --reinstall sudo), removed backdoor, implemented FIM on critical files. Attack contained without full system rebuild.

βœ… Best Practices

🧰 Cheat Sheet

# Basic verification
sudo debsums                    # Check all packages (verbose)
sudo debsums -s                 # Silent (errors only)
sudo debsums -e -s              # Exclude missing files, silent

# Configuration files
sudo debsums -a                 # Include config files (expected changes)
sudo debsums -c                 # Check config files only

# Specific package
sudo debsums <package>          # Check one package
sudo debsums sudo openssh-server coreutils

# Generate checksums (if missing)
sudo debsums -g                 # Generate missing MD5s

# Forensic workflow
sudo debsums -e -s > tampered_files.txt
while read file; do stat "$file"; done < tampered_files.txt

# Restore integrity
sudo apt install --reinstall <package>

❌ Common Misconceptions

πŸ“š References