Researchers at Sucuri, a firm focused on website security awareness and attack recovery, have discovered attackers using a known, but a rather uncommon method of maintaining access to an already compromised server: They're hiding backdoors inside the headers of legitimate image files.
Daniel Cid, Sucuri's CTO, told CSO in an interview that the company has discovered more than a dozen sites that have been impacted by this method of attack. However, he didn't mention if there was any evidence to connect all of them to a single source. At present, the company is still investigating while they work with their clients.
The images were discovered on a previously compromised webserver. Cid told CSO during a phone conversation that in the cases they've seen so far, including the 'bun.jpg' case that was covered on the Sucuri blog, the website was either running an outdated version of WordPress (a popular CMS platform used by millions of domains), or outdated versions of Joomla, which is an alternate platform similar to WordPress.
The images themselves "still load and work properly," Cid said.
"In fact," he adds in the blog post, "on these compromised sites, the attackers modified a legit, pre-existent image from the site. This is a curious steganographic way to hide the malware."
Once the server is compromised, the attackers will modify the image's EXIF headers and re-upload the image. At this sage, the image renders normally, and most webmasters won't notice anything off. However, should the compromise be discovered and the server's security tightened, the image provides a firm hold that the attackers will later use in order to regain access.
Using the exif_read_data function in PHP to read the image's headers, and the preg_replace function to execute the embedded commands; the attackers can keep control over a webserver long after the vulnerable software and the server's other core files have been patched. This happens because the image's MAKE header has "/.*/e" as a keyword -- this is the 'eval' modifier, which is used to execute the content fed to preg_replace.
Once the header was parsed, Sucuri's researchers discovered base64 encoded lines, that when decoded offered the final part to the backdoor itself, a function that will execute any content delivered to it via POST. Using this, an attacker can issue commands, or call for shell scripts hosted remotely and execute them. Moreover, depending on how the server is configured, the commands issued to the backdoor could be running with elevated privileges.
Cid explained that the backdoors were discovered during memory examinations after a client requested help recovering from a breach. When questioned about detection, he added that unless modified to detect these kinds of patterns within a given file, IDS and IPS systems wouldn't have prevented this type of attack.
"The thing I recommend the most is file integrity monintoring," Cid told CSO. "If you can detect files being modified, then you can discover this type of attack."
He also noted that it is possible to watch log files for command instances, such as file creation and modification. However, the key point is to stay on top of updates, especially for platforms such as WordPress and Joomla, which are popular targets for attackers and constantly updated in order to address security concerns.