HTML Smuggling

Bypassing an IDS/Firewall through HTML Smuggling

HTML smuggling is a type of web attack in which an attacker injects malicious code into an HTML script to compromise a web page.

An attacker creates a malicious link by developing a JavaScript-based blob with a compatible MIME that is set to automatically download the malware.

Working of HTML Smuggling

  1. Attackers initiate an attack by embedding malware within a HTML5 attachment or web page. When the victim clicks on the malicious link, the specially crafted malware executes on the victim system.
<a href="malicious.doc" download="Myfile.doc">Click</a>
  1. The executed malware is saved with an unsuspicious name on the device.
  2. Attackers can also perform HTML smuggling using JavaScript, as shown below:
var myAnchorElement = myAnchorElement.download = 'Myfile.doc'; 
document.createElement('a');
  1. In this case, the malicious file is built using the JavaScript Blob. Instead of supplying a URL for the malicious file to be downloaded, the file itself can be built from the Blob:
var fakeBlob = new Blob([myfakeFile], {type: 'octet/stream'});
  1. Attackers create a URL to lure victims into downloading the malicious file:
var myfileUrl = myAnchor.href = myfileUrl; 
myAnchor.click();

The IDS/firewall expects JavaScript and HTML traffic from the clients. The JavaScript actually hides the blob content to evade detection and allows a connection with the malicious server.

Signs of HTML Smuggling

Signs of malware-smuggling HTML attachments include:

Countermeasures

window.URL.createObjectURL(fakeBlob);