Example #1
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            BinaryLauncher binaryLauncher = ((BinaryLauncherMenuItem)menuItem).binaryLauncher;

            string[] commands = UserInput.Split(" ");
            if (commands.Length != 3 || commands[0].ToLower() != "set")
            {
                menuItem.PrintInvalidOptionError(UserInput);
            }
            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] + "\"");
                    }
                    else
                    {
                        binaryLauncher.ListenerId = listener.Id;
                    }
                }
                else if (commands[1].ToLower() == "dotnetframeworkversion")
                {
                    if (commands[2].ToLower().Contains("35") || commands[2].ToLower().Contains("3.5"))
                    {
                        binaryLauncher.DotNetFrameworkVersion = DotNetVersion.Net35;
                    }
                    else if (commands[2].ToLower().Contains("40") || commands[2].ToLower().Contains("4.0"))
                    {
                        binaryLauncher.DotNetFrameworkVersion = DotNetVersion.Net40;
                    }
                }
                else if (commands[1].ToLower() == "delay")
                {
                    int.TryParse(commands[2], out int n);
                    binaryLauncher.Delay = n;
                }
                else if (commands[1].ToLower() == "jitter")
                {
                    int.TryParse(commands[2], out int n);
                    binaryLauncher.Jitter = n;
                }
                else if (commands[1].ToLower() == "connectattempts")
                {
                    int.TryParse(commands[2], out int n);
                    binaryLauncher.ConnectAttempts = n;
                }
                else if (commands[1].ToLower() == "launcherstring")
                {
                    binaryLauncher.LauncherString = commands[2];
                }
                this.CovenantClient.ApiLaunchersBinaryPut(binaryLauncher);
            }
            else
            {
                menuItem.PrintInvalidOptionError(UserInput);
            }
        }
Example #2
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            BinaryLauncherMenuItem binaryLauncherMenuItem = (BinaryLauncherMenuItem)menuItem;

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

            fileToHost = this.CovenantClient.ApiListenersByIdHostedfilesPost(listener.Id ?? default, fileToHost);
            binaryLauncherMenuItem.binaryLauncher = this.CovenantClient.ApiLaunchersBinaryHostedPost(fileToHost);

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

            EliteConsole.PrintFormattedHighlightLine("BinaryLauncher hosted at: " + hostedLocation);
        }
Example #3
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);
     }
 }
Example #4
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            menuItem.Refresh();
            ListenersMenuItem listenersMenu = ((ListenersMenuItem)menuItem);

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

            Listener listener = listenersMenu.Listeners.FirstOrDefault(L => L.Name.ToLower() == commands[1]);

            if (listener == null)
            {
                EliteConsole.PrintFormattedErrorLine("Listener with name: " + commands[1] + " does not exist.");
                menuItem.PrintInvalidOptionError(UserInput);
            }
            else if (listenersMenu.Listeners.Where(L => L.Name.ToLower() == commands[2].ToLower()).Any())
            {
                EliteConsole.PrintFormattedErrorLine("Listener with name: " + commands[2] + " already exists.");
                menuItem.PrintInvalidOptionError(UserInput);
            }
            else
            {
                listener.Name = commands[2];
                this.CovenantClient.ApiListenersPut(listener);
            }
        }
Example #5
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);
            }
        }
Example #6
0
        public override bool ValidateMenuParameters(string[] parameters, bool forwardEntrance = true)
        {
            if (forwardEntrance)
            {
                if (parameters.Length != 1)
                {
                    EliteConsole.PrintFormattedErrorLine("Must specify a ListenerName.");
                    EliteConsole.PrintFormattedErrorLine("Usage: Interact <listener_name>");
                    return(false);
                }
                string   listenerName      = parameters[0].ToLower();
                Listener specifiedListener = CovenantClient.ApiListenersGet().FirstOrDefault(L => L.Name.ToLower() == listenerName);
                if (specifiedListener == null)
                {
                    EliteConsole.PrintFormattedErrorLine("Specified invalid ListenerName: " + listenerName);
                    EliteConsole.PrintFormattedErrorLine("Usage: Interact <listener_name>");
                    return(false);
                }
                this.listener     = specifiedListener;
                this.listenerType = this.CovenantClient.ApiListenersTypesByIdGet(this.listener.ListenerTypeId ?? default);
                ((HostedFilesMenuItem)this.MenuOptions.FirstOrDefault(MO => MO.MenuTitle == "HostedFiles")).Listener = listener;

                this.MenuTitle = listenerName;
            }
            this.Refresh();
            return(true);
        }
Example #7
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);
        }
Example #8
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            Listener listener = ((HostedFilesMenuItem)menuItem).Listener;

            string[] commands = UserInput.Split(" ");
            if (commands.Length != 3 || commands[0].ToLower() != "host")
            {
                menuItem.PrintInvalidOptionError(UserInput);
            }
            else
            {
                FileInfo file = new FileInfo(commands[1]);
                if (!file.Exists)
                {
                    menuItem.PrintInvalidOptionError(UserInput);
                    EliteConsole.PrintFormattedErrorLine("File: \"" + commands[1] + "\" does not exist on the local system.");
                    return;
                }
                HostedFile hostedFile = new HostedFile
                {
                    ListenerId = listener.Id,
                    Path       = commands[2],
                    Content    = Convert.ToBase64String(File.ReadAllBytes(commands[1]))
                };
                this.CovenantClient.ApiListenersByIdHostedfilesPost(listener.Id ?? default, hostedFile);
            }
        }
Example #9
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);
            }
        }
Example #10
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            ListenerInteractMenuItem listenerInteractMenuItem = (ListenerInteractMenuItem)menuItem;

            // TODO: error if http lsitener already on this port
            if (listenerInteractMenuItem.listener.Status == ListenerStatus.Active)
            {
                EliteConsole.PrintFormattedErrorLine("Listener: " + listenerInteractMenuItem.listener.Name + " is already active.");
                menuItem.PrintInvalidOptionError(UserInput);
            }
            else
            {
                switch (listenerInteractMenuItem.listenerType.Name)
                {
                case "HTTP":
                    HttpListener httpListener = this.CovenantClient.ApiListenersHttpByIdGet(listenerInteractMenuItem.listener.Id ?? default);
                    httpListener.Status = ListenerStatus.Active;
                    this.CovenantClient.ApiListenersHttpPut(httpListener);
                    break;
                }
                listenerInteractMenuItem.Refresh();
                // EliteConsole.PrintFormattedHighlightLine("Started Listener: " + listenerInteractMenuItem.listener.Name);
                EventModel eventModel = new EventModel {
                    Message = "Started Listener: " + listenerInteractMenuItem.listener.Name,
                    Level   = EventLevel.Highlight,
                    Context = "*"
                };
                eventModel = this.CovenantClient.ApiEventsPost(eventModel);
                this.EventPrinter.PrintEvent(eventModel);
            }
        }
Example #11
0
        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);
            }
        }
Example #12
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            MSBuildLauncherMenuItem msbuildMenuItem = (MSBuildLauncherMenuItem)menuItem;

            string[] commands = UserInput.Split(" ");
            if (commands.Length < 1 || commands.Length > 2 || commands[0].ToLower() != "code")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            else if (commands.Length == 2 && (!new List <string> {
                "stager", "gruntstager", "xml"
            }.Contains(commands[1].ToLower())))
            {
                EliteConsole.PrintFormattedErrorLine("Type must be one of: \"Stager\"\\\"GruntStager\" or \"XML\"");
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            msbuildMenuItem.Refresh();
            if (msbuildMenuItem.msbuildLauncher.LauncherString == "")
            {
                msbuildMenuItem.CovenantClient.ApiLaunchersMsbuildPost();
                msbuildMenuItem.Refresh();
                EliteConsole.PrintFormattedHighlightLine("Generated MSBuildLauncher: " + msbuildMenuItem.msbuildLauncher.LauncherString);
            }
            if (commands.Length == 1 || (commands.Length == 2 && (commands[1].ToLower() == "stager" || commands[1].ToLower() == "gruntstager")))
            {
                EliteConsole.PrintInfoLine(msbuildMenuItem.msbuildLauncher.StagerCode);
            }
            else if (commands.Length == 2 && commands[1].ToLower() == "xml")
            {
                EliteConsole.PrintInfoLine(msbuildMenuItem.msbuildLauncher.DiskCode);
            }
        }
Example #13
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);
     }
 }
Example #14
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            UsersMenuItem usersMenuItem = (UsersMenuItem)menuItem;

            usersMenuItem.Refresh();
            string[] commands = UserInput.Split(" ");
            if (commands.Length != 2 || commands[0].ToLower() != "delete")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                EliteConsole.PrintFormattedErrorLine("Usage: Delete <username>");
                return;
            }

            CovenantUser user = usersMenuItem.Users.FirstOrDefault(U => U.UserName == commands[1]);

            if (user != null)
            {
                EliteConsole.PrintFormattedWarning("Delete user: \"" + commands[1] + "\"? [y/N] ");
                string input = EliteConsole.Read();
                if (input.ToLower().StartsWith("y"))
                {
                    this.CovenantClient.ApiUsersByUidDelete(user.Id);
                }
            }
            else
            {
                EliteConsole.PrintFormattedErrorLine("User: \"" + commands[1] + "\" does not exist.");
            }
        }
Example #15
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);
                }
            }
        }
Example #16
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);
     }
 }
Example #17
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            Regsvr32LauncherMenuItem regsvr32MenuItem = (Regsvr32LauncherMenuItem)menuItem;

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

            fileToHost = this.CovenantClient.ApiListenersByIdHostedfilesPost(listener.Id ?? default, fileToHost);
            regsvr32MenuItem.regsvr32Launcher = this.CovenantClient.ApiLaunchersRegsvr32HostedPost(fileToHost);

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

            EliteConsole.PrintFormattedHighlightLine("Regsvr32Launcher hosted at: " + hostedLocation);
            EliteConsole.PrintFormattedInfoLine("Launcher: " + regsvr32MenuItem.regsvr32Launcher.LauncherString);
        }
Example #18
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);
            }
        }
Example #19
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);
     }
 }
Example #20
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            GruntsMenuItem gruntsMenuItem = (GruntsMenuItem)menuItem;

            string[] commands = UserInput.Split(" ");
            if (commands.Length != 2 || !commands[0].Equals("unhide", StringComparison.OrdinalIgnoreCase))
            {
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            if (commands[1].Equals("all", StringComparison.OrdinalIgnoreCase))
            {
                gruntsMenuItem.HiddenGruntNames.Clear();
                return;
            }
            string gruntName = gruntsMenuItem.HiddenGruntNames.FirstOrDefault(HGN => HGN == commands[1]);

            if (string.IsNullOrEmpty(gruntName))
            {
                EliteConsole.PrintFormattedErrorLine("Invalid GruntName: \"" + commands[1] + "\"");
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            gruntsMenuItem.HiddenGruntNames.Remove(gruntName);
        }
Example #21
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);
     }
 }
Example #22
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);
     }
 }
Example #23
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);
        }
Example #24
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            menuItem.Refresh();
            GruntsMenuItem gruntsMenu = ((GruntsMenuItem)menuItem);

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

            Grunt grunt = gruntsMenu.Grunts.FirstOrDefault(G => G.Name.ToLower() == commands[1]);

            if (grunt == null)
            {
                EliteConsole.PrintFormattedErrorLine("Grunt with name: " + commands[1] + " does not exist.");
                menuItem.PrintInvalidOptionError(UserInput);
            }
            else if (gruntsMenu.Grunts.Where(G => G.Name.ToLower() == commands[2].ToLower()).Any())
            {
                EliteConsole.PrintFormattedErrorLine("Grunt with name: " + commands[2] + " already exists.");
                menuItem.PrintInvalidOptionError(UserInput);
            }
            else
            {
                grunt.Name = commands[2];
                this.CovenantClient.ApiGruntsPut(grunt);
            }
        }
Example #25
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            GruntsMenuItem gruntsMenuItem = (GruntsMenuItem)menuItem;

            string[] commands = UserInput.Split(" ");
            if (commands.Length != 2 || commands[0].ToLower() != "hide")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            if (commands[1].ToLower() == "all")
            {
                gruntsMenuItem.HiddenGruntNames.AddRange(gruntsMenuItem.Grunts.Select(G => G.Name));
            }
            Grunt grunt = gruntsMenuItem.Grunts.FirstOrDefault(G => G.Name == commands[1]);

            if (grunt == null)
            {
                EliteConsole.PrintFormattedErrorLine("Invalid GruntName: \"" + commands[1] + "\"");
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            EliteConsole.PrintFormattedWarning("Hide Grunt: " + commands[1] + "? [y/N] ");
            string input = EliteConsole.Read();

            if (!input.ToLower().StartsWith("y"))
            {
                return;
            }
            gruntsMenuItem.HiddenGruntNames.Add(grunt.Name);
        }
Example #26
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            GruntsMenuItem gruntsMenuItem = (GruntsMenuItem)menuItem;

            string[] commands = UserInput.Split(" ");
            if (commands.Length != 2 || commands[0].ToLower() != "kill")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            if (commands[1].ToLower() == "all")
            {
                EliteConsole.PrintFormattedWarning("Kill all Grunts? [y/N] ");
                string input1 = EliteConsole.Read();
                if (!input1.ToLower().StartsWith("y"))
                {
                    return;
                }
                gruntsMenuItem.HiddenGruntNames.AddRange(gruntsMenuItem.Grunts.Select(G => G.Name));
                foreach (Grunt g in gruntsMenuItem.Grunts)
                {
                    GruntTasking gt = new GruntTasking {
                        Type = GruntTaskingType.Kill, GruntId = g.Id
                    };
                    this.CovenantClient.ApiGruntsByIdTaskingsPost(g.Id ?? default, gt);
                }
            }
            Grunt grunt = gruntsMenuItem.Grunts.FirstOrDefault(G => G.Name == commands[1]);

            if (grunt == null)
            {
                EliteConsole.PrintFormattedErrorLine("Invalid GruntName: \"" + commands[1] + "\"");
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            EliteConsole.PrintFormattedWarning("Kill Grunt: " + commands[1] + "? [y/N] ");
            string input2 = EliteConsole.Read();

            if (!input2.ToLower().StartsWith("y"))
            {
                return;
            }
            GruntTasking gruntTasking = new GruntTasking {
                Type = GruntTaskingType.Kill, GruntId = grunt.Id
            };

            this.CovenantClient.ApiGruntsByIdTaskingsPost(grunt.Id ?? default, gruntTasking);
        }
 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);
     }
 }
Example #28
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);
            }
        }
Example #29
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;
                }
                this.CovenantClient.ApiLaunchersMshtaPost();
                WmicLauncher launcher = ((WmicLauncherMenuItem)menuItem).WmicLauncher;
                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;
                }
                if (!commands[1].EndsWith(".xsl", StringComparison.Ordinal))
                {
                    EliteConsole.PrintFormattedErrorLine("WmicLaunchers must end with the extension: .xsl");
                    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.ApiLaunchersWmicHostedPost(fileToHost);

                Uri hostedLocation = new Uri(listener.Url + fileToHost.Path);
                EliteConsole.PrintFormattedHighlightLine("WmicLauncher hosted at: " + hostedLocation);
                EliteConsole.PrintFormattedInfoLine("Launcher (cmd.exe):        " + launcher.LauncherString);
                EliteConsole.PrintFormattedInfoLine("Launcher (powershell.exe): " + launcher.LauncherString.Replace("\"", "`\""));
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
Example #30
0
        public override bool ValidateMenuParameters(string[] parameters, bool forwardEntrance = true)
        {
            try
            {
                if (forwardEntrance)
                {
                    if (parameters.Length != 1)
                    {
                        EliteConsole.PrintFormattedErrorLine("Must specify a Task Name.");
                        EliteConsole.PrintFormattedErrorLine("Usage: Task <task_name>");
                        return(false);
                    }
                    GruntTask gruntTask = this.CovenantClient.ApiGrunttasksByTasknameGet(parameters[0]);
                    if (gruntTask == null)
                    {
                        EliteConsole.PrintFormattedErrorLine("Specified invalid Task Name: " + parameters[0]);
                        EliteConsole.PrintFormattedErrorLine("Usage: Task <task_name>");
                        return(false);
                    }
                    this.Task      = gruntTask;
                    this.MenuTitle = this.Task.Name;
                }
                MenuCommand setCommand = GetTaskMenuSetCommand(this.Task.Name, CovenantClient);
                setCommand.Parameters.FirstOrDefault(P => P.Name == "Option").Values = this.Task.Options
                                                                                       .Select(TO => new MenuCommandParameterValue {
                    Value = TO.Name
                })
                                                                                       .ToList();
                this.AdditionalOptions[AdditionalOptions.IndexOf(
                                           this.AdditionalOptions.FirstOrDefault(MC => MC.Name == "Set")
                                           )] = setCommand;
                AdditionalOptions[AdditionalOptions.IndexOf(
                                      this.AdditionalOptions.FirstOrDefault(MC => MC.Name == "Unset")
                                      )] = new MenuCommandGenericUnset(setCommand.Parameters.FirstOrDefault(P => P.Name == "Option").Values);

                this.Refresh();
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
            return(true);
        }