Пример #1
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();
                CscriptLauncher launcher = ((CscriptLauncherMenuItem)menuItem).CscriptLauncher;
                if (launcher.LauncherString == "")
                {
                    this.CovenantClient.ApiLaunchersBinaryPost();
                    menuItem.Refresh();
                    EliteConsole.PrintFormattedHighlightLine("Generated CscriptLauncher: " + 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 CscriptLauncher to: \"" + OutputFilePath + "\"");
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
Пример #2
0
        public override void Refresh()
        {
            try
            {
                this.CscriptLauncher = this.CovenantClient.ApiLaunchersCscriptGet();

                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);
            }
        }
Пример #3
0
        public ActionResult <CscriptLauncher> PutCscriptLauncher([FromBody] CscriptLauncher cscriptLauncher)
        {
            CscriptLauncher launcher = (CscriptLauncher)_context.Launchers.FirstOrDefault(S => S.Type == Launcher.LauncherType.Cscript);

            if (launcher == null || launcher.Id != cscriptLauncher.Id)
            {
                return(NotFound());
            }
            Listener listener = _context.Listeners.FirstOrDefault(L => L.Id == cscriptLauncher.ListenerId);

            if (listener != null)
            {
                launcher.ListenerId = cscriptLauncher.ListenerId;
            }
            launcher.Delay                  = cscriptLauncher.Delay;
            launcher.Jitter                 = cscriptLauncher.Jitter;
            launcher.ConnectAttempts        = cscriptLauncher.ConnectAttempts;
            launcher.ScriptLanguage         = cscriptLauncher.ScriptLanguage;
            launcher.DotNetFrameworkVersion = cscriptLauncher.DotNetFrameworkVersion;
            launcher.LauncherString         = cscriptLauncher.LauncherString;
            launcher.DiskCode               = cscriptLauncher.DiskCode;
            launcher.StagerCode             = cscriptLauncher.StagerCode;

            _context.Launchers.Update(launcher);
            _context.SaveChanges();

            return(Ok(launcher));
        }
Пример #4
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            CscriptLauncherMenuItem cscriptMenuItem = (CscriptLauncherMenuItem)menuItem;

            cscriptMenuItem.cscriptLauncher = this.CovenantClient.ApiLaunchersCscriptGet();
            CscriptLauncher launcher = cscriptMenuItem.cscriptLauncher;
            Listener        listener = this.CovenantClient.ApiListenersGet().FirstOrDefault(L => L.Id == cscriptMenuItem.cscriptLauncher.ListenerId);

            EliteConsoleMenu menu = new EliteConsoleMenu(EliteConsoleMenu.EliteConsoleMenuType.Parameter, "CscriptLauncher");

            menu.Rows.Add(new List <string> {
                "Name:", launcher.Name
            });
            menu.Rows.Add(new List <string> {
                "Description:", launcher.Description
            });
            menu.Rows.Add(new List <string> {
                "ListenerName:", listener == null ? "" : listener.Name
            });
            menu.Rows.Add(new List <string> {
                "ScriptLanguage:", launcher.ScriptLanguage.ToString()
            });
            menu.Rows.Add(new List <string> {
                "DotNetFramework:", launcher.DotNetFrameworkVersion.ToString()
            });
            menu.Rows.Add(new List <string> {
                "Delay:", (launcher.Delay ?? default).ToString()
            });
Пример #5
0
        public ActionResult <CscriptLauncher> GetCscriptLauncher()
        {
            CscriptLauncher launcher = (CscriptLauncher)_context.Launchers.FirstOrDefault(S => S.Type == Launcher.LauncherType.Cscript);

            if (launcher == null)
            {
                return(NotFound());
            }
            return(Ok(launcher));
        }
Пример #6
0
 public override void Refresh()
 {
     this.cscriptLauncher = this.CovenantClient.ApiLaunchersCscriptGet();
     this.AdditionalOptions.FirstOrDefault(AO => AO.Name.ToLower() == "set").Parameters
     .FirstOrDefault(P => P.Name.ToLower() == "option").Values
     .FirstOrDefault(V => V.Value.ToLower() == "listenername")
     .NextValueSuggestions = this.CovenantClient.ApiListenersGet()
                             .Where(L => L.Status == ListenerStatus.Active)
                             .Select(L => L.Name).ToList();
     this.SetupMenuAutoComplete();
 }
Пример #7
0
        // GET: /launcher/cscriptdownload
        public async Task <IActionResult> CscriptDownload()
        {
            try
            {
                CscriptLauncher cscriptLauncher = await _context.GetCscriptLauncher();

                return(File(Common.CovenantEncoding.GetBytes(cscriptLauncher.DiskCode), MediaTypeNames.Text.Plain, "GruntStager.js"));
            }
            catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(RedirectToAction(nameof(Create), new { id = "Cscript" }));
            }
        }
Пример #8
0
 public override void Command(MenuItem menuItem, string UserInput)
 {
     try
     {
         this.CovenantClient.ApiLaunchersCscriptPost();
         menuItem.Refresh();
         CscriptLauncher launcher = ((CscriptLauncherMenuItem)menuItem).CscriptLauncher;
         EliteConsole.PrintFormattedHighlightLine("Generated CscriptLauncher: " + launcher.LauncherString);
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
Пример #9
0
 public async Task <ActionResult <CscriptLauncher> > EditCscriptLauncher([FromBody] CscriptLauncher launcher)
 {
     try
     {
         return(await _service.EditCscriptLauncher(launcher));
     }
     catch (ControllerNotFoundException e)
     {
         return(NotFound(e.Message));
     }
     catch (ControllerBadRequestException e)
     {
         return(BadRequest(e.Message));
     }
 }
Пример #10
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            try
            {
                menuItem.Refresh();
                CscriptLauncher launcher = ((CscriptLauncherMenuItem)menuItem).CscriptLauncher;
                Listener        listener = this.CovenantClient.ApiListenersGet().FirstOrDefault(L => L.Id == launcher.ListenerId);

                EliteConsoleMenu menu = new EliteConsoleMenu(EliteConsoleMenu.EliteConsoleMenuType.Parameter, "CscriptLauncher");
                menu.Rows.Add(new List <string> {
                    "Name:", launcher.Name
                });
                menu.Rows.Add(new List <string> {
                    "Description:", launcher.Description
                });
                menu.Rows.Add(new List <string> {
                    "ListenerName:", listener == null ? "" : listener.Name
                });
                menu.Rows.Add(new List <string> {
                    "CommType:", launcher.CommType.ToString()
                });
                if (launcher.CommType == CommunicationType.HTTP)
                {
                    menu.Rows.Add(new List <string> {
                        "  ValidateCert:", launcher.ValidateCert.ToString()
                    });
                    menu.Rows.Add(new List <string> {
                        "  UseCertPinning:", launcher.UseCertPinning.ToString()
                    });
                }
                else if (launcher.CommType == CommunicationType.SMB)
                {
                    menu.Rows.Add(new List <string> {
                        "  SMBPipeName:", launcher.SmbPipeName
                    });
                }
                menu.Rows.Add(new List <string> {
                    "DotNetFramework:", launcher.DotNetFrameworkVersion == DotNetVersion.Net35 ? "v3.5" : "v4.0"
                });
                menu.Rows.Add(new List <string> {
                    "ScriptLanguage:", launcher.ScriptLanguage.ToString()
                });
                menu.Rows.Add(new List <string> {
                    "Delay:", (launcher.Delay ?? default).ToString()
                });
                menu.Rows.Add(new List <string> {
                    "JitterPercent:", (launcher.JitterPercent ?? default).ToString()
                });
Пример #11
0
        public CscriptLauncherMenuItem(CovenantAPI CovenantClient, EventPrinter EventPrinter) : base(CovenantClient, EventPrinter)
        {
            this.cscriptLauncher = CovenantClient.ApiLaunchersCscriptGet();
            this.MenuTitle       = cscriptLauncher.Name;
            this.MenuDescription = cscriptLauncher.Description;

            this.AdditionalOptions.Add(new MenuCommandCscriptLauncherShow(CovenantClient));
            this.AdditionalOptions.Add(new MenuCommandCscriptLauncherGenerate(CovenantClient));
            this.AdditionalOptions.Add(new MenuCommandCscriptLauncherCode());
            this.AdditionalOptions.Add(new MenuCommandCscriptLauncherHost(CovenantClient));
            this.AdditionalOptions.Add(new MenuCommandCscriptLauncherWriteFile());
            var setCommand = new MenuCommandCscriptLauncherSet(CovenantClient);

            this.AdditionalOptions.Add(setCommand);
            this.AdditionalOptions.Add(new MenuCommandGenericUnset(setCommand.Parameters.FirstOrDefault(P => P.Name == "Option").Values));

            this.Refresh();
        }
Пример #12
0
        // POST: /launcher/hostcscript
        public async Task <IActionResult> HostCscript(HostedFile file)
        {
            try
            {
                CscriptLauncher launcher = await _context.GenerateCscriptLauncher();

                HttpListener listener = await _context.GetHttpListener(file.ListenerId);

                file = await _context.CreateHostedFile(listener.Id, file);

                launcher = await _context.GenerateCscriptHostedLauncher(file);

                return(RedirectToAction(nameof(Create), new { id = launcher.Name }));
            }
            catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(RedirectToAction(nameof(Create), new { id = "Cscript" }));
            }
        }
Пример #13
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.ApiLaunchersCscriptPost();
                menuItem.Refresh();
                CscriptLauncher launcher = ((CscriptLauncherMenuItem)menuItem).CscriptLauncher;
                HttpListener    listener = this.CovenantClient.ApiListenersHttpByIdGet(launcher.ListenerId ?? default);
                if (listener == null)
                {
                    EliteConsole.PrintFormattedErrorLine("Can only host a file on a valid HttpListener.");
                    menuItem.PrintInvalidOptionError(UserInput);
                    return;
                }
                HostedFile fileToHost = new HostedFile
                {
                    ListenerId = listener.Id,
                    Path       = commands[1],
                    Content    = Convert.ToBase64String(Common.CovenantEncoding.GetBytes(launcher.DiskCode))
                };

                fileToHost = this.CovenantClient.ApiListenersByIdHostedfilesPost(listener.Id ?? default, fileToHost);
                launcher   = this.CovenantClient.ApiLaunchersCscriptHostedPost(fileToHost);

                Uri hostedLocation = new Uri(listener.Url + fileToHost.Path);
                EliteConsole.PrintFormattedHighlightLine("CscriptLauncher hosted at: " + hostedLocation);
                EliteConsole.PrintFormattedWarningLine("cscript.exe cannot execute remotely hosted files, the payload must first be written to disk");
                EliteConsole.PrintFormattedInfoLine("Launcher: " + launcher.LauncherString);
            }
            catch (HttpOperationException e)
            {
                EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
            }
        }
Пример #14
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 && (!new List <string> {
             "gruntstager", "scriptlet"
         }.Contains(commands[1], StringComparer.OrdinalIgnoreCase)))
         {
             EliteConsole.PrintFormattedErrorLine("Type must be one of: \"GruntStager\" or \"Scriptlet\"");
             menuItem.PrintInvalidOptionError(UserInput);
             return;
         }
         CscriptLauncher launcher = ((CscriptLauncherMenuItem)menuItem).CscriptLauncher;
         if (launcher.LauncherString == "")
         {
             this.CovenantClient.ApiLaunchersCscriptPost();
             menuItem.Refresh();
             launcher = ((CscriptLauncherMenuItem)menuItem).CscriptLauncher;
             EliteConsole.PrintFormattedHighlightLine("Generated CscriptLauncher: " + launcher.LauncherString);
         }
         if (commands.Length == 1 || (commands.Length == 2 && commands[1].Equals("gruntstager", StringComparison.OrdinalIgnoreCase)))
         {
             EliteConsole.PrintInfoLine(launcher.StagerCode);
         }
         else if (commands.Length == 2 && commands[1].Equals("scriptlet", StringComparison.OrdinalIgnoreCase))
         {
             EliteConsole.PrintInfoLine(launcher.DiskCode);
         }
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
Пример #15
0
        public CscriptLauncherMenuItem(CovenantAPI CovenantClient) : base(CovenantClient)
        {
            try
            {
                this.CscriptLauncher = CovenantClient.ApiLaunchersCscriptGet();
                this.MenuTitle       = CscriptLauncher.Name;
                this.MenuDescription = CscriptLauncher.Description;

                this.AdditionalOptions.Add(new MenuCommandCscriptLauncherShow(CovenantClient));
                this.AdditionalOptions.Add(new MenuCommandCscriptLauncherGenerate(CovenantClient));
                this.AdditionalOptions.Add(new MenuCommandCscriptLauncherCode(CovenantClient));
                this.AdditionalOptions.Add(new MenuCommandCscriptLauncherHost(CovenantClient));
                this.AdditionalOptions.Add(new MenuCommandCscriptLauncherWriteFile(CovenantClient));
                var setCommand = new MenuCommandCscriptLauncherSet(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);
            }
        }
Пример #16
0
        public async Task <IActionResult> Cscript(CscriptLauncher launcher)
        {
            try
            {
                launcher = await _context.EditCscriptLauncher(launcher);

                launcher = await _context.GenerateCscriptLauncher();

                ViewBag.Launcher  = launcher;
                ViewBag.Listeners = await _context.GetListeners();

                return(RedirectToAction(nameof(Create), new { id = launcher.Name }));
            }
            catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                ViewBag.Launcher  = launcher;
                ViewBag.Listeners = await _context.GetListeners();

                return(RedirectToAction(nameof(Create), new { id = launcher.Name }));
            }
        }
Пример #17
0
        public ActionResult <CscriptLauncher> GenerateCscriptHostedFileLauncher(HostedFile hostedFile)
        {
            CscriptLauncher launcher = (CscriptLauncher)_context.Launchers.FirstOrDefault(S => S.Type == Launcher.LauncherType.Cscript);

            if (launcher == null)
            {
                return(NotFound());
            }
            Listener   listener        = _context.Listeners.FirstOrDefault(S => S.Id == hostedFile.ListenerId);
            HostedFile savedHostedFile = _context.HostedFiles.FirstOrDefault(HF => HF.Id == hostedFile.Id);

            if (listener == null || savedHostedFile == null)
            {
                return(NotFound());
            }
            string hostedLauncher = launcher.GetHostedLauncher(listener, savedHostedFile);

            _context.Launchers.Update(launcher);
            _context.SaveChanges();

            return(Ok(launcher));
        }
Пример #18
0
        public ActionResult <CscriptLauncher> GenerateCscriptLauncher()
        {
            CscriptLauncher launcher = (CscriptLauncher)_context.Launchers.FirstOrDefault(S => S.Type == Launcher.LauncherType.Cscript);

            if (launcher == null)
            {
                return(NotFound());
            }
            Listener listener = _context.Listeners.FirstOrDefault(S => S.Id == launcher.ListenerId);

            if (listener == null)
            {
                return(NotFound());
            }
            HttpProfile profile = (HttpProfile)_context.Profiles.FirstOrDefault(P => P.Id == listener.ProfileId);

            if (profile == null)
            {
                return(NotFound());
            }

            Grunt grunt = new Grunt
            {
                ListenerId        = listener.Id,
                CovenantIPAddress = listener.BindAddress,
                Delay             = launcher.Delay,
                Jitter            = launcher.Jitter,
                ConnectAttempts   = launcher.ConnectAttempts
            };

            _context.Grunts.Add(grunt);
            _context.SaveChanges();
            launcher.GetLauncher(listener, grunt, profile);
            _context.Launchers.Update(launcher);
            _context.SaveChanges();

            return(Ok(launcher));
        }
Пример #19
0
 public Task <CscriptLauncher> EditCscriptLauncher(CscriptLauncher launcher)
 {
     return(_connection.InvokeAsync <CscriptLauncher>("EditCscriptLauncher", launcher));
 }
Пример #20
0
 public override async void Command(MenuItem menuItem, string UserInput)
 {
     try
     {
         List <string> commands = Utilities.ParseParameters(UserInput);
         if (commands.Count() != 3 || !commands[0].Equals(this.Name, StringComparison.OrdinalIgnoreCase))
         {
             menuItem.PrintInvalidOptionError(UserInput);
             return;
         }
         CscriptLauncher launcher = ((CscriptLauncherMenuItem)menuItem).CscriptLauncher;
         if (this.Parameters.FirstOrDefault(P => P.Name == "Option").Values.Select(V => V.Value).Contains(commands[1], StringComparer.OrdinalIgnoreCase))
         {
             if (commands[1].Equals("listenername", StringComparison.OrdinalIgnoreCase))
             {
                 Listener listener = this.CovenantClient.ApiListenersGet().FirstOrDefault(L => L.Name == commands[2]);
                 if (listener == null || listener.Name != commands[2])
                 {
                     EliteConsole.PrintFormattedErrorLine("Invalid ListenerName: \"" + commands[2] + "\"");
                     menuItem.PrintInvalidOptionError(UserInput);
                     return;
                 }
                 launcher.ListenerId = listener.Id;
             }
             else if (commands[1].Equals("dotnetframeworkversion", StringComparison.OrdinalIgnoreCase))
             {
                 if (commands[2].Contains("35", StringComparison.OrdinalIgnoreCase) || commands[2].Contains("3.5", StringComparison.OrdinalIgnoreCase))
                 {
                     launcher.DotNetFrameworkVersion = DotNetVersion.Net35;
                 }
                 else if (commands[2].Contains("40", StringComparison.OrdinalIgnoreCase) || commands[2].Contains("4.0", StringComparison.OrdinalIgnoreCase))
                 {
                     launcher.DotNetFrameworkVersion = DotNetVersion.Net40;
                 }
                 else
                 {
                     EliteConsole.PrintFormattedErrorLine("Invalid DotNetFrameworkVersion \"" + commands[2] + "\". Valid options are: v3.5, v4.0");
                     menuItem.PrintInvalidOptionError(UserInput);
                     return;
                 }
             }
             else if (commands[1].Equals("commtype", StringComparison.OrdinalIgnoreCase))
             {
                 if (commands[2].Equals("smb", StringComparison.OrdinalIgnoreCase))
                 {
                     launcher.CommType = CommunicationType.SMB;
                 }
                 else
                 {
                     launcher.CommType = CommunicationType.HTTP;
                 }
             }
             else if (commands[1].Equals("validatecert", StringComparison.OrdinalIgnoreCase))
             {
                 bool parsed = bool.TryParse(commands[2], out bool validate);
                 if (parsed)
                 {
                     launcher.ValidateCert = validate;
                 }
                 else
                 {
                     menuItem.PrintInvalidOptionError(UserInput);
                     return;
                 }
             }
             else if (commands[1].Equals("usecertpinning", StringComparison.OrdinalIgnoreCase))
             {
                 bool parsed = bool.TryParse(commands[2], out bool pin);
                 if (parsed)
                 {
                     launcher.UseCertPinning = pin;
                 }
                 else
                 {
                     menuItem.PrintInvalidOptionError(UserInput);
                     return;
                 }
             }
             else if (commands[1].Equals("smbpipename", StringComparison.OrdinalIgnoreCase))
             {
                 launcher.SmbPipeName = commands[2];
             }
             else if (commands[1].Equals("scriptlanguage", StringComparison.OrdinalIgnoreCase))
             {
                 if (commands[2].StartsWith("js", StringComparison.OrdinalIgnoreCase))
                 {
                     launcher.ScriptLanguage = ScriptingLanguage.JScript;
                 }
                 else if (commands[2].StartsWith("vb", StringComparison.OrdinalIgnoreCase))
                 {
                     launcher.ScriptLanguage = ScriptingLanguage.VBScript;
                 }
                 else
                 {
                     EliteConsole.PrintFormattedErrorLine("Invalid ScriptLanguage \"" + commands[2] + "\". Valid options are: JScript, VBScript");
                     menuItem.PrintInvalidOptionError(UserInput);
                     return;
                 }
             }
             else if (commands[1].Equals("delay", StringComparison.OrdinalIgnoreCase))
             {
                 int.TryParse(commands[2], out int n);
                 launcher.Delay = n;
             }
             else if (commands[1].Equals("jitterpercent", StringComparison.OrdinalIgnoreCase))
             {
                 int.TryParse(commands[2], out int n);
                 launcher.JitterPercent = n;
             }
             else if (commands[1].Equals("connectattempts", StringComparison.OrdinalIgnoreCase))
             {
                 int.TryParse(commands[2], out int n);
                 launcher.ConnectAttempts = n;
             }
             else if (commands[1].Equals("killdate", StringComparison.OrdinalIgnoreCase))
             {
                 DateTime.TryParse(commands[2], out DateTime result);
                 launcher.KillDate = result;
             }
             else if (commands[1].Equals("launcherstring", StringComparison.OrdinalIgnoreCase))
             {
                 launcher.LauncherString = commands[2];
             }
             await this.CovenantClient.ApiLaunchersCscriptPutAsync(launcher);
         }
         else
         {
             menuItem.PrintInvalidOptionError(UserInput);
         }
     }
     catch (HttpOperationException e)
     {
         EliteConsole.PrintFormattedWarningLine("CovenantException: " + e.Response.Content);
     }
 }
Пример #21
0
        public override void Command(MenuItem menuItem, string UserInput)
        {
            CscriptLauncher cscriptLauncher = ((CscriptLauncherMenuItem)menuItem).cscriptLauncher;

            string[] commands = UserInput.Split(" ");
            if (commands.Length < 3 || commands[0].ToLower() != "set")
            {
                menuItem.PrintInvalidOptionError(UserInput);
                return;
            }
            else if (this.Parameters.FirstOrDefault(P => P.Name == "Option").Values.Select(V => V.Value.ToLower()).Contains(commands[1].ToLower()))
            {
                if (commands[1].ToLower() == "listenername")
                {
                    Listener listener = this.CovenantClient.ApiListenersGet().FirstOrDefault(L => L.Name == commands[2]);
                    if (listener == null || listener.Name != commands[2])
                    {
                        EliteConsole.PrintFormattedErrorLine("Invalid ListenerName: \"" + commands[2] + "\"");
                        menuItem.PrintInvalidOptionError(UserInput);
                        return;
                    }
                    else
                    {
                        cscriptLauncher.ListenerId = listener.Id;
                    }
                }
                else if (commands[1].ToLower() == "dotnetframeworkversion")
                {
                    if (commands[2].ToLower().Contains("35") || commands[2].ToLower().Contains("3.5"))
                    {
                        cscriptLauncher.DotNetFrameworkVersion = DotNetVersion.Net35;
                    }
                    else if (commands[2].ToLower().Contains("40") || commands[2].ToLower().Contains("4.0"))
                    {
                        cscriptLauncher.DotNetFrameworkVersion = DotNetVersion.Net40;
                    }
                    else
                    {
                        EliteConsole.PrintFormattedErrorLine("Invalid DotNetFrameworkVersion \"" + commands[2] + "\". Valid options are: v3.5, v4.0");
                        menuItem.PrintInvalidOptionError(UserInput);
                        return;
                    }
                }
                else if (commands[1].ToLower() == "scriptlanguage")
                {
                    if (commands[2].ToLower().StartsWith("js"))
                    {
                        cscriptLauncher.ScriptLanguage = ScriptingLanguage.JScript;
                    }
                    else if (commands[2].ToLower().StartsWith("vb"))
                    {
                        cscriptLauncher.ScriptLanguage = ScriptingLanguage.VBScript;
                    }
                    else
                    {
                        EliteConsole.PrintFormattedErrorLine("Invalid ScriptLanguage \"" + commands[2] + "\". Valid options are: JScript, VBScript");
                        menuItem.PrintInvalidOptionError(UserInput);
                        return;
                    }
                }
                else if (commands[1].ToLower() == "delay")
                {
                    int.TryParse(commands[2], out int n);
                    cscriptLauncher.Delay = n;
                }
                else if (commands[1].ToLower() == "jitter")
                {
                    int.TryParse(commands[2], out int n);
                    cscriptLauncher.Jitter = n;
                }
                else if (commands[1].ToLower() == "connectattempts")
                {
                    int.TryParse(commands[2], out int n);
                    cscriptLauncher.ConnectAttempts = n;
                }
                else if (commands[1].ToLower() == "launcherstring")
                {
                    cscriptLauncher.LauncherString = commands[2];
                }

                CovenantAPIExtensions.ApiLaunchersCscriptPut(this.CovenantClient, cscriptLauncher);
            }
            else
            {
                menuItem.PrintInvalidOptionError(UserInput);
            }
        }