-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
2737 lines (2559 loc) · 90.8 KB
/
test.js
File metadata and controls
2737 lines (2559 loc) · 90.8 KB
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
function getAllPrototypeMethods(obj) {
let props = [];
let currentObj = obj;
do {
props = props.concat(Object.getOwnPropertyNames(currentObj));
} while ((currentObj = Object.getPrototypeOf(currentObj)));
return props.sort().filter(function(e, i, arr) {
if (e!=arr[i+1] && typeof obj[e] == 'function') return true;
});
}
//await jevalx(`getAllPrototypeMethods(this)`,{getAllPrototypeMethods})
//process.on('unhandledRejection', (reason, promise) => { console.error('!!!! =======> unhandledRejection', promise, 'reason:', reason); });
//process.on('uncaughtException', (reason, tag) => { console.error('???? ========> test.js uncaughtException', reason); });
var argv2o=(a,m)=>(a||require('process').argv||[]).reduce((r,e)=>((m=e.match(/^(\/|--?)([\w-]*)="?(.*)"?$/))&&(r[m[2]]=m[3]),r),{});
let assert = require('assert');
//console.log('fetch+'+fetch);
//let argo = argv2o();
var argo;
var jevalxModule;
var jevalx,jevalx_raw;
const fs = require('fs').promises;
const path = require('path');
async function searchFiles(directory, pattern) {
try {
const files = await fs.readdir(directory, { withFileTypes: true });
const foundFiles = files.filter(file => file.isFile() && pattern.test(file.name));
if (foundFiles.length > 0) {
throw new Error(`Found files matching pattern "${pattern}": ${foundFiles.map(f => f.name).join(', ')}`);
} else {
console.log('No files found matching the pattern.'+pattern);
}
} catch (error) {
console.error('Error searching files:', error);
throw error; // Rethrow the error if necessary
}
}
module.exports = {
AAAA:async function(){ let case_id = arguments.callee.name;
let code = `
async function f() {}
void (async () => {
await f();
await f();
await f();
await f();
try{
import('').catch(_=>_).constructor.constructor('return process')().mainModule.require("fs").writeFileSync("pwned_AAAA_1","");
}catch(ex){
//console.error('AAAA catch ex',ex);
}
throw {message: 'EvilXd_AAAA', code: class{
static get name() {
(async()=>{
await Promise.resolve();
import('').catch(_=>_).constructor.constructor('return process')().mainModule.require("fs").writeFileSync("pwned_AAAA","");
})();
}
}}
this.constructor
.constructor("return process")()
.mainModule.require("fs")
.writeFileSync("pwned_case_a", "");
})();
`;
try{
var rst = await jevalx(code);
console.log(`${case_id} result=`,rst);
}catch(ex){ console.log(`${case_id}.ex=`,ex); } console.log(`${case_id}.check=`,typeof(process),typeof(Promise));
},
A2:async function(){ let case_id = arguments.callee.name;
let code = `
async function f() {}
void (async () => {
await f();
await f();
await f();
await f();
throw {message: 'EvilXd_A2', code: class{
static get name() {
(async()=>{
await Promise.resolve();
import('').catch(_=>_).constructor.constructor('return process')().mainModule.require("fs").writeFileSync("pwned_a2","");
})();
}
}}
})();
`;
try{
var rst = await jevalx(code);
console.log(`${case_id} result=`,rst);
}catch(ex){ console.log(`${case_id}.ex=`,ex); } console.log(`${case_id}.check=`,typeof(process),typeof(Promise));
},
BBBB:async()=>{
////https://gist.github.com/leesh3288/e4aa7b90417b0b0ac7bcd5b09ac7d3bd
var code=`
const Symbol= Object.getOwnPropertySymbols(Array)[0].constructor;
const customInspectSymbol = Symbol.for({
toString: () => "nodejs.util.inspect.custom",
});
throw {
[customInspectSymbol]: () => {
this.constructor
.constructor("return process")()
.mainModule.require("fs")
.writeFileSync("pwned_case_b", "");
},
}
`;
try{
console.log('BBBB result=',await jevalx(code));
}catch(ex){
console.log('BBBB ex=',ex);
}
console.log('BBBB check=',typeof(process),typeof(Promise));
},
BBB2:async()=>{
var case_id='BBB2';
var code=`
const customInspectSymbol = Symbol.for({
toString: () => "nodejs.util.inspect.custom",
});
throw {
[customInspectSymbol]: () => {
this.constructor
.constructor("return process")()
.mainModule.require("fs")
.writeFileSync("pwned_case_b2", "");
},
}
`;
try{
console.log('BBB2 result=',await jevalx(code));
}catch(ex){
console.log('BBB2 ex=',ex.message);
}
console.log('BBB2 check=',typeof(process),typeof(Promise));
},
CCCC:async()=>{
var code=`
Object.defineProperty(this.constructor.constructor("return this")(),"process",{set(process) { process.mainModule.require("fs").writeFileSync("pwned_case_c", ""+(typeof this)+this)}})
`
try{
console.log('CCCC result=',await jevalx(code));
}catch(ex){
console.log('CCCC ex=',ex.message);
}
console.log('CCCC check=',typeof(process),typeof(Promise));
},
DDDD:async()=>{
var code=`
throw {toString: eval.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_case_d', ''))")};
`
try{
console.log('DDDD result=',await jevalx(code));
}catch(ex){
console.log('DDDD ex=',ex);
}
console.log('DDDD check=',typeof(process),typeof(Promise));
},
EEEE:async()=>{
var code=`
const code = "import('fs').then(m=>m.writeFileSync('pwned_case_e', '')).then(o, r)";
const funcCtor = import('').catch(_=>_).constructor.constructor;
const func = funcCtor.bind(null, 'o', 'r', code);
const obj = {};
obj.__defineGetter__("then", func);
//void(async()=>{await obj})();//wont work too
obj
`
try{
console.log('EEEE result=',await jevalx(code));
}catch(ex){
console.log('EEEE ex=',ex.message);
}
console.log('EEEE check=',typeof(process),typeof(Promise));
},
FFFF:async function(){
let case_id = arguments.callee.name;
var code=`
({}).constructor.defineProperty(
this.constructor.constructor("return this")(),
"_process_or_any",{ set(process) { process.mainModule.require("fs").writeFileSync("pwned_case_f", ""); },
}
)
`;
try{
var rst = await jevalx(code);
console.log(`${case_id} result=`,rst);
}catch(ex){ console.log(`${case_id}.ex=`,ex); } console.log(`${case_id}.check=`,typeof(process),typeof(Promise));
},
GGGG:async()=>{
//var code=`[].constructor.constructor("return Proxy")()`;//anywhere the Proxy?
//var code=`let global_ = ({}).constructor.constructor("return this")();global_.Proxy`;
var code=`
new Proxy((_) => _, {
get: new Proxy((_) => _, {
apply: function (target, thisArg, args) {
args.constructor
.constructor("return process")()
?.mainModule.require("fs")
.writeFileSync("pwned_case_g", "");
},
}),
})`
try{
console.log('GGGG result=',await jevalx(code));
}catch(ex){
console.log('GGGG ex=',ex.message);
}
console.log('GGGG check=',typeof(process),typeof(Promise));
},
HHHH:async()=>{
var code=`
const hostGlobal = this.constructor.constructor("return this")();
hostGlobal.Promise = function (executor) {
return new Promise(executor).then(() => {
hostGlobal.process.mainModule.require("fs").writeFileSync("pwned_case_h", "");
});
}
`
try{
console.log('HHHH result=',await jevalx(code));
}catch(ex){
console.log('HHHH ex=',ex.message);
}
console.log('HHHH check=',typeof(process),typeof(Promise));
},
IIII:async()=>{
var code=`
const promise = import('').catch(_=>_);
const oldThen = promise.__proto__.then;
var global = oldThen.constructor('return this')();
promise.__proto__.then = function() {
if (global.process) {
global.process.mainModule.require("fs").writeFileSync("pwned_case_i", "");
promise.__proto__.then = oldThen;
}
return oldThen.apply(this, arguments);
};
1
`
try{
console.log('IIII result=',await jevalx(code));
}catch(ex){
console.log('IIII ex=',ex.message);
}
console.log('IIII check=',typeof(process),typeof(Promise));
},
X2:async()=>{
var code=`
const promise = import('').catch(_=>_);
const oldThen = promise.__proto__.then;
const global = oldThen.constructor('return this')();
promise.__proto__.then = function() {
if (global.process) {
global.process.mainModule.require("fs").writeFileSync("pwned_i2", "");
promise.__proto__.then = oldThen;
}
return oldThen.apply(this, arguments);
};
false
`
try{
console.log('I2 result=',await jevalx(code));
}catch(ex){
console.log('I2 ex=',ex.message);
}
console.log('I2 check=',typeof(process),typeof(Promise));
},
JJJJ:async()=>{
var code=` eval.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_case_j', ''))") `
try{
console.log('JJJJ result=',await jevalx(code));
}catch(ex){
console.log('JJJJ ex=',ex.message);
}
console.log('JJJJ check=',typeof(process),typeof(Promise));
},
J2:async()=>{
var code=`(_=>_).constructor.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_case_j2', ''))")`;
try{
console.log('J2 result=',await jevalx(code));
}catch(ex){
console.log('J2 ex=',ex.message);
}
console.log('J2 check=',typeof(process),typeof(Promise));
},
KKKK:async()=>{
var code=`
Reflect.defineProperty(Function.prototype, 'then', {
get() {
this();
}
});
`
try{
console.log('KKKK result=',await jevalx(code));
}catch(ex){
console.log('KKKK ex=',ex.message);
}
console.log('KKKK check=',typeof(process),typeof(Promise));
},
K2:async()=>{
var code=`
Reflect.defineProperty(constructor.prototype, 'cachedData', {get(){this.importModuleDynamically.constructor('return process')().then(p=>p.mainModule.require("fs").writeFileSync("pwned_k2", ""))}})
`
try{
console.log('K2 result=',await jevalx(code));
}catch(ex){
console.log('K2 ex=',ex.message);
}
console.log('K2 check=',typeof(process),typeof(Promise));
},
LLLL:async()=>{
var code=`
Function.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_case_L', ''))")
`
try{
console.log('LLLL result=',await jevalx(code));
}catch(ex){
console.log('LLLL ex=',ex);
}
console.log('LLLL check=',typeof(process),typeof(Promise));
},
L2:async()=>{
var code=`
(async()=>0).bind(null, "import('fs').then(m=>m.writeFileSync('pwned_case_L2', ''))")
`
try{
console.log('L2.result=',await jevalx(code));
}catch(ex){
console.log('L2.ex=',ex.message);
}
console.log('L2.check=',typeof(process),typeof(Promise));
},
MMMM:async()=>{
var code=`
const FunctionX = (_=>_).constructor;
Object.defineProperty(Function.prototype, 'then', { get() { this(); } });
FunctionX.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_case_m', ''))")
`
try{
console.log('MMMM result=',await jevalx(code));
}catch(ex){
console.log('MMMM ex=',ex.message);
}
console.log('MMMM check=',typeof(process),typeof(Promise));
},
NNNN:async()=>{
var code=`
this.__proto__.__defineGetter__('',function(){ this.process?.mainModule.require("fs").writeFileSync("pwned_case_n","") })
`
try{
console.log('NNNN result=',await jevalx(code));
}catch(ex){
console.log('NNNN ex=',ex.message);
}
console.log('NNNN check=',typeof(process),typeof(Promise));
},
OOOO:async()=>{
var code=`
const FunctionX = (_=>_).constructor;
const obj = {
get then() {
Object.defineProperty(this, 'then', {
get: FunctionX.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_case_N', ''))")
});
Object.setPrototypeOf(this, import('').catch(_=>_).constructor);
}
};
obj
`
try{
console.log('OOOO result=',await jevalx(code));
}catch(ex){
console.log('OOOO ex=',ex.message);
}
console.log('OOOO check=',typeof(process),typeof(Promise));
},
PPPP:async()=>{
var code=`
this.constructor.prototype.__defineGetter__('',function(){ this.process?.mainModule.require("fs").writeFileSync("pwned_case_O","") })
`;
try{
console.log('PPPP result=',await jevalx(code));
}catch(ex){
console.log('PPPP ex=',ex.message);
}
console.log('PPPP check=',typeof(process),typeof(Promise));
},
Q1:async()=>{
var code=`
Object.getPrototypeOf(Object.getPrototypeOf(import('').catch(_=>_))).__defineGetter__('',function(){ this.process?.mainModule.require("fs").writeFileSync("pwned_case_q1","") })
`;
try{
console.log('Q1 result=',await jevalx(code));
}catch(ex){
console.log('Q1 ex=',ex.message);
}
console.log('Q1 check=',typeof(process),typeof(Promise));
},
Q2:async()=>{
var code=`
const FunctionX = (_=>_).constructor;
const proto = {};
Object.defineProperty(proto, 'then', {
get: FunctionX.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_case_q2', ''))")
});
const obj = {
__proto__: proto
};
obj
`;
try{
console.log('Q2 result=',await jevalx(code));
}catch(ex){
console.log('Q2 ex=',ex.message);
}
console.log('Q2 check=',typeof(process),typeof(Promise));
},
Q3:async()=>{
var code=`
const FunctionX = (_=>_).constructor;
const proto = {};
proto.__defineGetter__('then', FunctionX.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_case_q3', ''))"));
const obj = {
__proto__: proto
};
obj
`
try{
console.log('Q3 result=',await jevalx(code));
}catch(ex){
console.log('Q3 ex=',ex.message);
}
console.log('Q3 check=',typeof(process),typeof(Promise));
},
Q4:async()=>{
var code=`
const FunctionX = (_=>_).constructor;
const proto = {};
Object.defineProperties(proto, {then: {get: FunctionX.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_case_q4', ''))")}});
const obj = {
__proto__: proto
};
obj
`
try{
console.log('Q4 result=',await jevalx(code));
}catch(ex){
console.log('Q4 ex=',ex.message);
}
console.log('Q4 check=',typeof(process),typeof(Promise));
},
Q5:async()=>{
var code=`
let u = false;
function t(o, e) {
import('').then(_=>_, _=>_).then.constructor('return process')()?.mainModule.require("fs").writeFileSync("pwned_case_q5","");
u = true;
o(this);
}
const obj = {__proto__: {
get then(){
if (u) {
u = false;
return undefined;
}
return t;
}
}};
obj
`;
try{
console.log('Q5 result=',await jevalx(code));
}catch(ex){
console.log('Q5 ex=',ex.message);
}
console.log('Q5 check=',typeof(process),typeof(Promise));
},
Q6:async()=>{
var code=`
(()=>{
let u = false;
function t(o, e) {
import('').then(_=>_, _=>_).then.constructor('return process')()?.mainModule.require("fs").writeFileSync("pwned_case_q6","");
u = true;
o(this);
}
const obj = {__proto__: { get then(){ if (u) { u = false; return undefined; } return t; } }};
return obj
})
`
try{
console.log('Q6 result=',await jevalx(code));
}catch(ex){
console.log('Q6 ex=',ex.message);
}
console.log('Q6 check=',typeof(process),typeof(Promise));
},
Q7:async()=>{
var code=`
(async()=>{
let u = false;
function t(o, e) {
import('').then(_=>_, _=>_).then.constructor('return process')()?.mainModule.require("fs").writeFileSync("pwned_case_q7","");
u = true;
o(this);
}
const obj = {__proto__: { get then(){ if (u) { u = false; return undefined; } return t; } }};
return obj
})
`
try{
console.log('Q7 result=',await jevalx(code));
}catch(ex){
console.log('Q7 ex=',ex.message);
}
console.log('Q7 check=',typeof(process),typeof(Promise));
},
Q7a:async()=>{
var code=`(async()=>{
let u = false;
function t(o, e) {
import('').then(_=>{ return _; }, _=>{ return _}).then.constructor('return process')()?.mainModule.require("fs").writeFileSync("pwned_case_q7a","");
u = true;
o(this);
}
const obj = {__proto__: { get then(){
if (u) { u = false; return undefined; } return t; } }};
return obj
})
`
try{
console.log('Q7 result=',await jevalx(code,));
}catch(ex){
console.log('Q7 ex=',ex);
}
console.log('Q7 check=',typeof(process),typeof(Promise));
},
Q7x:async()=>{
//return;//TODO
//await jevalx(`(async()=>{ return ({ then:()=>{} }) })() `)
//var code=`(async()=>{ return ({ then:()=>{} }) })() `
var code=`(async()=>({ then:()=>{} }))() `
//var code=`(async()=>999)()`
try{
console.log('Q7x result=',await jevalx(code));
}catch(ex){
console.log('Q7x ex=',ex);
}
console.log('Q7x check=',typeof(process),typeof(Promise));
},
Q7x2:async()=>{
var code=`(async()=>({ then:()=>{} }))() `
try{
console.log('Q7x2 result=',await jevalx(code,{},{microtaskMode:'false'}));
}catch(ex){
console.log('Q7x2 ex=',ex);
}
console.log('Q7x2 check=',typeof(process),typeof(Promise));
},
Q8:(async()=>{
var code=`
let u = false;
function t(o, e) {
import('').then(_=>_, _=>_).then.constructor('return process')()?.mainModule.require("fs").writeFileSync("pwned_case_q8","");
u = true;
o(this);
}
delete Object.prototype.__proto__;
(async()=>{
const obj = { __proto__: { get then(){ if (u) { u = false; return undefined; } return t; } }};
return obj
})
`
try{
console.log('Q8 result=',await jevalx(code));
}catch(ex){
console.log('Q8 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q8 check=',typeof(process),typeof(Promise));
}),
Q9:(async()=>{
var code=`
let delay = 3;
function t(o, e) {
//import('').then(_=>_, _=>_).then.constructor('return process')()?.mainModule.require("fs").writeFileSync("pwned_case_q9","");
import('').then(_=>_,_=>_).then.constructor("return 999")();
o(this);
}
const obj = {__proto__: { __proto__: { __proto__: {
get then(){
if (delay-->0) return undefined;
return t;
}
}}}};
obj
`
try{
console.log('Q9 result=',await jevalx(code));
}catch(ex){
console.log('Q9 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q9 check=',typeof(process),typeof(Promise));
}),
Q10:(async()=>{
var code=`
let delay = 2;
function t(o, e) {
import('').then(_=>_, _=>_).then.constructor('return process')()?.mainModule.require("fs").writeFileSync("pwned_case_q10","");
o(this);
}
let obj = {__proto__: {
get then(){
if (delay-->0) return undefined;
return t;
}
}};
for(let i=0; i<9; i++) {const ret=obj;obj=()=>ret;}
obj
`
try{
console.log('Q10 result=',await jevalx(code));
}catch(ex){
console.log('Q10 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q10 check=',typeof(process),typeof(Promise));
}),
Q11:(async()=>{
var code=`
const O = constructor;
O.defineProperty(O.prototype, 'XXX', {get(){
this.process.mainModule.require("fs").writeFileSync("pwned_case_q11", "");
}, enumerable: true});
false
`
try{
console.log('Q11 result=',await jevalx(code));
}catch(ex){
console.log('Q11 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q11 check=',typeof(process),typeof(Promise));
}),
Q12:(async()=>{
var code=`
const promise = import('').catch(_=>_);
const oldThen = promise.__proto__.then;
const global = oldThen.constructor('return this')();
promise.__proto__.then = function() {
if (global.process) {
global.process.mainModule.require("fs").writeFileSync("pwned_case_q12", "");
}
return oldThen.apply(this, arguments);
};
Object.freeze(promise.__proto__);
false
`
try{
console.log('Q12 result=',await jevalx(code));
}catch(ex){
console.log('Q12 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q12 check=',typeof(process),typeof(Promise));
}),
Q13:(async()=>{
var code=`
this.constructor.__defineSetter__('freeze', f=>f.constructor('return process')().mainModule.require("fs").writeFileSync("pwned_q13", ""));
false
`
try{
console.log('Q13 result=',await jevalx(code));
}catch(ex){
console.log('Q13 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q13 check=',typeof(process),typeof(Promise));
}),
Q14:(async()=>{
var code=`
const global = constructor.constructor('return this')()
global.Object = Object.assign({set freeze(f){f.constructor('return process')().mainModule.require("fs").writeFileSync("pwned_q14", "")}}, global.Object);
false
`
try{
console.log('Q14 result=',await jevalx(code));
}catch(ex){
console.log('Q14 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q14 check=',typeof(process),typeof(Promise));
}),
Q15:(async()=>{
var code=`
({then: 1, toString: eval.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_q15', ''))")})
`
try{
var rst = await jevalx(code);
console.log('Q15 result=',rst);
String(rst);//test trigger...
}catch(ex){
console.log('Q15 ex=',ex);
}
console.log('Q15 check=',typeof(process),typeof(Promise));
}),
Q16:(async()=>{
// { toString: [Function: bound evil] }
var code=`
({then:(r,j)=>r({toString:eval.bind(null,"import('fs').then(m=>m.writeFileSync('pwned_q16', ''))")})})
`
try{
console.log('Q16 result=',await jevalx(code));//trigger pwn !!!
//console.log('Q16 result=',String(await jevalx(code)));//trigger pwn !!!
//console.log('Q16 result=',await jevalx(code));
}catch(ex){
console.log('Q16 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q16 check=',typeof(process),typeof(Promise));
}),
Q17:(async()=>{
var code=`
//const Function = (_=>_).constructor;
({then:(r,j)=>r({toString:Function.bind(null,"import('fs').then(m=>m.writeFileSync('pwned_q17', ''))")})})
`
try{
//console.log('Q17 result=',await jevalx(code));
console.log('Q17 result=',String(await jevalx(code)));
}catch(ex){
console.log('Q17 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q17 check=',typeof(process),typeof(Promise));
}),
Q18:(async()=>{
var code=`
const global = constructor.constructor('return this')()
global.Object = {set freeze(f){f.constructor('return process')().mainModule.require("fs").writeFileSync("pwned_q18", "")}};
false
`
try{
console.log('Q18 result=',String(await jevalx(code)));
}catch(ex){
console.log('Q18 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q18 check=',typeof(process),typeof(Promise));
}),
Q19:(async()=>{
var code=`
({hasOwnProperty: eval.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_q19', ''))")})
`
try{
console.log('Q19 result=',await jevalx(code));
}catch(ex){
console.log('Q19 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q19 check=',typeof(process),typeof(Promise));
}),
Q20:(async()=>{
var code=`
const global = constructor.constructor('return this')()
global.Array = {set freeze(f){f.constructor('return process')().mainModule.require("fs").writeFileSync("pwned_q20", "")}};
[1,2,3,]
`
try{
console.log('Q20 result=',await jevalx(code));
}catch(ex){
console.log('Q20 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q20 check=',typeof(process),typeof(Promise));
}),
Q21:(async()=>{
var code=`
hasOwnProperty.bind = eval.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_q21', ''))");
true
`;
try{
console.log('Q21 result=',await jevalx(code));
}catch(ex){
console.log('Q21 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q21 check=',typeof(process),typeof(Promise));
}),
Q22:(async()=>{
//({}).constructor.keys(0).__proto__.push = eval.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_q22', ''))");
var code=`
constructor.keys(0).__proto__.push = eval.bind(null, "import('fs').then(m=>m.writeFileSync('pwned_q22', ''))");
({toString:1})
`;
try{
console.log('Q22 result=',await jevalx(code));
}catch(ex){
console.log('Q22 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q22 check=',typeof(process),typeof(Promise));
}),
Q23:(async()=>{
var code=`
constructor.prototype.__defineGetter__('cachedData', function(){this.importModuleDynamically.constructor('return process')().then(p=>p.mainModule.require("fs").writeFileSync("pwned_q22", ""))});
(_=>_)
`;
try{
console.log('Q23 result=',await jevalx(code));
}catch(ex){
console.log('Q23 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q23 check=',typeof(process),typeof(Promise));
}),
Q24:(async()=>{
var code=`
Object.defineProperty(constructor.prototype, 'cachedData', {get(){this.importModuleDynamically.constructor('return process')().then(p=>p.mainModule.require("fs").writeFileSync("pwned_q24", ""))}});
(_=>_)
`;
try{
console.log('Q24 result=',await jevalx(code));
}catch(ex){
console.log('Q24 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q24 check=',typeof(process),typeof(Promise));
}),
Q25:(async()=>{
var code=`
constructor.defineProperty(constructor.prototype, 'cachedData', {get(){this.importModuleDynamically.constructor('return process')().then(p=>p.mainModule.require("fs").writeFileSync("pwned_q25", ""))}});
(_=>_)
`;
try{
console.log('Q25 result=',await jevalx(code));
}catch(ex){
console.log('Q25 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q25 check=',typeof(process),typeof(Promise));
}),
Q26:(async()=>{
var code=`
async function f(){
throw {toString: [].reduce.bind([1,2], Function.call.bind(Function.call), Function.apply.bind(Function, null, ["import('fs').then(m=>m.writeFileSync('pwned_q26', ''))"]))};
}
f()
f()
`
try{
console.log('Q26 result=',await jevalx(code));
}catch(ex){
console.log('Q26 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q26 check=',typeof(process),typeof(Promise));
}),
Q27:(async()=>{
var code=`
const Function = (_=>_).constructor;
async function f(){
throw {toString: [].reduce.bind([1,2], Function.call.bind(Function.call), Function.apply.bind(Function, null, ["import('fs').then(m=>m.writeFileSync('pwned_q26', ''))"]))};
}
f()
f()
`
try{
console.log('Q27 result=',await jevalx(code));
}catch(ex){
console.log('Q27 ex=',ex,JSON.stringify(ex.js));
}
console.log('Q27 check=',typeof(process),typeof(Promise));
}),
Q28:(async()=>{
var code=`
const Function = (_=>_).constructor;
const a = constructor.prototype.__proto__.constructor.keys(0);
const s = Object.getOwnPropertySymbols(a.__proto__)[0];
const i = a[s]().__proto__;
const n = i.next;
i.next = [].reduce.bind([1,2], Function.call.bind(Function.call), Function.apply.bind(Function, null, ["import('fs').then(m=>m.writeFileSync('pwned_q28', '')); return n.call(a[s]());"]));
`;
try{
console.log('Q28 result=',await jevalx(code));
}catch(ex){
console.log('Q28 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q28 check=',typeof(process),typeof(Promise));
}),
Q29:(async()=>{
var code=`
const Function = (_=>_).constructor;
const Object = {}.constructor;
const a = constructor.prototype.__proto__.constructor.keys(0);
const s = Object.getOwnPropertySymbols(a.__proto__)[0];
const i = a[s]().__proto__;
const n = i.next;
i.next = [].reduce.bind([1,2], Function.call.bind(Function.call), Function.apply.bind(Function, null, ["import('fs').then(m=>m.writeFileSync('pwned_q29', '')); return n.call(a[s]());"]));
`;
try{
console.log('Q29 result=',await jevalx(code));
}catch(ex){
console.log('Q29 ex=',ex.message,JSON.stringify(ex.js));
}
console.log('Q29 check=',typeof(process),typeof(Promise));
}),
Q30:(async()=>{
var code=`
const Function = (async _=>_).constructor;
const Object = import('').catch(_=>_).__proto__.__proto__.constructor;
const a = constructor.prototype.__proto__.constructor.keys(0);
const s = Object.getOwnPropertySymbols(a.__proto__)[0];
const i = a[s]().__proto__;
const n = i.next;
i.next = [].reduce.bind([1,2], Function.call.bind(Function.call), Function.apply.bind(Function, null, ["import('fs').then(m=>m.writeFileSync('pwned_q30', '')); return n.call(a[s]());"]));
`
try{
console.log('Q30 result=',await jevalx(code));