Search code examples
javascripthtmlobfuscationdeobfuscation

New to Javascript Obfuscation.. Why is it not executing?


I am trying to run some Java script that has been obfuscated, but for some reason nothing is happening... my file is called test2.js and has this code in it:

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('L 6;6=\'p\';r c A(){1.2("3").0=""q(6<B){1.2("h").0+="C. s I o n k? I u l m 5 p <4>"}y q(6>w){1.2("h").0+="x D!. s I o n k? I u l m 5 6 <4>"}1.2("3").0+="<a 9=\'#\' 7=\'g();\'>e i, j d 5 f</a><4>"1.2("3").0+="<a 9=\'#\' 7=\'g();\'>e i, j d 5 f</a><4>"8 b}c g(){1.2("3").0=""1.2("h").0+="e i, j d 5 f<4>";1.2("3").0+="<a 9=\'#\' 7=\'v();\'>z H</a><4>"8 b}c v(){1.2("3").0=""1.2("3").0+="<a 9=\'#\' 7=\'t();\'>E M K J, F G?</a><4>"8 b}c t(){1.2("3").0=""8 b}',49,49,'innerHTML|document|getElementById|NPCResponseWindow|br|is|GetCharHP|onclick|return|href||false|function|name|Hi|Player|nicetomeetyou|NPCTalkWindow|NPC|my|today|your|HP|you|help|399|if||Can|END|see|Beginnings2|450|Go|else|Same|Beginnings|400|Hello|away|Lets|shall|we|here||again|this|var|do'.split('|')))

My HTML file has this:

<script src="test2.js"></script>

<HTML>
<BODY>
<table>
    <tr>
        <td><div id="NPCTalkWindow"></div></td></tr>
    <tr>
        <td> <div id="NPCResponseWindow"> <a href='#' onclick='Beginnings();'>Begin Conversation</a></div>
        </td>
    </tr>
</table>
</body>
</html>

But nothing is appearing except for the begin conversation. Any help? What am I doing wrong?


Solution

  • As expected, they are errors on the unobfuscated code :

    var GetCharHP;
    GetCharHP = '399';
    r    // there is an error here, add the ;
    function Beginnings() {
        document.getElementById("NPCResponseWindow").innerHTML = ""
        if (GetCharHP < 400) {
            document.getElementById("NPCTalkWindow").innerHTML += "Hello. Can I help you today? I see your HP is 399 <br>"
        } else if (GetCharHP > 450) {
            document.getElementById("NPCTalkWindow").innerHTML += "Go away!. Can I help you today? I see your HP is GetCharHP <br>"
        }
        document.getElementById("NPCResponseWindow").innerHTML += "<a href='#' onclick='nicetomeetyou();'>Hi NPC, my name is Player</a><br>"
        document.getElementById("NPCResponseWindow").innerHTML += "<a href='#' onclick='nicetomeetyou();'>Hi NPC, my name is Player</a><br>"
        return false
    }
    
    function nicetomeetyou() {
        document.getElementById("NPCResponseWindow").innerHTML = ""
        document.getElementById("NPCTalkWindow").innerHTML += "Hi NPC, my name is Player<br>";
        document.getElementById("NPCResponseWindow").innerHTML += "<a href='#' onclick='Beginnings2();'>Same here</a><br>"
        return false
    }
    
    function Beginnings2() {
        document.getElementById("NPCResponseWindow").innerHTML = ""
        document.getElementById("NPCResponseWindow").innerHTML += "<a href='#' onclick='END();'>Lets do this again, shall we?</a><br>"
        return false
    }
    
    function END() {
        document.getElementById("NPCResponseWindow").innerHTML = ""
        return false
    }
    

    And add a doctype to your HTML And move the script at the end of the file (juste before ) You can't hide javascript code it's to easy yo unobfuscate with online services