public async Task <GruntTaskOption> CreateGruntTaskOption(GruntTaskOption option) { _context.Add(option); // _notifier.OnCreateGruntTaskOption(this, option); return(option); }
public override void Command(MenuItem menuItem, string UserInput) { try { List <string> commands = UserInput.Split(" ").ToList(); if (commands.Count() < 3 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase)) { menuItem.PrintInvalidOptionError(UserInput); return; } GruntTask task = ((TaskMenuItem)menuItem).Task; GruntTaskOption option = task.Options.FirstOrDefault(O => O.Name.ToLower() == commands[1].ToLower()); if (option == null) { EliteConsole.PrintFormattedErrorLine("Invalid Set option: \"" + commands[1] + "\""); menuItem.PrintInvalidOptionError(UserInput); return; } option.Value = String.Join(" ", commands.GetRange(2, commands.Count() - 2)); this.CovenantClient.ApiGrunttasksPut(task); } catch (HttpOperationException e) { EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content); } }
public override void Command(MenuItem menuItem, string UserInput) { TaskMenuItem taskMenuItem = ((TaskMenuItem)menuItem); List <string> commands = UserInput.Split(" ").ToList(); IList <GruntTaskOption> options = taskMenuItem.task.Options; GruntTaskOption option = options.FirstOrDefault(O => O.Name.ToLower() == commands[1].ToLower()); if (commands.Count() < 3 || commands.First().ToLower() != "set") { menuItem.PrintInvalidOptionError(UserInput); } else if (commands[1].ToLower() == "FilePath".ToLower()) { string FilePath = Path.Combine(Common.EliteDataFolder, commands[2]); if (!File.Exists(FilePath)) { menuItem.PrintInvalidOptionError(UserInput); EliteConsole.PrintFormattedErrorLine("File: \"" + FilePath + "\" does not exist on the local system."); return; } options.FirstOrDefault(O => O.Name == "FileContents").Value = Convert.ToBase64String(File.ReadAllBytes(FilePath)); options.FirstOrDefault(O => O.Name == "FileName").Value = Path.GetFileName(FilePath); CovenantClient.ApiGruntTasksByIdPut(taskMenuItem.task.Id ?? default, taskMenuItem.task); } else if (option == null) { menuItem.PrintInvalidOptionError(UserInput); EliteConsole.PrintFormattedErrorLine("Invalid Set option: \"" + commands[1] + "\""); } else { option.Value = String.Join(" ", commands.GetRange(2, commands.Count() - 2)); CovenantClient.ApiGruntTasksByIdPut(taskMenuItem.task.Id ?? default, taskMenuItem.task); } }
public override async void Command(MenuItem menuItem, string UserInput) { try { List <string> commands = UserInput.Split(" ").ToList(); if (commands.Count() < 3 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase)) { menuItem.PrintInvalidOptionError(UserInput); return; } GruntTask task = ((TaskMenuItem)menuItem).Task; GruntTaskOption option = task.Options.FirstOrDefault(O => O.Name.Equals(commands[1], StringComparison.OrdinalIgnoreCase)); if (commands[1].Equals("LocalFilePath", StringComparison.OrdinalIgnoreCase)) { string FilePath = Path.Combine(Common.EliteDataFolder, commands[2]); if (!File.Exists(FilePath)) { menuItem.PrintInvalidOptionError(UserInput); EliteConsole.PrintFormattedErrorLine("File: \"" + FilePath + "\" does not exist on the local system."); return; } byte[] FileContents = File.ReadAllBytes(FilePath); StringBuilder hex = new StringBuilder(); foreach (byte b in FileContents) { hex.AppendFormat("{0:x2}", b); } task.Options.FirstOrDefault(O => O.Name == "Hex").Value = hex.ToString(); await this.CovenantClient.ApiGrunttasksPutAsync(task); } else if (option == null) { menuItem.PrintInvalidOptionError(UserInput); EliteConsole.PrintFormattedErrorLine("Invalid Set option: \"" + commands[1] + "\""); return; } else { option.Value = String.Join(" ", commands.GetRange(2, commands.Count() - 2)); await this.CovenantClient.ApiGrunttasksPutAsync(task); } } catch (HttpOperationException e) { EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content); } }
public override void Command(MenuItem menuItem, string UserInput) { TaskMenuItem taskMenuItem = ((TaskMenuItem)menuItem); List <string> commands = UserInput.Split(" ").ToList(); GruntTaskOption option = taskMenuItem.task.Options.FirstOrDefault(O => O.Name.ToLower() == commands[1].ToLower()); if (commands.Count() < 3 || commands.First().ToLower() != "set") { menuItem.PrintInvalidOptionError(UserInput); } else if (option == null) { EliteConsole.PrintFormattedErrorLine("Invalid Set option: \"" + commands[1] + "\""); } else { option.Value = String.Join(" ", commands.GetRange(2, commands.Count() - 2)); this.CovenantClient.ApiGruntTasksByIdPut(taskMenuItem.task.Id ?? default, taskMenuItem.task); } }
public async Task <GruntCommand> Input(CovenantUser user, Grunt grunt, string UserInput) { GruntCommand GruntCommand = await _context.CreateGruntCommand(new GruntCommand { Command = GetCommandFromInput(UserInput), CommandTime = DateTime.UtcNow, User = user, GruntId = grunt.Id, Grunt = grunt, CommandOutputId = 0, CommandOutput = new CommandOutput() }, _grunthub, _eventhub); List <ParsedParameter> parameters = ParseParameters(UserInput).ToList(); GruntTask commandTask = null; try { commandTask = await _context.GetGruntTaskByName(parameters.FirstOrDefault().Value); if (commandTask.Options.Count == 1 && new List <string> { "Command", "ShellCommand", "PowerShellCommand", "Code" }.Contains(commandTask.Options[0].Name)) { parameters = new List <ParsedParameter> { new ParsedParameter { Value = commandTask.Name, Label = "", IsLabeled = false, Position = 0 }, new ParsedParameter { Value = UserInput.Substring(UserInput.IndexOf(" ", StringComparison.Ordinal) + 1).Trim('"'), Label = "", IsLabeled = false, Position = 0 } }; } } catch (ControllerNotFoundException) { } string output = ""; if (parameters.FirstOrDefault().Value.ToLower() == "show") { output = await Show(grunt); } else if (parameters.FirstOrDefault().Value.ToLower() == "help") { output = await Help(parameters); } else if (parameters.FirstOrDefault().Value.ToLower() == "sharpshell") { output = await SharpShell(grunt, GruntCommand, parameters); } else if (parameters.FirstOrDefault().Value.ToLower() == "kill") { output = await Kill(grunt, GruntCommand, parameters); } else if (parameters.FirstOrDefault().Value.ToLower() == "set") { output = await Set(grunt, GruntCommand, parameters); } else if (parameters.FirstOrDefault().Value.ToLower() == "history") { output = await History(grunt, parameters); } else if (parameters.FirstOrDefault().Value.ToLower() == "connect") { output = await Connect(grunt, GruntCommand, parameters); } else if (parameters.FirstOrDefault().Value.ToLower() == "disconnect") { output = await Disconnect(grunt, GruntCommand, parameters); } else if (parameters.FirstOrDefault().Value.ToLower() == "jobs") { output = await Jobs(grunt, GruntCommand, parameters); } else if (parameters.FirstOrDefault().Value.ToLower() == "note") { grunt.Note = string.Join(" ", parameters.Skip(1).Select(P => P.Value).ToArray()); await _context.EditGrunt(grunt, user, _grunthub, _eventhub); output = "Note: " + grunt.Note; } else if (parameters.FirstOrDefault().Value.ToLower() == "powershellimport") { grunt.PowerShellImport = parameters.Count >= 2 ? parameters[1].Value : ""; await _context.EditGrunt(grunt, user, _grunthub, _eventhub); output = "PowerShell Imported"; } else if (commandTask != null) { parameters = parameters.Skip(1).ToList(); if (parameters.Count() < commandTask.Options.Count(O => !O.Optional)) { _context.Entry(GruntCommand).State = EntityState.Detached; GruntCommand.CommandOutput.Output = EliteConsole.PrintFormattedErrorLine(GetUsage(commandTask)); return(await _context.EditGruntCommand(GruntCommand, _grunthub, _eventhub)); } // All options begin unassigned List <bool> OptionAssignments = commandTask.Options.Select(O => false).ToList(); commandTask.Options.ForEach(O => O.Value = ""); for (int i = 0; i < parameters.Count; i++) { if (parameters[i].IsLabeled) { var option = commandTask.Options.FirstOrDefault(O => O.Name.Equals(parameters[i].Label, StringComparison.OrdinalIgnoreCase)); option.Value = parameters[i].Value; OptionAssignments[commandTask.Options.IndexOf(option)] = true; } else { GruntTaskOption nextOption = null; // Find next unassigned option for (int j = 0; j < commandTask.Options.Count; j++) { if (!OptionAssignments[j]) { nextOption = commandTask.Options[j]; OptionAssignments[j] = true; break; } } if (nextOption == null) { // This is an extra parameter _context.Entry(GruntCommand).State = EntityState.Detached; GruntCommand.CommandOutput.Output = EliteConsole.PrintFormattedErrorLine(GetUsage(commandTask)); return(await _context.EditGruntCommand(GruntCommand, _grunthub, _eventhub)); } nextOption.Value = parameters[i].Value; } } // Check for unassigned required options for (int i = 0; i < commandTask.Options.Count; i++) { if (!OptionAssignments[i] && !commandTask.Options[i].Optional) { // This is an extra parameter StringBuilder toPrint = new StringBuilder(); toPrint.Append(EliteConsole.PrintFormattedErrorLine(commandTask.Options[i].Name + " is required.")); toPrint.Append(EliteConsole.PrintFormattedErrorLine(GetUsage(commandTask))); _context.Entry(GruntCommand).State = EntityState.Detached; GruntCommand.CommandOutput.Output = toPrint.ToString(); return(await _context.EditGruntCommand(GruntCommand, _grunthub, _eventhub)); } } // Parameters have parsed successfully commandTask = await _context.EditGruntTask(commandTask); await StartTask(grunt, commandTask, GruntCommand); } else { output = EliteConsole.PrintFormattedErrorLine("Unrecognized command"); } _context.Entry(GruntCommand).State = EntityState.Detached; GruntCommand.CommandOutput.Output = output; return(await _context.EditGruntCommand(GruntCommand, _grunthub, _eventhub)); }
public Task <GruntTaskOption> EditGruntTaskOption(GruntTaskOption option) { return(_connection.InvokeAsync <GruntTaskOption>("EditGruntTaskOption", option)); }
public Task <GruntTaskOption> CreateGruntTaskOption(GruntTaskOption option) { return(_connection.InvokeAsync <GruntTaskOption>("CreateGruntTaskOption", option)); }
public async Task <GruntTaskOption> EditGruntTaskOption(GruntTaskOption option) { /*_context.Entry(option).State = EntityState.Modified; * await _context.SaveChangesAsync();*/ return(option); }
//Not sure why the grunt options are added separately instead of a member of the Grunt Task class public void Add(GruntTaskOption entity) { gruntTaskOptions.Add(entity); }