You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.4 KiB

  1. <?php
  2. require "config.php";
  3. if (!isset($_GET['getcwd'])) {
  4. header("Location: ./404.php");
  5. exit;
  6. } elseif (!is_dir($getcwd = trim($_GET['getcwd']))) {
  7. header("Location: ./404.php");
  8. exit;
  9. } elseif (!function_exists("shell_exec") && (!function_exists("proc_open") || !function_exists("stream_get_contents") || php_uname("s") != "Linux")) {
  10. xhtml_head("SHELL");
  11. echo "<div class=\"like\">\n";
  12. echo "<a href=\"./index.php?path=" . urlencode($getcwd) . "\"]>返回目录</a>错误提示\n";
  13. echo "</div>\n";
  14. echo "<div class=\"love\">\n";
  15. echo "您没有打开SHELL权限!";
  16. echo "</div>\n";
  17. xhtml_footer();
  18. exit;
  19. }
  20. chdir($getcwd);
  21. xhtml_head("SHELL");
  22. echo "<div class=\"like\">\n";
  23. echo "<a href=\"./index.php?path=" . urlencode($getcwd) . "\">返回目录</a>SHELL\n";
  24. echo "</div>\n";
  25. echo "<div class=\"love\">\n";
  26. echo "<form action=\"?getcwd=" . urlencode($getcwd) . "\" method=\"POST\">\n";
  27. echo "<input type=\"submit\" value=\"执行命令\" />\n";
  28. echo "<input type=\"reset\" value=\"重置终端\" />\n<br />\n";
  29. echo "<textarea name=\"shell\" style=\"width:99%;height:100px;\"></textarea>\n<br/>\n";
  30. echo "</form>\n";
  31. echo "</div>\n";
  32. if (isset($_POST['shell'])) if (($s = trim($_POST['shell'])) != "") {
  33. echo "<div class=\"like\">\n结果返回SHELL\n</div>\n";
  34. echo "<div class=\"love\">\n";
  35. if (function_exists("proc_open") && function_exists("stream_get_contents") && php_uname("s") == "Linux") {
  36. if (!($sh = proc_open("sh", array(0 => array("pipe", "r"), 1 => array("pipe", "w")), $pipes))) {
  37. echo "Open Shell Error !";
  38. } else {
  39. $i = 0;
  40. $shell = explode("\n", $s);
  41. while ($i < count($shell)) {
  42. $x = trim($shell[$i]);
  43. fwrite($pipes[0], "$x\n");
  44. $i++;
  45. }
  46. fclose($pipes[0]);
  47. $stream = stream_get_contents($pipes[1]);
  48. if ($stream != "") {
  49. echo "<pre>" . nl2br(___codepre(trim($stream))) . "</pre>";
  50. } else {
  51. echo "NULL";
  52. }
  53. fclose($pipes[1]);
  54. proc_close($sh);
  55. }
  56. } else {
  57. $i = 0;
  58. $shell = explode("\n", $s);
  59. while ($i < count($shell)) {
  60. $sh = trim($shell[$i]);
  61. echo "shell#&ensp;$sh<br />\n";
  62. echo nl2br(___codepre(shell_exec($sh))) . "\n";
  63. $i++;
  64. }
  65. }
  66. echo "</div>\n";
  67. }
  68. xhtml_footer();
  69. ?>