Website Defacement — Detect, Investigate and Recover with Kali Linux
Intermediate hands-on lab · Cybersecurity and digital forensics
A fictional café’s homepage has been replaced. Use Linux file checks and an Apache access log to determine what changed, build a defensible timeline and verify a recovery in local staging. You’ll need a Linux terminal, familiarity with paths and an ordinary user account. The exercise works offline with Bash, GNU coreutils, diff, grep, awk and unzip.
Download the practical lab (ZIP)
What website defacement looks like
Website defacement is the unauthorised alteration of public website content. A replacement homepage is obvious. Hidden links, unexpected redirects or small changes to a script or stylesheet may be harder to spot. Compare the version users see with a trusted release, and check legitimate deployment records. For a real incident, examine origin content and CDN or proxy behaviour separately so cached responses do not confuse the timeline.
Set up the lab
Open a terminal in the folder containing the downloaded ZIP. Extraction creates one top-level lab/ directory. The three files under clean_site/ are the baseline, defaced_site/ contains the affected snapshot, and logs/access.log records fictional requests. Start the supplied worksheet as you work. The archive also includes a sample incident report and a recovery verification checklist.
workspace=$(mktemp -d) &&
unzip website-defacement-exercise.zip -d "$workspace" &&
cd "$workspace/lab"
Preserve evidence and compare files
Work from the copies created below. The first command checks the clean snapshot against the original SHA-256 manifest. The next block records hashes for the affected files and log, then verifies their working copies. Stop and investigate any failed integrity check.
sha256sum --strict -c hashes.txt
umask 077
case_dir=$(mktemp -d ./case.XXXXXX) &&
cp -a defaced_site logs "$case_dir/" &&
(sha256sum defaced_site/* logs/access.log > "$case_dir/evidence.sha256") &&
(cd "$case_dir" && sha256sum --strict -c evidence.sha256)
In a real incident, coordinate acquisition and containment with the hosting provider or response team. Preserve snapshots, rotated logs and relevant application, hosting-panel and deployment records. Keep protected originals separate from working copies. Record the case ID, origin, collector, date and UTC offset, acquisition method, digest, storage location and every transfer. A checksum detects a difference from an independently trusted reference. It provides no information about who made a change or when it happened.
diff -qr clean_site "$case_dir/defaced_site"
diff -u clean_site/style.css "$case_dir/defaced_site/style.css"
sha256sum clean_site/* "$case_dir"/defaced_site/*
A recursive comparison identifies different, added and missing files. A unified diff shows the changed lines. GNU diff returns 0 for a match, 1 for differences and 2 for trouble. Here, index.html contains the simulated replacement message. The stylesheet has an added comment that claims the file is unchanged. Its CSS rules match, but its bytes and SHA-256 digest differ. about.html is the only unchanged file.
Read the access log and build a timeline
The fixture uses Apache’s Common Log Format. A line records the client address, identity fields, timestamp and UTC offset, quoted request, final status and reported response size. Combined Log Format adds the referrer and user agent. The sample addresses come from RFC 5737 documentation ranges. A real client address can represent a proxy or shared connection. Confirm how your server derives it before attributing activity.
nl -ba "$case_dir/logs/access.log"
grep -nF '"POST /admin/content ' "$case_dir/logs/access.log"
awk -F'"' '{print NR, $2, $3}' "$case_dir/logs/access.log"
| UTC on 28 November 2026 | Source | Observation |
|---|---|---|
| 19:15:22 | Line 3 | The server logged 538 bytes for the homepage, consistent with the clean fixture. |
| 19:15:45 | Line 4 | A content admin POST received HTTP 200 and had a 64-byte response. |
| 19:18:41 | Line 5 | The server logged 1,291 bytes for the homepage, consistent with the affected fixture. |
| 19:18:42 | Line 6 | The stylesheet response size is consistent with the affected fixture. |
The file comparison confirms that the captured homepage and CSS differ from the baseline. The response sizes suggest a time window, but size alone cannot identify a response body. The POST is a lead. HTTP 200 gives the response status. The record does not establish a successful write, the operator’s identity or the initial cause. In the worksheet, link each conclusion to a log line or file and record its confidence level. In a real case, correlate login, application audit, deployment and proxy records and account for clock drift and log gaps.
Restore and verify locally
Run the block from lab/. It creates a fresh staging directory, verifies the baseline and copies the clean files. The rewritten manifest points to filenames relative to staging. The subshell changes into staging before verifying those files. The final recursive comparison also detects extra or missing files that a manifest of known filenames could miss.
sha256sum --strict -c hashes.txt &&
restored=$(mktemp -d ./restored_site.XXXXXX) &&
cp -a clean_site/. "$restored/" &&
sed 's| clean_site/| |' hashes.txt > "$restored.sha256" &&
(cd "$restored" && sha256sum --strict -c "../${restored##*/}.sha256") &&
diff -qr clean_site "$restored"
Expect two groups of three OK results and no comparison output. Record the staging path, then open its index.html locally and check the About link and stylesheet. Use the checklist to record the outcome. In a live incident, backup validation also needs to cover application configuration, databases and dependencies where applicable. Maintain versioned backups protected from production writes and rehearse restoring them offline.
Contain and remediate before reopening
- Confirm the unexpected change and coordinate containment promptly. Isolate affected service or move traffic to a trusted maintenance page. Preserve relevant evidence as containment proceeds.
- Investigate the scope and plausible entry points. If the host’s integrity is uncertain, recover into a clean environment. Patch affected components, remove unauthorised changes, revoke exposed credentials and sessions where applicable, and check for persistence.
- Restore from a verified backup or clean deployment. Check integrity, essential routes, permissions and monitoring in isolation. Return to public service after the incident owner approves the verified recovery.
- Monitor for recurrence. Review the timeline, coverage gaps, backup recovery time and preventive controls. Assign owners and dates to follow-up improvements, then re-test them.
Prevent and monitor unauthorised changes
| Weakness | Prevention |
|---|---|
| Shared, reused or phished admin credentials | Use unique accounts, a password manager, MFA and scoped deployment credentials. Review access and keep authentication audit records. |
| Unsupported or unpatched software | Inventory the web server, CMS, plugins and dependencies. Apply supported updates and remove unused components. |
| Unsafe uploads | Restrict uploads by purpose and file type. Store them outside the document root where possible and prevent execution. |
| Excessive write permissions | Give the web service read access to deployed content and reserve write access for a separate deployment identity. Keep runtime-write paths separate and tightly scoped. |
Use stat -c '%A %a %U:%G %n' clean_site clean_site/* to inspect lab permissions and ownership. Modes 644 for public files and 755 for public directories are common examples for a static site. Choose modes and ownership for your deployment model, keep secrets more restrictive and review group membership and ACLs. Directory write access can allow someone to replace a file even when the file itself is read-only.
Monitor integrity with AIDE
AIDE records digests and selected metadata in a baseline database. Configure its rules to include deployed site content and relevant configuration, and handle volatile caches and logs separately. Use aide --init on a verified clean system, then promote the generated database to the configured input location. Store a protected copy of the baseline and configuration away from the monitored host. Schedule aide --check, review alerts for added, removed and changed files, and update the baseline only after reviewing an authorised change. Consult the AIDE documentation and your distribution’s package notes for database paths and scheduling. The core lab uses the supplied SHA-256 manifest and requires only standard Linux tools.
Related DarkPC tutorials
- Kali Linux Workstation
- Hash a Practice Evidence File and Verify the Manifest
- Write a Chain-of-Custody Log for a Practice Case
- Wireshark — Ethical Network Traffic Analysis
- Linux permissions made understandable