Rufai
Supreme Member
- May 23, 2020
- 1,363
- 1,177
I figured I'd share this in case it helps someone else. I spent days trying to figure this out because I couldn't find much useful information online, and none of the security or malware removal plugins I tried actually solved the problem.
Overview
A sophisticated mobile-specific WordPress redirection malware that redirected visitors to spam sites. The malicious code specifically checked the User-Agent string to detect mobile browsers, then redirected only those visitors to avoid detection by administrators, who usually check sites from desktop devices. At first, I thought it was just a typical WordPress infection, but it turned out to be much worse.How the Infection Worked
While digging through the files, I found malicious code injected into wp-config.php. It contained Base64-encoded payloads using eval(base64_decode(...)).After decoding it, I found that it was:
- Checking whether the visitor was using a mobile device
- Redirecting only mobile users to spam sites
- Injecting hidden scripts from external domains
- Skipping admin, CLI, and API requests to avoid being noticed
While investigating, I found:
- Backdoor administrator accounts using the sys_ naming pattern and a [email protected] emails
- Backdoor SSH authorized_keys with immutable flags which means the attacker locked the files to prevent removal and the attacker had root-level access to the server at some point, not just WordPress access.
- Copied themselves to wp-content/mu-plugins/ as 01-mu-*.php files (auto-loading, undeletable from dashboard)
- Re-injected wp-config.php on every page load
- Auto-created hidden sys_ admin accounts
- Exfiltrated credentials to a remote server
- Were installed as far months back
After decoding more of the payload, I found a malicious script injection, ak.akam60800.net, a fake domain designed to look like Akamai CDN injecting a script into every frontend page visit to redirect or infect visitors.
After investigation and checking for malicious systemd services, two things stand out:
- defunct.service — described as "D-Bus System Connection Bus", which was a lie. The real D-Bus service is called dbus.service. Which means it was a malicious service masquerading as D-Bus.
- rc-local.service — runs /etc/rc.local on boot, a classic persistence point.
Checking the full service file and the dat file revealed the smoking gun:
- /usr/bin/defunct — the malware binary, disguised as [raid5wq] (a fake kernel thread name)
- /lib/systemd/system/defunct.dat — its config/key file
Root cause:
A malicious systemd service called defunct.service was running a hidden ELF binary (/usr/bin/defunct) disguised as a kernel thread [raid5wq]. It was continuously injecting a fake Akamai script (ak.akam60800.net) into both wp-config.php files to redirect/infect site visitors, and restarting every 5 minutes.