Malware Obfuscation using plain HTML: 7 Examples (2024)

Nov 25, 2019 7:10:11 AM


Dmitry Belomestnykh

As a member of the Malware Intelligence Team, Dmitry Belomestnykh researches and investigates malware samples and trends on a day-to-day basis. He is a web-application security researcher, malware analyst, programmer and CERT engineer, as well as being a lover of outdoor activities.

  • malware
  • obfuscation
  • Imunify360
  • Antivirus

Malware Obfuscation using plain HTML: 7 Examples

Malware Obfuscation using plain HTML: 7 Examples (2)

Hackers will use any method they can to infect your server.

Just because a web site is using plain HTML, doesn’t mean it’s safer than one built on PHP. In this article are seven common examples of obfuscated malware and their de-obfuscated equivalents. To complement my article on PHP malware obfuscation (php goto), this article will look at obfuscation using plain HTML and JavaScript. Additionally, read our website hosting security article and learn how to keep your website secure in 2021.

Why do hackers obfuscate malware?

Here’s a quick reminder of why malware and obfuscation are familiar bedfellows.

  • Malware steals stuff: extracting database content and leaving it for later extraction.
  • Malware does stuff: using your web server resources for nefarious purposes, such as email spamming, or cryptocurrency mining.
  • Malware ranks stuff: using black-hat SEO techniques to down-grade your web site’s Google ranking or increase your competitor’s.

Malware can’t perform these actions unless it is well hidden. That’s the purpose of obfuscation. When a search engine is notified of malware on your domain, it will block or exclude your website’s content from their SERPs. This is not what you want, because you’ll loose money and suffer reputation damage. It’s not what the malware wants either, because without traffic, it can’t spread or make money for its controllers.

One of the problems with malware scanning is that obfuscation isn’t only used by malware. For example, a developer might scramble a piece of proprietary code to protect their own or their company’s intellectual property. Generally speaking, honest programmer’s code, once de-obfuscated, is easy to understand and has obvious behavior. Also, when a developer obfuscates for legitimate purposes, they keep the scrambled portion small and within the HTML tags.

By contrast, obfuscated malware is often put outside the main <html> tags where we’re less likely to spot it. Malicious code will use other tricks to hide any manifestation of itself. Some of the more popular ones are:

  • using small values for height and width, so the element is small;
  • set a location outside the visible area of the screen;
  • for elements that support them (e.g. div, iframe, p, table, etc.) hide the element with visibility:hidden or display:none.

Examples of Obfuscated Malware in Plain HTML and JavaScript

I’m going to show you some examples of malicious scripts that use plain HTML/JavaScript with obfuscation to hide their intentions.

Example 1: Obfuscated Value Assignment

This first example uses the simple technique of assigning an obfuscated value to a variable. The value is later converted using the replace() function, then evaluated with eval(unescape(<VALUE>)). When fully expanded, the value becomes code containing functions such as document_write, scriptEngine, indexOf and others.

Malware Obfuscation using plain HTML: 7 Examples (3)

After I de-obfuscate and prettify the code, it looks like this.

Malware Obfuscation using plain HTML: 7 Examples (4)

Example 2: Abusing HTML Element Size and Visibility

Here, the iframe element is hidden with the style attribute, as well as being 2 pixels wide and 4 pixels high, small enough to escape the notice of most casual observers.

Malware Obfuscation using plain HTML: 7 Examples (5)

Example 3: Multiple Encoded JavaScript

This example shows an attempt to disguise a JavaScript document.write call using a combination of hexadecimal and decimal encodings and expanding them with eval(unescape()).

Malware Obfuscation using plain HTML: 7 Examples (6)

When de-obfuscated, the resulting HTML becomes a zero-sized iframe page insert.

Malware Obfuscation using plain HTML: 7 Examples (7)

Example 4: Singly-Encoded JavaScript

Like example 3, but using only a hexadecimal encoding.

Malware Obfuscation using plain HTML: 7 Examples (8)

Here’s the de-obfuscated version, another example of an invisible, 1-pixel-square iframe.

Malware Obfuscation using plain HTML: 7 Examples (9)

Example 5: Mixed Format Hexadecimal Encoding

This example shows a simple but effective approach that uses hexadecimal encoding and mixes the value formats (prefixing values with x and u00). It also shows the use of array assignments, which is rarely used.

Malware Obfuscation using plain HTML: 7 Examples (10)

When de-obfuscated, the sample becomes this.

Malware Obfuscation using plain HTML: 7 Examples (11)

Example 6: All-Uppercase Alphanumeric Values

Here is another simple but effective obfuscation method: the use of all-uppercase alphanumeric variable and value strings.

Malware Obfuscation using plain HTML: 7 Examples (12)

The de-obfuscated version is much clearer, showing how effective this technique is.

Malware Obfuscation using plain HTML: 7 Examples (13)

Example 7:

In this example, PHP evaluates a base 64-encoded string to create the following JavaScript code snippet that implements a cryptocurrency miner.

Malware Obfuscation using plain HTML: 7 Examples (14)

Conclusion

I’ve shown seven examples of simple obfuscation techniques that hackers use to disguise malware written with plain HTML and JavaScript. Most of the examples are HTML file inserts, but each could use a different approach to hiding itself within the file.

The most common approaches are:

  • Placing inserted code after the page’s </html> tag.
  • Inserting code at the end of a <script></script> block.
  • Inserting obfuscated JavaScript.
  • Inserting long and complex obfuscated code sequences in the page body.
  • Using invisible elements (small- or zero-sized dimensions, with or without visibility attributes set).

You’ll appreciate that it takes a lot of time and knowledge to keep track of the various methods malware writers use to hide their intentions and their malicious code. I should know because hunting malware and understanding it is a big part of my day job.

But if you’re running a web hosting business or running more than one Linux web server, you should be using a serious, enterprise-ready cybersecurity tool, or at least run an antivirus and anti-malware scanner now and then.

Postscript

I’m glad to report that Imunify360 detects all classes of malware listed here, and many more besides.

Malware Obfuscation using plain HTML: 7 Examples (15)

Malware Obfuscation using plain HTML: 7 Examples (2024)

FAQs

What are the examples of obfuscation in malware? ›

Compression, encryption, and encoding are some of the most common obfuscation methods used by threat actors. Multiple methods are often used in tandem to evade a wider variety of cybersecurity tools at the initial point of intrusion.

How do I obfuscate an HTML file? ›

You could encode it with base64 in javascript. Note that obfuscation isn't a secure solution, in the end, frontend code (HTML) will always be visible and modifiable by the user. In DevTools when using "inspect" you see the DOM elements, not the source code from which they were created.

What is an example of obfuscation in cyber security? ›

Obfuscation means to make something difficult to understand. Programming code is often obfuscated to protect intellectual property or trade secrets, and to prevent an attacker from reverse engineering a proprietary software program. Encrypting some or all of a program's code is one obfuscation method.

What is the most common obfuscation? ›

Top data obfuscation methods

Three of the most common techniques used to obfuscate data are encryption, tokenization, and data masking. Encryption, tokenization, and data masking work in different ways.

What is an example of obfuscation? ›

Here is an example of deliberate obfuscation: "I cannot say that I do not disagree with you." It allows you to say "you're wrong" but leaves your victim thinking you said "you're right".

What are the 8 examples of malwares? ›

So what are the main types of malware? There are 8 common types of malware threats that you should be aware of: adware, malvertising, spyware, viruses, worms, trojans, hybrids and ransomware. Each of these malware types are a threat to your personal or business information, as well as your device health.

What is the HTML code for hiding content? ›

---" and "--->" tags to hide text in a webpage template so that it can be reused for multiple purposes.

How do you manipulate HTML files? ›

If you prefer to code websites by hand, you can edit HTML files in a basic text editor like Notepad (Windows) or TextEdit (macOS). If you would rather be able to move elements around on the screen and see live previews, you can use a WYSIWYG (What You See Is What You Get) editor like Dreamweaver or Kompozer.

How do you suppress in HTML? ›

You can suppress individual elements by making a small modification to your page's HTML. This includes image suppression. Your development team can add “data-hj-suppress” as an HTML attribute or class to the element(s). This suppresses all text and image content inside the element, including child elements.

What is HTML obfuscation? ›

To obfuscate an HTML code page means to encrypt or hide strings of characters which are likely email addresses and other source code within the code page. When HTML is obfuscated, spam robots are not able to glean email addresses from the code.

What does obfuscated code look like? ›

The characters used are usually notations and numbers, the names are confusing in order to distract the reader, and in some cases, characters can be invisible or unprintable. Although altered, the code performs the same functions as if there is no obfuscation applied.

What are the three most common techniques used to obfuscate data? ›

Data masking, encryption, and tokenization are three common data obfuscation techniques. Each type has strengths in protecting against destructive malware. Familiarizing yourself with data obfuscation techniques will help you protect your sensitive data—and educate you in case obfuscation is used against you.

What is obfuscated malware code? ›

Malware obfuscation is the act of making the code of a program hard to discover or understand—by both humans and computers—but without changing how the program works. The goal is not just to make a program unreadable, but to hide its presence completely.

How to make code unreadable? ›

Here are some of the best camouflaging techniques.
  1. Code That Masquerades As Comments and Vice Versa. ...
  2. namespaces. ...
  3. Hide Macro Definitions. ...
  4. Look Busy. ...
  5. Use Continuation to hide variables. ...
  6. Arbitrary Names That Masquerade as Keywords. ...
  7. Code Names Must Not Match Screen Names. ...
  8. Don't Change Names.

Which of the following tools can be used to obfuscate malware code? ›

The tools that can be used to obfuscate malware code are PEID and UPX. Both tools are used to pack executable files, making them harder to detect by antivirus software. PEID, also known as PEiD, is a program that can analyze portable executable (PE) files and detect if they are packed with a particular type of packer.

What does obfuscation look like? ›

The rename code obfuscation involves altering the methods and names of the variables within the code. The characters used are usually notations and numbers, the names are confusing in order to distract the reader, and in some cases, characters can be invisible or unprintable.

What are viruses obfuscating their code? ›

Definition. A virus obfuscation technique (also called Polymorphism) is a way of constructing a virus that make it more difficult to detect. If a virus is hard to detect, it is likely to spread more widely.

Top Articles
Latest Posts
Article information

Author: Patricia Veum II

Last Updated:

Views: 6034

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.