Steps to clean up malicious redirects on a compromised web server

Malicious redirects are often the visible symptom of a deeper server compromise. Attackers inject PHP code, rewrite access rules, alter CMS templates, poison database content, or reuse stolen credentials so visitors land on phishing pages, malware downloads, or affiliate fraud. The site can look normal to its owner while particular devices, locations, or referral sources receive a different destination.

Cleaning the visible redirect is not enough. An attacker may retain a dormant web shell, scheduled task, newly created administrator, modified deployment script, or changed DNS record. The response should move from evidence preservation to containment, code restoration, infrastructure repair, and monitored validation, with each action tied to a known system and timestamp.

This matters for Australian organisations whose customers commonly follow parcel, ticketing, and digital-banking links from mobile phones. CARM Security, developed by Exclusive Networks, supports this coordinated workflow by combining vendor technologies for identifying, containing, responding to, and remediating active attacks rather than treating one suspicious file as the whole incident.

Confirm the compromise and preserve evidence

Begin by proving what the server is doing. Record sample source and destination URLs, HTTP status codes, response headers, affected pages, and the time in UTC. Repeat checks with a clean browser, a mobile connection, and different referral sources. Avoid repeatedly loading suspected destinations from a work device, because each visit may expose credentials or trigger additional tracking.

Observed behaviour Likely location First verification
Every request returns a 301 or 302 .htaccess, web-server or load-balancer configuration Inspect redirect headers and edge configuration
Only CMS pages are affected Plugin, theme, template, or database modification Compare files and records with a known-good copy
Destination changes by device, geography, or referrer Injected JavaScript or a conditional edge rule Test clean sessions and correlate request logs
The website looks normal but sends phishing email Mailbox or server credential abuse Audit SMTP activity, accounts, and authentication logs

Preserve logs, database exports, cloud audit trails, and a forensic copy before making broad changes. Record every administrator action and keep an evidence log with UTC timestamps. Where possible, take an immutable snapshot and export security logs to storage outside the potentially compromised host, since local logs and files may have been altered.

If the server also sends email, examine that activity separately. A DMARC failure report guide can help determine whether unauthorised senders are active in a phishing campaign, although email authentication findings do not prove the cause of the web redirect.

Contain access and map the compromise

Take administrative control out of band and restrict access to the compromised environment. Temporarily disable public administration, revoke active sessions, and rotate passwords and API tokens for hosting panels, SSH, SFTP or FTP, the CMS, database, registrar, DNS, CDN, and cloud accounts. Remove unknown accounts, SSH keys, OAuth grants, and mobile authenticators; enable phishing-resistant MFA wherever the platform supports it.

Then map entry and persistence. Compare web roots, plugins, themes, configuration files, cron jobs, scheduled tasks, package scripts, and deployment pipelines against a trusted baseline. Review recent file changes, but do not trust timestamps alone. Search for unfamiliar outbound domains, encoded payloads, suspicious file managers, and auto-prepend directives. Check who can write to the web root, and determine whether a shared host or agency account widened the blast radius.

Correlate redirect destinations and infrastructure indicators with current threat activity. This threat intelligence guide explains how campaign context can help teams rank remediation work; an indicator linked to an active credential-phishing or malware campaign deserves faster containment than a generic suspicious domain.

Remove malicious code and restore clean files

Start from a trusted baseline. Update the CMS, extensions, themes, and application dependencies after reviewing the known exploited paths, remove unauthorised components and administrator accounts, and restore changed files from an offline known-good release or backup. Preserve correct ownership and permissions, and avoid copying live production configuration from another potentially exposed environment. If trustworthy code or history is unavailable, rebuild the application rather than declaring files clean after deleting the visible redirect.

Remove persistence at every layer, not just the redirect itself. Review .htaccess, web.config, Nginx and Apache virtual-host rules, PHP configuration, service-worker files, JavaScript bundles, CMS templates, database fields, cron entries, container images, CI/CD workflows, and DNS records. Search for the exact malicious destination, but also treat that domain as an indicator rather than proof that every related file is trustworthy. Rebuild auto-generated caches and compiled assets from clean sources.

Keep all credentials issued before containment invalid and rotate any remaining application or service secrets. Review outbound network connections, process creation, cron execution, cloud API calls, and email-sending logs. Rebuild the operating system or hosting environment when integrity cannot be established; reinstalling a CMS inside a persistently compromised host can simply restore the attacker’s access.

Repair delivery, search, and customer pathways

After clean code is deployed, purge CDN, reverse-proxy, page-cache, and application caches in the correct order. Test direct requests rather than relying on an administrator preview, because a logged-in session, cookie, or edge rule can hide a problem. Check every redirect chain, canonical URL, sitemap, robots directive, and security header. Confirm that intended redirects resolve in one hop where possible, while removed malware URLs return 404 or 410 rather than sending visitors back to the homepage.

Search visibility also needs correction. Review Google Search Console hack alerts, crawl errors, indexed redirect destinations, and suspicious site-search results, then submit clean canonical URLs for inspection. For an .au or .com.au property, confirm domain ownership, transfer locks, DNS and DNSSEC settings, and registrar access. A malicious redirect that changes only for bots can damage search rankings even when customer sessions appear unaffected.

Protect customers during recovery. Give affected users a direct, known route to myGov, ATO, Australia Post, their bank, or event ticketing services rather than asking them to follow links from the compromised site. Australians frequently encounter convincing parcel and ticket messages on mobile devices, so treat unexpected redirects as potential credential theft. Pause payment flows if users could have entered banking details on a fake destination.

Harden the environment and prevent recurrence

Use the incident to strengthen controls around the server, its people, and its suppliers. Australian retailers, professional-services firms, and online businesses often rely on shared hosting, managed service providers, or third-party agencies; contracts and access inventories should show who can alter code, content, or accounts. Align priority controls with the ASD Essential Eight, including MFA, patching, application control, protected backups, central logging, and tested restoration. File-integrity monitoring should flag changes to web roots and configuration, while a WAF or CDN can provide temporary virtual patching without replacing host controls.

Four controls provide a practical minimum for the next release cycle:

Residual monitoring should cover the web root, DNS, certificates, email, and endpoints for at least 30 days after remediation. Automated checks can confirm that clean URLs return 200, removed paths return the chosen error, and no unauthorised destination appears in response headers or page source. Review the alerts daily during the highest-risk period, because a dormant web shell often reactivates after administrators believe the incident is closed.

Verify ownership and close the incident

Validate the fix from an independent network and device, using representative mobile browsers, desktop browsers, and key referral paths. Compare current file hashes, accounts, DNS records, certificates, and scheduled tasks with the approved baseline. Keep enhanced logging and threat hunting active while search engines recrawl the site and customers resume sensitive transactions. A clean result from one browser is evidence, not proof that every conditional path has been repaired.

Record the root cause, initial access, affected assets, removed persistence, rotated secrets, customer impact, and notification decision. Under the Privacy Act 1988, assess whether personal information was accessed or lost and whether notification to affected people or the Office of the Australian Information Commissioner is required; document the reasoning even when notification is not. Consider any applicable state or territory privacy law and coordinate advice with the hosting provider, cyber insurer, banks, or Scamwatch where the facts support escalation.

The concrete next step is to schedule a two-hour validation window for the first 30 days after the next production deployment, with a named owner checking redirects, file hashes, privileged accounts, DNS, and outbound traffic and recording the evidence in the incident register.