0
votes

I'm trying to understand what a malicious JS script does. The script obfuscated, so I can not read on their own. I known that it creates an ActiveXObject object.

So I decided to declare my object with this name, which does nothing but output a log. The virus uses the construction

var x = new ActiveXObject('file_name')

Google Scripts does not allow you to declare your own classes (is it?), so I declare a constructor function for the new AX object. Everything works fine until the virus tries to access the AX object as a function like

var AX = new ActiveXObject()  
AX()

This return type mismatch (Object!=Function).

There my code: https://script.google.com/d/1IrkYN_Sg0j_uiMD4fAmEPag3HLH07c1fd2t7QOQEphEg38R-t0LAPIAF/edit?usp=sharing

I comment line 195 to prevent error.

Run function doGet for test and view logs. Or just open https://script.google.com/macros/s/AKfycbyiYp4kX07jMwjM6B0fynfMrqQwX1ykJHfy8wFpX6Op/dev

1
If function constructor return function you can call it. function x() { return x; } you call (new x())() or even (new x())()()()()()() or (new (new x())). Maybe it was used to confuse the reader, not sure if there is other case, and I know nothing about how ActiveX behave. - jcubic
@jcubic, if function return function, not object, so construtor new create function. Ok, then I can call it like function, but I cant get it like object. So I can't get his properties, can't call his methods. - Qukish
You can add fields to function, because functions are just objects. function foo() { var bar = function(x) { console.log(x); }; bar.baz = 10; bar.quux = function() { return this.baz; }; return bar; } and call it like this var x = new foo(); x('hello'); x.quux() - jcubic
But in both cases new operator make no difference and result code will act the same with or without it. Because we don't use this in constructor. But of course we can create object in this and return in inner function. function foo() { this.y = 10; return () => this; } var x = new foo(); console.log(x() instanceof foo); - jcubic
@jcubic thx! It's work for me! - Qukish

1 Answers

0
votes
function Foo(x){
  var res = function(a,b){
    //do something when call like function
    return a+b;
  };

  //add props & methods
  res.bar = x; //some prop
  res.add = function(a){return res.bar+=a} //some method
  res.quad = function(){return (res.bar*res.bar)} //other method

  return res; //return function with custom prop&methods
};

var foo = new Foo(1);

console.log(foo.bar); //1 
console.log(foo.add(2)); //3
console.log(foo.bar); //3
console.log(foo.quad()); //9
console.log(foo.bar); //3
console.log(foo(8,10)); //18 call like function