Esempio n. 1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            txtLog.Text = "";
            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.OptionFixNestedTags = true;
            var objTable = new List <ScanTable>();

            try
            {
                AppendToLog("Begining process");
                AppendToLog("Reading HTML");
                if (!File.Exists(txtHTML.Text))
                {
                    throw new FileNotFoundException();
                }
                htmlDoc.Load(txtHTML.Text);

                if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
                {
                    foreach (var item in htmlDoc.ParseErrors)
                    {
                        AppendToLog("\t" + item.Reason, true);
                    }
                }
                AppendToLog("HTML read successfull");

                AppendToLog("Selecting tables");
                var tables = htmlDoc.DocumentNode.Descendants().Where(x => x.HasClass("results")).ToList();
                AppendToLog("Selecting tables completed. Table count :" + tables.Count);

                AppendToLog("Creating objects");
                int i = 0;
                foreach (var item in tables)
                {
                    var tmpTable = new ScanTable();
                    var rows     = item.SelectNodes(".//tr").ToList();
                    tmpTable.Severity      = rows.First().SelectNodes(".//th").ElementAt(0).InnerText;
                    tmpTable.Vulnerability = rows.First().SelectNodes(".//th").ElementAt(1).InnerText;
                    rows.RemoveAt(0);
                    tmpTable.Description = rows.First().SelectNodes(".//td").ElementAt(1).InnerText;
                    rows.RemoveAt(0);

                    var urlFound = false;
                    var tmpURL   = new string[2];
                    foreach (var item2 in rows)
                    {
                        if (item2.SelectSingleNode(".//td").GetAttributeValue("class", null) == "indent1")
                        {
                            tmpURL[0] = item2.SelectNodes(".//td").ElementAt(1).InnerText;
                            urlFound  = true;
                        }
                        else if (urlFound)
                        {
                            tmpURL[1] = item2.SelectNodes(".//td").ElementAt(1).InnerText;
                            tmpTable.URLs.Add(tmpURL);
                            urlFound = false;
                        }

                        if (item2.SelectSingleNode(".//td").InnerText == "CWE Id")
                        {
                            tmpTable.CWE = int.Parse(item2.SelectNodes(".//td").ElementAt(1).InnerText);
                        }
                    }

                    i++;
                    objTable.Add(tmpTable);
                    AppendToLog("\t Tables " + i + " of " + tables.Count + " completed.");
                }
                AppendToLog("Creating objects completed.");

                AppendToLog("Creating excel file.");
                Excel.Application xlApp = new Excel.Application();
                if (xlApp == null)
                {
                    AppendToLog("Creating excel file failed. Please try again.", true);
                    return;
                }

                Excel.Workbook  xlWorkBook;
                Excel.Worksheet xlWorkSheet;
                object          misValue = System.Reflection.Missing.Value;

                xlWorkBook  = xlApp.Workbooks.Add(Type.Missing);
                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

                xlWorkSheet.Cells[1, 1] = "Severity";
                xlWorkSheet.Cells[1, 2] = "Vulnerability";
                xlWorkSheet.Cells[1, 3] = "Desctiption";
                xlWorkSheet.Cells[1, 4] = "URL";
                xlWorkSheet.Cells[1, 5] = "Method";
                xlWorkSheet.Cells[1, 6] = "CWE ID";
                xlWorkSheet.Cells[1, 7] = "Comments";

                AppendToLog("\t Adding data to table");
                var row = 2;
                foreach (var item in objTable)
                {
                    xlWorkSheet.Cells[row, 1] = item.Severity;
                    xlWorkSheet.Cells[row, 2] = item.Vulnerability;
                    xlWorkSheet.Cells[row, 3] = item.Description;
                    xlWorkSheet.Cells[row, 6] = item.CWE;
                    foreach (var item2 in item.URLs)
                    {
                        xlWorkSheet.Cells[row, 4] = item2[0];
                        xlWorkSheet.Cells[row, 5] = item2[1];
                        row++;
                    }
                }
                AppendToLog("\t Adding data to table complete");

                AppendToLog("\t Merging cells");
                row = 2;
                foreach (var item in objTable)
                {
                    var severityRange      = xlWorkSheet.Range[xlWorkSheet.Cells[row, 1], xlWorkSheet.Cells[row + item.URLs.Count - 1, 1]];
                    var vulnerabilityRange = xlWorkSheet.Range[xlWorkSheet.Cells[row, 2], xlWorkSheet.Cells[row + item.URLs.Count - 1, 2]];
                    var descriptionRange   = xlWorkSheet.Range[xlWorkSheet.Cells[row, 3], xlWorkSheet.Cells[row + item.URLs.Count - 1, 3]];
                    var cweRange           = xlWorkSheet.Range[xlWorkSheet.Cells[row, 6], xlWorkSheet.Cells[row + item.URLs.Count - 1, 6]];

                    severityRange.Merge();
                    vulnerabilityRange.Merge();
                    descriptionRange.Merge();
                    cweRange.Merge();

                    row += item.URLs.Count;
                }
                AppendToLog("\t Merging cells complete");

                AppendToLog("\t Saving excel file");
                string fileName = txtOutput.Text + "\\" + Path.GetFileNameWithoutExtension(txtHTML.Text) + ".xlsx";
                xlWorkBook.SaveAs(fileName);
                xlWorkBook.Close();
                xlApp.Quit();

                Marshal.ReleaseComObject(xlWorkSheet);
                Marshal.ReleaseComObject(xlWorkBook);
                Marshal.ReleaseComObject(xlApp);
                AppendToLog("\t Saving excel file complete");
                AppendToLog("Creating excel file completed.");
            }
            catch (Exception ex)
            {
                AppendToLog("Error : " + ex.Message.ToString(), true);
            }
        }
Esempio n. 2
0
        void ReleaseDesignerOutlets()
        {
            if (addrBox != null)
            {
                addrBox.Dispose();
                addrBox = null;
            }

            if (addressTable != null)
            {
                addressTable.Dispose();
                addressTable = null;
            }

            if (bpIndex != null)
            {
                bpIndex.Dispose();
                bpIndex = null;
            }

            if (bpStepper != null)
            {
                bpStepper.Dispose();
                bpStepper = null;
            }

            if (byteBoxx != null)
            {
                byteBoxx.Dispose();
                byteBoxx = null;
            }

            if (bytes != null)
            {
                bytes.Dispose();
                bytes = null;
            }

            if (clearWP != null)
            {
                clearWP.Dispose();
                clearWP = null;
            }

            if (convertFrom != null)
            {
                convertFrom.Dispose();
                convertFrom = null;
            }

            if (convertFromItems != null)
            {
                convertFromItems.Dispose();
                convertFromItems = null;
            }

            if (convertResults != null)
            {
                convertResults.Dispose();
                convertResults = null;
            }

            if (convertTo != null)
            {
                convertTo.Dispose();
                convertTo = null;
            }

            if (convertToItems != null)
            {
                convertToItems.Dispose();
                convertToItems = null;
            }

            if (descTable != null)
            {
                descTable.Dispose();
                descTable = null;
            }

            if (dissassembleField != null)
            {
                dissassembleField.Dispose();
                dissassembleField = null;
            }

            if (dissassField != null)
            {
                dissassField.Dispose();
                dissassField = null;
            }

            if (elfPath != null)
            {
                elfPath.Dispose();
                elfPath = null;
            }

            if (getMemory != null)
            {
                getMemory.Dispose();
                getMemory = null;
            }

            if (grabMemTable != null)
            {
                grabMemTable.Dispose();
                grabMemTable = null;
            }

            if (hexView != null)
            {
                hexView.Dispose();
                hexView = null;
            }

            if (idk != null)
            {
                idk.Dispose();
                idk = null;
            }

            if (idkLOL != null)
            {
                idkLOL.Dispose();
                idkLOL = null;
            }

            if (instructionField != null)
            {
                instructionField.Dispose();
                instructionField = null;
            }

            if (ipTextBox != null)
            {
                ipTextBox.Dispose();
                ipTextBox = null;
            }

            if (justATest != null)
            {
                justATest.Dispose();
                justATest = null;
            }

            if (justTes != null)
            {
                justTes.Dispose();
                justTes = null;
            }

            if (mainWindow != null)
            {
                mainWindow.Dispose();
                mainWindow = null;
            }

            if (memScanFrom != null)
            {
                memScanFrom.Dispose();
                memScanFrom = null;
            }

            if (memScanProgress != null)
            {
                memScanProgress.Dispose();
                memScanProgress = null;
            }

            if (memScanRange != null)
            {
                memScanRange.Dispose();
                memScanRange = null;
            }

            if (memScanTotalRange != null)
            {
                memScanTotalRange.Dispose();
                memScanTotalRange = null;
            }

            if (memScanType != null)
            {
                memScanType.Dispose();
                memScanType = null;
            }

            if (memScanValue != null)
            {
                memScanValue.Dispose();
                memScanValue = null;
            }

            if (OutPutTable != null)
            {
                OutPutTable.Dispose();
                OutPutTable = null;
            }

            if (processBox != null)
            {
                processBox.Dispose();
                processBox = null;
            }

            if (ptTable != null)
            {
                ptTable.Dispose();
                ptTable = null;
            }

            if (ptTableFilePath != null)
            {
                ptTableFilePath.Dispose();
                ptTableFilePath = null;
            }

            if (ptTableSaveName != null)
            {
                ptTableSaveName.Dispose();
                ptTableSaveName = null;
            }

            if (scanRes != null)
            {
                scanRes.Dispose();
                scanRes = null;
            }

            if (ScanTable != null)
            {
                ScanTable.Dispose();
                ScanTable = null;
            }

            if (scanTableOffset != null)
            {
                scanTableOffset.Dispose();
                scanTableOffset = null;
            }

            if (scanTableValue != null)
            {
                scanTableValue.Dispose();
                scanTableValue = null;
            }

            if (selectPTTable != null)
            {
                selectPTTable.Dispose();
                selectPTTable = null;
            }

            if (setMemAddrBox != null)
            {
                setMemAddrBox.Dispose();
                setMemAddrBox = null;
            }

            if (setMemByteBox != null)
            {
                setMemByteBox.Dispose();
                setMemByteBox = null;
            }

            if (setStringAddr != null)
            {
                setStringAddr.Dispose();
                setStringAddr = null;
            }

            if (setStringBtn != null)
            {
                setStringBtn.Dispose();
                setStringBtn = null;
            }

            if (setStringString != null)
            {
                setStringString.Dispose();
                setStringString = null;
            }

            if (statusLabel != null)
            {
                statusLabel.Dispose();
                statusLabel = null;
            }

            if (test != null)
            {
                test.Dispose();
                test = null;
            }

            if (testin != null)
            {
                testin.Dispose();
                testin = null;
            }

            if (testing != null)
            {
                testing.Dispose();
                testing = null;
            }

            if (testingAGAIN != null)
            {
                testingAGAIN.Dispose();
                testingAGAIN = null;
            }

            if (testingText != null)
            {
                testingText.Dispose();
                testingText = null;
            }

            if (testinLOL != null)
            {
                testinLOL.Dispose();
                testinLOL = null;
            }

            if (testLabel != null)
            {
                testLabel.Dispose();
                testLabel = null;
            }

            if (textView != null)
            {
                textView.Dispose();
                textView = null;
            }

            if (typeTable != null)
            {
                typeTable.Dispose();
                typeTable = null;
            }

            if (wpIndex != null)
            {
                wpIndex.Dispose();
                wpIndex = null;
            }

            if (wpLength != null)
            {
                wpLength.Dispose();
                wpLength = null;
            }

            if (wpStepper != null)
            {
                wpStepper.Dispose();
                wpStepper = null;
            }

            if (wpType != null)
            {
                wpType.Dispose();
                wpType = null;
            }

            if (uartOutputBox != null)
            {
                uartOutputBox.Dispose();
                uartOutputBox = null;
            }

            if (comPort != null)
            {
                comPort.Dispose();
                comPort = null;
            }

            if (filterTextUart != null)
            {
                filterTextUart.Dispose();
                filterTextUart = null;
            }

            if (textToFilter != null)
            {
                textToFilter.Dispose();
                textToFilter = null;
            }
        }