/* Copyright (c) 2009-2010 C-DAC All Rights Reserved Developed by: C-DAC Hyderabad Project: MPS-II Module Name: dD.js ************ Module for i. accesing user requested webpage and monitor for vulnerable tags & javascript injections ii. injecting a script into webpage to acess javascript functions & its arguments and check for maliciousness ***********************************************************************************************/ //To get full URL var fullurl=window.location.href; //only proto var proto=location.protocol; var score_ifd=0,score_w=0,score_ev=0,score_sh=0,score_req=0,score=0,shellp1=[],docWrite1=[],re1=[],req1=[],reqq1=[],alertt2=[],alertt3=[];//create global arrays to store the parameters of dynamic functions /* * Calling handy injection function for injecting the variables into the webpage * @returns {undefined} */ addJS_Node ("var count=0,shellp=[],docWrite=[],re=[],req=[],reqq=[],alert2=[],alert3=[],al2='';");// create local arrays /* * Creating hook to document.create and document.write for obtaining the * parameters of the respective methods * @returns {undefined} */ function LogDocCreateElement () { var host1=document.location.hostname; try{ var oldDocumentCreateElement = document.createElement; document.createElement = function(tagName) { var elem = oldDocumentCreateElement.apply (document, arguments); if (tagName === "script"){ getScriptAttributes (elem, tagName); //Identifying the attributes of suspicious tags } if (tagName === "iframe"){ getScriptAttributes (elem, tagName); } if (tagName === "a"){ getScriptAttributes (elem, tagName); } if (tagName === "link"){ getScriptAttributes (elem, tagName); } return elem; } //Creating hook to document.write to obtain the parameters of the method var oldDocumentWrite = document.write; document.write = function (str) { var host1=document.location.hostname; var elem1 = oldDocumentWrite.apply (document,arguments); /* * Filling the content of doc.write into the docWrite array variable * which is already injected into the webpage */ docWrite.push(str); if(str.length > 20){ encodeJs(str); // verifying the existance of encoded JS nonPrint(str); //verifying the presence of shellcode; } /* * Checking whether any tags are created through doc.write content * Uses DOM parser for converting string into DOM format * @type DOMParser */ var parser = new DOMParser(); var div = parser.parseFromString(str, "text/html"); //Verifying the presence of suspicious tags var tagifr=div.getElementsByTagName("iframe"); var tagsc=div.getElementsByTagName("script"); //iframe properties if(tagifr.length>0){ /* ---- Retrieving the attributes of the iframe tag ---- */ for(var j=0;j