-
-
Notifications
You must be signed in to change notification settings - Fork 730
/
__GenericHeuristicAnalysis_By_DosX.7.sg
2864 lines (2050 loc) · 102 KB
/
__GenericHeuristicAnalysis_By_DosX.7.sg
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
/*
██████╗ ███████╗███╗ ██╗███████╗██████╗ ██╗ ██████╗
██╔════╝ ██╔════╝████╗ ██║██╔════╝██╔══██╗██║██╔════╝
██║ ███╗█████╗ ██╔██╗ ██║█████╗ ██████╔╝██║██║
██║ ██║██╔══╝ ██║╚██╗██║██╔══╝ ██╔══██╗██║██║
╚██████╔╝███████╗██║ ╚████║███████╗██║ ██║██║╚██████╗
╚═════╝ ╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═════╝
██╗ ██╗ ██╗███████╗██╗ ██╗██████╗ ██╗███████╗████████╗██╗ ██████╗ ██╗
██╔╝ ██║ ██║██╔════╝██║ ██║██╔══██╗██║██╔════╝╚══██╔══╝██║██╔════╝ ╚██╗
██╔╝ ███████║█████╗ ██║ ██║██████╔╝██║███████╗ ██║ ██║██║ ╚██╗
╚██╗ ██╔══██║██╔══╝ ██║ ██║██╔══██╗██║╚════██║ ██║ ██║██║ ██╔╝
╚██╗ ██║ ██║███████╗╚██████╔╝██║ ██║██║███████║ ██║ ██║╚██████╗ ██╔╝
╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝
█████╗ ███╗ ██╗ █████╗ ██╗ ██╗ ██╗███████╗██╗███████╗
██╔══██╗████╗ ██║██╔══██╗██║ ╚██╗ ██╔╝██╔════╝██║██╔════╝
███████║██╔██╗ ██║███████║██║ ╚████╔╝ ███████╗██║███████╗
██╔══██║██║╚██╗██║██╔══██║██║ ╚██╔╝ ╚════██║██║╚════██║
██║ ██║██║ ╚████║██║ ██║███████╗██║ ███████║██║███████║
╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝╚══════╝╚═╝ ╚══════╝╚═╝╚══════╝
*/
// Detect It Easy: detection rule file
// =================== [ ABOUT ] ===================
// This heuristic analysis will help identify
// presence of obfuscation the or wrapper
// tricks through advanced complex checks.
// Static emulation, signature analysis,
// smart checks and much more!
// ================================================
// ================== [ DONATE ] ==================
// Did you like my work? :D Thank you! But what
// about donation? I'll be very grateful <3
//
// >> Payeer: P1066822521 [Recommended]
//
// >> BTC: 37uRiHBqK3QiJ2jamqmmk1Q3sCmAmWngcC
// 0,0005 BTC minimum
//
// >> LTC: MCwRK1Z7K4GYHt9ZrbTR2SMCEqzqQaTbRF
// 0,001 LTC minimum
//
// >> USDT: TUVH7QkcZws78QMC3XyAwfuzxUbaeLnfAC
// TRC-20 5 USDT minimum
// ================================================
// ================= [ CONTACTS ] =================
// Author: DosX
// E-Mail: [email protected]
// GitHub: https://github.com/DosX-dev
// Telegram: @DosX_dev
// ================================================
// If I don't respond to email, message to Telegram
// ================================================
// For the script to work correctly, the following
// official Detect It Easy components are required:
// "language", "FASM", "RosASM", "SpASM", "FPC"
// "PE\linker.6.sg", "Microsoft.6.sg"
// Please do not read the code out loud unless you have exorcism skills
const logType = {
warning: -2,
about: -1,
nothing: 0,
any: 1,
net: 2
},
heurLabel = "HEUR";
var lastOffsetDetected = "0x00";
const detect = main;
function main() {
if (stubForWrongEnvironment()) return null; // 'PE' is undefined
if (stubForLegacyEngines()) return null; // old DIE version
if (PE.isHeuristicScan()) {
if (!PE.isVerbose()) {
log(logType.warning, "To get the full heuristic scan result use '--verbose'");
}
log(logType.about, "Generic Heuristic Analysis by DosX (@DosX_dev)");
log(logType.nothing, "Scanning has begun!");
if (PE.isNET()) {
scanForObfuscations_NET();
scanForAntiAnalysis_NET();
} else {
scanForObfuscations_Native();
}
scanForPackersAndCryptors_NET_and_Native();
scanForLicensingSystems_NET_and_Native();
if (PE.isVerbose()) {
scanForLanguages_NET_and_Native();
}
// >> Happy end <<
log(logType.nothing, "Scan completed.");
// scanForMaciliousCode_NET_and_Native();
} else {
log(logType.warning, "Heuristic scan is disabled. Use '--heuristicscan' to enable");
}
}
function stubForLegacyEngines() {
if (typeof _error === 'undefined') {
stdout(">>> Update DIE Engine to 3.11 and higher for using Heuristic-analyser by DosX <<<");
return true;
}
return false;
}
function stubForWrongEnvironment() {
if (typeof PE === 'undefined') {
stdout(">>> Wrong environment! 'PE' is undefined. Check DIE-engine for correct installation <<<");
return true;
}
return false;
}
function stdout(stringToOut) {
if (typeof console === 'object') {
console.warn(stringToOut);
} else if (typeof File === 'object') {
_setResult("~Warning", stringToOut, String(), String());
} else {
if (typeof _error === 'function') {
_error(stringToOut);
} else {
throw stringToOut;
}
}
}
function scanForObfuscations_NET() {
var options = String();
var isDetected = Boolean();
const isVbNet = isVbNetStandartLibraryPresent();
var isEntryPointModified = false;
const vbNetEntries = [
"Main",
"main",
"MAIN",
"MyApplication"
],
defaultEntries = [ // like MSIL, C#, C++ NET etc
"Main",
"main", // F# entry
"main@", // F# entry
"<Main>$", // For programs with top-level operators (C#)
"mainCRTStartup", // C++ CLR .NET (CLI)
"wWinMainCRTStartup" // C++ CLR .NET (GUI)
]
if (!PE.isDll()) {
if (isVbNet) {
if (isAllNetReferencesMissing(vbNetEntries)) {
isEntryPointModified = true;
}
} else if (isAllNetReferencesMissing(defaultEntries)) {
isEntryPointModified = true;
}
if (isEntryPointModified) {
log(logType.net, "No 'Main' method found")
}
}
if (isEntryPointModified) options = "Modified EP";
var isNetCctorPresent = false;
if (PE.isNetGlobalCctorPresent() && !isClrNET()) {
isNetCctorPresent = true;
}
if (isNetCctorPresent) options += (options.length != 0 ? " + " : String()) + "CLR constructor";
var isStrangeEpPosition = false;
const netMetaHeaders = [
"~",
"Strings",
"US",
"GUID",
"Blob"
];
// Specify the default .NET section index
const defaultNetSection = 0;
// Check conditions for a strange entry point position (not for CLR apps)
if (!PE.isDll() && PE.getNumberOfSections() > 1 && !isClrNET()) {
// Iterate through .NET metadata headers
for (var s = 0; s < netMetaHeaders.length; s++) {
const headerName = netMetaHeaders[s];
// Check if the signature is not present in the default .NET section
if (!PE.isSignatureInSectionPresent(defaultNetSection, "00'#" + headerName + "'00")) {
isStrangeEpPosition = true;
break;
}
}
}
if (isStrangeEpPosition) options += (options.length != 0 ? " + " : String()) + "Strange EP position";
var isNativeEntryPointModified = false;
if (!PE.isDll() && !isClrNET()) { // not for CLR apps
if (!PE.is64()) {
// FF2500????00: jmp dword ptr [ ... ]
const firstOpCode = getFirstEpAsmOpCode();
if (firstOpCode !== "JMP") {
if (PE.VAToOffset(PE.getAddressOfEntryPoint()) != -1) {
log(logType.net, "Very strange EP pattern: " + getEpAsmPattern(onlyOpCodes = true, numberOf = 4).split("|").join(" .. "));
} else {
log(logType.net, "No native entry point")
}
isNativeEntryPointModified = true;
}
} else { // AMD64
if (PE.VAToOffset(PE.getAddressOfEntryPoint()) != 0x00) {
isNativeEntryPointModified = true;
}
}
}
if (isNativeEntryPointModified) options += (options.length != 0 ? " + " : String()) + "Modified native EP";
// Check if the specified DOS message is not found in the DOS stub
var isDosMessageModified = false;
if (PE.findSignature(PE.getDosStubOffset(), PE.getDosStubSize(), "'This program cannot be run in DOS mode.'") === -1) {
log(logType.net, "DOS-stub modified!");
isDosMessageModified = true;
}
if (isDosMessageModified) options += (options.length != 0 ? " + " : String()) + "Modified DOS";
// Check PE image for strange sections
var strangeSections = false;
const badChars = '_-=+~!@#$%^&*()"№;%:?*():;,/\\|\'`<>.0123456789'; // Very very bad!
if (PE.getNumberOfSections() > (!isClrNET() ? 6 : 10) || !PE.isSectionNamePresent(".text")) { strangeSections = true; } else {
// Iterate through each section
for (var i = 0; i < PE.getNumberOfSections() && !strangeSections; i++) {
const sectionName = PE.getSectionName(i);
// Check if the first character is not "." and the length of name is less than 3
if (sectionName[0] !== "." && sectionName.length < 3) {
strangeSections = true;
break;
}
// Iterate through characters after "."
// Check if the character is in the badChars list
for (var d = 0; d < badChars.length && !strangeSections; d++) {
if (sectionName.substr(1, sectionName.length).indexOf(badChars[d]) !== -1) {
strangeSections = true;
}
}
}
}
if (strangeSections) options += (options.length != 0 ? " + " : String()) + "Strange sections";
const opCodes = new NetOpCodes();
// A popular way to obfuscate numbers/booleans
var isIntConfusionPresent = false;
const intConfusionXorPattern = opCodes.ldc_i4 + opCodes.ldc_i4 + opCodes.xor + opCodes.ldc_i4;
if (validateNetByteCode(intConfusionXorPattern)) {
if (validateNetByteCode( // samples by: Inx Obfuscator
intConfusionXorPattern +
(opCodes.bne_un_s + opCodes.ldc_i4_2 + opCodes.stloc_0 + opCodes.sizeof + opCodes.add)
) ||
validateNetByteCode( // samples by: MindLated, NetShield
intConfusionXorPattern +
(opCodes.bne_un + opCodes.ldc_i4 + opCodes.stloc + opCodes.sizeof + opCodes.add)
) ||
validateNetByteCode( // samples by: VavilonProtect
intConfusionXorPattern +
(opCodes.bne_un + opCodes.ldc_i4_2 + opCodes.stloc_s + opCodes.sizeof + opCodes.add)
)
) {
log(logType.net, "Int confusion detected! Offset: " + lastOffsetDetected);
isIntConfusionPresent = true;
}
}
if (isIntConfusionPresent) options += (options.length != 0 ? " + " : String()) + "Int confusion";
// Virtualization is a method of protection in which some code segments are rewritten into instructions inherent in the built-in virtual machine and executed by it
var isVirtualizationPresent = false;
if (
isAllNetReferencesPresent(
references = [
"System.Reflection", // System.Reflection.dll
"GetILGenerator", // MSIL: 'System.Reflection.Emit.DynamicMethod::GetILGenerator()'
"BeginInvoke",
"EndInvoke",
"OpCode" // MSIL: 'System.Reflection.Emit.OpCode'
]
) &&
(
PE.isNetObjectPresent("Ldarg_0") || // MSIL: 'System.Reflection.Emit.OpCodes.Ldarg_0'
PE.isNetObjectPresent("CreateDelegate") // MSIL: 'System.Delegate.CreateDelegate'
) && !isFrameworkComponent()
) {
isVirtualizationPresent = true;
}
if (isVirtualizationPresent) options += (options.length != 0 ? " + " : String()) + "Virtualization";
// Hiding calls using delegate tricks
var callsEncrypt = false;
if (
isAllNetReferencesPresent(
references = [
"GetTypeFromHandle", // MSIL: 'System.Type::GetTypeFromHandle( ... )'
"BinaryReader", // MSIL: 'System.IO.BinaryReader'
"CreateDelegate", // MSIL: '[Delegate].CreateDelegate'
"MakeByRefType", // MSIL: 'System.Type::MakeByRefType()'
"DynamicMethod" // MSIL: 'System.Reflection.Emit.DynamicMethod'
]
) && !isFrameworkComponent()
) {
callsEncrypt = true;
}
if (callsEncrypt) options += (options.length != 0 ? " + " : String()) + "Calls encrypt";
// https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.suppressildasmattribute
var isAntiIldasmPresent = false;
if (validateNetObject("SuppressIldasmAttribute")) {
isAntiIldasmPresent = true;
}
if (isAntiIldasmPresent) options += (options.length != 0 ? " + " : String()) + "Anti-ILDASM";
// Anti de4dot via inheritance
var isAntiDe4dotPresent = false;
if (
validateSignature("'Form'******00'Form'******00'Form'******00") || // samples by: NetShield
validateNetObject("Form0") // samples by: MindLated
) {
isAntiDe4dotPresent = true;
}
if (isAntiDe4dotPresent) options += (options.length != 0 ? " + " : String()) + "Anti-de4dot";
// An obfuscation method in which calli is used instead of regular calls
var isCalliInvokesPresent = false;
if (validateNetByteCode( // samples by: MindLated
opCodes.setStrict(opCodes.ldftn, "** ?? 00 0A") +
opCodes.setStrict(opCodes.calli, "** 00 00 11")
) ||
validateNetByteCode( // samples by: ArmDot, DarksProtector
opCodes.idelem_i +
opCodes.setStrict(opCodes.calli, "** 00 00 11")
)) {
log(logType.net, "Calli invokes detected! Offset: " + lastOffsetDetected);
isCalliInvokesPresent = true;
}
if (isCalliInvokesPresent) options += (options.length != 0 ? " + " : String()) + "Calli invokes";
var isLdftnPointersPresent = false;
if (validateNetByteCode(
opCodes.nop + opCodes.setStrict(opCodes.ldftn, "** 00 00 06") + opCodes.stelem_i
) ||
validateNetByteCode(
opCodes.nop + opCodes.setStrict(opCodes.ldftn, "** 00 00 0A") + opCodes.stelem_i
) ||
validateNetByteCode( // samples by: Quantum (private)
opCodes.setStrict(opCodes.ldftn, "** 00 00 0A") +
opCodes.setStrict(opCodes.calli, "** 00 00 11")
)) {
log(logType.net, "Ldftn pointers method-obfuscation detected! Offset: " + lastOffsetDetected);
isLdftnPointersPresent = true;
}
if (isLdftnPointersPresent) options += (options.length != 0 ? " + " : String()) + "Ldftn pointers";
// Turns the code into spaghetti by splitting it into blocks that it executes depending on the situation
var isCtrlFlowPresent = false;
if (validateNetByteCode( // samples by: ConfuserEx
opCodes.nop + opCodes.ldloc_0 + opCodes.ldc_i4 + opCodes.mul + opCodes.ldc_i4 + opCodes.xor + opCodes.br_s +
opCodes.nop + opCodes.ldloc_0 + opCodes.ldc_i4 + opCodes.mul + opCodes.ldc_i4 + opCodes.xor + opCodes.br_s
) ||
validateNetByteCode( // samples by: ConfuserEx (neo mod)
opCodes.ldc_i4 + opCodes.ldc_i4 + opCodes.xor + opCodes.dup + opCodes.stloc_0 + opCodes.ldc_i4_3 + opCodes.rem_un + opCodes.switch__nobody
) ||
validateNetByteCode( // samples by: .NET Reactor (v6.9.8)
opCodes.setStrict(opCodes.ldc_i4, "00 00 00 00") + opCodes.br + opCodes.br + opCodes.ldloc
) ||
validateNetByteCode( // samples by: .NET Reactor
opCodes.ldsfld + opCodes.brfalse + opCodes.pop +
opCodes.setStrict(opCodes.ldc_i4, "01 00 00 00") + // MSIL: 'ldc.4 1'
opCodes.br + opCodes.nop
) ||
validateNetByteCode( // samples by: .NET Reactor
opCodes.setNullValue(opCodes.ldc_i4) +
opCodes.ldsfld + opCodes.brtrue + opCodes.pop + opCodes.ldc_i4 +
opCodes.br
) ||
validateNetByteCode( // samples by: .NET Reactor (legacy~~)
opCodes.stloc + opCodes.ldloc +
opCodes.setStrict(opCodes.switch__nobody, "** ** ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00") +
opCodes.ldc_i4 + opCodes.br
) ||
validateNetByteCode( // samples by: MindLated, NetShield
opCodes.setNullValue(opCodes.ldc_i4) + // MSIL: 'ldc.i4 0'
opCodes.stloc + opCodes.br + opCodes.nop + opCodes.ldloc +
opCodes.setStrict(opCodes.ldc_i4, "01 00 00 00") + // MSIL: 'ldc.i4 1'
opCodes.ceq + opCodes.brfalse
) ||
validateNetByteCode( // samples by: Rose Obfuscator
opCodes.setNullValue(opCodes.ldc_i4) + // MSIL: 'ldc.i4'
opCodes.stloc + opCodes.br + opCodes.nop + opCodes.ldloc + opCodes.ldc_i4 + opCodes.ceq + opCodes.brfalse
) ||
validateNetByteCode( // samples by: Smart Assembly
opCodes.ldc_i4 + opCodes.br + opCodes.ldloc_s + opCodes.ldc_i4_s + opCodes.ldc_i4_0 + opCodes.stelem_i1 +
opCodes.ldc_i4 + opCodes.br
) ||
validateNetByteCode( // samples by: ConfuserEx (Beds mod)
opCodes.ldc_i4 + opCodes.ldc_i4 + opCodes._unknown + opCodes.ldc_i4 + opCodes._unknown + opCodes.stloc_0 + opCodes.nop + opCodes.ldloc_0 +
opCodes.ldc_i4 + opCodes.ldc_i4 + opCodes._unknown + opCodes.ldc_i4 + opCodes._unknown + opCodes.ceq + opCodes.brfalse_s
) ||
validateNetByteCode( // samples by: DotNetPatcher
opCodes.setStrict(opCodes.stloc_s, "05") + opCodes.nop + opCodes.ldloc_s + opCodes._unknown + opCodes.ceq + opCodes.brfalse_s + opCodes._unknown +
opCodes.setStrict(opCodes.stloc_s, "05") + opCodes.nop + opCodes.ldloc_s + opCodes._unknown + opCodes.ceq + opCodes.brfalse_s
) ||
validateNetByteCode( // samples by: VMProtect
opCodes.ldloc_0 + opCodes.setStrict(opCodes.ldc_i4, "?? ** ** **") + opCodes._unknown + opCodes.stloc_0 +
opCodes.ldloc_0 + opCodes.setStrict(opCodes.ldc_i4, "?? ** ** **") + opCodes.xor + opCodes.stloc_0
) ||
validateNetByteCode( // samples by: VMProtect
opCodes.setStrict(opCodes.ldc_i4, "?? ** ** **") + opCodes._unknown + opCodes.stloc_0 + opCodes.setStrict(opCodes.ldftn, "** ?? ?? ??")
)
) {
log(logType.net, "Control flow obfuscation detected! Offset: " + lastOffsetDetected);
isCtrlFlowPresent = true;
}
if (isCtrlFlowPresent) options += (options.length != 0 ? " + " : String()) + "Ctrl flow";
const afterCtorOffset = PE.findSignature(PE.getDosStubOffset() + PE.getDosStubSize(), PE.getSize() - PE.getOverlaySize(), "'<Module>'00**") + 8;
// Indicates that the file uses short object names. Typically this indicates the presence of an obfuscation
// There are two ways to detect short names - find one-letter objects or just use signature mask at Ctor offset :D
var isShortNamesPresent = false;
if (PE.compare("00**00**00", afterCtorOffset) ||
PE.compare("00****00****00****00", afterCtorOffset) ||
PE.compare("00******00******00******00", afterCtorOffset) ||
PE.compare("00********00********00********00", afterCtorOffset) ||
PE.compare("00****00****00", afterCtorOffset) ||
PE.compare("00****00**00", afterCtorOffset) ||
PE.compare("00**00****00", afterCtorOffset)) {
log(logType.net, "Short names detected! (mask)");
isShortNamesPresent = true;
}
if (!isShortNamesPresent && PE.compare("00**00", afterCtorOffset)) { // second way :D
var shortNamesFound = 0;
const chars = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm";
for (var i = 1; i < chars.length && !isShortNamesPresent; i++) {
if (PE.isNetObjectPresent(chars[i])) {
shortNamesFound++;
log(logType.net, "Short name found: '" + chars[i] + "' (" + shortNamesFound + "/20)");
}
if (shortNamesFound === 20) {
isShortNamesPresent = true;
}
}
}
if (isShortNamesPresent) options += (options.length != 0 ? " + " : String()) + "Short names";
var badNamings = false;
var buffer = "";
// get next 0x12c bytes after <Module> .ctor
for (var i = 0; i < 0x12c; i++) {
var currentByte = PE.readByte(afterCtorOffset + i).toString(16);
if (currentByte === '0') currentByte += '0';
buffer += currentByte;
buffer += ' ';
}
var bufferString = String();
// 0x00 to [0x20, 0x20, 0x20]
const bufferArray = replaceAllInString(buffer, '00 ', '20 20 20 ').split(' ');
// buffer to a string
for (var i = 0; i < bufferArray.length; i++)
bufferString += String.fromCharCode(parseInt(bufferArray[i], 16));
const patternsToExplore = bufferString.split(" ");
var strangePatternsCounter = 0;
for (var i = 0; i < patternsToExplore.length && !badNamings; i++) {
const currentStringPattern = patternsToExplore[i];
if (currentStringPattern.indexOf("<") === -1 && currentStringPattern.match(/^(?=\d|[a-z])(?=.*[a-z]\d[a-z])(?=(?:.*\d){4,})/i))
strangePatternsCounter++;
if (strangePatternsCounter > 4)
badNamings = true;
}
if (badNamings) options += (options.length != 0 ? " + " : String()) + "Bad namings";
// AntiTamper protects the file from modification
var isAntiTamperPresent = false;
if (
validateNetUnicodeString(" is tampered.") || // samples by: .NET Reactor
validateNetUnicodeString("ping 127.0.0.1 > nul") || // samples by: ConfuserEx (Trinity, SkiDzEx like)
validateNetUnicodeString("/C ping 1.1.1.1 -n 1 -w 3000 > Nul & Del \"") || // samples by: MindLated
validateNetUnicodeString( // samples by: ConfuserEx
opCodes.ldloc_s + opCodes.ldc_i4_0 + opCodes.ldloc_s + opCodes.ldc_i4_0 + opCodes.ldelem_u4 + opCodes.ldloc_s + opCodes.ldc_i4_0 + opCodes.ldelem_u4 + opCodes._unknown + opCodes.stelem_i4 +
opCodes.ldloc_s + opCodes.ldc_i4_1 + opCodes.ldloc_s + opCodes.ldc_i4_1 + opCodes.ldelem_u4 + opCodes.ldloc_s + opCodes.ldc_i4_1 + opCodes.ldelem_u4 + opCodes._unknown + opCodes.stelem_i4 +
opCodes.ldloc_s + opCodes.ldc_i4_2 + opCodes.ldloc_s + opCodes.ldc_i4_2 + opCodes.ldelem_u4 + opCodes.ldloc_s + opCodes.ldc_i4_2 + opCodes.ldelem_u4 + opCodes._unknown + opCodes.stelem_i4 +
opCodes.ldloc_s + opCodes.ldc_i4_3 + opCodes.ldloc_s + opCodes.ldc_i4_3 + opCodes.ldelem_u4 + opCodes.ldloc_s + opCodes.ldc_i4_3 + opCodes.ldelem_u4 + opCodes._unknown + opCodes.stelem_i4 +
opCodes.ldloc_s + opCodes.ldc_i4_4 + opCodes.ldloc_s + opCodes.ldc_i4_4 + opCodes.ldelem_u4 + opCodes.ldloc_s + opCodes.ldc_i4_4 + opCodes.ldelem_u4 + opCodes._unknown + opCodes.stelem_i4
) ||
validateNetByteCode( // samples: ConfuserEx (Beds mod, private)
opCodes.ldloc_s + opCodes._unknown + opCodes.shr_un + opCodes.ldloc_s + opCodes.ldc_i4_s + opCodes.shl + opCodes.or + opCodes.stloc_s +
opCodes.ldloc_s + opCodes._unknown + opCodes.shr_un + opCodes.ldloc_s + opCodes.ldc_i4_s + opCodes.shl + opCodes.or + opCodes.stloc_s +
opCodes.ldloc_s + opCodes._unknown + opCodes.shr_un + opCodes.ldloc_s + opCodes.ldc_i4_s + opCodes.shl + opCodes.or + opCodes.stloc_s
)
) {
log(logType.net, "Anti-tamper detected!");
isAntiTamperPresent = true;
}
if (isAntiTamperPresent) options += (options.length != 0 ? " + " : String()) + "Anti-tamper";
// If in the assembly you can find a second object starting with “<Module>”, then this is a fakeee!
var isModuleCtorMultiple = false;
var currentCtorOffset = PE.findSignature(PE.getDosStubOffset() + PE.getDosStubSize(), PE.getSize() - PE.getOverlaySize(), "00'<Module>'00");
if (currentCtorOffset !== -1) {
var secondCtorNameOffset = PE.findSignature(currentCtorOffset + 10, PE.getSize() - PE.getOverlaySize(), "'<Module>'");
if (secondCtorNameOffset !== -1 && PE.readByte(secondCtorNameOffset + 8) !== 0x00) {
log(logType.net, "Fake <Module> detected! Offset: 0x" + Number(secondCtorNameOffset).toString(16));
isModuleCtorMultiple = true;
}
}
if (isModuleCtorMultiple) options += (options.length != 0 ? " + " : String()) + "Fake .cctor name";
var isBadCctor = false;
if (currentCtorOffset === -1) {
isBadCctor = true;
}
if (isBadCctor) options += (options.length != 0 ? " + " : String()) + "Bad .cctor format";
// Detects the use of unusual mathematical expressions that would be simplified by the compiler. For example, an expression like "912874 + 39188124^834"
var isMutationsPresent = false;
const mathOpCodes = [
opCodes.add, opCodes.sub,
opCodes.mul, opCodes.div,
opCodes.xor, opCodes.shr,
opCodes.shl, opCodes.or,
opCodes.not, opCodes.and
];
const mathTemplates = [ // %s = math opcode
opCodes.ldc_i4 + opCodes.ldc_i4 + "%s" + opCodes.stloc, // samples by: .NET Reactor
opCodes.ldc_i4 + opCodes.ldc_i4 + "%s" + opCodes.ldc_i4 + opCodes.add, // samples by: ConfuserEx (Beds mod)
opCodes.ldloc_1 + opCodes.ldc_i4 + opCodes.ldc_i4 + "%s" + opCodes.ldc_i4 + opCodes.ldc_i4, // samples by: SkiDzEX
opCodes.ldloc + opCodes.ldc_i4 + opCodes.ldc_i4 + opCodes.ldc_i4 + "%s" + opCodes.stelem_i1, // samples by: .NET Reactor
opCodes.ldc_i4 + opCodes.ldc_i4 + "%s" + opCodes.br_s // samples by: [Unknown protector, only samples]
];
for (var y = 0; y < mathTemplates.length && !isMutationsPresent; y++) {
const template = mathTemplates[y];
for (var e = 0; e < mathOpCodes.length && !isMutationsPresent; e++) {
if (e == 0 && !validateNetByteCode(template.replace("%s", opCodes._unknown))) break; // No math mutations
const pattern = template.replace("%s", mathOpCodes[e]);
if (validateNetByteCode(pattern)) {
log(logType.net, "Math mutations detected! Offset: " + lastOffsetDetected);
isMutationsPresent = true;
}
}
}
if (isMutationsPresent) options += (options.length != 0 ? " + " : String()) + "Math mutations";
// VB NET apps with resources only
var isStringsEncryptionPresent = false;
if (isVbNet) {
if (PE.isNetObjectPresent("Resources") && !validateGlobalUnicodeString(".Resources")) {
isStringsEncryptionPresent = true;
}
}
if (isStringsEncryptionPresent) options += (options.length != 0 ? " + " : String()) + "Strings encryption";
// A type of obfuscation of numbers in which they are inverted several times from positive to negative and vice versa...
var isMathInversionsPresent = false;
if (validateNetByteCode(opCodes.ldc_i4 + opCodes.not) && (
validateNetByteCode( // ~(-(~(-(~(-(~(-( num ))))))))
opCodes.ldc_i4 +
opCodes.not + opCodes.neg + opCodes.not + opCodes.neg +
opCodes.not + opCodes.neg + opCodes.not + opCodes.neg
) ||
validateNetByteCode( // ~(~(-(-(~(~( num ))))))
opCodes.ldc_i4 +
opCodes.not + opCodes.not + opCodes.neg + opCodes.neg +
opCodes.not + opCodes.not
) ||
validateNetByteCode( // ~(-(~(~(-(-( num ))))))
opCodes.ldc_i4 +
opCodes.not + opCodes.neg + opCodes.not + opCodes.not +
opCodes.neg + opCodes.neg
) ||
validateNetByteCode( // ~(-(~(-(~(~( num ))))))
opCodes.ldc_i4 +
opCodes.not + opCodes.neg + opCodes.not + opCodes.neg +
opCodes.not + opCodes.not
) ||
validateNetByteCode( // ~(-(~(-(~(-( num ))))))
opCodes.ldc_i4 +
opCodes.not + opCodes.neg + opCodes.not + opCodes.neg +
opCodes.not + opCodes.neg
)
)) {
log(logType.net, "Math inversions detected, offset " + lastOffsetDetected);
isMathInversionsPresent = true;
}
if (isMathInversionsPresent) options += (options.length != 0 ? " + " : String()) + "Math inversions";
// A technique that allows you to avoid code decompilation. dnSpy gives a parsing error when trying to open such a file
var invalidOpCodes = false;
if (
/* validateNetByteCode( // samples by: SugarGuard
opCodes.setStrict(opCodes.box, "?? 00 00 01") + opCodes.ret
) || */
validateNetByteCode( // samples by: ConfuserEx (Beds mod)
opCodes.setStrict(opCodes.calli, "FF FF FF FF") + opCodes.setStrict(opCodes.sizeof, "FF FF FF FF")
)
) {
log(logType, "Invalid OpCodes detected, offset " + lastOffsetDetected);
invalidOpCodes = true;
}
if (invalidOpCodes) options += (options.length != 0 ? " + " : String()) + "Invalid OpCodes";
var isProtectionRuntimePresent = false;
var runtimeFound = String();
const protectionsRuntime = [ // Need more
{ lib: "AgileDotNet.VMRuntime.dll", name: "Agile" },
{ lib: "Xerin.Runtime.dll", name: "XerinFuscator" },
{ lib: "OneVM.Runtime.dll", name: "OneVM" },
{ lib: "HVMRuntm.dll", name: "DNGuard" }
];
for (var i = 0; i < protectionsRuntime.length; i++) {
const
runtimeInfo = protectionsRuntime[i],
runtimeLibraryName = runtimeInfo.lib,
protectorName = runtimeInfo.name;
if (PE.isNetObjectPresent(runtimeLibraryName) || // "runtime.dll"
PE.isNetObjectPresent(runtimeLibraryName.substring(0, runtimeLibraryName.length - 4))) { // "runtime"
isProtectionRuntimePresent = true;
runtimeFound = protectorName;
break;
}
}
if (isProtectionRuntimePresent) options += (options.length != 0 ? " + " : String()) + runtimeFound + " runtime";
const obfuscatorsAttributes = [
"Xenocode.Client.Attributes.AssemblyAttributes.ProcessedByXenocode",
"CryptoObfuscator.ProtectedWithCryptoObfuscatorAttribute",
"SecureTeam.Attributes.ObfuscatedByAgileDotNetAttribute",
"Xenocode.Client.Attributes.AssemblyAttributes",
"SmartAssembly.Attributes.PoweredByAttribute",
"ObfuscatedByAgileDotNetAttribute",
"NineRays.Obfuscator.Evaluation",
"ObfuscatedByCliSecureAttribute",
"BabelObfuscatorAttribute",
"AsStrongAsFuckAttribute",
"ProtectedByDotnetsafer",
"Macrobject.Obfuscator",
"DotfuscatorAttribute",
"CodeWallTrialVersion",
"ConfusedByAttribute",
"ObfuscatedByGoliath",
"NETSpider.Attribute",
"NineRays.Obfuscator",
"PoweredByAttribute", // Smart Assembly
"RustemSoft.Skater",
"BabelAttribute",
"MRuntime3.dll", // Maxtocode
"YanoAttribute",
"EMyPID_8234_",
"ZYXDNGuarder",
"SkiDzEX", // ConfuserEx based
"Sixxpack",
"____KILL", // CodeVeil
"Reactor", // Fake .NET Reactor
];
var isFakeSignaturesPresent = false;
var isWatermarkPresent = false;
var signaturesCounter = 0;
var obfuscatorAttributeFound = String();
// Iterate through obfuscators attributes
for (var t = 0; t < obfuscatorsAttributes.length && !isFakeSignaturesPresent; t++) {
if (validateNetObject(obfuscatorsAttributes[t])) {
obfuscatorAttributeFound = obfuscatorsAttributes[t];
signaturesCounter++;
}
// Check if the number of detected signatures exceeds 1
if (signaturesCounter > 1) {
// Set flag indicating the presence of fake signatures
isFakeSignaturesPresent = true;
}
}
if (isFakeSignaturesPresent) {
options += (options.length != 0 ? " + " : String()) + "Fake signatures";
} else {
// "Watermark" is only possible in the absence of fake signatures
if (signaturesCounter === 1) {
log(logType.nothing, "Watermark (Attribute) found: '" + obfuscatorAttributeFound + "'");
isWatermarkPresent = true;
}
if ((!isWatermarkPresent && (
validateSignature("'Obfuscated'") ||
validateSignature("'obfuscated'") ||
validateSignature("'ByAttribute'") ||
validateSignature("'ObfuscatorAttribute'") ||
validateNetObject("ObfuscationAttribute")
)) && !isFrameworkComponent()) // System.Reflection.ObfuscationAttribute
{
isWatermarkPresent = true;
}
}
if (isWatermarkPresent) options += (options.length != 0 ? " + " : String()) + "Watermark";
const protectorsLabelsToRemove = [ // Protectors with these names will be removed from results
"SafeNet Sentinel LDK .NET",
"Xenocode Postbuild",
"Smart Assembly",
"XerinFuscator",
"Dotfuscator",
"Babel .NET",
"Spices.Net",
"Maxtocode",
"FISH .NET",
"CliSecure",
"CodeWall",
"CodeVeil",
"Sixxpack",
"DNGuard",
"Goliath",
"Agile",
"Yano"
],
packersLabelsToRemove = [
"ChainskiCrypter",
"Quest PowerGUI",
"DataAnubis",
"NsPack",
"ASPack"
],
protectionsLabelsToRemove = [
"Sentinel SuperPro dongle reference",
"Unikey/Activator dongle reference",
"Eutron SmartKey dongle reference",
"SenseLock dongle reference",
"Hardlock dongle reference",
"WIBU Key dongle reference",
"Wizzkey dongle reference",
"SoftLok dongle reference",
"NetHASP dongle reference"
];
// Волки делают АУФ 🐺☝️
if (isFakeSignaturesPresent) {
for (var d = 0; d < protectorsLabelsToRemove.length; d++) {
_removeResult("protector", protectorsLabelsToRemove[d]);
}
for (var d = 0; d < packersLabelsToRemove.length; d++) {
_removeResult("cryptor", packersLabelsToRemove[d]);
_removeResult("packer", packersLabelsToRemove[d]);
}
for (var d = 0; d < protectionsLabelsToRemove.length; d++) {
_removeResult("protection", protectionsLabelsToRemove[d]);
}
}
if (options.length != 0) isDetected = true;
if (isDetected) {
_setResult("~protection", "Obfuscation", String(), PE.isVerbose() ? options : String());
}
}
function scanForAntiAnalysis_NET() {
var options = String();
// Assumes the file can detect debugging protection
var isAntiDebugPresent = false;
const debuggerObject = "Debugger", // MSIL: 'System.Diagnostics.Debugger' from System.Diagnostics.dll
isAttached = "get_IsAttached", // MSIL: '*.Debugger::get_IsAttached()'
isLogging = "IsLogging" // MSIL: '*.Debugger::IsLogging()'
if (
(( // .NET Functions
validateNetObject(debuggerObject) || validateNetUnicodeString(debuggerObject) // Check for 'Debugger'
) && (
(validateNetObject(isAttached) || validateNetUnicodeString(isAttached)) || // Check for 'get_IsAttached' property
(validateNetObject(isLogging) || validateNetUnicodeString(isLogging)) // Check for 'IsLogging' function
) ||