Ejemplo n.º 1
0
 private static void RunTask(FullTest ft, string address, int sslPort, ReportAggregator aggregator, SSLTestArgs args)
 {
     try {
         Report rp = Run(ft, address, sslPort, args, @"raw_results\", "_" + address + "_" + sslPort);
         Report.UpdateReportAggregator(aggregator, rp);
         aggregator.IncrementScanCounter();
         Console.WriteLine("Done testing {0}:{1}\n", address, sslPort);
     } catch (Exception e) {
         Console.WriteLine("Failed to test {0}:{1} due to {2}", address, sslPort, e.Message);
     }
 }
Ejemplo n.º 2
0
        public DataTable ReadCsvFile(string filePath)
        {
            DataTable dtCsv = new DataTable();
            string    FullTest;

            using (StreamReader sr = new StreamReader(filePath))
            {
                while (!sr.EndOfStream)
                {
                    FullTest = sr.ReadToEnd().ToString(); //read full file text
                    string[] rows = FullTest.Split('\n'); //split full file text into rows
                    for (int i = 0; i < rows.Count() - 1; i++)
                    {
                        string[] rowValues = rows[i].Split(','); //split each row with comma to get individual values
                        {
                            if (i == 0)
                            {
                                for (int j = 0; j < rowValues.Count(); j++)
                                {
                                    dtCsv.Columns.Add(rowValues[j]); //add headers
                                }
                            }
                            else
                            {
                                DataRow dr     = dtCsv.NewRow();
                                var     length = rowValues.Count() > dtCsv.Columns.Count ? dtCsv.Columns.Count : rowValues.Count();
                                for (int k = 0; k < length; k++)
                                {
                                    dr[k] = rowValues[k].ToString();
                                }
                                dtCsv.Rows.Add(dr); //add other rows
                            }
                        }
                    }
                }
            }
            return(dtCsv);
        }
Ejemplo n.º 3
0
    static void Process(string[] args)
    {
        FullTest      ft         = new FullTest();
        List <string> r          = new List <string>();
        bool          withCerts  = false;
        string        proxString = null;
        string        textOut    = null;
        string        jsonOut    = null;
        string        logName    = null;
        int           rtm        = 20000;
        int           cwait      = 0;

        ft.AddECExt = true;
        for (int i = 0; i < args.Length; i++)
        {
            string a = args[i];
            switch (a.ToLowerInvariant())
            {
            case "-h":
            case "-help":
            case "--help":
                Usage();
                break;

            case "-v":
            case "--verbose":
                ft.Verbose = true;
                break;

            case "-sni":
            case "--sni":
                if (++i >= args.Length)
                {
                    Usage();
                }
                ft.ExplicitSNI = args[i];
                break;

            case "-all":
            case "--all-suites":
                ft.AllSuites = true;
                break;

            case "-min":
            case "--min-version":
                if (++i >= args.Length)
                {
                    Usage();
                }
                ft.MinVersion = ParseVersion(args[i]);
                if (ft.MinVersion < M.SSLv20 ||
                    ft.MinVersion > M.TLSv12)
                {
                    Usage();
                }
                break;

            case "-max":
            case "--max-version":
                if (++i >= args.Length)
                {
                    Usage();
                }
                ft.MaxVersion = ParseVersion(args[i]);
                if (ft.MaxVersion < M.SSLv20 ||
                    ft.MaxVersion > M.TLSv12)
                {
                    Usage();
                }
                break;

            case "-certs":
            case "--with-certificates":
                withCerts = true;
                break;

            case "-t":
            case "--read-timeout":
                if (++i >= args.Length)
                {
                    Usage();
                }
                if (!Int32.TryParse(args[i], out rtm))
                {
                    Usage();
                }
                if (rtm <= 0)
                {
                    rtm = -1;
                }
                else if (rtm > Int32.MaxValue / 1000)
                {
                    rtm = -1;
                }
                else
                {
                    rtm *= 1000;
                }
                break;

            case "-w":
            case "--wait":
                if (++i >= args.Length)
                {
                    Usage();
                }
                if (!Int32.TryParse(args[i], out cwait))
                {
                    Usage();
                }
                if (cwait <= 0)
                {
                    cwait = 0;
                }
                break;

            case "-prox":
            case "--proxy":
                if (++i >= args.Length)
                {
                    Usage();
                }
                proxString = args[i];
                break;

            case "-proxssl":
            case "--proxy-ssl":
                ft.ProxSSL = true;
                break;

            case "-ec":
            case "--with-ec-ext":
                ft.AddECExt = true;
                break;

            case "-noec":
            case "--without-ec-ext":
                ft.AddECExt = false;
                break;

            case "-text":
            case "--text-output":
                if (++i >= args.Length)
                {
                    Usage();
                }
                textOut = args[i];
                break;

            case "-json":
            case "--json-output":
                if (++i >= args.Length)
                {
                    Usage();
                }
                jsonOut = args[i];
                break;

            case "-log":
            case "--log-output":
                if (++i >= args.Length)
                {
                    Usage();
                }
                logName = args[i];
                break;

            default:
                if (a.Length > 0 && a[0] == '-')
                {
                    Usage();
                }
                r.Add(a);
                break;
            }
        }
        args = r.ToArray();
        if (args.Length == 0 || args.Length > 2)
        {
            Usage();
        }

        /*
         * While the parameters should be a _server name_ (and
         * optional port), some people instinctively provide an
         * "https://" URL. We will support that case.
         */
        string sn = args[0];

        if (sn.StartsWith("https://"))
        {
            sn = sn.Substring(8);
            int j = sn.IndexOf('/');
            if (j >= 0)
            {
                sn = sn.Substring(0, j);
            }
            j = sn.IndexOf('@');
            if (j >= 0)
            {
                sn = sn.Substring(j + 1);
            }
        }

        /*
         * The "server name" might end with ':' followed by a port
         * number (e.g. if it came for a URL, or through creative
         * invocation from the user). However, if there are several
         * colon characters, then we infer the server name to be
         * an explicit IPv6 address, and we do not try to extract
         * a port number from it.
         */
        int sj = sn.IndexOf(':');

        if (sj >= 0 && sj < (sn.Length - 1) &&
            sn.IndexOf(':', sj + 1) < 0)
        {
            try {
                ft.ServerPort = Int32.Parse(
                    sn.Substring(sj + 1));
            } catch (Exception) {
                Usage();
            }
            sn = sn.Substring(0, sj);
        }
        ft.ServerName = sn;

        /*
         * An explicit port number overrides the port value
         * extracted from the server name (if applicable).
         */
        if (args.Length == 2)
        {
            try {
                ft.ServerPort = Int32.Parse(args[1]);
            } catch (Exception) {
                Usage();
            }
        }

        ft.ReadTimeout    = rtm;
        ft.ConnectionWait = cwait;
        if (proxString != null)
        {
            int j = proxString.IndexOf(':');
            if (j > 0)
            {
                try {
                    string sp = proxString
                                .Substring(j + 1).Trim();
                    ft.ProxPort = Int32.Parse(sp);
                } catch (Exception) {
                    Usage();
                }
                ft.ProxName = proxString.Substring(0, j).Trim();
            }
        }

        /*
         * If there is no specified output, then use stdout.
         */
        if (textOut == null && jsonOut == null)
        {
            textOut = "-";
        }

        if (logName != null)
        {
            if (logName == "-")
            {
                ft.DebugLog = Console.Out;
            }
            else
            {
                ft.DebugLog = File.CreateText(logName);
            }
        }

        Report rp = ft.Run();

        rp.ShowCertPEM = withCerts;

        if (textOut != null)
        {
            if (textOut == "-")
            {
                rp.Print(Console.Out);
            }
            else
            {
                using (TextWriter w =
                           File.CreateText(textOut))
                {
                    rp.Print(w);
                }
            }
        }
        if (jsonOut != null)
        {
            if (jsonOut == "-")
            {
                rp.Print(new JSON(Console.Out));
            }
            else
            {
                using (TextWriter w =
                           File.CreateText(jsonOut))
                {
                    rp.Print(new JSON(w));
                }
            }
        }

        if (logName != null)
        {
            ft.DebugLog.Flush();
            if (logName != "-")
            {
                ft.DebugLog.Close();
            }
        }
    }
Ejemplo n.º 4
0
//    private static SSLTestArgs _testArgs = new SSLTestArgs(new List<string>());

    static void Process(string[] args)
    {
        FullTest    ft        = new FullTest();
        SSLTestArgs _testArgs = new SSLTestArgs(new List <string>());

        for (int i = 0; i < args.Length; i++)
        {
            string a = args[i];
            switch (a.ToLowerInvariant())
            {
            case "-h":
            case "-help":
            case "--help":
                Usage();
                break;

            case "-v":
            case "--verbose":
                ft.Verbose = true;
                break;

            case "-sni":
            case "--sni":
                if (++i >= args.Length)
                {
                    Usage();
                }
                ft.ExplicitSNI = args[i];
                break;

            case "-all":
            case "--all-suites":
                ft.AllSuites = true;
                break;

            case "-min":
            case "--min-version":
                if (++i >= args.Length)
                {
                    Usage();
                }
                ft.MinVersion = ParseVersion(args[i]);
                if (ft.MinVersion < M.SSLv20 ||
                    ft.MinVersion > M.TLSv12)
                {
                    Usage();
                }
                break;

            case "-max":
            case "--max-version":
                if (++i >= args.Length)
                {
                    Usage();
                }
                ft.MaxVersion = ParseVersion(args[i]);
                if (ft.MaxVersion < M.SSLv20 ||
                    ft.MaxVersion > M.TLSv12)
                {
                    Usage();
                }
                break;

            case "-certs":
            case "--with-certificates":
                _testArgs.WithCerts = true;
                break;

            case "-prox":
            case "--proxy":
                if (++i >= args.Length)
                {
                    Usage();
                }
                _testArgs.ProxString = args[i];
                break;

            case "-proxssl":
            case "--proxy-ssl":
                ft.ProxSSL = true;
                break;

            case "-ec":
            case "--with-ec-ext":
                ft.AddECExt = true;
                break;

            case "-text":
            case "--text-output":
                if (++i >= args.Length)
                {
                    Usage();
                }
                _testArgs.TextOut = args[i];
                break;

            case "-json":
            case "--json-output":
                if (++i >= args.Length)
                {
                    Usage();
                }
                _testArgs.JsonOut = args[i];
                break;

            case "-ar":
            case "--address-range":
                _testArgs.MultiAddr = true;
                break;

            case "-ap":
            case "--all-ports":
                _testArgs.IterateOverAllSslPorts = true;
                break;

            default:
                if (a.Length > 0 && a[0] == '-')
                {
                    Usage();
                }
                _testArgs.R.Add(a);
                break;
            }
        }
        args = _testArgs.R.ToArray();
        if (args.Length == 0 || args.Length > 2)
        {
            Usage();
        }

        string serverName = args[0];
        int    port       = -1;

        if (args.Length == 2)
        {
            try
            {
                port = Int32.Parse(args[1]);
            }
            catch (Exception)
            {
                Usage();
            }
        }

        ReportAggregator aggregator = new ReportAggregator();

        aggregator.SetSubnet(serverName);

        if (!_testArgs.MultiAddr)
        {
            Report.UpdateReportAggregator(aggregator, Run(ft, serverName, port, _testArgs));
        }
        else
        {
            IpRange           range          = new IpRange(serverName);
            IpRangeEnumerator enumerator     = new IpRangeEnumerator();
            SslPortEnumerator portEnumerator = new SslPortEnumerator();
            Console.WriteLine("Starting test...");

            Directory.CreateDirectory("raw_results");
            foreach (var address in enumerator.GetIPRange(range))
            {
                RunTask(ft, address, 443, aggregator, _testArgs);
            }
            ZipFile.CreateFromDirectory("raw_results", "raw_results_" + serverName.Replace("/", "_") + ".zip");
            Directory.Delete("raw_results", true);
        }

        aggregator.SaveCsv();
        aggregator.SaveCerts();
    }
Ejemplo n.º 5
0
    static Report Run(FullTest ft, String serverName, Int32 port, SSLTestArgs args, String prefix = "", String suffix = "")
    {
        ft.ServerName = serverName;
        if (port > 0)
        {
            ft.ServerPort = port;
        }
        if (args.ProxString != null)
        {
            int j = args.ProxString.IndexOf(':');
            if (j > 0)
            {
                try
                {
                    string sp = args.ProxString
                                .Substring(j + 1).Trim();
                    ft.ProxPort = Int32.Parse(sp);
                }
                catch (Exception)
                {
                    Usage();
                }
                ft.ProxName = args.ProxString.Substring(0, j).Trim();
            }
        }

        /*
         * If there is no specified output, then use stdout.
         */
        if (args.TextOut == null && args.JsonOut == null)
        {
            args.TextOut = "-";
        }

        Task <Report> rTask = Task <Report> .Factory.StartNew(ft.Run);

        Thread.Sleep(15000);
        if (!rTask.IsCompleted)
        {
            throw new Exception("Timeout");
        }

        Report rp = rTask.Result;

//        Report rp = ft.Run();
        rp.ShowCertPEM = args.WithCerts;

        if (args.TextOut != null)
        {
            if (args.TextOut == "-")
            {
                rp.Print(Console.Out);
            }
            else
            {
                using (TextWriter w =
                           File.CreateText(prefix + args.TextOut + suffix))
                {
                    rp.Print(w);
                }
            }
        }
        if (args.JsonOut != null)
        {
            if (args.JsonOut == "-")
            {
                rp.Print(new JSON(Console.Out));
            }
            else
            {
                using (TextWriter w =
                           File.CreateText(args.JsonOut + suffix))
                {
                    rp.Print(new JSON(w));
                }
            }
        }

        return(rp);
    }