public ActionResult <InstallUtilLauncher> PutInstallUtilLauncher([FromBody] InstallUtilLauncher installutilLauncher) { InstallUtilLauncher launcher = (InstallUtilLauncher)_context.Launchers.FirstOrDefault(S => S.Type == Launcher.LauncherType.InstallUtil); if (launcher == null || launcher.Id != installutilLauncher.Id) { return(NotFound()); } Listener listener = _context.Listeners.FirstOrDefault(L => L.Id == installutilLauncher.ListenerId); if (listener != null) { launcher.ListenerId = installutilLauncher.ListenerId; } launcher.Delay = installutilLauncher.Delay; launcher.Jitter = installutilLauncher.Jitter; launcher.ConnectAttempts = installutilLauncher.ConnectAttempts; launcher.DotNetFrameworkVersion = installutilLauncher.DotNetFrameworkVersion; launcher.LauncherString = installutilLauncher.LauncherString; launcher.DiskCode = installutilLauncher.DiskCode; launcher.StagerCode = installutilLauncher.StagerCode; _context.Launchers.Update(launcher); _context.SaveChanges(); return(Ok(launcher)); }
public override void Refresh() { try { this.InstallUtilLauncher = this.CovenantClient.ApiLaunchersInstallutilGet(); this.AdditionalOptions.FirstOrDefault(AO => AO.Name == "Set").Parameters .FirstOrDefault(P => P.Name == "Option").Values .FirstOrDefault(V => V.Value == "ListenerName") .NextValueSuggestions = this.CovenantClient.ApiListenersGet() .Where(L => L.Status == ListenerStatus.Active) .Select(L => L.Name) .ToList(); var filevalues = new MenuCommandParameterValuesFromFilePath(Common.EliteDataFolder); this.AdditionalOptions.FirstOrDefault(AO => AO.Name == "Write").Parameters .FirstOrDefault().Values = filevalues; this.SetupMenuAutoComplete(); } catch (HttpOperationException e) { EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content); } }
public override void Command(MenuItem menuItem, string UserInput) { try { string[] commands = UserInput.Split(" "); if (commands.Length != 2 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase)) { menuItem.PrintInvalidOptionError(UserInput); return; } menuItem.Refresh(); InstallUtilLauncher launcher = ((InstallUtilLauncherMenuItem)menuItem).InstallUtilLauncher; if (launcher.LauncherString == "") { this.CovenantClient.ApiLaunchersBinaryPost(); menuItem.Refresh(); EliteConsole.PrintFormattedHighlightLine("Generated InstallUtilLauncher: " + launcher.LauncherString); } string OutputFilePath = Common.EliteDataFolder + String.Concat(commands[1].Split(System.IO.Path.GetInvalidFileNameChars())); System.IO.File.WriteAllBytes(OutputFilePath, Convert.FromBase64String(launcher.DiskCode)); EliteConsole.PrintFormattedHighlightLine("Wrote InstallUtilLauncher to: \"" + OutputFilePath + "\""); } catch (HttpOperationException e) { EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content); } }
public override void Command(MenuItem menuItem, string UserInput) { InstallUtilLauncherMenuItem installutilMenuItem = (InstallUtilLauncherMenuItem)menuItem; installutilMenuItem.installutilLauncher = this.CovenantClient.ApiLaunchersInstallutilGet(); InstallUtilLauncher launcher = installutilMenuItem.installutilLauncher; Listener listener = this.CovenantClient.ApiListenersGet().FirstOrDefault(L => L.Id == installutilMenuItem.installutilLauncher.ListenerId); EliteConsoleMenu menu = new EliteConsoleMenu(EliteConsoleMenu.EliteConsoleMenuType.Parameter, "InstallUtilLauncher"); menu.Rows.Add(new List <string> { "Name:", launcher.Name }); menu.Rows.Add(new List <string> { "Description:", launcher.Description }); menu.Rows.Add(new List <string> { "ListenerName:", listener == null ? "" : listener.Name }); menu.Rows.Add(new List <string> { "DotNetFramework:", launcher.DotNetFrameworkVersion.ToString() }); menu.Rows.Add(new List <string> { "Delay:", (launcher.Delay ?? default).ToString() });
public ActionResult <InstallUtilLauncher> GetInstallUtilLauncher() { InstallUtilLauncher launcher = (InstallUtilLauncher)_context.Launchers.FirstOrDefault(S => S.Type == Launcher.LauncherType.InstallUtil); if (launcher == null) { return(NotFound()); } return(Ok(launcher)); }
public override void Refresh() { this.installutilLauncher = this.CovenantClient.ApiLaunchersInstallutilGet(); this.AdditionalOptions.FirstOrDefault(AO => AO.Name.ToLower() == "set").Parameters .FirstOrDefault(P => P.Name.ToLower() == "option").Values .FirstOrDefault(V => V.Value.ToLower() == "listenername") .NextValueSuggestions = this.CovenantClient.ApiListenersGet() .Where(L => L.Status == ListenerStatus.Active) .Select(L => L.Name).ToList(); this.SetupMenuAutoComplete(); }
// GET: /launcher/installutildownload public async Task <IActionResult> InstallUtilDownload() { try { InstallUtilLauncher installUtilLauncher = await _context.GetInstallUtilLauncher(); return(File(Convert.FromBase64String(installUtilLauncher.DiskCode), MediaTypeNames.Application.Octet, "GruntStager.dll")); } catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException) { ModelState.AddModelError(string.Empty, e.Message); return(RedirectToAction(nameof(Create), new { id = "InstallUtil" })); } }
// GET: /launcher/installutildownload public async Task <IActionResult> InstallUtilDownload() { try { InstallUtilLauncher installUtilLauncher = await _context.GetInstallUtilLauncher(); return(File(Common.CovenantEncoding.GetBytes(installUtilLauncher.DiskCode), MediaTypeNames.Text.Xml, "GruntStager.xml")); } catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException) { ModelState.AddModelError(string.Empty, e.Message); return(RedirectToAction(nameof(Create), new { id = "InstallUtil" })); } }
public override void Command(MenuItem menuItem, string UserInput) { try { menuItem.Refresh(); InstallUtilLauncher launcher = ((InstallUtilLauncherMenuItem)menuItem).InstallUtilLauncher; Listener listener = this.CovenantClient.ApiListenersGet().FirstOrDefault(L => L.Id == launcher.ListenerId); EliteConsoleMenu menu = new EliteConsoleMenu(EliteConsoleMenu.EliteConsoleMenuType.Parameter, "InstallUtilLauncher"); menu.Rows.Add(new List <string> { "Name:", launcher.Name }); menu.Rows.Add(new List <string> { "Description:", launcher.Description }); menu.Rows.Add(new List <string> { "ListenerName:", listener == null ? "" : listener.Name }); menu.Rows.Add(new List <string> { "CommType:", launcher.CommType.ToString() }); if (launcher.CommType == CommunicationType.HTTP) { menu.Rows.Add(new List <string> { " ValidateCert:", launcher.ValidateCert.ToString() }); menu.Rows.Add(new List <string> { " UseCertPinning:", launcher.UseCertPinning.ToString() }); } else if (launcher.CommType == CommunicationType.SMB) { menu.Rows.Add(new List <string> { " SMBPipeName:", launcher.SmbPipeName }); } menu.Rows.Add(new List <string> { "DotNetFramework:", launcher.DotNetFrameworkVersion == DotNetVersion.Net35 ? "v3.5" : "v4.0" }); menu.Rows.Add(new List <string> { "Delay:", (launcher.Delay ?? default).ToString() }); menu.Rows.Add(new List <string> { "JitterPercent:", (launcher.JitterPercent ?? default).ToString() });
public InstallUtilLauncherMenuItem(CovenantAPI CovenantClient, EventPrinter EventPrinter) : base(CovenantClient, EventPrinter) { this.installutilLauncher = CovenantClient.ApiLaunchersInstallutilGet(); this.MenuTitle = installutilLauncher.Name; this.MenuDescription = installutilLauncher.Description; this.AdditionalOptions.Add(new MenuCommandInstallUtilLauncherShow(CovenantClient)); this.AdditionalOptions.Add(new MenuCommandInstallUtilLauncherGenerate(CovenantClient)); this.AdditionalOptions.Add(new MenuCommandInstallUtilLauncherCode()); this.AdditionalOptions.Add(new MenuCommandInstallUtilLauncherHost(CovenantClient)); this.AdditionalOptions.Add(new MenuCommandInstallUtilLauncherWriteFile()); var setCommand = new MenuCommandInstallUtilLauncherSet(CovenantClient); this.AdditionalOptions.Add(setCommand); this.AdditionalOptions.Add(new MenuCommandGenericUnset(setCommand.Parameters.FirstOrDefault(P => P.Name == "Option").Values)); this.Refresh(); }
// POST: /launcher/hostinstallutil public async Task <IActionResult> HostInstallUtil(HostedFile file) { try { InstallUtilLauncher launcher = await _context.GenerateInstallUtilLauncher(); HttpListener listener = await _context.GetHttpListener(file.ListenerId); file = await _context.CreateHostedFile(listener.Id, file); launcher = await _context.GenerateInstallUtilHostedLauncher(file); return(RedirectToAction(nameof(Create), new { id = launcher.Name })); } catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException) { ModelState.AddModelError(string.Empty, e.Message); return(RedirectToAction(nameof(Create), new { id = "InstallUtil" })); } }
public override void Command(MenuItem menuItem, string UserInput) { try { string[] commands = UserInput.Split(" "); if (commands.Length != 2 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase)) { menuItem.PrintInvalidOptionError(UserInput); return; } this.CovenantClient.ApiLaunchersInstallutilPost(); menuItem.Refresh(); InstallUtilLauncher launcher = ((InstallUtilLauncherMenuItem)menuItem).InstallUtilLauncher; HttpListener listener = this.CovenantClient.ApiListenersHttpByIdGet(launcher.ListenerId ?? default); if (listener == null) { EliteConsole.PrintFormattedErrorLine("Can only host a file on a valid HttpListener."); menuItem.PrintInvalidOptionError(UserInput); return; } HostedFile fileToHost = new HostedFile { ListenerId = listener.Id, Path = commands[1], Content = Convert.ToBase64String(Common.CovenantEncoding.GetBytes(launcher.DiskCode)) }; fileToHost = this.CovenantClient.ApiListenersByIdHostedfilesPost(listener.Id ?? default, fileToHost); launcher = this.CovenantClient.ApiLaunchersInstallutilHostedPost(fileToHost); Uri hostedLocation = new Uri(listener.Url + fileToHost.Path); EliteConsole.PrintFormattedHighlightLine("InstallUtilLauncher hosted at: " + hostedLocation); EliteConsole.PrintFormattedWarningLine("installutil.exe cannot execute remotely hosted files, the payload must first be written to disk"); EliteConsole.PrintFormattedInfoLine("Launcher: " + launcher.LauncherString); } catch (HttpOperationException e) { EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content); } }
public override void Command(MenuItem menuItem, string UserInput) { try { string[] commands = UserInput.Split(" "); if (commands.Length < 1 || commands.Length > 2 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase)) { menuItem.PrintInvalidOptionError(UserInput); return; } if (commands.Length == 2 && (!new List <string> { "gruntstager", "xml" }.Contains(commands[1], StringComparer.OrdinalIgnoreCase))) { EliteConsole.PrintFormattedErrorLine("Type must be one of: \"GruntStager\" or \"XML\""); menuItem.PrintInvalidOptionError(UserInput); return; } InstallUtilLauncher launcher = ((InstallUtilLauncherMenuItem)menuItem).InstallUtilLauncher; if (launcher.LauncherString == "") { this.CovenantClient.ApiLaunchersCscriptPost(); menuItem.Refresh(); launcher = ((InstallUtilLauncherMenuItem)menuItem).InstallUtilLauncher; EliteConsole.PrintFormattedHighlightLine("Generated CscriptLauncher: " + launcher.LauncherString); } if (commands.Length == 1 || (commands.Length == 2 && commands[1].Equals("gruntstager", StringComparison.OrdinalIgnoreCase))) { EliteConsole.PrintInfoLine(launcher.StagerCode); } else if (commands.Length == 2 && commands[1].Equals("xml", StringComparison.OrdinalIgnoreCase)) { EliteConsole.PrintInfoLine(launcher.DiskCode); } } catch (HttpOperationException e) { EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content); } }
public InstallUtilLauncherMenuItem(CovenantAPI CovenantClient) : base(CovenantClient) { try { this.InstallUtilLauncher = CovenantClient.ApiLaunchersInstallutilGet(); this.MenuTitle = InstallUtilLauncher.Name; this.MenuDescription = InstallUtilLauncher.Description; this.AdditionalOptions.Add(new MenuCommandInstallUtilLauncherShow(CovenantClient)); this.AdditionalOptions.Add(new MenuCommandInstallUtilLauncherGenerate(CovenantClient)); this.AdditionalOptions.Add(new MenuCommandInstallUtilLauncherCode(CovenantClient)); this.AdditionalOptions.Add(new MenuCommandInstallUtilLauncherHost(CovenantClient)); this.AdditionalOptions.Add(new MenuCommandInstallUtilLauncherWriteFile(CovenantClient)); var setCommand = new MenuCommandInstallUtilLauncherSet(CovenantClient); this.AdditionalOptions.Add(setCommand); this.AdditionalOptions.Add(new MenuCommandGenericUnset(setCommand.Parameters.FirstOrDefault(P => P.Name == "Option").Values)); } catch (HttpOperationException e) { EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content); } }
public ActionResult <InstallUtilLauncher> GenerateInstallUtilHostedFileLauncher(HostedFile hostedFile) { InstallUtilLauncher launcher = (InstallUtilLauncher)_context.Launchers.FirstOrDefault(S => S.Type == Launcher.LauncherType.InstallUtil); if (launcher == null) { return(NotFound()); } Listener listener = _context.Listeners.FirstOrDefault(S => S.Id == hostedFile.ListenerId); HostedFile savedHostedFile = _context.HostedFiles.FirstOrDefault(HF => HF.Id == hostedFile.Id); if (listener == null || savedHostedFile == null) { return(NotFound()); } string hostedLauncher = launcher.GetHostedLauncher(listener, savedHostedFile); _context.Launchers.Update(launcher); _context.SaveChanges(); return(Ok(launcher)); }
public async Task <IActionResult> InstallUtil(InstallUtilLauncher launcher) { try { launcher = await _context.EditInstallUtilLauncher(launcher); launcher = await _context.GenerateInstallUtilLauncher(); ViewBag.Launcher = launcher; ViewBag.Listeners = await _context.GetListeners(); return(RedirectToAction(nameof(Create), new { id = launcher.Name })); } catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException) { ModelState.AddModelError(string.Empty, e.Message); ViewBag.Launcher = launcher; ViewBag.Listeners = await _context.GetListeners(); return(RedirectToAction(nameof(Create), new { id = launcher.Name })); } }
public ActionResult <InstallUtilLauncher> GenerateInstallUtilLauncher() { InstallUtilLauncher launcher = (InstallUtilLauncher)_context.Launchers.FirstOrDefault(S => S.Type == Launcher.LauncherType.InstallUtil); if (launcher == null) { return(NotFound()); } Listener listener = _context.Listeners.FirstOrDefault(S => S.Id == launcher.ListenerId); if (listener == null) { return(NotFound()); } HttpProfile profile = (HttpProfile)_context.Profiles.FirstOrDefault(P => P.Id == listener.ProfileId); if (profile == null) { return(NotFound()); } Grunt grunt = new Grunt { ListenerId = listener.Id, CovenantIPAddress = listener.BindAddress, Delay = launcher.Delay, Jitter = launcher.Jitter, ConnectAttempts = launcher.ConnectAttempts }; _context.Grunts.Add(grunt); _context.SaveChanges(); launcher.GetLauncher(listener, grunt, profile); _context.Launchers.Update(launcher); _context.SaveChanges(); return(Ok(launcher)); }
public async Task <ActionResult <InstallUtilLauncher> > EditInstallUtilLauncher([FromBody] InstallUtilLauncher launcher) { try { return(await _service.EditInstallUtilLauncher(launcher)); } catch (ControllerNotFoundException e) { return(NotFound(e.Message)); } catch (ControllerBadRequestException e) { return(BadRequest(e.Message)); } }
public Task <InstallUtilLauncher> EditInstallUtilLauncher(InstallUtilLauncher launcher) { return(_connection.InvokeAsync <InstallUtilLauncher>("EditInstallUtilLauncher", launcher)); }
public override async void Command(MenuItem menuItem, string UserInput) { try { List <string> commands = Utilities.ParseParameters(UserInput); if (commands.Count() != 3 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase)) { menuItem.PrintInvalidOptionError(UserInput); return; } InstallUtilLauncher launcher = ((InstallUtilLauncherMenuItem)menuItem).InstallUtilLauncher; if (this.Parameters.FirstOrDefault(P => P.Name == "Option").Values.Select(V => V.Value).Contains(commands[1], StringComparer.OrdinalIgnoreCase)) { if (commands[1].Equals("listenername", StringComparison.OrdinalIgnoreCase)) { Listener listener = this.CovenantClient.ApiListenersGet().FirstOrDefault(L => L.Name == commands[2]); if (listener == null || listener.Name != commands[2]) { EliteConsole.PrintFormattedErrorLine("Invalid ListenerName: \"" + commands[2] + "\""); menuItem.PrintInvalidOptionError(UserInput); return; } launcher.ListenerId = listener.Id; } else if (commands[1].Equals("dotnetframeworkversion", StringComparison.OrdinalIgnoreCase)) { if (commands[2].Contains("35", StringComparison.OrdinalIgnoreCase) || commands[2].Contains("3.5", StringComparison.OrdinalIgnoreCase)) { launcher.DotNetFrameworkVersion = DotNetVersion.Net35; } else if (commands[2].Contains("40", StringComparison.OrdinalIgnoreCase) || commands[2].Contains("4.0", StringComparison.OrdinalIgnoreCase)) { launcher.DotNetFrameworkVersion = DotNetVersion.Net40; } else { EliteConsole.PrintFormattedErrorLine("Invalid DotNetFrameworkVersion \"" + commands[2] + "\". Valid options are: v3.5, v4.0"); menuItem.PrintInvalidOptionError(UserInput); return; } } else if (commands[1].Equals("commtype", StringComparison.OrdinalIgnoreCase)) { if (commands[2].Equals("smb", StringComparison.OrdinalIgnoreCase)) { launcher.CommType = CommunicationType.SMB; } else { launcher.CommType = CommunicationType.HTTP; } } else if (commands[1].Equals("validatecert", StringComparison.OrdinalIgnoreCase)) { bool parsed = bool.TryParse(commands[2], out bool validate); if (parsed) { launcher.ValidateCert = validate; } else { menuItem.PrintInvalidOptionError(UserInput); return; } } else if (commands[1].Equals("usecertpinning", StringComparison.OrdinalIgnoreCase)) { bool parsed = bool.TryParse(commands[2], out bool pin); if (parsed) { launcher.UseCertPinning = pin; } else { menuItem.PrintInvalidOptionError(UserInput); return; } } else if (commands[1].Equals("smbpipename", StringComparison.OrdinalIgnoreCase)) { launcher.SmbPipeName = commands[2]; } else if (commands[1].Equals("delay", StringComparison.OrdinalIgnoreCase)) { int.TryParse(commands[2], out int n); launcher.Delay = n; } else if (commands[1].Equals("jitterpercent", StringComparison.OrdinalIgnoreCase)) { int.TryParse(commands[2], out int n); launcher.JitterPercent = n; } else if (commands[1].Equals("connectattempts", StringComparison.OrdinalIgnoreCase)) { int.TryParse(commands[2], out int n); launcher.ConnectAttempts = n; } else if (commands[1].Equals("killdate", StringComparison.OrdinalIgnoreCase)) { DateTime.TryParse(commands[2], out DateTime result); launcher.KillDate = result; } else if (commands[1].Equals("launcherstring", StringComparison.OrdinalIgnoreCase)) { launcher.LauncherString = commands[2]; } await this.CovenantClient.ApiLaunchersInstallutilPutAsync(launcher); } else { menuItem.PrintInvalidOptionError(UserInput); } } catch (HttpOperationException e) { EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content); } }
public override void Command(MenuItem menuItem, string UserInput) { InstallUtilLauncher installutilLauncher = ((InstallUtilLauncherMenuItem)menuItem).installutilLauncher; string[] commands = UserInput.Split(" "); if (commands.Length < 3 || commands[0].ToLower() != "set") { menuItem.PrintInvalidOptionError(UserInput); return; } else if (this.Parameters.FirstOrDefault(P => P.Name == "Option").Values.Select(V => V.Value.ToLower()).Contains(commands[1].ToLower())) { if (commands[1].ToLower() == "listenername") { Listener listener = this.CovenantClient.ApiListenersGet().FirstOrDefault(L => L.Name == commands[2]); if (listener == null || listener.Name != commands[2]) { EliteConsole.PrintFormattedErrorLine("Invalid ListenerName: \"" + commands[2] + "\""); menuItem.PrintInvalidOptionError(UserInput); return; } else { installutilLauncher.ListenerId = listener.Id; } } else if (commands[1].ToLower() == "dotnetframeworkversion") { if (commands[2].ToLower().Contains("35") || commands[2].ToLower().Contains("3.5")) { installutilLauncher.DotNetFrameworkVersion = DotNetVersion.Net35; } else if (commands[2].ToLower().Contains("40") || commands[2].ToLower().Contains("4.0")) { installutilLauncher.DotNetFrameworkVersion = DotNetVersion.Net40; } else { EliteConsole.PrintFormattedErrorLine("Invalid DotNetFrameworkVersion \"" + commands[2] + "\". Valid options are: v3.5, v4.0"); menuItem.PrintInvalidOptionError(UserInput); return; } } else if (commands[1].ToLower() == "delay") { int.TryParse(commands[2], out int n); installutilLauncher.Delay = n; } else if (commands[1].ToLower() == "jitter") { int.TryParse(commands[2], out int n); installutilLauncher.Jitter = n; } else if (commands[1].ToLower() == "connectattempts") { int.TryParse(commands[2], out int n); installutilLauncher.ConnectAttempts = n; } else if (commands[1].ToLower() == "launcherstring") { installutilLauncher.LauncherString = commands[2]; } CovenantAPIExtensions.ApiLaunchersInstallutilPut(this.CovenantClient, installutilLauncher); } else { menuItem.PrintInvalidOptionError(UserInput); } }