public void ScanVulnerabilities(WebServiceToInvoke wsInvoker, WSOperation operation, VulnerabilitiesVulnerability vuln,
     string targetNameSpace, WSDescriber wsDesc, WSDescriberForReport WSItemVulnerabilities, ReportObject reportObject,
     bool isDebug, ref List<Param> respHeader, string customSoapHeaderTags, string customSoapBodyTags)
 {
     if (vuln.id == 1) // check authentication
     {
         CheckUnAuthenticatedMethod(wsInvoker, operation, vuln, targetNameSpace, WSItemVulnerabilities, reportObject, isDebug, ref respHeader, customSoapHeaderTags, customSoapBodyTags);
     }
     else
     {
         CheckVulnsExceptAuth(wsInvoker, operation, vuln, targetNameSpace, wsDesc, WSItemVulnerabilities, reportObject, isDebug, ref respHeader, customSoapHeaderTags, customSoapBodyTags);
     }
 }
        private void CheckUnAuthenticatedMethod(WebServiceToInvoke wsInvoker, WSOperation operation, VulnerabilitiesVulnerability vuln,
            string targetNameSpace, WSDescriberForReport WSItemVulnerabilities, ReportObject reportObject,
            bool isDebug, ref List<Param> respHeader, string customSoapHeaderTags, string customSoapBodyTags)
        {
            for (int j = 0; j < operation.Parameters.Count; j++)
            {
                SetParameterDefaultValue(wsInvoker, operation.Parameters[j], isDebug);
            }

            try
            {
                try
                {
                    reportObject.TotalRequestCount++;
                    wsInvoker.InvokeMethod(operation.MethodName, targetNameSpace, null, ref respHeader, customSoapHeaderTags, customSoapBodyTags);
                }
                catch (SoapException soapEx)
                {
                    //throw ex;
                    SetSoapFaultException(operation, soapEx, WSItemVulnerabilities, isDebug);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            finally { wsInvoker.PosInvoke(); }

            if (!vuln.statusCode.Equals(wsInvoker.StatusCode.ToString())) // status code is not 401, no redirect
            {
                VulnerabilityForReport authVuln = new VulnerabilityForReport();
                authVuln.Vuln = MainForm.vulnerabilities.Vulnerability.Where(v => v.id == 1).FirstOrDefault();
                authVuln.VulnerableMethodName = operation.MethodName;
                authVuln.VulnerableParamName = "";
                authVuln.Payload = "";
                authVuln.Response = wsInvoker.ResultString;
                authVuln.StatusCode = wsInvoker.StatusCode.ToString();

                WSItemVulnerabilities.Vulns.Add(authVuln);

                mainForm.Log("   Auth Vulnerability Found: " + wsInvoker.ResultString + " - status code is : " + wsInvoker.StatusCode.ToString(), FontStyle.Bold, true);
            }
        }
Exemple #3
0
        private void btnScan_Click(object sender, EventArgs e)
        {
            if (services != null && services.Count > 0)
            {
                lvResult.Items.Clear();

                scanDirectory = DirectoryHelper.GetScanDirectoryName();
                DirectoryHelper.CreateScanDirectory(scanDirectory);

                ReportObject reportObject = new ReportObject();
                reportObject.ScanStartDate = DateTime.Now;
                reportObject.WsDescs = new List<WSDescriberForReport>();
                reportObject.TotalRequestCount = 0;

                Log("Scan Started: " + reportObject.ScanStartDate.ToString("dd.MM.yyyy HH:mm:ss"), FontStyle.Bold, true);

                foreach (WSDescriber wsDesc in services)
                {
                    WSDescriberForReport WSItemVulnerabilities = new WSDescriberForReport();

                    WSItemVulnerabilities.WsDesc = wsDesc;
                    WSItemVulnerabilities.Vulns = new List<VulnerabilityForReport>();
                    WSItemVulnerabilities.StaticVulns = new List<StaticVulnerabilityForReport>();
                    WSItemVulnerabilities.InfoVulns = new List<DisclosureVulnerabilityForReport>();

                    Log("WSDL Address: " + wsDesc.WSDLAddress, FontStyle.Bold, true);
                    Log("Parsing WSDL...", FontStyle.Regular, true);

                    List<Param> respHeader = new List<Param>();

                    bool untrustedSSLSecureChannel = false;
                    Parser parser = new Parser(wsDesc, ref untrustedSSLSecureChannel, ref respHeader);

                    if (chkStaticScan.Checked)
                    {
                        Log("Static Analysis Started", FontStyle.Regular, true);

                        StaticVulnerabilityScanner svs = new StaticVulnerabilityScanner();

                        foreach (StaticVulnerabilitiesStaticVulnerability staticVuln in staticVulnerabilities.StaticVulnerability)
                        {
                            Log("   Testing: " + staticVuln.title, FontStyle.Regular, chkDebug.Checked);

                            string staticScanRes = svs.ScanIt(staticVuln, parser.rawWSDL);

                            if (!string.IsNullOrEmpty(staticScanRes))
                            {
                                Log("   " + staticVuln.title + " Vulnerability Found: " + staticScanRes, FontStyle.Bold, true);
                                StaticVulnerabilityForReport vulnRep = new StaticVulnerabilityForReport();
                                vulnRep.Vuln = staticVuln;
                                vulnRep.XMLLine = staticScanRes;

                                WSItemVulnerabilities.StaticVulns.Add(vulnRep);
                            }
                        }

                        Log("Static Analysis Finished", FontStyle.Regular, true);
                    }

                    if (chkDynamicScan.Checked)
                    {
                        Log("Getting Methods...", FontStyle.Regular, true);
                        List<WSOperation> operations = parser.GetOperations();

                        WebServiceToInvoke wsInvoker = new WebServiceToInvoke(wsDesc.WSDLAddress.Replace("?WSDL", ""));

                        if (!wsDesc.WSUri.Scheme.Equals("https"))
                        {
                            Log(" Vulnerability Found - SSL Not Used, Uri Schema is " + wsDesc.WSUri.Scheme, FontStyle.Bold, true);
                            AddSSLRelatedVulnerability(WSItemVulnerabilities, 0);
                        }
                        else
                        {
                            if (untrustedSSLSecureChannel)
                            {
                                Log(" Vulnerability Found - Could not establish trust relationship for the SSL/TLS secure channel.", FontStyle.Bold, true);
                                AddSSLRelatedVulnerability(WSItemVulnerabilities, -1);
                            }
                        }

                        DynamicVulnerabilityScanner dynScn = new DynamicVulnerabilityScanner(this);

                        foreach (WSOperation operation in operations)
                        {
                            Log("Method: " + operation.MethodName, FontStyle.Regular, chkDebug.Checked);

                            foreach (VulnerabilitiesVulnerability vuln in vulnerabilities.Vulnerability)
                            {
                                if (vuln.id != 0 && vuln.id != 7) // 0 for insecure transport - ssl not used , 7 for verbose soap fault message
                                {
                                    wsInvoker.PreInvoke();

                                    Log("   Testing: " + vuln.title, FontStyle.Regular, chkDebug.Checked);
                                    Log("   Parameter Count: " + operation.Parameters.Count, FontStyle.Regular, chkDebug.Checked);

                                    try
                                    {
                                        dynScn.ScanVulnerabilities(wsInvoker, operation, vuln, parser.TargetNameSpace, wsDesc, WSItemVulnerabilities, reportObject,
                                            chkDebug.Checked, ref respHeader, txtCustomSoapHeaderTags.Text.Trim(), txtCustomSoapBodyTags.Text.Trim());
                                    }
                                    catch (System.Web.Services.Protocols.SoapException soapEx)
                                    {
                                        dynScn.SetSoapFaultException(operation, soapEx, WSItemVulnerabilities, chkDebug.Checked);
                                    }
                                    catch (Exception ex)
                                    {
                                        Log("   Exception: " + ex.ToString(), FontStyle.Regular, chkDebug.Checked);
                                    }
                                }
                            }
                        }
                    }

                    if (chkInfoDisclosure.Checked)
                    {
                        Log("Information Disclosure Analysis Started", FontStyle.Regular, true);

                        InformationDisclosureVulnerabilityScanner idvs = new InformationDisclosureVulnerabilityScanner(this);

                        foreach (InformationDisclosureVulnerability infoVuln in disclosureVulnerabilities.Vulnerability)
                        {
                            Log("   Searching Response Header: " + infoVuln.title, FontStyle.Regular, chkDebug.Checked);

                            string infoScanRes = idvs.ScanIt(infoVuln, respHeader);

                            if (!string.IsNullOrEmpty(infoScanRes))
                            {
                                Log("   " + infoVuln.title + " Information Disclosure Found: " + infoScanRes, FontStyle.Bold, true);
                                DisclosureVulnerabilityForReport vulnRep = new DisclosureVulnerabilityForReport();
                                vulnRep.Vuln = infoVuln;
                                vulnRep.Value = infoScanRes;

                                WSItemVulnerabilities.InfoVulns.Add(vulnRep);
                            }
                        }

                        Log("Information Disclosure Analysis Finished", FontStyle.Regular, true);
                    }

                    reportObject.WsDescs.Add(WSItemVulnerabilities);
                }

                reportObject.ScanEndDate = DateTime.Now;

                Log("Scan Finished: " + reportObject.ScanEndDate.ToString("dd.MM.yyyy HH:mm:ss"), FontStyle.Bold, true);

                string reportFilePath = scanDirectory + @"\Report\Report.html";

                ReportHelper.CreateHTMLReport(reportObject,
                    System.AppDomain.CurrentDomain.BaseDirectory + @"\ReportTemplates\HTMLReportTemplate.html",
                    reportFilePath);

                Process.Start(reportFilePath);
            }
            else
            {
                MessageBox.Show("Please Select WSDL List File!!!");
            }
        }
        private void CheckVulnsExceptAuth(WebServiceToInvoke wsInvoker, WSOperation operation, VulnerabilitiesVulnerability vuln,
           string targetNameSpace, WSDescriber wsDesc, WSDescriberForReport WSItemVulnerabilities, ReportObject reportObject,
            bool isDebug, ref List<Param> respHeader, string customSoapHeaderTags, string customSoapBodyTags)
        {
            int paramIndexToTest = 0;

            for (int i = 0; i < operation.Parameters.Count; i++)
            {
                if (i == paramIndexToTest)
                {
                    foreach (string payload in vuln.request)
                    {
                        bool vulnFoundForParam = false;

                        wsInvoker.AddParameter(operation.Parameters[i].Name, payload.Trim());
                        for (int j = 0; j < operation.Parameters.Count; j++)
                        {
                            if (j != paramIndexToTest)
                            {
                                SetParameterDefaultValue(wsInvoker, operation.Parameters[j], isDebug);
                            }
                        }

                        try
                        {
                            try
                            {
                                reportObject.TotalRequestCount++;
                                wsInvoker.InvokeMethod(operation.MethodName, targetNameSpace, wsDesc, ref respHeader, customSoapHeaderTags, customSoapBodyTags);
                            }
                            catch (SoapException soapEx)
                            {
                                SetSoapFaultException(operation, soapEx, WSItemVulnerabilities, isDebug);
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                        finally { wsInvoker.PosInvoke(); }

                        mainForm.Log("   StatusCode: " + wsInvoker.StatusCode, FontStyle.Regular, isDebug);
                        mainForm.Log("   Result: " + wsInvoker.ResultString, FontStyle.Regular, isDebug);

                        if (!string.IsNullOrEmpty(vuln.statusCode))
                        {
                            if (vuln.statusCode.Equals(wsInvoker.StatusCode.ToString()))
                            {
                                if (vuln.response == null || vuln.response.Count() == 0)
                                {
                                    SetVuln(wsInvoker, WSItemVulnerabilities, vuln, operation, payload, operation.Parameters[i].Name, "   " + vuln.title + " Vulnerability Found: " + wsInvoker.ResultString + " - Status Code: " + vuln.statusCode);
                                    vulnFoundForParam = true;
                                }
                                else
                                {
                                    foreach (string text in vuln.response)
                                    {
                                        if (wsInvoker.ResultString.Trim().Contains(text.Trim()))
                                        {
                                            SetVuln(wsInvoker, WSItemVulnerabilities, vuln, operation, payload, operation.Parameters[i].Name, "   " + vuln.title + " Vulnerability Found: " + wsInvoker.ResultString + " - Response Text Contains: " + text + " - Status Code: " + vuln.statusCode);
                                            vulnFoundForParam = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (string text in vuln.response)
                            {
                                //if (System.Text.RegularExpressions.Regex.IsMatch(wsInvoker.ResultString.Trim(), text.Trim(), System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                                if (wsInvoker.ResultString.Trim().Contains(text.Trim()))
                                {
                                    // Vulnerability Found
                                    SetVuln(wsInvoker, WSItemVulnerabilities, vuln, operation, payload, operation.Parameters[i].Name, "   " + vuln.title + " Vulnerability Found: " + wsInvoker.ResultString + " - Response Text Contains: " + text);
                                    vulnFoundForParam = true;
                                    break;
                                }
                            }
                        }
                        if (vulnFoundForParam)
                        {
                            break;
                        }
                    }
                }
                paramIndexToTest++;
            }
        }
Exemple #5
0
        public static void CreateHTMLReport(ReportObject reportObject, string templateFilePath, string pathToSave)
        {
            StreamReader reader = new StreamReader(templateFilePath);
            StringBuilder htmlContent = new StringBuilder(reader.ReadToEnd());
            reader.Close();

            htmlContent = htmlContent.Replace("{ScanDuration}", reportObject.Duration.ToString("N2"));
            htmlContent = htmlContent.Replace("{ScanStartDate}", reportObject.ScanStartDate.ToString("dd.MM.yyyy HH:mm:ss"));
            htmlContent = htmlContent.Replace("{TotalRequestCount}", reportObject.TotalRequestCount.ToString());

            double totalStaticVulnCount = 0;
            double totalDynamicVulnCount = 0;
            double totalInfoVulnCount = 0;
            double totalVulnCount = 0;

            StringBuilder htmlVulns = new StringBuilder();
            List<Param> allVulns = new List<Param>();

            foreach (WSDescriberForReport wsDesc in reportObject.WsDescs)
            {
                htmlVulns.Append(GetHtmlRowForWsdl(wsDesc, ref allVulns));
                totalDynamicVulnCount += wsDesc.Vulns.Count;
                totalStaticVulnCount += wsDesc.StaticVulns.Count;
                totalInfoVulnCount += wsDesc.InfoVulns.Count;
            }

            totalVulnCount = totalStaticVulnCount + totalDynamicVulnCount
                + totalInfoVulnCount;

            htmlContent = htmlContent.Replace("{TotalVulnCount}", totalVulnCount.ToString());
            htmlContent = htmlContent.Replace("{Content}", htmlVulns.ToString());

            string chart1Data = "['Static (" + totalStaticVulnCount + ")', " + totalStaticVulnCount +
                "], ['Dynamic (" + totalDynamicVulnCount + ")', " + totalDynamicVulnCount +
                "], ['Information (" + totalInfoVulnCount + ")', " + totalInfoVulnCount + "]";

            string chart2Data = string.Empty;
            int criticalVulnCount = 0, highVulnCount = 0, mediumVulnCount = 0, lowVulnCount = 0, infoVulnCount = 0;
            foreach (Param param in allVulns)
            {
                chart2Data += "['" + param.Name + " (" + param.Value + ")', " + param.Value + "],";
                switch (param.Severity)
                {
                    case "Critical": criticalVulnCount += int.Parse(param.Value); break;
                    case "High": highVulnCount += int.Parse(param.Value); break;
                    case "Medium": mediumVulnCount += int.Parse(param.Value); break;
                    case "Low": lowVulnCount += int.Parse(param.Value); break;
                    case "Info": infoVulnCount += int.Parse(param.Value); break;
                    default: break;
                }
            }

            if (!string.IsNullOrEmpty(chart2Data))
            {
                chart2Data = chart2Data.Remove(chart2Data.Length - 1); // remove last ","
            }

            string chart3Data = "['Critical (" + criticalVulnCount + ")', " + criticalVulnCount +
                "],['High (" + highVulnCount + ")', " + highVulnCount +
                "], ['Medium (" + mediumVulnCount + ")', " + mediumVulnCount +
                "], ['Low (" + lowVulnCount + ")', " + lowVulnCount +
                "], ['Info (" + infoVulnCount + ")', " + infoVulnCount + "]";

            htmlContent = htmlContent.Replace("{ChartData1}", chart1Data);
            htmlContent = htmlContent.Replace("{ChartData2}", chart2Data);
            htmlContent = htmlContent.Replace("{ChartData3}", chart3Data);

            File.WriteAllText(pathToSave, htmlContent.ToString());
        }