Exemple #1
0
        private async Task DumpServiceTicket(KerberosClient client)
        {
            var rep = await client.GetServiceTicket(this.DumpServicePrincipalName);

            string apreq;

            if (this.DumpAsNegotiate)
            {
                apreq = Convert.ToBase64String(rep.EncodeGssApi().ToArray());
            }
            else
            {
                apreq = Convert.ToBase64String(rep.EncodeApplication().ToArray());
            }

            var command = new KerberosDumpCommand(CommandLineParameters.Parse($"kdecode --ticket \"{apreq}\""));

            await command.Execute();
        }
        private async Task StartLoop()
        {
            bool attemptExternal = !string.IsNullOrWhiteSpace(this.CommandLine) || !string.IsNullOrWhiteSpace(this.LoadingModule);
            bool singleRun       = false;

            while (true)
            {
                string commandLine = null;

                if (attemptExternal)
                {
                    commandLine     = this.CommandLine;
                    attemptExternal = false;
                }

                if (string.IsNullOrWhiteSpace(commandLine) && string.IsNullOrWhiteSpace(this.LoadingModule))
                {
                    this.io.Writer.Write(this.ShellPrefix);
                    commandLine = this.io.Reader.ReadLine();
                }

                if (!string.IsNullOrWhiteSpace(this.LoadingModule))
                {
                    commandLine = $"{this.LoadingModule} {commandLine}".Trim();
                    singleRun   = true;
                }

                var parameters = CommandLineParameters.Parse(commandLine);

                if (string.IsNullOrWhiteSpace(parameters?.Command))
                {
                    continue;
                }

                if (this.TryProcessSystemCommand(parameters, out bool exiting))
                {
                    if (exiting && !this.TryPopShell())
                    {
                        break;
                    }

                    continue;
                }

                try
                {
                    await this.ExecuteCommand(parameters);
                }
                catch (AggregateException agg)
                {
                    this.io.Writer.WriteLine();

                    foreach (var ex in agg.InnerExceptions)
                    {
                        this.io.Writer.WriteLine(ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    if (ex is TargetInvocationException tex)
                    {
                        ex = tex.InnerException;
                    }

                    this.io.Writer.WriteLine();

                    if (this.Verbose)
                    {
                        this.io.Writer.WriteLine(ex);
                    }
                    else
                    {
                        this.io.Writer.WriteLine(ex.Message);
                    }

                    this.io.Writer.WriteLine();
                }

                if (singleRun)
                {
                    break;
                }
            }
        }