-
Notifications
You must be signed in to change notification settings - Fork 85
/
boilerplate.js
1347 lines (1224 loc) · 39.9 KB
/
boilerplate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const parse = require("node-html-parser").parse;
const lib = require("./lib.js");
// Dummy event to use for faked event handler calls.
const dummyEvent = {
// A boolean value indicating whether or not the event bubbles up through the DOM.
bubbles: true,
// A boolean value indicating whether the event is cancelable.
cancelable: true,
//A boolean indicating whether or not the event can bubble across
//the boundary between the shadow DOM and the regular DOM.
composed: true,
// A reference to the currently registered target for the
// event. This is the object to which the event is currently
// slated to be sent. It's possible this has been changed along
// the way through retargeting.
currentTarget: "??",
// Indicates whether or not the call to event.preventDefault() canceled the event.
defaultPrevented: false,
// Indicates which phase of the event flow is being processed. It
// is one of the following numbers: NONE, CAPTURING_PHASE,
// AT_TARGET, BUBBLING_PHASE.
eventPhase: 1, // CAPTURING_PHASE
// Indicates whether or not the event was initiated by the browser
// (after a user click, for instance) or by a script (using an
// event creation method, for example).
isTrusted: true,
// A reference to the object to which the event was originally
// dispatched.
target: "??",
// The time at which the event was created (in milliseconds). By
// specification, this value is time since epoch—but in reality,
// browsers' definitions vary. In addition, work is underway to
// change this to be a DOMHighResTimeStamp instead.
timeStamp: 1702919791198,
// The name identifying the type of the event.
type: "FILL IN BASED ON FAKED HANDLER",
// For Key events.
key: 97, // "a"
stopPropagation: function() {},
preventDefault: function() {},
composedPath: function() {
return {
includes: function() { return false; },
};
},
};
// Handle Blobs. All Blob methods in the real Blob class for dumping
// the data in a Blob are asynch and box-js is all synchronous, so
// rather than rewriting the entire tool to be asynch we are just
// stubbing out a simple Blob class that is synchronous.
class Blob {
constructor(data, type) {
this.raw_data = data;
// Convert to a data string if this is an array of bytes.
this.data = "";
var flat = [];
for (let i = 0; i < data.length; i++) {
if ((Array.isArray(data[i])) || (data[i].constructor.name == "Uint8Array")) {
for (let j = 0; j < data[i].length; j++) {
flat.push(data[i][j]);
}
}
}
if (!flat.some(i => (!Number.isInteger(i) || (i < 0) || (i > 255)))) {
for (let i = 0; i < flat.length; i++) {
this.data += String.fromCharCode(flat[i]);
};
};
};
toString() { return this.data };
charAt(x) { return this.toString().charAt(x); };
static charAt() { return ""; };
};
Object.prototype.Blob = Blob;
// Simple Enumerator class implementation.
class Enumerator {
constructor(collection) {
if (typeof(collection.length) == "undefined") throw "Enumerator collection has no .length attr";
this.collection = collection;
this.currIndex = 0;
};
atEnd() {
return (this.currIndex >= this.collection.length);
};
moveNext() {
this.currIndex++;
};
item() {
if (this.atEnd()) throw "Over end of all Enumerator data";
return this.collection[this.currIndex];
};
};
// JScript VBArray class.
class VBArray {
constructor(values) {
this.values = values;
};
getItem(index) {
return this.values[index];
};
};
function btoa(data) {
if (typeof(data) == "undefined") return "";
return Buffer.from(data, 'binary').toString('base64')
}
// atob() taken from abab.atob.js .
/**
* Implementation of atob() according to the HTML and Infra specs, except that
* instead of throwing INVALID_CHARACTER_ERR we return null.
*/
function atob(data) {
// Web IDL requires DOMStrings to just be converted using ECMAScript
// ToString, which in our case amounts to using a template literal.
data = `${data}`;
// "Remove all ASCII whitespace from data."
data = data.replace(/[ \t\n\f\r]/g, "");
// "If data's length divides by 4 leaving no remainder, then: if data ends
// with one or two U+003D (=) code points, then remove them from data."
if (data.length % 4 === 0) {
data = data.replace(/==?$/, "");
}
// "If data's length divides by 4 leaving a remainder of 1, then return
// failure."
//
// "If data contains a code point that is not one of
//
// U+002B (+)
// U+002F (/)
// ASCII alphanumeric
//
// then return failure."
if (data.length % 4 === 1 || /[^+/0-9A-Za-z]/.test(data)) {
return null;
}
// "Let output be an empty byte sequence."
let output = "";
// "Let buffer be an empty buffer that can have bits appended to it."
//
// We append bits via left-shift and or. accumulatedBits is used to track
// when we've gotten to 24 bits.
let buffer = 0;
let accumulatedBits = 0;
// "Let position be a position variable for data, initially pointing at the
// start of data."
//
// "While position does not point past the end of data:"
for (let i = 0; i < data.length; i++) {
// "Find the code point pointed to by position in the second column of
// Table 1: The Base 64 Alphabet of RFC 4648. Let n be the number given in
// the first cell of the same row.
//
// "Append to buffer the six bits corresponding to n, most significant bit
// first."
//
// atobLookup() implements the table from RFC 4648.
buffer <<= 6;
buffer |= atobLookup(data[i]);
accumulatedBits += 6;
// "If buffer has accumulated 24 bits, interpret them as three 8-bit
// big-endian numbers. Append three bytes with values equal to those
// numbers to output, in the same order, and then empty buffer."
if (accumulatedBits === 24) {
output += String.fromCharCode((buffer & 0xff0000) >> 16);
output += String.fromCharCode((buffer & 0xff00) >> 8);
output += String.fromCharCode(buffer & 0xff);
buffer = accumulatedBits = 0;
}
// "Advance position by 1."
}
// "If buffer is not empty, it contains either 12 or 18 bits. If it contains
// 12 bits, then discard the last four and interpret the remaining eight as
// an 8-bit big-endian number. If it contains 18 bits, then discard the last
// two and interpret the remaining 16 as two 8-bit big-endian numbers. Append
// the one or two bytes with values equal to those one or two numbers to
// output, in the same order."
if (accumulatedBits === 12) {
buffer >>= 4;
output += String.fromCharCode(buffer);
} else if (accumulatedBits === 18) {
buffer >>= 2;
output += String.fromCharCode((buffer & 0xff00) >> 8);
output += String.fromCharCode(buffer & 0xff);
}
// "Return output."
return output;
}
/**
* A lookup table for atob(), which converts an ASCII character to the
* corresponding six-bit number.
*/
function atobLookup(chr) {
if (/[A-Z]/.test(chr)) {
return chr.charCodeAt(0) - "A".charCodeAt(0);
}
if (/[a-z]/.test(chr)) {
return chr.charCodeAt(0) - "a".charCodeAt(0) + 26;
}
if (/[0-9]/.test(chr)) {
return chr.charCodeAt(0) - "0".charCodeAt(0) + 52;
}
if (chr === "+") {
return 62;
}
if (chr === "/") {
return 63;
}
// Throw exception; should not be hit in tests
return undefined;
}
function extractJSFromHTA(s) {
const root = parse("" + s);
items = root.querySelectorAll('script');
r = "";
var chunkNum = 0;
for (let i1 = 0; i1 < items.length; ++i1) {
item = items[i1];
for (let i2 = 0; i2 < item.childNodes.length; ++i2) {
chunkNum += 1;
child = item.childNodes[i2]
attrs = ("" + child.parentNode.rawAttrs).toLowerCase();
if (!attrs.includes("vbscript")) {
r += "// Chunk #" + chunkNum + "\n" + child._rawText + "\n\n";
}
}
}
return r;
}
var location = {
/*
Location.ancestorOrigins
Is a static DOMStringList containing, in reverse order, the origins
of all ancestor browsing contexts of the document associated with
the given Location object.
*/
ancestorOrigins: '',
/*
Location.href
Is a stringifier that returns a USVString containing the entire
URL. If changed, the associated document navigates to the new
page. It can be set from a different origin than the associated
document.
*/
get href() {
if (typeof(this._href) === "undefined") this._href = 'http://mylegitdomain.com:2112/and/i/have/a/path.php#tag?var1=12&ref=otherlegitdomain.moe';
return this._href;
},
set href(url) {
url = url.replace(/\r?\n/g, "");
this._href = url;
logIOC('HREF Location', {url}, "The script changed location.href.");
logUrl('HREF Location', url);
},
/*
Location.protocol
Is a USVString containing the protocol scheme of the URL, including
the final ':'.
*/
protocol: 'http:',
/*
Location.host
Is a USVString containing the host, that is the hostname, a ':', and
the port of the URL.
*/
host: 'mylegitdomain.com:2112',
/*
Location.hostname
Is a USVString containing the domain of the URL.
*/
hostname: 'mylegitdomain.com',
/*
Location.port
Is a USVString containing the port number of the URL.
*/
port: '2112',
/*
Location.pathname
Is a USVString containing an initial '/' followed by the path of the URL.
*/
pathname: '/and/i/have/a/path.php',
/*
Location.search
Is a USVString containing a '?' followed by the parameters or
"querystring" of the URL. Modern browsers provide URLSearchParams
and URL.searchParams to make it easy to parse out the parameters
from the querystring.
*/
search: '',
/*
Location.hash
Is a USVString containing a '#' followed by the fragment identifier
of the URL.
*/
get hash() {
// Return a fake fragment ID if location is not set.
if (typeof(this._href) === "undefined") {
return '#eyAiZW1haWwiIDogInZpY3RpbUBwbGVhc2UucGhpc2gubWUiIH0K';
};
// Return the actual fragment ID if we have one.
const i = this._href.indexOf("#");
var r = "";
if (i >= 0) r = this._href.slice(i);
return r;
},
/*
Location.origin Read only
Returns a USVString containing the canonical form of the origin of
the specific location.
*/
origin: 'http://mylegitdomain.com:2112',
replace: function (url) {
logIOC('Window Location', {url}, "The script changed the window location URL.");
logUrl('Window Location', url);
},
// The location.reload() method reloads the current URL, like the Refresh button.
reload: function() {},
// box-js specific. Used to tell when window.location is used as a string.
toString: function() {
// Should return the URL (href) but looks like some JS malware
// expects this to be the file URL for the sample.
//return this.href;
return "file:///C:\Users\User\AppData\Roaming\CURRENT_SCRIPT_IN_FAKED_DIR.js"
},
};
tagNameMap = {
/* !! ADD TAG TO VALUE MAPPINGS HERE !! */
};
function __makeFakeElem(data) {
var func = function(content) {
logIOC('DOM Write', {content}, "The script added a HTML node to the DOM");
const urls = pullActionUrls(content);
if (typeof(urls) !== "undefined") {
for (const url of urls) {
logUrl('Action Attribute', url);
};
}
return "";
};
var fakeDict = {
"appendChild" : func,
"insertBefore" : func,
"parentNode" : {
"appendChild" : func,
"insertBefore" : func,
},
"getElementsByTagName" : __getElementsByTagName,
"title" : "My Fake Title",
style: {},
navigator: navigator,
getAttribute: function() { return {}; },
addEventListener: function(tag, func) {
if (typeof(func) === "undefined") return;
// Simulate the event happing by running the function.
logIOC("Element.addEventListener()", {event: tag}, "The script added an event listener for the '" + tag + "' event.");
func(dummyEvent);
},
removeEventListener: function(tag) {
logIOC("Element.removeEventListener()", {event: tag}, "The script removed an event listener for the '" + tag + "' event.");
},
"classList" : {
add: function() {},
remove: function() {},
trigger: function() {},
special: {},
},
innerHTML: data,
item: function() {},
};
return fakeDict;
}
function __getElementsByTagName(tag) {
// Do we have data for this tag?
const tagData = tagNameMap[tag];
if (tagData) {
var r = [];
for (var i = 0; i < tagData.length; i++) {
r.push(__makeFakeElem(tagData[i]));
}
return r;
}
else {
return [__makeFakeElem("")];
}
};
var __currSelectedVal = undefined;
var __fakeParentElem = undefined;
function __createElement(tag) {
var fake_elem = {
set src(url) {
// Looks like you can leave off the http from the url.
if (url.startsWith("//")) url = "https:" + url;
// Is the script source base64 encoded?
if (url.startsWith("data:text/html;base64,")) {
// Strip off the HTML info.
url = url.slice("data:text/html;base64,".length)
// Decode the base64.
url = atob(url);
}
// Save the IOC.
logIOC('Remote Script', {url}, "The script set a remote script source.");
logUrl('Remote Script', url);
},
set onerror(func) {
// Call the onerror handler.
func();
},
set value(txt) {
this.val = txt;
},
get value() {
return this.val;
},
get href() {
if (typeof(this._href) === "undefined") this._href = 'http://mylegitdomain.com:2112/and/i/have/a/path.php#tag?var1=12&ref=otherlegitdomain.moe';
return this._href;
},
set href(url) {
url = url.replace(/\r?\n/g, "");
this._href = url;
logIOC('HREF Location', {url}, "The script changed location.href.");
logUrl('HREF Location', url);
},
// Not ideal or close to correct, but sometimes needs a parentNode field.
parentNode: __fakeParentElem,
log: [],
style: [],
appendChild: function() {
return __createElement("__append__");
},
append: function() {
return __createElement("__append__");
},
attributes: {},
setAttribute: function(name, val) {
this.attributes[name] = val;
// Setting the source of an element to (maybe) a URL?
if (name === "src") {
if (val.startsWith("//")) val = "https:" + val;
logIOC('Element Source', {val}, "The script set the src field of an element.");
logUrl('Element Source', val);
}
},
setAttributeNode: function(name, val) {
if (typeof(val) !== "undefined") {
this.attributes[name] = val;
};
if ((typeof(name.nodeValue !== "undefined")) &&
(typeof(name.nodeValue.valueOf == "function"))) {
name.nodeValue.valueOf();
};
},
removeAttributeNode: function(node) {
// Stubbed out until needed.
},
getAttribute: function(name) {
return this.attributes[name];
},
clearAttributes: function() {
this.attributes = {};
},
firstChild: {
nodeType: 3,
},
lastChild: {
nodeType: 3,
},
getElementsByTagName: __getElementsByTagName,
getElementsByClassName: __getElementsByTagName,
// Probably wrong, fix this if it causes problems.
querySelector: function(tag) {
return __createElement(tag);
},
select: function() {
__currSelectedVal = this.val;
},
cloneNode: function() {
// Actually clone the element (deep copy).
return JSON.parse(JSON.stringify(this));
},
toLowerCase: function() {
return "// NOPE";
},
onclick: undefined,
click: function() {
lib.info("click() method called on a document element.");
if (typeof(this.onclick) !== "undefined") this.onclick();
},
insertAdjacentHTML: function(position, content) {
logIOC('DOM Write', {content}, "The script added a HTML node to the DOM");
const urls = pullActionUrls(content);
if (typeof(urls) !== "undefined") {
for (const url of urls) {
logUrl('Action Attribute', url);
};
}
},
set innerHTML(content) {
this._innerHTML = content;
logIOC("Set innerHTML", {content}, "The script set the innerHTML of an element.");
const urls = pullActionUrls(content);
if (typeof(urls) !== "undefined") {
for (const url of urls) {
logUrl('Action Attribute', url);
};
}
},
get innerHTML() {
if (typeof(this._innerHTML) === "undefined") this._innerHTML = "";
return this._innerHTML;
},
addEventListener: function(tag, func) {
if (typeof(func) === "undefined") return;
// Simulate the event happing by running the function.
logIOC("Element.addEventListener()", {event: tag}, "The script added an event listener for the '" + tag + "' event.");
func(dummyEvent);
},
removeEventListener: function(tag) {
logIOC("Element.removeEventListener()", {event: tag}, "The script removed an event listener for the '" + tag + "' event.");
},
removeChild: function() {},
"classList" : {
add: function() {},
remove: function() {},
trigger: function() {},
// Trivial stubbing. Just say nothing is in the class
// list. May need a flag to control this.
contains: function(x) { return false; },
special: {},
},
};
return fake_elem;
};
__fakeParentElem = __createElement("FakeParentElem");
// Stubbed global navigator object.
const navigator = {
userAgent: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Tablet PC 2.0; InfoPath.3)',
clipboard: {
writeText : function(txt) {
logIOC('Clipboard', txt, "The script pasted text into the clipboard.");
},
},
connection: {
},
cookieEnabled: {
},
credentials: {
},
deviceMemory: {
},
geolocation: {
},
gpu: {
},
hid: {
},
hardwareConcurrency: {
},
ink: {
},
keyboard: {
},
language: "english",
languages: {
},
locks: {
},
maxTouchPoints: {
},
mediaCapabilities: {
},
mediaDevices: {
},
mediaSession: {
},
onLine: {
},
pdfViewerEnabled: {
},
permissions: {
},
platform: "Win32",
presentation: {
},
serial: {
},
serviceWorker: {
},
scheduling: {
},
storage: {
},
userActivation: {
},
userAgentData: {
},
virtualKeyboard: {
},
webdriver: false,
windowControlsOverlay: {
},
xr: {
},
};
var _generic_append_func = function(content) {
logIOC('DOM Write', {content}, "The script added a HTML node to the DOM");
const urls = pullActionUrls(content);
if (typeof(urls) !== "undefined") {
for (const url of urls) {
logUrl('Action Attribute', url);
};
}
return "";
};
// Stubbed global document object.
var document = {
documentMode: 8, // Fake running in IE8
nodeType: 9,
scripts: [],
title: "A Web Page",
referrer: 'https://www.bing.com/',
body: __createElement("__document_body__"),
location: location,
readyState: "complete",
head: {
innerHTML: "",
append: _generic_append_func,
appendChild: _generic_append_func,
prepend: _generic_append_func,
},
defaultView: {},
set cookie(val) {
this._cookie = val;
logIOC('document.cookie', val, "The script set a cookie.");
},
get cookie() {
if (typeof(this._cookie) === "undefined") this._cookie = "";
return this._cookie;
},
ready: function(func) {
func();
},
elementCache : {},
execCommand : function(cmd) {
if ((cmd == "copy") && (typeof(__currSelectedVal) !== "undefined")) {
logIOC('Clipboard', __currSelectedVal, "The script pasted text into the clipboard.");
}
},
getElementById : function(id) {
// Normalize ID.
if (id.startsWith(".")) id = id.slice(1);
// Already looked this up?
if (typeof(this.elementCache[id]) !== "undefined") return this.elementCache[id];
var char_codes_to_string = function (str) {
var codes = ""
for (var i = 0; i < str.length; i++) {
codes += String.fromCharCode(str[i])
}
return codes
}
/* IDS_AND_DATA */
if (typeof(ids) != "undefined") {
// Look for it in ID map.
for (var i = 0; i < ids.length; i++) {
if (char_codes_to_string(ids[i]) == id) {
var r = __createElement(id);
r.innerHTML = char_codes_to_string(data[i]);
r.innerText = char_codes_to_string(data[i]);
r.getAttribute = function(attrId) {
return this.attrs[attrId];
};
r.attrs = attrs[i];
this.elementCache[id] = r;
r.val = jqueryVals[id];
return r;
}
}
// Maybe just tracked as attr?
for (var i = 0; i < attrs.length; i++) {
if ((attrs[i].class === id) || ((attrs[i].id === id))) {
var r = __createElement(id);
r.value = attrs[i].value;
return r;
}
}
}
// got nothing to return. Make up some fake element and hope for the best.
var r = __createElement(id);
r.val = jqueryVals[id];
if (typeof(r.val) == "undefined") r.val = "";
return r;
},
documentElement: {
style: {},
className: "",
},
write: function (content) {
logIOC('DOM Write', {content}, 'The script wrote to the DOM')
const urls = pullActionUrls(content);
if (typeof(urls) !== "undefined") {
for (const url of urls) {
logUrl('Action Attribute', url);
};
}
eval.apply(null, [extractJSFromHTA(content)]);
},
writeln: function (content) {
this.write(content);
},
appendChild: function(content) {
logIOC('DOM Write', {content}, "The script appended an HTML node to the DOM")
const urls = pullActionUrls(content);
if (typeof(urls) !== "undefined") {
for (const url of urls) {
logUrl('Action Attribute', url);
};
}
eval(extractJSFromHTA(content));
},
insertBefore: function(node) {
logIOC('DOM Insert', {node}, "The script inserted an HTML node on the DOM")
eval(extractJSFromHTA(node));
},
getElementsByTagName: __getElementsByTagName,
getElementsByName: __getElementsByTagName,
getElementsByClassName: __getElementsByTagName,
createDocumentFragment: function() {
return __createElement("__doc_fragment__");
},
createElement: __createElement,
createTextNode: function(text) {},
addEventListener: function(tag, func) {
if (typeof(func) === "undefined") return;
// Simulate the event happing by running the function.
logIOC("Document.addEventListener()", {event: tag}, "The script added an event listener for the '" + tag + "' event.");
func(dummyEvent);
},
removeEventListener: function(tag) {
logIOC("Document.removeEventListener()", {event: tag}, "The script removed an event listener for the '" + tag + "' event.");
},
createAttribute: function(name) {
logIOC('Document.createAttribute()', {name}, "The script added attribute '" + name + "' to the document.");
return __createElement(name);
},
querySelector: function(selectors) {
logIOC('Document.querySelector()', {selectors}, "The script queried the DOM for selectors '" + selectors + "' .");
return document.getElementById(selectors);
},
};
// Stubbed out URL class.
class URL {
constructor(url, base="") {
if (typeof(url) == "undefined") url = "???";
this.url = url + base;
this.hostname = "???";
const startHost = this.url.indexOf("://");
if (startHost >= 0) {
this.hostname = this.url.slice(startHost + 3);
const endHost = this.hostname.indexOf("/");
if (endHost >= 0) {
this.hostname = this.hostname.slice(0, endHost);
}
}
lib.logIOC("URL()", {method: "URL()", url: this.url}, "The script created a URL object.");
lib.logUrl("URL()", this.url);
};
static _blobCount = 0;
static createObjectURL(urlObject) {
// If we have a Blob this is probably creating a file download
// link. Save the "file".
if (urlObject.constructor.name == "Blob") {
const fname = "URL_Blob_file_" + URL._blobCount++;
const uuid = lib.getUUID();
lib.writeFile(fname, urlObject.data);
lib.logResource(uuid, fname, urlObject.data);
}
};
static revokeObjectURL() {};
};
function requestAnimationFrame(func) {
lib.logIOC("requestAnimationFrame()", {}, "The script ran a function with requestAnimationFrame().");
func();
}
// Initial stubbed object. Add items a needed.
var screen = {
availHeight: 2000,
availWidth: 4000,
colorDepth: 12,
height: 1000,
isExtended: false,
mozBrightness: .3,
mozEnabled: false,
orientation: {
type: "landscape-primary",
},
pixelDepth: 9,
width: 2000,
};
class XMLHttpRequest {
constructor(){
this.method = null;
this.url = null;
this.readyState = 4;
this.status = 200;
this.responseText = "";
};
_onreadystatechange = undefined;
get onreadystatechange() {
return this._onreadystatechange;
};
set onreadystatechange(func) {
lib.info("onreadystatechange() method set for XMLHTTP object.");
this._onreadystatechange = func;
if (typeof(func) !== "undefined") {
try {
func("fake");
}
catch (e) {
lib.info("Callback function execution failed. Continuing analysis anyway.");
}
}
};
addEventListener(tag, func) {
if (typeof(func) === "undefined") return;
// Simulate the event happing by running the function.
logIOC("XMLHttpRequest.addEventListener()", {event: tag}, "The script added an event listener for the '" + tag + "' event.");
func(dummyEvent);
};
removeEventListener(tag) {
logIOC("XMLHttpRequest.removeEventListener()", {event: tag}, "The script removed an event listener for the '" + tag + "' event.");
};
open(method, url) {
this.method = method;
// Maybe you can skip the http part of the URL and XMLHTTP
// still handles it?
if (url.startsWith("//")) {
url = "http:" + url;
}
this.url = url;
lib.logIOC("XMLHttpRequest", {method: method, url: url}, "The script opened a HTTP request.");
lib.logUrl("XMLHttpRequest", url);
};
setRequestHeader(field, val) {
lib.logIOC("XMLHttpRequest", {field: field, value: val}, "The script set a HTTP header value.");
};
send() {};
};
dataLayer = [];
// Stubbed global window object.
function makeWindowObject() {
var window = {
get park() {
if (typeof(this._park) === "undefined") this._park = '???';
return this._park;
},
set park(val) {
logIOC('Window Parking', val, "The script changed window.park.");
},
eval: function(cmd) { return eval(cmd); },
resizeTo: function(a,b){},
moveTo: function(a,b){},
open: function(url) {
if ((typeof(url) == "string") && (url.length > 0)){
logIOC('window.open()', {url}, "The script loaded a resource.");
}
},
close: function(){},
requestAnimationFrame: requestAnimationFrame,
matchMedia: function(){ return {}; },
setInterval:function(){ return {}; },
atob: function(s){
return atob(s);
},
setTimeout: function(f, i) {},
Date: Date,
addEventListener: function(tag, func) {
if (typeof(func) === "undefined") return;
// Simulate the event happing by running the function.
logIOC("Window.addEventListener()", {event: tag}, "The script added an event listener for the '" + tag + "' event.");
func(dummyEvent);
},
removeEventListener: function(tag) {
logIOC("Window.removeEventListener()", {event: tag}, "The script removed an event listener for the '" + tag + "' event.");
},
attachEvent: function(){},
getComputedStyle: function(){
return ["??",
"-moz-"];
},
createDocumentFragment: function() {},
createElement: __createElement,
screen: screen,
_location: location,
get location() {
return this._location;
},
set location(url) {
this._location.href = url;
},
localStorage: {
// Users and session to distinguish and generate statistics about website traffic.
"___utma" : undefined,
// Users and session to distinguish and generate statistics about website traffic.
"__utma" : undefined,
// Determine new sessions and visits and generate statistics about website traffic.
"__utmb" : undefined,
// Determine new sessions and visits and generate statistics about website traffic.
"__utmc" : undefined,
// Process user requests and generate statistics about the website traffic.
"__utmt" : undefined,
// Store customized variable data at visitor level and generate statistics about the website traffic.
"__utmv" : undefined,
// To record the traffic source or campaign how users ended up on the website.
"__utmz" : undefined,
},
document: document,
dataLayer: [],
navigator: navigator,