예제 #1
0
        // GET: api/Users
        public IHttpActionResult GetUser(PublicModel publicModel)
        {
            SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();

            ie.Navigate("https://login.taobao.com/member/login.jhtml?redirectURL=https%3A%2F%2Fai.taobao.com%2F%3Fpid%3Dmm_112599953_14918079_77950911");
            ie.Visible = true;

            IHTMLDocument3 doc = (IHTMLDocument3)ie.Document;

            doc.getElementById("TPL_username_1").innerText = "肖梓璇35834616";
            doc.getElementById("TPL_password_1").innerText = "xiao4563515";
            doc.getElementById("J_SubmitStatic").click();


            ie.Navigate("http://i.taobao.com/my_taobao.htm");
            ie.Visible = true;

            ie.Navigate(" https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm?spm=a1z02.1.972272805.d4919663.73d2782d6TTeTm&action=itemlist/BoughtQueryAction&event_submit_do_query=1&tabCode=waitRate");
            ie.Visible = true;
            doc.getElementById("rateOrder").click();
            var ss = doc.documentElement.outerText = "1111";


            var userList = db.User.ToList();
            var data     = Newtonsoft.Json.JsonConvert.SerializeObject(userList);

            return(Json(data));
        }
예제 #2
0
        private void OpenWebPage(string url)
        {
            //WebPlayer wp = new WebPlayer();
            //wp.Show();
            //wp.Play(url);

            SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();

            ie.DocumentComplete += (object pDisp, ref object URL) => {
                ThreadPool.QueueUserWorkItem((o) =>
                {
                    try
                    {
                        mshtml.HTMLDocument doc = (mshtml.HTMLDocument)ie.Document;

                        doc.bgColor = "black";

                        doc.getElementById("player").removeAttribute("style");
                        doc.getElementById("player").setAttribute("width", "100%");
                        doc.getElementById("player").setAttribute("height", "100%");
                        doc.getElementById("player").setAttribute("align", "center");
                    }
                    catch
                    {
                    }
                });
            };

            ie.Visible     = true;
            ie.TheaterMode = true;
            ie.Navigate(url);

            BringWindowToTop(new IntPtr(ie.HWND));
        }
예제 #3
0
        public static void Main(string[] args)
        {
            String res = "";
            var    ie  = new SHDocVw.InternetExplorer();

            //ネット接続
            try
            {
                ie.Navigate("https://moneykit.net/visitor/sb_rate/");
                Wait(ie);
                //DOM操作 
                var doc    = ie.Document as mshtml.IHTMLDocument3;
                var tmpCol = doc.getElementsByTagName("tbody") as mshtml.IHTMLElementCollection;
                tmpCol = tmpCol.item(0).getElementsByTagName("td") as mshtml.IHTMLElementCollection;
                res    = tmpCol.item(2).innerText;
            }
            catch (Exception)
            {
                res = "接続エラー";
            }
            finally
            {
                ie.Quit();
                FileOutput(res);
            }
        }
예제 #4
0
        /// <summary>
        /// Obtiene el formulario para que pueda ser utilizado en toda la clase
        /// </summary>
        /// <param name="formUID"></param>
        public void obtenerFormulario(string formUID, string ruta)
        {
            try
            {
                //Obtiene el formulario de Visualizar XML
                visualiza = SAPbouiCOM.Framework.Application.SBO_Application.Forms.Item("frmVisualizar");

                //Agrega el objeto Browser de tipo ActiveX en el formulario
                Item oItem = visualiza.Items.Add("Brwsr", SAPbouiCOM.BoFormItemTypes.it_ACTIVE_X);
                oItem.Height = visualiza.Height - 37;
                oItem.Width  = visualiza.Width - 15;

                ActiveX axBrwsr = (ActiveX)oItem.Specific;

                //Se define la clase para el objeto ActiveX
                axBrwsr.ClassID = "Shell.Explorer.2";

                //Se crea el visor de Internet Explorer
                oSHDocVw = ((SHDocVw.InternetExplorer)(axBrwsr.Object));

                //Se carga el archivo xml al visor
                oSHDocVw.Navigate(ruta, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

                //Se borra el archivo cargado
                File.Delete(ruta);
            }
            catch (Exception ex)
            {
                SAPbouiCOM.Framework.Application.SBO_Application.MessageBox("ObtenerFormulario/Error:" + ex.ToString());
            }
        }
예제 #5
0
파일: Form1.cs 프로젝트: alansif/ah_bp
        private void button2_Click(object sender, EventArgs e)
        {
            string Url = System.Configuration.ConfigurationManager.AppSettings["Url"];

            SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
            ie.Navigate(Url);
            ie.Visible = true;
            OpenComm();
        }
예제 #6
0
        private void IE_Open(String searchEngine)
        {
            SHDocVw.InternetExplorer objIE = new SHDocVw.InternetExplorer(); //オブジェクトを作成
            objIE.Navigate("about:blank");                                   //空ページの表示
            objIE.Visible = true;                                            //IEを表示


            String encodedKeyword = System.Web.HttpUtility.UrlEncode(this.textBox1.Text, System.Text.Encoding.UTF8);

            String targetUrl = searchEngine + encodedKeyword;

            objIE.Navigate(targetUrl);

            //読み込み完了まで待つ
            while (objIE.Busy || objIE.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
            {
                //無処理
                System.Windows.Forms.Application.DoEvents();
                System.Threading.Thread.Sleep(100);
            }

            var ObjHtml = (mshtml.HTMLDocument)objIE.Document;

            var bodys = ObjHtml.getElementsByTagName("body");

            foreach (mshtml.IHTMLElement element in bodys)
            {
                if (element != null)
                {
                    Debug.WriteLine(element.outerHTML);
                }
            }

            System.Threading.Thread.Sleep(5000);

            if (objIE == null)
            {
                objIE.Quit();
            }
        }
예제 #7
0
파일: clsAllnew.cs 프로젝트: Lewishui/CITS
        public void InitialBusinessLink()
        {
            //https://app.singlewindow.cn/cas/login?service=http%3A%2F%2Fwww.singlewindow.cn%2Fsinglewindow%2Flogin.jspx&logoutFlag=1&_swCardF=1
            MyWebBrower.Navigate("https://app.singlewindow.cn/cas/login?service=http%3A%2F%2Fwww.singlewindow.cn%2Fsinglewindow%2Flogin.jspx&logoutFlag=1&_swCardF=1", ref o, ref o, ref o, ref o);
            DateTime strFileName = DateTime.Now;//开始时间

            while (!isReadyForSearch)
            {
                System.Windows.Forms.Application.DoEvents();
            }
            MyWebBrower.Quit();
            isReadyForSearch = false;
        }
예제 #8
0
        public IHttpActionResult appClick(PublicModel publicModel)
        {
            SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();

            ie.Navigate(publicModel.Url);
            ie.Visible = true;

            IHTMLDocument3 doc = (IHTMLDocument3)ie.Document;

            doc.getElementById(publicModel.InputText1).innerText = "hello world";
            doc.getElementById(publicModel.SavaId).click();
            return(Json("yes"));
        }
예제 #9
0
        public string AnalogClicks([FromUri] PublicFindModel findModel)
        {
            SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();

            ie.Navigate(findModel.Url);
            ie.Visible = true;

            IHTMLDocument3 doc = (IHTMLDocument3)ie.Document;

            doc.getElementById(findModel.InputText1).innerText = "hello world";
            doc.getElementById(findModel.SavaId).click();
            return("yes");
        }
예제 #10
0
        public Task Start(System.Threading.CancellationToken token)
        {
            var tcs = new TaskCompletionSource <string>();

            SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
            ie.Visible           = true;
            ie.DocumentComplete += (object pDisp, ref object URL) =>
            {
                ParseProxies(ie.Document as mshtml.HTMLDocument);
            };
            ie.Navigate("http://spys.ru/en/non-anonymous-proxy-list/");
            return(tcs.Task);
        }
예제 #11
0
        public void  IeExp()
        {
            ie.Height            = 1200;
            ie.Width             = 1500;
            ie.Visible           = true;
            ie.DocumentComplete += Ie_DocomentComplete;
            ie.Navigate("http://www.baidu.com");
            ie.Visible = true;
            ie_read    = false;
            compWait();
            HTMLDocument doc = ie.Document;

            doc.getElementById("kw").innerText = "234567";

            //ie.Quit();
        }
예제 #12
0
        /// <summary>
        /// Establecer el formulario como seleccionado para que muestre en el frente de la pantalla
        /// </summary>
        public void seleccionarFormulario(string ruta)
        {
            try
            {
                //Se comprueba que el objeto no este nulo
                if (oSHDocVw != null)
                {
                    //Se carga el archivo xml al visor
                    oSHDocVw.Navigate(ruta);
                }

                visualiza.Select();
            }
            catch (Exception)
            {
            }
        }
예제 #13
0
파일: IEWrapper.cs 프로젝트: fwka1605/next
        public async Task <string> GetAuthorizationCodeAsync(string uri)
        {
            var authorizationCode = string.Empty;

            SHDocVw.InternetExplorer ie = null;
            try
            {
                ie = new SHDocVw.InternetExplorer();
                ie.Navigate(uri);
                await WaitAsync(ie);

                ie.Visible = true;
                do
                {
                    var url = ie.LocationURL;
                    if (url.Contains("?code="))
                    {
                        var index = url.IndexOf("?code=");
                        if (index > 0)
                        {
                            authorizationCode = url.Substring(index + 6);
                        }
                        break;
                    }
                    await Task.Delay(TimeSpan.FromMilliseconds(100));
                } while (true);
            }
            catch (Exception)
            {
                // ie を閉じたときに ie.LocationURL にアクセスするタイミングで COMException が発生する
            }
            finally
            {
                if (ie != null)
                {
                    try
                    {
                        ie.Quit();
                    }
                    catch (Exception) { }
                    Marshal.ReleaseComObject(ie);
                    ie = null;
                }
            }
            return(authorizationCode);
        }
예제 #14
0
        static void Main(string[] args)
        {
            SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
            ie.DocumentComplete += ie_DocumentComplete;

            ie.Navigate("https://www.baidu.com/");
            ie.Visible = true;
            //while (ie_Read)
            //{
            //    Thread.Sleep(1000);
            //    if (ie.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
            //        break;
            //}
            IHTMLDocument3 doc = (IHTMLDocument3)ie.Document;

            doc.getElementById("kw").innerText = "hello world";
            doc.getElementById("su").click();
            Console.Read();
        }
예제 #15
0
        public override void RunCommand(object sender)
        {
            var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;

            var instanceName = v_InstanceName.ConvertToUserVariable(sender);

            SHDocVw.InternetExplorer newBrowserSession = new SHDocVw.InternetExplorer();
            try
            {
                newBrowserSession.Navigate(v_URL.ConvertToUserVariable(sender));
                WaitForReadyState(newBrowserSession);
                newBrowserSession.Visible = true;
            }
            catch (Exception ex) { }

            //add app instance
            engine.AddAppInstance(instanceName, newBrowserSession);

            //handle app instance tracking
            if (v_InstanceTracking == "Keep Instance Alive")
            {
                GlobalAppInstances.AddInstance(instanceName, newBrowserSession);
            }
        }
예제 #16
0
파일: ECM.cs 프로젝트: Javanei/clientes
 private void viewDocument(ECMFolderService.documentDto doc)
 {
     if (doc != null)
     {
         //LOG.imprimeLog(System.DateTime.Now + " ========= Exibindo documento: " + doc.documentId + " - " + doc.version + " = " + doc.documentDescription);
         SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
         string url = ecmURL;
         if (!url.EndsWith("/"))
         {
             url = url + "/";
         }
         url = url + "documentviewer?WDNrDocto=" + doc.documentId + "&WDNrVersao=" + doc.version;
         //LOG.imprimeLog(System.DateTime.Now + " ========= URL: " + url);
         ie.Navigate(url);
         ie.ToolBar = 0;
         ie.AddressBar = false;
         ie.Visible = true;
     }
     else
     {
         LOG.imprimeLog(System.DateTime.Now + " ========= Lascou!!! Nao achou o documento!!");
     }
 }
예제 #17
0
        private void OpenWebPage(string url)
        {
            //WebPlayer wp = new WebPlayer();
            //wp.Show();
            //wp.Play(url);

            SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();

            ie.DocumentComplete += (object pDisp, ref object URL) => {

                ThreadPool.QueueUserWorkItem((o) =>
                {
                    try
                    {
                        mshtml.HTMLDocument doc = (mshtml.HTMLDocument)ie.Document;

                        doc.bgColor = "black";

                        doc.getElementById("player").removeAttribute("style");
                        doc.getElementById("player").setAttribute("width", "100%");
                        doc.getElementById("player").setAttribute("height", "100%");
                        doc.getElementById("player").setAttribute("align", "center");

                    }
                    catch
                    {
                    }
                });

            };

            ie.Visible = true;
            ie.TheaterMode = true;
            ie.Navigate(url);

            BringWindowToTop(new IntPtr(ie.HWND));
        }
예제 #18
0
        private void loadPosts()
        {
            try
            {
                error = false;
                posts.Clear();
                int count = 0;
                SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
                IE.Visible = false;
                for (int i = (int)Math.Floor(minPage.Value); i <= (int)Math.Floor(maxPage.Value); i++)
                {
                    IE.Navigate(File.ReadAllText("MafiaUrlConfig") + "?pagenum=" + i);
                    while (IE.ReadyState.ToString() != "READYSTATE_COMPLETE")
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    if (!IE.LocationURL.ToString().Contains("pagenum") && count < 5)
                    {
                        count++;
                        i--;
                    }
                    else if (count >= 5)
                    {
                        MessageBox.Show("Could not connect to forum post. Make sure that you are logged into roll20 on Internet Explorer, and that you have the correct url.");
                        count = 0;
                        posts.Clear();
                        break;
                    }
                    else
                    {
                        var htmlDoc = IE.Document;

                        string content = htmlDoc.body.outerHTML;
                        File.WriteAllText("temporaryHold.html", content);

                        // load snippet
                        HtmlAgilityPack.HtmlDocument htmlSnippet = new HtmlAgilityPack.HtmlDocument();
                        htmlSnippet = LoadHtmlSnippetFromFile();

                        // extract Posts
                        if (ExtractAllPosts(htmlSnippet, i.ToString()) != null)
                        {
                            posts.AddRange(ExtractAllPosts(htmlSnippet, i.ToString()));
                        }
                        else
                        {
                            error = true;
                            posts.Clear();
                            break;
                        }
                    }
                }
                IE.Quit();
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Please click on the New Game button in the bottom left of the page to add your game");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            try
            {
                using (StreamWriter sw = File.CreateText("All.html"))
                {
                    sw.WriteLine("<head>");
                    sw.WriteLine("<meta charset='utf-8'>");
                    sw.WriteLine("</head>");
                    sw.WriteLine("<body>");
                    if (!error)
                    {
                        foreach (ForumPost f in posts)
                        {
                            AddToComboBox(f.name);
                            sw.WriteLine("<table style='width:100%'><tr><td><h3><font color='" + dictionary[comboBox1.Items.IndexOf(f.name)] + "'>" + f.name + "</font></h3></td>" + "<td align='right'><h4> Page: " + f.page + "</h4></td></tr>");
                            sw.WriteLine("<h4>" + f.time + "</h4>");
                            sw.WriteLine("<p>" + f.post + "</p>");
                            sw.WriteLine();
                            sw.WriteLine("<hr>");

                        }
                        sw.WriteLine("</body>");
                    }
                    else
                    {
                        sw.WriteLine("<h1>ERROR</h1>");
                        sw.WriteLine("</body>");
                    }
                }
                NavigateWebBrowserThread(di.ToString() + "\\All.html");
                MovePostsToMainThread(posts);
                SetComboBoxToIndexThread(0);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
예제 #19
0
 public void Navigate(string url)
 {
     ie.Navigate(url);
     Wait();
 }
예제 #20
0
        private void startButton_Click(object asdf, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            //-------------------------
            //openVAS Report Parsing
            //-------------------------
            if (NessusRadio.Checked == true)
            {
                //----------------------------------
                // Ensure a path has been specified
                //----------------------------------
                if (pathTextBox.Text == "")
                {
                    MessageBox.Show("Please enter a path to a Nessus CSV file.");
                }
                else
                {
                    String            path     = Directory.GetCurrentDirectory();
                    Excel.Application excelApp = new Excel.Application();
                    excelApp.Visible       = true;
                    excelApp.DisplayAlerts = false;
                    Excel.Workbook excelWorkbooks     = null;
                    Excel.Workbook pivotTableTemplate = null;


                    //-------------------------
                    // Check file extension
                    //-------------------------
                    if (Path.GetExtension(pathTextBox.Text).Equals(".csv"))
                    {
                        //-------------------------------------------------
                        // copy initial template for pivot table
                        //-------------------------------------------------
                        File.Copy("template_nessus.xlsx", pathTextBox.Text + "-parsedNessus.xlsx", true);
                        //-------------------------------------------------
                        // This opens the csv file and converts it to xlsx
                        // Saves it in the specified path in the text box
                        //-------------------------------------------------
                        try
                        {
                            excelWorkbooks = excelApp.Workbooks.Open(pathTextBox.Text);

                            excelWorkbooks.SaveAs(pathTextBox.Text + ".xlsx", FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook);
                            excelWorkbooks.Close();

                            excelWorkbooks = excelApp.Workbooks.Open(pathTextBox.Text + ".xlsx");
                            Excel._Worksheet convertedCSVWorksheet = excelWorkbooks.ActiveSheet;

                            //Get range to use for loops
                            Excel.Range usedRange = convertedCSVWorksheet.UsedRange;


                            /*
                             * transfer all the information
                             * into the excel pivot table
                             */
                            pivotTableTemplate = excelApp.Workbooks.Open(pathTextBox.Text + "-parsedNessus.xlsx");
                            Excel._Worksheet pivotTableData = pivotTableTemplate.Sheets[2];


                            for (int i = 0; i < usedRange.Rows.Count; ++i)
                            {
                                if (i == 0)
                                {
                                    continue;
                                }
                                else
                                {
                                    //ID
                                    pivotTableData.Cells[i + 9, 1] = convertedCSVWorksheet.Cells[i + 1, 1];

                                    //IP
                                    pivotTableData.Cells[i + 9, 2] = convertedCSVWorksheet.Cells[i + 1, 5];

                                    //Vulnerability Name
                                    pivotTableData.Cells[i + 9, 3] = convertedCSVWorksheet.Cells[i + 1, 8];

                                    //Risk and Severity
                                    if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 4].Value).Equals("None") || Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 4].Value).Equals("Info"))
                                    {
                                        pivotTableData.Cells[i + 9, 4] = "Info";
                                        pivotTableData.Cells[i + 9, 5] = "0";
                                    }
                                    if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 4].Value).Equals("Low"))
                                    {
                                        pivotTableData.Cells[i + 9, 4] = "Low";
                                        pivotTableData.Cells[i + 9, 5] = "1";
                                    }
                                    if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 4].Value).Equals("Medium"))
                                    {
                                        pivotTableData.Cells[i + 9, 4] = "Medium";
                                        pivotTableData.Cells[i + 9, 5] = "2";
                                    }
                                    if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 4].Value).Equals("High"))
                                    {
                                        pivotTableData.Cells[i + 9, 4] = "High";
                                        pivotTableData.Cells[i + 9, 5] = "3";
                                    }
                                    if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 4].Value).Equals("Critical") || Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 4].Value).Equals("Serious"))
                                    {
                                        pivotTableData.Cells[i + 9, 4] = "Critical";
                                        pivotTableData.Cells[i + 9, 5] = "4";
                                    }

                                    //Protocol
                                    pivotTableData.Cells[i + 9, 6] = convertedCSVWorksheet.Cells[i + 1, 6];

                                    //Port
                                    if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 7].Value).Equals("0"))
                                    {
                                        pivotTableData.Cells[i + 9, 7] = "---";
                                    }
                                    else
                                    {
                                        pivotTableData.Cells[i + 9, 7] = convertedCSVWorksheet.Cells[i + 1, 7];
                                    }
                                    pivotTableData.Cells[i + 9, 8] = convertedCSVWorksheet.Cells[i + 1, 10];
                                    pivotTableData.Cells[i + 9, 9] = convertedCSVWorksheet.Cells[i + 1, 11];
                                    //cvss vector, exploit available, and vulnerability publish date
                                    if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 2].Value) != null && !(Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 2].Value).Equals("-")))
                                    {
                                        String[] cve                = Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 2].Value).Split(','); //must do in openvas due to csv cve
                                        String   NVDurl             = "https://web.nvd.nist.gov/view/vuln/detail?vulnId=" + cve[0];
                                        SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
                                        IE.Visible = false;
                                        IE.Navigate(NVDurl);
                                        System.Threading.Thread.Sleep(2000);
                                        mshtml.IHTMLDocument2 htmlDoc = IE.Document as mshtml.IHTMLDocument2;
                                        string content = htmlDoc.body.parentElement.outerHTML;
                                        int    CVSSVectorStartIndex = content.IndexOf("(AV", content.IndexOf("(AV") + 1);
                                        int    CVSSVectorEndIndex   = 28;
                                        int    vulnDateStartIndex   = content.IndexOf("Original release date:") + 42;
                                        int    vulnDateEndIndex     = 10;
                                        pivotTableData.Cells[i + 9, 8] = convertedCSVWorksheet.Cells[i + 1, 10];
                                        pivotTableData.Cells[i + 9, 9] = convertedCSVWorksheet.Cells[i + 1, 11];
                                        if (vulnDateStartIndex != -1)
                                        {
                                            string stringVulndDate = content.Substring(vulnDateStartIndex, vulnDateEndIndex);
                                            pivotTableData.Cells[i + 9, 11] = stringVulndDate;
                                        }
                                        if (CVSSVectorStartIndex != -1)
                                        {
                                            string stringCVSSVector = content.Substring(CVSSVectorStartIndex, CVSSVectorEndIndex);
                                            pivotTableData.Cells[i + 9, 15] = stringCVSSVector;
                                        }
                                        IE.Quit();
                                    }

                                    //Exploit available
                                    if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 2].Value) != null)
                                    {
                                        pivotTableData.Cells[i + 9, 10] = "Exploit is available.";
                                    }

                                    //See Also
                                    pivotTableData.Cells[i + 9, 13] = convertedCSVWorksheet.Cells[i + 1, 12];

                                    //CVSS SCORE
                                    pivotTableData.Cells[i + 9, 14] = convertedCSVWorksheet.Cells[i + 1, 3];

                                    //CVE
                                    pivotTableData.Cells[i + 9, 16] = convertedCSVWorksheet.Cells[i + 1, 2];
                                }
                            }
                            //---------------------------------------------------
                            // Close worksheets and workbooks. Release Resources
                            // and close excel
                            //---------------------------------------------------
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(convertedCSVWorksheet);
                            excelWorkbooks.Close(false);
                            pivotTableTemplate.Close(true);
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbooks);
                            excelApp.Quit();
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
                            MessageBox.Show("Done parsing file.");
                        }
                        catch (Exception err)
                        {
                            MessageBox.Show("Error encountered. Please try again.");
                            if (excelWorkbooks != null)
                            {
                                excelWorkbooks.Close();
                            }
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbooks);
                            excelApp.Quit();
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
                        }
                    }

                    else
                    {
                        if (excelWorkbooks != null)
                        {
                            excelWorkbooks.Close();
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbooks);
                        }
                        excelApp.Quit();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
                        MessageBox.Show("Please select a CSV file.");
                    }
                }
            }

            //-----------------------
            // Nessus Report Parsing
            //-----------------------
            else
            {
                if (pathTextBox.Text == "")
                {
                    MessageBox.Show("Please enter a path to a Nessus CSV file.");
                }
                else
                {
                    String            path     = Directory.GetCurrentDirectory();
                    Excel.Application excelApp = new Excel.Application();
                    excelApp.Visible       = true;
                    excelApp.DisplayAlerts = false;
                    Excel.Workbook excelWorkbooks     = null;
                    Excel.Workbook pivotTableTemplate = null;


                    //-------------------------
                    // Check file extension
                    //-------------------------
                    if (Path.GetExtension(pathTextBox.Text).Equals(".xlsx"))
                    {
                        //-------------------------------------------------
                        // copy initial template for pivot table
                        //-------------------------------------------------
                        File.Copy("template_openvas.xlsx", pathTextBox.Text + "-parsedOpenVAS.xlsx", true);
                        try
                        {
                            //start timer for time analysis
                            Stopwatch stopwatch = new Stopwatch();
                            stopwatch.Start();
                            excelWorkbooks = excelApp.Workbooks.Open(pathTextBox.Text);
                            //                            excelWorkbooks.SaveAs(pathTextBox.Text + ".xlsx", FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook);
                            //                            excelWorkbooks.Close(); //closes first workbook

                            //                            excelWorkbooks = excelApp.Workbooks.Open(pathTextBox.Text + ".xlsx");
                            Excel._Worksheet convertedCSVWorksheet = excelWorkbooks.ActiveSheet; //opens another workbook on index 1


                            /*
                             * Getting range and iterating through
                             * the open file to get information
                             * for report
                             */
                            Excel.Range usedRange = convertedCSVWorksheet.UsedRange;
                            pivotTableTemplate = excelApp.Workbooks.Open(pathTextBox.Text + "-parsedOpenVAS.xlsx");
                            Excel._Worksheet pivotTableData = pivotTableTemplate.Sheets[2];


                            for (int i = 0; i < usedRange.Rows.Count; ++i)
                            {
                                if (i < 6)
                                {
                                    continue;
                                }
                                else
                                {
                                    //ID
                                    pivotTableData.Cells[i + 4, 1] = convertedCSVWorksheet.Cells[i + 1, 4];

                                    //IP
                                    pivotTableData.Cells[i + 4, 2] = convertedCSVWorksheet.Cells[i + 1, 2];

                                    //Hostname
                                    pivotTableData.Cells[i + 4, 3] = convertedCSVWorksheet.Cells[i + 1, 1];

                                    //Operating System/software check
                                    if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 13].Value) != "n/a")
                                    {
                                        pivotTableData.Cells[i + 4, 4] = convertedCSVWorksheet.Cells[i + 1, 13];
                                    }

                                    //Vulnerability Name
                                    if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 8].Value) != "n/a")
                                    {
                                        pivotTableData.Cells[i + 4, 5] = convertedCSVWorksheet.Cells[i + 1, 8];
                                    }
                                    else
                                    {
                                        pivotTableData.Cells[i + 4, 5] = "Not available.";
                                    }

                                    //Risk Level
                                    if (convertedCSVWorksheet.Cells[i + 1, 7].Value2 != null)
                                    {
                                        if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 7].Value2).Equals("None") || Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 7].Value2).Equals("Info"))
                                        {
                                            pivotTableData.Cells[i + 4, 6] = "Info";
                                            pivotTableData.Cells[i + 4, 7] = "0";
                                        }
                                        if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 7].Value2).Equals("Low"))
                                        {
                                            pivotTableData.Cells[i + 4, 6] = "Low";
                                            pivotTableData.Cells[i + 4, 7] = "1";
                                        }
                                        if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 7].Value2).Equals("Medium"))
                                        {
                                            pivotTableData.Cells[i + 4, 6] = "Medium";
                                            pivotTableData.Cells[i + 4, 7] = "2";
                                        }
                                        if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 7].Value2).Equals("High"))
                                        {
                                            pivotTableData.Cells[i + 4, 6] = "High";
                                            pivotTableData.Cells[i + 4, 7] = "3";
                                        }
                                        if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 7].Value2).Equals("Critical") || Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 7].Value2).Equals("Serious"))
                                        {
                                            pivotTableData.Cells[i + 4, 6] = "Critical";
                                            pivotTableData.Cells[i + 4, 7] = "4";
                                        }
                                    }

                                    String[] parenthSplit = Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 3].Value).Split('(');
                                    //service
                                    pivotTableData.Cells[i + 4, 8] = parenthSplit[0];
                                    //protocol
                                    String[] slashSplit = parenthSplit[1].Split('/');
                                    pivotTableData.Cells[i + 4, 9] = slashSplit[1].Substring(0, slashSplit[1].Length - 1);
                                    //port
                                    pivotTableData.Cells[i + 4, 10] = slashSplit[0];

                                    //Vulnerability Description
                                    pivotTableData.Cells[i + 4, 11] = convertedCSVWorksheet.Cells[i + 1, 9];

                                    //Remediation check
                                    if (!(Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 10].Value2).Equals("n/a")))
                                    {
                                        pivotTableData.Cells[i + 4, 12] = convertedCSVWorksheet.Cells[i + 1, 10];
                                    }

                                    //Results check
                                    // pivotTableData.Cells[i + 4, 13] = convertedCSVWorksheet.Cells[i + 1, 12];
                                    if (!(Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 12].Value2).Equals("n/a")))
                                    {
                                        pivotTableData.Cells[i + 4, 13] = convertedCSVWorksheet.Cells[i + 1, 12].Value2;
                                    }
                                    //pivotTableData.Cells[i + 4, 13] = convertedCSVWorksheet.Cells[i + 1, 12].Value2;

                                    //exploit available
                                    if (Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 6].Value) != null && !(Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 6].Value).Equals("-")))
                                    {
                                        pivotTableData.Cells[i + 4, 14] = "Exploit is available.";
                                        //cvss score 18
                                        if (Convert.ToInt32(convertedCSVWorksheet.Cells[i + 1, 5].Value) != 0)
                                        {
                                            pivotTableData.Cells[i + 4, 18] = convertedCSVWorksheet.Cells[i + 1, 5];
                                        }

                                        //cvss vector 19
                                        String[] cve    = Convert.ToString(convertedCSVWorksheet.Cells[i + 1, 6].Value).Split(','); //must do in openvas due to csv cve
                                        String   NVDurl = "https://web.nvd.nist.gov/view/vuln/detail?vulnId=" + cve[0];
                                        pivotTableData.Cells[i + 4, 17] = NVDurl;
                                        SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
                                        IE.Visible = false;
                                        IE.Navigate(NVDurl);
                                        System.Threading.Thread.Sleep(2000);
                                        mshtml.IHTMLDocument2 htmlDoc = IE.Document as mshtml.IHTMLDocument2;
                                        string content = htmlDoc.body.parentElement.outerHTML;
                                        int    CVSSVectorStartIndex = content.IndexOf("(AV", content.IndexOf("(AV") + 1);
                                        int    CVSSVectorEndIndex   = 28;
                                        int    vulnDateStartIndex   = content.IndexOf("Original release date:") + 42;
                                        int    vulnDateEndIndex     = 10;
                                        if (vulnDateStartIndex != -1)
                                        {
                                            string stringVulndDate = content.Substring(vulnDateStartIndex, vulnDateEndIndex);
                                            pivotTableData.Cells[i + 4, 15] = stringVulndDate;
                                        }
                                        if (CVSSVectorStartIndex != -1)
                                        {
                                            string stringCVSSVector = content.Substring(CVSSVectorStartIndex, CVSSVectorEndIndex);
                                            pivotTableData.Cells[i + 4, 19] = stringCVSSVector;
                                        }
                                        IE.Quit();

                                        //cve 20
                                        pivotTableData.Cells[i + 4, 20] = convertedCSVWorksheet.Cells[i + 1, 6];

                                        //Console.WriteLine(cve[0]);
                                        //WebClient browser = new WebClient();
                                        //string nvdWebsite = browser.DownloadString(NVDurl);
                                        //int index1 = nvdWebsite.IndexOf("Date Entry Created") + 49;
                                        //int index2 = 8;
                                        //string substr = nvdWebsite.Substring(index1, index2);
                                        //Console.WriteLine(substr);
                                        //HtmlAgilityPack.HtmlDocument page = new HtmlAgilityPack.HtmlDocument();
                                        //Console.WriteLine(nvdWebsite);
                                        //WatiN.Core.Settings.MakeNewIeInstanceVisible = false;
                                        //WatiN.Core.Settings.AutoMoveMousePointerToTopLeft = false;
                                        //page.LoadHtml(nvdWebsite);
                                        //HtmlNode titleNode = page.DocumentNode.SelectSingleNode("/html/body/div[1]/div[4]/table/tr[9]/td/b");
                                        //if (titleNode == null)
                                        //{
                                        //    Console.WriteLine("NULL OMG NULL");
                                        //}
                                        //HtmlNode titleNode = pageResult.Html.CssSelect(".hohoho-header").First();
                                        //string stuffnode = titleNode.InnerText;
                                        //Console.WriteLine(titleNode);
                                        //pivotTableData.Cells[i + 4, 15] = titleNode;
                                    }
                                }
                            }


                            //---------------------------------------------------
                            // Close worksheets and workbooks. Release Resources
                            // and close excel
                            //---------------------------------------------------
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(convertedCSVWorksheet);
                            excelWorkbooks.Close(false);
                            pivotTableTemplate.Close(true);
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbooks);
                            excelApp.Quit();
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
                            MessageBox.Show("Done parsing file.");
                        }
                        catch (Exception err)
                        {
                            MessageBox.Show("Error encountered. Please try again.");
                            if (excelWorkbooks != null)
                            {
                                excelWorkbooks.Close();
                            }
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbooks);
                            excelApp.Quit();
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
                        }
                    }
                    else
                    {
                        if (excelWorkbooks != null)
                        {
                            excelWorkbooks.Close();
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbooks);
                        }
                        excelApp.Quit();
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
                        MessageBox.Show("Please select a XLSX file.");
                    }
                }
            }
            this.Cursor = Cursors.Default;
        }
예제 #21
0
 void CommandBinding_Help(object sender, ExecutedRoutedEventArgs e)
 {
     IE = new SHDocVw.InternetExplorer();
     IE.Navigate(System.Windows.Forms.Application.StartupPath + @"\Help\Help.html");
     IE.Visible = true;
 }