Ejemplo n.º 1
0
        public static async Task ScanURL(string url, RichTextBox richtextbox, DataGridView datagridview)
        {
            try
            {
                VirusTotalNET.VirusTotal virusTotal = new VirusTotalNET.VirusTotal(APIKey);

                //Use HTTPS instead of HTTP
                virusTotal.UseTLS = true;

                UrlReport urlReport = await virusTotal.GetUrlReport(url);

                bool hasUrlBeenScannedBefore = urlReport.ResponseCode == ReportResponseCode.Present;

                //If the url has been scanned before, the results are embedded inside the report.
                if (hasUrlBeenScannedBefore)
                {
                    PrintScan(urlReport, url, hasUrlBeenScannedBefore, richtextbox, datagridview);
                }
                else
                {
                    UrlScanResult urlResult = await virusTotal.ScanUrl(url);

                    PrintScan(urlResult, url, hasUrlBeenScannedBefore, richtextbox, datagridview);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Something went wrong!");
            }
        }
        /// <summary>
        /// Performs a URL scan.
        /// Request a URL scan.
        /// Then checks every thirty seconds for a result.
        /// Doesn't return until VT results come in. Can take up to five minutes
        /// </summary>
        /// <param name="url"></param>
        /// <param name="delayBetweenRequestsMs">Virus Total only allows up to 4 request per minute. This delay adds a pause between each api call. Avoids exceptions. Defaults to 30.5 seconds.</param>
        /// <returns>A Tuple. Item 1 is a detection ratio (a float derived from positives divided by total). Item 2 is Virus Total permalink for scan.</returns>
        public async Task <Tuple <float, string> > ScanUrlComplete(string url, int delayBetweenRequestsMs = 30500)
        {
            Console.WriteLine($"Getting Url Report: {url}");

            await _virusTotal.ScanUrl(url);

            UrlReport urlReport = null;

            while (urlReport == null || urlReport.ResponseCode != ResponseCodes.ReportResponseCode.Present)
            {
                await Task.Delay(delayBetweenRequestsMs);

                Console.WriteLine($"Waiting {delayBetweenRequestsMs} ms");
                urlReport = await _virusTotal.GetUrlReport(url);
            }

            var detectionRatio = urlReport.Positives / (float)urlReport.Total;

            Console.WriteLine($"Detection Ratio: {urlReport.Positives} / {urlReport.Total} = {detectionRatio}");

            return(new Tuple <float, string>(detectionRatio, urlReport.Permalink));
        }