A
A
Anton Kokarev2019-04-03 23:52:29
JavaScript
Anton Kokarev, 2019-04-03 23:52:29

How to declare a function object in JS?

An obfuscated js file came to the mail, in fact a virus loader. It became interesting what it does, I decided to debug using script.google.com, it's safer.
All work in the script goes through the ActiveX object. Clearly, Google does not have such an object, but it is to our advantage, we will announce our own. Classes could not be used, so through the function.

function cFields() {
  this.append = function(a,b,c){Logger.log('ActiveXObject ('+this.fileName+'.fields) append('+a+','+b+','+c+')');return 'fields.append'};
}

function ActiveXObject(file_name) {
  this.fileName = file_name;
  Logger.log('ActiveXObject ('+this.fileName+') NEW');
  this.Status = 200;
  this.fields = new cFields();
  
  this.open = function(a,b,c){Logger.log('ActiveXObject ('+this.fileName+') open: ('+a+','+b+','+c+')');return 'open'};
  this.send = function(a,b,c){Logger.log('ActiveXObject ('+this.fileName+') send()');return 'send'};
  this.GetSpecialFolder = function(a){Logger.log('ActiveXObject ('+this.fileName+') GetSpecialFolder('+a+')'); return 'SpecFolder'};
  this.GetTempName = function(a){Logger.log("ActiveXObject ("+this.fileName+") GetTempName()"); return 'TempName'};
  this.Open = function(){Logger.log('ActiveXObject ('+this.fileName+') Open()');return 'Open'};
  this.Write = function(a){Logger.log('ActiveXObject ('+this.fileName+') Write('+a+')');return 'Write'};
  this.Read = function(a){Logger.log('ActiveXObject ('+this.fileName+') Read('+a+')');return 'Read'};
  this.addNew = function(a){Logger.log('ActiveXObject ('+this.fileName+'.fields) addNew('+a+')');return 'fields.addNew'};
}

In such a simple way in the logs I see everything that the script does. At some point, the script stops:
TypeError: [object Object] is not a function but an object.

uKi = new ActiveXObject('ADODB.Recordset')
St = 'appendChunk'
q = 'Read'
uKi(Z)[St](q);

Actually the question is how to declare a method in the source object that will be called when the object is accessed like a function?
UPD:
At this link you can see the full script yourself.
https://script.google.com/d/1IrkYN_Sg0j_uiMD4fAmEP...
To launch, execute the doGet function or follow the link:
https://script.google.com/macros/s/AKfycbyiYp4kX07...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dollar, 2019-04-04
@dollar

So add it.

this.appendChunk = function(a){Logger.log('ActiveXObject ('+this.fileName+') appendChunk('+a+')');return 'appendChunk'};

S
Stockholm Syndrome, 2019-04-04
@StockholmSyndrome

like so

function ActiveXObject() {
 // ...
  return Object.assign(() => {
    // ...
  }, this);
}

V
Vladimir Proskurin, 2019-04-04
@Vlad_IT

Actually, functions are objects.

function func() {
    alert("Hello world");
}

func.prop1 = "prop";
func.prop2 = "prop";

func(); // Hello world
console.warn(func.prop1); // prop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question