Exploit database

GH-8a710cc51cfc594e82ab501a2175c35b

onsec-fr/cve-2020-0688-scanner

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2020-0688

37 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files10
onsec-fr/cve-2020-0688-scannerRevision 9357ea15fe67

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

Sources/Program.cs

C# · 11,724 bytes
using HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace CVE_2020_0688_Scanner
{
    class Program
    {
        static string getRawVersion(string url)
        {
            try
            {
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
                var web = new HtmlWeb();
                var doc = web.Load(url);
                var value = doc.DocumentNode
                    .SelectNodes("//link")
                    .First()
                    .Attributes["href"].Value;
                string rawVersion = "";
                Regex regex = new Regex(@"/[0-9.]+/");
                rawVersion = regex.Match(value).ToString();
                if (rawVersion == "")
                    return "[ERROR] Unable to retrieve the version number.";
                else
                    return rawVersion.Replace("/", "");
            }
            catch (Exception ex)
            {
                return "[ERROR] Unable to connect to the server : " + ex.ToString();
            }
        }

        static string getServerVersion(string rawVersion)
        {
            if (rawVersion.StartsWith("6.5."))
            {
                return "2003";
            }
            if (rawVersion.StartsWith("8."))
            {
                return "2007";
            }
            if (rawVersion.StartsWith("14."))
            {
                return "2010";
            }
            if (rawVersion.StartsWith("15.0."))
            {
                return "2013";
            }
            if (rawVersion.StartsWith("15.1."))
            {
                return "2016";
            }
            if (rawVersion.StartsWith("15.2."))
            {
                return "2019";
            }
            return "[ERROR] Unable to identify server version.";
        }

        static void Main(string[] args)
        {
            // Args
            if (args.Length < 1)
            {
                Console.WriteLine("[ERROR] Missing argument 1 : File to process." + Environment.NewLine);
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine(Properties.Resources.helpText);
                Console.ForegroundColor = ConsoleColor.White;
                Environment.Exit(0);
            }
            string input = args[0];
            if (!File.Exists(@input))
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("[ERROR] File " + input + " not found." + Environment.NewLine);
                Environment.Exit(0);
            }
            // Display banner
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine(Properties.Resources.bannerText);
            // Init
            System.IO.StreamReader file = new System.IO.StreamReader(@input);
            string host;
            int processed = 0;
            List<String> lstFailed = new List<string>();
            List<String> lstSafe = new List<string>();
            List<String> lstVulnerable = new List<string>();
            List<String> lstMaybeSafe = new List<string>();
            // Process each line
            while ((host = file.ReadLine()) != null)
            {
                // Process one item
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine(Environment.NewLine + "[DEBUG] Processing " + host);
                // Check input format
                if (!host.Contains("http://") && !host.Contains("https://"))
                {
                    host = "https://" + host;
                }
                if (!Uri.IsWellFormedUriString(host, UriKind.Absolute))
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("[ERROR] Malformed URL " + host);
                    lstFailed.Add(host);
                    goto end;
                }
                // Get raw version
                string rawVersion = getRawVersion(host);
                if (rawVersion.Contains("[ERROR]"))
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine(rawVersion);
                    lstFailed.Add(host);
                    goto end;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("[INFO] Identified version " + rawVersion);
                }
                // Get exchange version
                string serverVersion = getServerVersion(rawVersion);
                if (serverVersion.Contains("[ERROR]"))
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine(serverVersion);
                    lstFailed.Add(host);
                    goto end;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("[INFO] Server version is Exchange " + serverVersion);
                }
                string vulnerable = "unknow";
                try
                {
                    // Check if vulnerable
                    if (serverVersion == "2007" || serverVersion == "2003")
                    {
                        // 2003 & 2007 can't be patched against CVE-2020-0688
                        vulnerable = "yes";
                    }
                    else if (serverVersion == "2010")
                    {
                        // If version is equal or greather than 14.3.496 then server is patched
                        if (Convert.ToInt32(rawVersion.Split('.')[2]) >= 496)
                            vulnerable = "no";
                        else
                            vulnerable = "yes";

                    }
                    else if (serverVersion == "2013")
                    {
                        /* If version starts with 15.0.1497 then it may be vulnerable (only 15.0.1497.6 is patched)
                        If version is greater than 15.0.1497 then server is patched */
                        if (Convert.ToInt32(rawVersion.Split('.')[2]) == 1497)
                            vulnerable = "maybe";
                        else if (Convert.ToInt32(rawVersion.Split('.')[2]) > 1497)
                            vulnerable = "no";
                        else
                            vulnerable = "yes";
                    }
                    else if (serverVersion == "2016")
                    {
                        /* If version starts with 15.1.1913 or 15.1.1847 then it may be vulnerable (only 15.1.1913.7 and 15.1.1847.7 are patched)
                        If version is greater than 15.1.1913 then server is patched */
                        if (Convert.ToInt32(rawVersion.Split('.')[2]) == 1913 || Convert.ToInt32(rawVersion.Split('.')[2]) == 1847)
                            vulnerable = "maybe";
                        else if (Convert.ToInt32(rawVersion.Split('.')[2]) > 1913)
                            vulnerable = "no";
                        else
                            vulnerable = "yes";
                    }
                    else if (serverVersion == "2019")
                    {
                        /* If version starts with 15.2.529 or 15.2.464 then it may be vulnerable (only 15.2.529.8 and 15.2.464.11 are patched)
                        If version is greater than 15.2.529 then server is patched */
                        if (Convert.ToInt32(rawVersion.Split('.')[2]) == 529 || Convert.ToInt32(rawVersion.Split('.')[2]) == 464)
                            vulnerable = "maybe";
                        else if (Convert.ToInt32(rawVersion.Split('.')[2]) > 529)
                            vulnerable = "no";
                        else
                            vulnerable = "yes";
                    }
                }
                catch
                {

                }
                if (vulnerable == "yes")
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[CRITICAL] Server is vulnerable to CVE-2020-0688 !");
                    lstVulnerable.Add(host);
                }
                else if (vulnerable == "maybe")
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("[WARNING] Server may be patched for CVE-2020-0688.");
                    lstMaybeSafe.Add(host);
                }
                else if (vulnerable == "no")
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("[OK] Server is patched for CVE-2020-0688.");
                    lstSafe.Add(host);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("[ERROR] Uknown error.");
                    lstFailed.Add(host);
                }
            // End item
            end:
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.WriteLine("[DEBUG] Item processed." + Environment.NewLine);
                processed++;
            }
            // Display stats
            Console.WriteLine("=====> STATS");
            Console.WriteLine("> Processed: " + processed.ToString()); ;
            Console.WriteLine("> Error: " + lstFailed.Count);
            Console.WriteLine("> Vulnerable: " + lstVulnerable.Count);
            Console.WriteLine("> (Maybe) Patched: " + lstMaybeSafe.Count);
            Console.WriteLine("> Patched: " + lstSafe.Count);
            // Write to output file
            string outfile = "CVE_2020_0688_Scan_" + DateTime.Now.ToString().Replace(":", "").Replace("/", "").Replace(" ", "_") + ".txt";
            Console.WriteLine(Environment.NewLine + "=====> Writing results in " + outfile);
            using (System.IO.StreamWriter file2 = new System.IO.StreamWriter(@outfile))
            {
                file2.WriteLine("---------- Patched servers ----------");
                file2.WriteLine("");
                foreach (string line in lstSafe)
                {
                    file2.WriteLine(line);
                }
                file2.WriteLine("---------- (Maybe) Patched servers ----------");
                file2.WriteLine("");
                foreach (string line in lstMaybeSafe)
                {
                    file2.WriteLine(line);
                }
                file2.WriteLine("---------- Vulnerable servers ----------");
                file2.WriteLine("");
                foreach (string line in lstVulnerable)
                {
                    file2.WriteLine(line);
                }
                file2.WriteLine("---------- Errors ----------");
                file2.WriteLine("");
                foreach (string line in lstFailed)
                {
                    file2.WriteLine(line);
                }
            }
            // Exit file
            file.Close();
            // Exit program
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(Environment.NewLine + "Press any key to exit...");
            Console.ReadKey();
        }
    }
}