예제 #1
0
 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);
     }
 }
예제 #2
0
        public override async void Command(MenuItem menuItem, string UserInput)
        {
            try
            {
                string[] commands = UserInput.Split(" ");
                if (commands.Length != 3 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase))
                {
                    menuItem.PrintInvalidOptionError(UserInput);
                    return;
                }

                List <Listener> Listeners = ((ListenersMenuItem)menuItem).Listeners;
                Listener        listener  = Listeners.FirstOrDefault(L => L.Name.Equals(commands[1], StringComparison.OrdinalIgnoreCase));
                if (listener == null)
                {
                    EliteConsole.PrintFormattedErrorLine("Listener with name: " + commands[1] + " does not exist.");
                    menuItem.PrintInvalidOptionError(UserInput);
                    return;
                }

                if (Listeners.Any(L => L.Name.Equals(commands[2], StringComparison.OrdinalIgnoreCase)))
                {
                    EliteConsole.PrintFormattedErrorLine("Listener with name: " + commands[2] + " already exists.");
                    menuItem.PrintInvalidOptionError(UserInput);
                    return;
                }

                listener.Name = commands[2];
                await this.CovenantClient.ApiListenersPutAsync(listener);
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
예제 #3
0
        public override void Refresh()
        {
            try
            {
                this.ListenerTypes = this.CovenantClient.ApiListenersTypesGet().ToList();
                this.Listeners     = this.CovenantClient.ApiListenersGet().Where(L => L.Status != ListenerStatus.Uninitialized).ToList();
                List <MenuCommandParameterValue> listenerNames = this.Listeners.Select(L => new MenuCommandParameterValue {
                    Value = L.Name
                }).ToList();

                this.MenuOptions.FirstOrDefault(M => M.MenuTitle == "Interact")
                .MenuItemParameters
                .FirstOrDefault(P => P.Name == "Listener Name")
                .Values = listenerNames;

                this.AdditionalOptions.FirstOrDefault(AO => AO.Name == "Rename")
                .Parameters
                .FirstOrDefault(P => P.Name == "Old Name")
                .Values = listenerNames;

                this.SetupMenuAutoComplete();
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
예제 #4
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            InstallUtilLauncherMenuItem installutilMenuItem = (InstallUtilLauncherMenuItem)menuItem;

            string[] commands = UserInput.Split(" ");
            if (commands.Length != 2 || commands[0].ToLower() != "host")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            installutilMenuItem.installutilLauncher = this.CovenantClient.ApiLaunchersInstallutilPost();
            HttpListener listener = this.CovenantClient.ApiListenersHttpByIdGet(installutilMenuItem.installutilLauncher.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    = installutilMenuItem.installutilLauncher.DiskCode
            };

            fileToHost = this.CovenantClient.ApiListenersByIdHostedfilesPost(listener.Id ?? default, fileToHost);
            installutilMenuItem.installutilLauncher = 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: " + installutilMenuItem.installutilLauncher.LauncherString);
        }
예제 #5
0
        public TaskMenuItem(CovenantAPI CovenantClient, Grunt Grunt) : base(CovenantClient)
        {
            try
            {
                this.Grunt              = Grunt;
                this.MenuTitle          = "Task";
                this.MenuDescription    = "Task a Grunt to do something.";
                this.MenuItemParameters = new List <MenuCommandParameter> {
                    new MenuCommandParameter {
                        Name   = "Task Name",
                        Values = this.CovenantClient.ApiGrunttasksGet().Select(T => new MenuCommandParameterValue {
                            Value = T.Name
                        }).ToList()
                    }
                };

                this.AdditionalOptions.Add(new MenuCommandTaskShow(CovenantClient));
                this.AdditionalOptions.Add(new MenuCommandTaskStart(CovenantClient));
                var setCommand = new MenuCommandTaskSet(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);
            }
        }
예제 #6
0
 public override void Command(MenuItem menuItem, string UserInput)
 {
     try
     {
         string[] commands = UserInput.Split(" ");
         if (commands.Length < 3 || commands.Length > 4 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase))
         {
             menuItem.PrintInvalidOptionError(UserInput);
             EliteConsole.PrintFormattedErrorLine("Usage: Create <username> <password> [<roles>]");
             return;
         }
         CovenantUser user = this.CovenantClient.ApiUsersPost(new CovenantUserLogin(commands[1], commands[2]));
         if (user != null)
         {
             if (commands.Length == 4)
             {
                 string[] roleNames = commands[3].Split(",");
                 foreach (string roleName in roleNames)
                 {
                     IdentityRole role = this.CovenantClient.ApiRolesGet().FirstOrDefault(R => R.Name == roleName);
                     this.CovenantClient.ApiUsersByIdRolesByRidPost(user.Id, role.Id);
                 }
             }
         }
         else
         {
             EliteConsole.PrintFormattedErrorLine("Failed to create user: \"" + commands[1] + "\"");
         }
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #7
0
        public override void Refresh()
        {
            try
            {
                this.MSBuildLauncher = this.CovenantClient.ApiLaunchersMsbuildGet();

                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);
            }
        }
예제 #8
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            try
            {
                menuItem.Refresh();
                Listener          listener    = ((HostedFilesMenuItem)menuItem).Listener;
                List <HostedFile> HostedFiles = ((HostedFilesMenuItem)menuItem).HostedFiles;

                EliteConsoleMenu menu = new EliteConsoleMenu(EliteConsoleMenu.EliteConsoleMenuType.List, "HostedFiles");
                menu.Columns.Add("Listener");
                menu.Columns.Add("Address");
                menu.Columns.Add("Path");
                HostedFiles.ForEach(HF =>
                {
                    menu.Rows.Add(new List <string> {
                        listener.Name, listener.ConnectAddress, HF.Path
                    });
                });
                menu.Print();
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
예제 #9
0
 public override async 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;
         }
         Listener   listener   = ((HostedFilesMenuItem)menuItem).Listener;
         HostedFile hostedFile = ((HostedFilesMenuItem)menuItem).HostedFiles.FirstOrDefault(HF => HF.Path == commands[1]);
         if (hostedFile == null)
         {
             menuItem.PrintInvalidOptionError(UserInput);
             EliteConsole.PrintFormattedErrorLine("No file is currently being hosted at: \"" + commands[1] + "\".");
             return;
         }
         await this.CovenantClient.ApiListenersByIdHostedfilesByHfidDeleteAsync(listener.Id ?? default, hostedFile.Id ?? default);
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #10
0
        public override void Refresh()
        {
            try
            {
                this.Listener    = this.CovenantClient.ApiListenersByIdGet(this.Listener.Id ?? default);
                this.HostedFiles = this.CovenantClient.ApiListenersByIdHostedfilesGet(this.Listener.Id ?? default).ToList();

                this.AdditionalOptions.FirstOrDefault(AO => AO.Name == "Remove").Parameters
                .FirstOrDefault(P => P.Name == "HostPath").Values =
                    this.HostedFiles
                    .Select(HF => new MenuCommandParameterValue {
                    Value = HF.Path
                })
                    .ToList();

                var filevalues = new MenuCommandParameterValuesFromFilePath(Common.EliteDataFolder);
                this.AdditionalOptions.FirstOrDefault(AO => AO.Name == "Host").Parameters
                .FirstOrDefault(P => P.Name == "LocalFilePath").Values = filevalues;

                this.SetupMenuAutoComplete();
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
예제 #11
0
        public void PrintEvent(EventModel theEvent, string Context = "*")
        {
            lock (_EventLock)
            {
                if (this.WillPrintEvent(theEvent, Context))
                {
                    switch (theEvent.Level)
                    {
                    case EventLevel.Highlight:
                        EliteConsole.PrintFormattedHighlightLine(theEvent.Message);
                        break;

                    case EventLevel.Info:
                        EliteConsole.PrintInfoLine(theEvent.Message);
                        break;

                    case EventLevel.Warning:
                        EliteConsole.PrintFormattedWarningLine(theEvent.Message);
                        break;

                    case EventLevel.Error:
                        EliteConsole.PrintFormattedErrorLine(theEvent.Message);
                        break;

                    default:
                        EliteConsole.PrintFormattedInfo(theEvent.Message);
                        break;
                    }
                    PrintedEvents.Add(theEvent.Id ?? default);
                }
            }
        }
예제 #12
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            MSBuildLauncherMenuItem msbuildMenuItem = (MSBuildLauncherMenuItem)menuItem;

            string[] commands = UserInput.Split(" ");
            if (commands.Length != 2 || commands[0].ToLower() != "host")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            msbuildMenuItem.msbuildLauncher = this.CovenantClient.ApiLaunchersMsbuildPost();
            HttpListener listener = this.CovenantClient.ApiListenersHttpByIdGet(msbuildMenuItem.msbuildLauncher.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(msbuildMenuItem.msbuildLauncher.DiskCode))
            };

            fileToHost = this.CovenantClient.ApiListenersByIdHostedfilesPost(listener.Id ?? default, fileToHost);
            msbuildMenuItem.msbuildLauncher = this.CovenantClient.ApiLaunchersMsbuildHostedPost(fileToHost);

            Uri hostedLocation = new Uri(listener.Url + fileToHost.Path);

            EliteConsole.PrintFormattedHighlightLine("MSBuildLauncher hosted at: " + hostedLocation);
            EliteConsole.PrintFormattedWarningLine("msbuild.exe cannot execute remotely hosted files, the payload must first be written to disk");
            EliteConsole.PrintFormattedInfoLine("Launcher: " + msbuildMenuItem.msbuildLauncher.LauncherString);
        }
예제 #13
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            try
            {
                string[] commands = UserInput.Split(" ");
                if (commands.Length != 2 || commands[0].ToLower() != "write")
                {
                    menuItem.PrintInvalidOptionError(UserInput);
                    return;
                }
                menuItem.Refresh();
                MSBuildLauncher launcher = ((MSBuildLauncherMenuItem)menuItem).MSBuildLauncher;
                if (launcher.LauncherString == "")
                {
                    this.CovenantClient.ApiLaunchersBinaryPost();
                    menuItem.Refresh();
                    EliteConsole.PrintFormattedHighlightLine("Generated MSBuildLauncher: " + launcher.LauncherString);
                }

                string OutputFilePath = Common.EliteDataFolder + String.Concat(commands[1].Split(System.IO.Path.GetInvalidFileNameChars()));
                System.IO.File.WriteAllText(OutputFilePath, launcher.DiskCode);
                EliteConsole.PrintFormattedHighlightLine("Wrote MSBuildLauncher to: \"" + OutputFilePath + "\"");
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
예제 #14
0
 public override void Command(MenuItem menuItem, string UserInput)
 {
     try
     {
         menuItem.Refresh();
         List <CovenantUser> Users = ((UsersMenuItem)menuItem).Users;
         EliteConsoleMenu    menu  = new EliteConsoleMenu(EliteConsoleMenu.EliteConsoleMenuType.List, "Users");
         menu.Columns.Add("Username");
         menu.Columns.Add("Roles");
         menu.Columns.Add("Status");
         Users.ForEach(U =>
         {
             var userRoles       = this.CovenantClient.ApiUsersByIdRolesGet(U.Id).ToList();
             List <string> roles = new List <string>();
             foreach (var userRole in userRoles)
             {
                 IdentityRole role = this.CovenantClient.ApiRolesByRidGet(userRole.RoleId);
                 if (role != null)
                 {
                     roles.Add(role.Name);
                 }
             }
             menu.Rows.Add(new List <string> {
                 U.UserName, String.Join(", ", roles), "Active"
             });
         });
         menu.Print();
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #15
0
        public override async void Command(MenuItem menuItem, string UserInput)
        {
            GruntsMenuItem gruntsMenu = ((GruntsMenuItem)menuItem);

            string[] commands = UserInput.Split(" ");
            if (commands.Length != 3 || !commands[0].Equals("rename", StringComparison.OrdinalIgnoreCase))
            {
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }

            Grunt grunt = gruntsMenu.Grunts.FirstOrDefault(G => G.Name.Equals(commands[1], StringComparison.OrdinalIgnoreCase));

            if (grunt == null)
            {
                EliteConsole.PrintFormattedErrorLine("Grunt with name: " + commands[1] + " does not exist.");
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            if (gruntsMenu.Grunts.Any(G => G.Name.Equals(commands[2], StringComparison.OrdinalIgnoreCase)))
            {
                EliteConsole.PrintFormattedErrorLine("Grunt with name: " + commands[2] + " already exists.");
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            grunt.Name = commands[2];
            try
            {
                await this.CovenantClient.ApiGruntsPutAsync(grunt);
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
예제 #16
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            try
            {
                string[] commands = UserInput.Split(" ");
                if (commands.Length != 1 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase))
                {
                    menuItem.PrintInvalidOptionError(UserInput);
                    EliteConsole.PrintFormattedErrorLine("Usage: Create <username> <password> [<roles>]");
                    return;
                }

                EliteConsole.PrintHighlight("Password: "******"CovenantException: " + e.Response.Content);
            }
        }
예제 #17
0
 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 && !commands[1].Equals("gruntstager", StringComparison.OrdinalIgnoreCase))
         {
             EliteConsole.PrintFormattedErrorLine("Type must be one of: \"GruntStager\"");
             menuItem.PrintInvalidOptionError(UserInput);
             return;
         }
         BinaryLauncher launcher = ((BinaryLauncherMenuItem)menuItem).BinaryLauncher;
         if (launcher.LauncherString == "")
         {
             this.CovenantClient.ApiLaunchersBinaryPost();
             menuItem.Refresh();
             launcher = ((BinaryLauncherMenuItem)menuItem).BinaryLauncher;
             EliteConsole.PrintFormattedHighlightLine("Generated BinaryLauncher: " + launcher.LauncherString);
         }
         EliteConsole.PrintInfoLine(launcher.StagerCode);
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #18
0
 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);
             EliteConsole.PrintFormattedErrorLine("Usage: Delete <username>");
             return;
         }
         List <CovenantUser> Users = ((UsersMenuItem)menuItem).Users;
         CovenantUser        user  = Users.FirstOrDefault(U => U.UserName == commands[1]);
         if (user != null)
         {
             EliteConsole.PrintFormattedWarning("Delete user: \"" + commands[1] + "\"? [y/N] ");
             string input = EliteConsole.Read();
             if (input.StartsWith("y", StringComparison.OrdinalIgnoreCase))
             {
                 this.CovenantClient.ApiUsersByIdDelete(user.Id);
             }
         }
         else
         {
             EliteConsole.PrintFormattedErrorLine("User: \"" + commands[1] + "\" does not exist.");
         }
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #19
0
        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();
                BinaryLauncher launcher = ((BinaryLauncherMenuItem)menuItem).BinaryLauncher;
                if (launcher.LauncherString == "")
                {
                    this.CovenantClient.ApiLaunchersBinaryPost();
                    menuItem.Refresh();
                    EliteConsole.PrintFormattedHighlightLine("Generated BinaryLauncher: " + launcher.Base64ILByteString);
                }

                string OutputFilePath = Common.EliteDataFolder + String.Concat(commands[1].Split(System.IO.Path.GetInvalidFileNameChars()));
                System.IO.File.WriteAllBytes(OutputFilePath, Convert.FromBase64String(launcher.Base64ILByteString));
                EliteConsole.PrintFormattedHighlightLine("Wrote BinaryLauncher to: \"" + OutputFilePath + "\"");
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
예제 #20
0
        public override void Refresh()
        {
            try
            {
                this.HttpListener = this.CovenantClient.ApiListenersHttpByIdGet(this.HttpListener.Id ?? default);
                this.ListenerType = this.CovenantClient.ApiListenersTypesGet().FirstOrDefault(LT => LT.Name == "HTTP");
                this.HttpProfiles = this.CovenantClient.ApiProfilesHttpGet().ToList();
                this.HttpProfile  = this.HttpProfiles.FirstOrDefault(HP => this.HttpListener.ProfileId == HP.Id);

                this.MenuTitle       = this.ListenerType.Name;
                this.MenuDescription = this.ListenerType.Description;

                List <string> profiles = this.CovenantClient.ApiProfilesHttpGet()
                                         .Select(P => P.Name)
                                         .ToList();

                this.AdditionalOptions.FirstOrDefault(AO => AO.Name == "Set").Parameters
                .FirstOrDefault(P => P.Name == "Option").Values
                .FirstOrDefault(V => V.Value == "HttpProfile")
                .NextValueSuggestions = profiles;

                this.AdditionalOptions.FirstOrDefault(AO => AO.Name == "Set").Parameters
                .FirstOrDefault(P => P.Name == "Option").Values
                .FirstOrDefault(V => V.Value == "SSLCertPath")
                .NextValueSuggestions = Utilities.GetFilesForPath(Common.EliteDataFolder);

                this.SetupMenuAutoComplete();
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
예제 #21
0
 public override async void Command(MenuItem menuItem, string UserInput)
 {
     try
     {
         string[] commands = UserInput.Split(" ");
         if (commands.Length != 3 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase))
         {
             menuItem.PrintInvalidOptionError(UserInput);
             return;
         }
         FileInfo file = new FileInfo(Path.Combine(Common.EliteDataFolder, commands[1]));
         if (!file.Exists)
         {
             menuItem.PrintInvalidOptionError(UserInput);
             EliteConsole.PrintFormattedErrorLine("File: \"" + file.FullName + "\" does not exist on the local system.");
             return;
         }
         Listener   listener   = ((HostedFilesMenuItem)menuItem).Listener;
         HostedFile hostedFile = new HostedFile
         {
             ListenerId = listener.Id,
             Path       = commands[2],
             Content    = Convert.ToBase64String(File.ReadAllBytes(file.FullName))
         };
         await this.CovenantClient.ApiListenersByIdHostedfilesPostAsync(listener.Id ?? default, hostedFile);
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #22
0
 public void RefreshHTTPTemplate()
 {
     try
     {
         this.HttpListener = this.CovenantClient.ApiListenersHttpPost(new HttpListener());
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #23
0
 public override void Command(MenuItem menuItem, string UserInput)
 {
     try
     {
         this.CovenantClient.ApiLaunchersMsbuildPost();
         menuItem.Refresh();
         EliteConsole.PrintFormattedHighlightLine("Generated MSBuildLauncher: " + ((MSBuildLauncherMenuItem)menuItem).MSBuildLauncher.LauncherString);
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #24
0
 public override void Refresh()
 {
     try
     {
         this.AllIndicators     = this.CovenantClient.ApiIndicatorsGet().ToList();
         this.NetworkIndicators = this.CovenantClient.ApiIndicatorsNetworksGet().ToList();
         this.FileIndicators    = this.CovenantClient.ApiIndicatorsFilesGet().ToList();
         this.TargetIndicators  = this.CovenantClient.ApiIndicatorsTargetsGet().ToList();
         this.SetupMenuAutoComplete();
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #25
0
 public override void Refresh()
 {
     try
     {
         this.Users = this.CovenantClient.ApiUsersGet()
                      .Where(U => !this.CovenantClient.ApiUsersByIdRolesGet(U.Id)
                             .Where(R => this.CovenantClient.ApiRolesByRidGet(R.RoleId).Name.ToLower() == "listener")
                             .Any()
                             ).ToList();
         this.SetupMenuAutoComplete();
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #26
0
 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);
     }
 }
예제 #27
0
        public override async void Command(MenuItem menuItem, string UserInput)
        {
            try
            {
                string[] commands = UserInput.Split(" ");
                if (commands.Length != 1 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase))
                {
                    menuItem.PrintInvalidOptionError(UserInput);
                    return;
                }
                HttpListener HttpListener = ((HTTPListenerMenuItem)menuItem).HttpListener;
                if ((HttpListener.UseSSL ?? default) && (string.IsNullOrEmpty(HttpListener.SslCertHash) || string.IsNullOrEmpty(HttpListener.SslCertificate)))
                {
                    EliteConsole.PrintWarning("No SSLCertificate specified. Would you like to generate and use a self-signed certificate? [y/N] ");
                    string input = EliteConsole.Read();
                    if (input.StartsWith("y", StringComparison.OrdinalIgnoreCase))
                    {
                        X509Certificate2 certificate = Utilities.CreateSelfSignedCertificate(HttpListener.BindAddress);

                        string autopath = "httplistener-" + HttpListener.Id + "-certificate.pfx";
                        File.WriteAllBytes(
                            Path.Combine(Common.EliteDataFolder, autopath),
                            certificate.Export(X509ContentType.Pfx, HttpListener.SslCertificatePassword)
                            );
                        EliteConsole.PrintFormattedHighlightLine("Certificate written to: " + autopath);
                        EliteConsole.PrintFormattedWarningLine("(Be sure to disable certificate validation on Launchers/Grunts using this self-signed certificate)");
                        menuItem.AdditionalOptions.FirstOrDefault(O => O.Name == "Set").Command(menuItem, "Set SSLCertPath " + autopath);
                        menuItem.Refresh();
                        HttpListener = ((HTTPListenerMenuItem)menuItem).HttpListener;
                    }
                    else
                    {
                        EliteConsole.PrintFormattedErrorLine("Must specify an SSLCertfiicate to Start an HTTP Listener with SSL.");
                        return;
                    }
                }
                HttpListener.Status = ListenerStatus.Active;
                await this.CovenantClient.ApiListenersHttpPutAsync(HttpListener);

                ((HTTPListenerMenuItem)menuItem).RefreshHTTPTemplate();
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
예제 #28
0
 public MenuCommandHostedFilesRemove(CovenantAPI CovenantClient) : base(CovenantClient)
 {
     this.Name        = "Remove";
     this.Description = "Remove a file being hosted.";
     try
     {
         this.Parameters = new List <MenuCommandParameter> {
             new MenuCommandParameter {
                 Name = "HostPath"
             }
         };
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #29
0
 public MenuCommandGruntsHide() : base()
 {
     this.Name        = "Hide";
     this.Description = "Hide an inactive Grunt.";
     try
     {
         this.Parameters = new List <MenuCommandParameter> {
             new MenuCommandParameter {
                 Name = "Grunt Name"
             }
         };
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
예제 #30
0
 public MenuCommandCredentialsTicket() : base()
 {
     this.Name        = "Ticket";
     this.Description = "Display full Base64EncodedTicket";
     try
     {
         this.Parameters = new List <MenuCommandParameter> {
             new MenuCommandParameter {
                 Name = "ID"
             }
         };
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }