JavaScript Malware Tactics: TDS, Server-Side Redirects & DNS TXT Records

Eshan Riyaz

May 4, 2024 . 17 min read

JavaScript Malware Tactics: There’s a new harmful campaign attacking WordPress sites. It added dangerous JavaScript code to these sites, which then sent visitors to harmful VexTrio domains. What’s interesting about this malware is that it used dynamic DNS TXT records from the tracker-cloud[.]com domain to get new redirect URLs.

Image: Ensure you're a human by simply tapping on the "allow' button.

Since then, we’ve observed how the campaign is changing the way it hides its actions and the domain names it uses to direct traffic.

In March, there was a major change when the campaign started redirecting traffic through the server instead of the client side.

In this article, we will explore these recent changes in methods and functions. We will also highlight common signs of a security breach and malicious domains to be cautious of. Plus, we will offer steps to reduce the risk and protect your website and server from these threats.

Exploring Scope and Detection

The most infections were found in February 2024, when 9,222 sites were infected in just that month. Right now, a URLScan.io search shows that thousands of websites are still infected with this malware.

DNS Traffic Distribution System (TDS) Domain Names

The following domain names are used as Traffic Distribution System (TDS) with dynamic DNS resolvers:

  1. cloud-stats[.]com: This domain was created on March 13, 2024, and has been in use since March 13, 2024.
  2. host-stats[.]io: Created on March 5, 2024, this domain has been operational since March 5, 2024.
  3. logsmetrics[.]com: Created on December 6, 2023, it has been in use since December 18, 2023.
  4. ads-promo[.]com: Created on August 23, 2023, it has been operational since October 13, 2023.
  5. tracker-cloud[.]com: Created on July 12, 2023, this domain has been in use since July 17, 2023.

Redirects On Client-side

Here’s a glimpse into the latest iteration of client-side injection techniques: a method commonly used by cyber attackers to compromise websites and spread malware. Take a closer look at how malicious scripts are injected into web pages, posing a serious threat to online security.

Unraveling the code reveals the utilization of dns.google service to fetch TXT records of dynamically generated subdomains linked to the attacker’s domain. This technique enhances cyber threat detection and mitigation strategies.

Here’s what you can expect from the dns.google server:

In the data parameter, we uncover a base64-encrypted string: aHR0cHM6Ly93ZWItaG9zdHMuaW8vP2NvMWtpb2lqdnEzMjdoaG45NnYw. This decodes to a suspicious link: hxxps://web-hosts[.]io/?co1kioijvq327hhn96v0.

Since March, web-hosts[.]io has been consistently utilized in redirecting users as part of a malware campaign. Noteworthy is the IP address linked: 185.161.248[.]253 (KISARA-AS, RU), hosting numerous domains involved in this malware’s redirection tactics.

Redirects On Server-side

After March 13, 2024, a noticeable trend emerged: website visitors were being redirected to the same destination, web-hosts[.]io. Surprisingly, this time, the redirects were executed server-side without any involvement of JavaScript injections.

Upon thorough investigation, we uncovered the source of these server-side redirects. It was a PHP adaptation of a notorious JavaScript injection method seen in previous cyber-attacks. The attackers utilized a similar approach, embedding a custom code snippet within the WPCode plugin (formerly Insert Headers and Footers by WPBeginner), a popular tool with over 2 million installations worldwide.

As per statistics from the official WordPress plugin repository, WPCode facilitates the injection of custom JavaScript, HTML, CSS, and PHP code snippets into WordPress websites. However, in this instance, attackers abused compromised systems to install this plugin surreptitiously.

Unlike previous tactics involving JavaScript snippets, the attackers opted for PHP snippets to cloak their malicious activities. This strategy rendered the malicious code invisible to external scanners, as only the redirect itself could be detected. Moreover, the intricacies of the Traffic Distribution System (TDS) logic, which tracks visitor IPs, added another layer of complexity, making it challenging to replicate the redirects.

Malicious PHP Snippets within WPCode

Let me illustrate how harmful code, sneaked in as a WPCode PHP snippet, can lurk within the WordPress admin interface, posing a threat to your website’s security and functionality.

You can now spot these useful snippets marked as ‘Untitled Snippets.’

Injected code may change slightly across websites, yet its fundamental function remains unchanged. Let’s explore a simple example:

Discovering more advanced versions of this issue might require a closer look. While they may contain extra code, they often stand out due to heavy reliance on the base64_decode function for decoding strings.

To identify these, consider manually scanning your database for the following suspicious strings:

The string is decoded to:

And:

That decodes to:

Another clear indication that your website might be infected is the presence of the DNS_TXT flag within the dns_get_record() function. When you see this flag, it’s like a red flag waving, signaling potential trouble. This function is a tool used to gather information about DNS records, and when the DNS_TXT flag appears, it often means that your site’s DNS records have been tampered with or compromised. This could lead to security breaches or unauthorized access to your website. If you notice this flag, it’s crucial to take immediate action to investigate and resolve any potential security threats. Ignoring it could leave your website vulnerable to further attacks and damage.

Note :Please be aware that the variable name used in the example below might vary depending on the website you’re working with. This is common practice across different sites and platforms.

Basic Functionality of Redirect

When decoded, the critical segment of the malware appears as follows:

Here’s a useful piece of code that sets up the _red() function to execute whenever a webpage loads, just before it sends any headers.

This function is cleverly designed to check if the visitor is not logged in (a tactic to avoid detection by site owners) and whether it’s their first visit within the past 24 hours.

A Request related to DNS TXT Record

When these certain conditions are fulfilled, the malware creates a unique subdomain on the attacker’s domain, ‘cloud-stats[.]com’. Following this, it asks for the TXT record of this generated subdomain:

Here’s what makes up the generated subdomain:

  • The domain name of the infected site (or ‘unk.com’ if it can’t be identified’)
  • The IP address of the visitor, but with periods and colons replaced by dashes
  • A random number ranging from 100,000 to 999,999
  • A platform marker indicating the device used:
    • ‘ni’ for iPhones
    • ‘nm’ for other mobile devices
    • ‘nd’ for desktops (not mobile)
  • The primary domain, controlled by attackers, is cloud-stats[.]co

Putting it all together, a fully generated subdomain might look like this: www.example.com.127-0-0-1.243385.ni.cloud-stats[.]com

URL Redirection within TXT Records

Here is the particular response to the TXT record requests of malware:

Discovering the redirect URL (hxxps://web-hosts[.]io/?cnpn7bajvq3e7o5kq5t0), encoded as a base64 string aHR0cHM6Ly93ZWItaG9…, reveals crucial information. Additionally, we uncover the IPs of the name servers: the well-known 185.161.248[.]253 (KISARA-AS, RU) and 95.216.232[.]139 (HETZNER-AS, DE).

Once the redirect URL is fetched from the cloud-stats[.]com DNS server, visitors are automatically rerouted there through the wp_redirect function.

Elusive Techniques and Backdoor Functionality

Injected PHP scripts may come with extra functionalities. One frequent addition is code that conceals the WPCode plugin (insert-headers-and-footers/ihaf.php) within the installed plugins list.

This tactic thwarts detection and deactivation attempts by website owners who didn’t install the plugin themselves. An unintended consequence is that even legitimate users of the plugin may find it hidden.

To further obscure the WPCode plugin, the malware modifies its notifications and messages on the WordPress dashboard, making them invisible by altering their display styles to { display: none; }.

Backdoor That is Cookie Based

Newer versions of this malicious software boast added features, including a backdoor function enabling attackers to transmit data to the script through base64-encoded cookies:

have a look on the Crucial Functions of this Backdoor at this point:

  • Dynamic Domain Update (sd): Seamlessly updates the primary DNS TDS domain and securely stores it in WordPress. A single discreet GET request can swap out the domain, ensuring easy concealment.
  • Admin User Creation (au): Allows the unauthorized creation of a malicious WordPress admin user, compromising website security. These functionalities pose a severe threat to website integrity. Take proactive steps to protect your online assets.

Persistence of Malware

Did you know? A recent malware campaign is wreaking havoc by installing the WPCode plugin onto unsuspecting websites. This plugin serves as a gateway for cyber attackers to inject their own custom JS and PHP code, compromising site security.

Our analysis, based on logs from various affected sites, reveals a troubling pattern. While it remains uncertain which vulnerability initially allowed this malware to infiltrate, our investigation pinpointed its activity to the moment attackers gain access to WordPress and install the WPCode plugin using valid admin credentials.

What’s truly alarming is the meticulous effort these attackers put in to ensure their malware remains undetected. After infecting a site, their bots diligently revisit it daily, sometimes even multiple times a day, to log into WordPress and verify the WPCode plugin’s activation status. In a remarkable display of persistence, we observed an instance where a site owner deactivated the plugin, only to have it reactivated by the attacker’s bot a mere two hours later!

Furthermore, our research uncovers another tactic employed by these malicious actors. They’re also experimenting with a similar plugin called ‘Head, Footer and Post Injections,’ using it as a backup plan. While this plugin serves the same purpose of allowing custom JS and PHP injections, it’s yet to become the primary tool in their arsenal.

User-Agents and Proxies

Discovering the origins of harmful bot requests reveals a diverse network of residential IPs spanning the globe, such as:

  • Mexico
  • Pakistan
  • Brazil
  • Egypt
  • Thailand
  • Kenya
  • Morocco
  • Serbia
  • etc.

These requests likely stem from compromised computers or public proxies, highlighting the widespread impact of cyber threats worldwide.

The User-Agent strings of all these requests differ very much, but you should typically use the older versions of browsers:

In online sessions, it’s common for your device’s identification (User-Agent) and internet location (IP address) to switch. For example, you might log in with one IP address and see another IP address accessing your /wp-admin/ URLs soon after, using a different User-Agent. This behavior often indicates the use of a proxy, which masks the original IP address. Understanding this can help you ensure the security of your online activities.

Steps Of Mitigation

Protect your website from cyber threats by taking proactive measures. Web hosts play a crucial role in safeguarding against malicious activities. By sinkholing domain names linked to suspicious activities, like DNS DTS, and blocking their associated name servers, such as cloud-stats[.]com, ns1.cloud-stats[.]com, and ns2.cloud-stats[.]com, the risks can be significantly reduced.

As a website owner, here’s what you can do to fortify your site:

  • Strengthen your WordPress admin passwords with unique and robust credentials for each account.
  • Regularly check for unfamiliar WordPress users and remove them promptly through the WordPress dashboard or database inspection.
  • If you’re using the WPCode plugin, thoroughly examine all installed code snippets and delete any that seem suspicious or unnecessary.
  • Audit all installed plugins to ensure they are legitimate. Some plugins may hide in directories like insert-headers-and-footers/ and header-footer/. Remove any plugins that don’t belong.
  • Keep all plugins and themes updated to the latest versions to patch known vulnerabilities. If updates aren’t possible immediately, consider employing a web application firewall for virtual patching.

By following these steps, you can bolster your website’s defenses and keep it safe from potential threats. Stay vigilant and proactive to maintain a secure online presence.

Conclusion

Having trouble with your website? Talk to us now! Our skilled security team at ElySpace is available 24/7 to handle malware problems, clean up your site, and fix it. Contact us anytime for quick help and to get your website working again!