Ejemplo n.º 1
0
        public static async Task <string> FindVirusTotalInfoAsync(string url)
        {
            string     returnString = "";
            VirusTotal virusTotal   = new VirusTotal("de0a5c113302967ab7d535c84e8a6ce49eacbd2952397c43dc99c13a26df423e");

            virusTotal.UseTLS = true;
            UrlReport urlReport = await virusTotal.GetUrlReportAsync(url);

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

            //do something return string with info about the url
            Console.WriteLine("URL has been scanned before: " + (hasUrlBeenScannedBefore ? "Yes" : "No"));

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

                PrintScan(urlResult);
            }
            returnString = returnString + urlReport.Permalink + "***" + urlReport.Positives + "/" + urlReport.Total;
            return(returnString);
            //repeat varius api interaction methods for the other analysis sites with each irl
        }
Ejemplo n.º 2
0
    private static async Task Main(string[] args)
    {
        VirusTotal virusTotal = new VirusTotal("YOUR API KEY HERE");

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

        //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html
        byte[] eicar = Encoding.ASCII.GetBytes(@"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*");

        //Check if the file has been scanned before.
        FileReport fileReport = await virusTotal.GetFileReportAsync(eicar);

        bool hasFileBeenScannedBefore = fileReport.ResponseCode == FileReportResponseCode.Present;

        Console.WriteLine("File has been scanned before: " + (hasFileBeenScannedBefore ? "Yes" : "No"));

        //If the file has been scanned before, the results are embedded inside the report.
        if (hasFileBeenScannedBefore)
        {
            PrintScan(fileReport);
        }
        else
        {
            ScanResult fileResult = await virusTotal.ScanFileAsync(eicar, "EICAR.txt");

            PrintScan(fileResult);
        }

        Console.WriteLine();

        string scanUrl = "http://www.google.com/";

        UrlReport urlReport = await virusTotal.GetUrlReportAsync(scanUrl);

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

        Console.WriteLine("URL has been scanned before: " + (hasUrlBeenScannedBefore ? "Yes" : "No"));

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

            PrintScan(urlResult);
        }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// The listBox1_DoubleClick
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/></param>
        /// <param name="e">The e<see cref="EventArgs"/></param>
        private async void listBox1_DoubleClick(object sender, EventArgs e)
        {
            var        ip         = listBox1.SelectedItem.ToString();
            VirusTotal virustotal =
                new VirusTotal("a3f22a4baa6bfb80942e3aa9824c0673acab04140cb7825487590d587d70c485")
            {
                UseTLS = true
            };
            UrlReport report = await virustotal.GetUrlReportAsync(ip);

            bool          Scancheck  = report.ResponseCode == UrlReportResponseCode.Present;
            UrlScanResult fileResult = await virustotal.ScanUrlAsync(ip);

            if (Scancheck)
            {
                linkLabel2.Text = fileResult.Permalink;
            }
            else
            {
                if (fileResult.Permalink.Contains("://"))
                {
                    Process.Start(fileResult.Permalink);
                }
            }

            if (report.ResponseCode == UrlReportResponseCode.Present)
            {
                foreach (KeyValuePair <string, UrlScanEngine> scan in report.Scans)
                {
                    ListViewItem itm = new ListViewItem {
                        Text = scan.Key
                    };
                    itm.SubItems.Add(scan.Value.Result);
                    if (scan.Value.Result == "clean site")
                    {
                        itm.SubItems[1].ForeColor   = Color.Green;
                        itm.UseItemStyleForSubItems = false;
                    }
                    else
                    {
                        itm.SubItems[1].ForeColor   = Color.Red;
                        itm.UseItemStyleForSubItems = false;
                    }

                    itm.SubItems.Add(report.ScanDate.ToString(CultureInfo.CurrentCulture));
                    itm.SubItems.Add(report.ScanId);
                    listView1.Items.Add(itm);
                }
            }
        }
Ejemplo n.º 4
0
        public async Task ExecuteVirusTotalScan(ScanRequest request)
        {
            try
            {
                VirusTotal virusTotal = new VirusTotal(_possibleScans.VirusTotalApiKey);

                UrlReport urlReport = await virusTotal.GetUrlReportAsync(request.WebsiteUrl);

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

                //_logger.LogInformation("URL has been scanned before: " + (hasUrlBeenScannedBefore ? "Yes" : "No"));

                //If the url has been scanned before, the results are embedded inside the report.
                if (hasUrlBeenScannedBefore)
                {
                    ParseVirusTotalScanResult(urlReport, request);
                }
                else
                {
                    UrlScanResult urlResult = await virusTotal.ScanUrlAsync(request.WebsiteUrl);

                    int tryCount = 0;
                    while (tryCount < 1000)
                    {
                        UrlReport urlCurrentReport = await virusTotal.GetUrlReportAsync(request.WebsiteUrl);

                        hasUrlBeenScannedBefore = urlCurrentReport.ResponseCode == UrlReportResponseCode.Present;
                        if (hasUrlBeenScannedBefore)
                        {
                            ParseVirusTotalScanResult(urlReport, request);
                            break;
                        }

                        _logger.LogDebug("SKIPPING");
                        await Task.Delay(2000);

                        tryCount++;
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error at ExecuteVirusTotalScan, Error: ");
            }
        }
Ejemplo n.º 5
0
    public async Task ScanUnknownUrl()
    {
        UrlScanResult fileResult = await VirusTotal.ScanUrlAsync(TestData.GetUnknownUrls(1).First());

        Assert.Equal(UrlScanResponseCode.Queued, fileResult.ResponseCode);
    }
Ejemplo n.º 6
0
        public async Task <ApiResponse> GetAsync(string host)
        {
            ApiResponse   apiResponse = null;
            UrlScanResult urlResult   = null;
            UrlReport     scanReport  = null;

            try
            {
                VirusTotal virusTotal = new VirusTotal(ApiSettingHelper.ApiKey);
                virusTotal.UseTLS = true;

                urlResult = await virusTotal.ScanUrlAsync(host);

                if (urlResult.ResponseCode == UrlScanResponseCode.Queued)
                {
                    scanReport = await virusTotal.GetUrlReportAsync(host);

                    VirusTotalReport report = new VirusTotalReport()
                    {
                        Host      = host,
                        ScanId    = scanReport.ScanId,
                        ScanDate  = scanReport.ScanDate,
                        Positives = scanReport.Positives,
                        Resource  = scanReport.Resource,
                        Total     = scanReport.Total
                    };

                    if (scanReport.ResponseCode == UrlReportResponseCode.Present)
                    {
                        scanReport.Scans.ToList().ForEach(scan =>
                        {
                            report.ReportDetails.Add(new ReportDetail()
                            {
                                Name     = scan.Key,
                                Detail   = scan.Value.Detail,
                                Detected = scan.Value.Detected,
                                Result   = scan.Value.Result
                            });
                        });

                        apiResponse = new ApiResponse()
                        {
                            StatusCode = HttpStatusCode.OK,
                            Result     = JObject.Parse(JsonConvert.SerializeObject(report))
                        };
                    }
                    else
                    {
                        apiResponse = new ApiResponse()
                        {
                            StatusCode   = HttpStatusCode.BadRequest,
                            ErrorMessage = scanReport.VerboseMsg
                        };
                    }
                }
                else
                {
                    apiResponse = new ApiResponse()
                    {
                        StatusCode   = HttpStatusCode.BadRequest,
                        ErrorMessage = urlResult.VerboseMsg
                    };
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Exception occurred calling external API for '{lookup}'", host);

                apiResponse = new ApiResponse()
                {
                    StatusCode   = HttpStatusCode.InternalServerError,
                    ErrorMessage = ex.Message,
                };
            }

            return(apiResponse);
        }
Ejemplo n.º 7
0
        private static async Task Main(string[] args)
        {
            Console.WriteLine("Hello, what do you want to scan?\n");
            Console.WriteLine("for url press 1, for file presss 2, for ip press 3");
            //int choice;
            String temp = Console.ReadLine();

            //choice=int.Parse(temp);
            Console.WriteLine(temp);



            VirusTotal virusTotal = new VirusTotal("50c1c91e9bfc7cb858022a0cbeaf1ba0f8782dbbd506be82f71b1e3f243000cf");

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

            //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html
            byte[] eicar = Encoding.ASCII.GetBytes(@"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*");

            //Check if the file has been scanned before.
            FileReport fileReport = await virusTotal.GetFileReportAsync(eicar);

            bool hasFileBeenScannedBefore = fileReport.ResponseCode == FileReportResponseCode.Present;

            Console.WriteLine("File has been scanned before: " + (hasFileBeenScannedBefore ? "Yes" : "No"));

            //If the file has been scanned before, the results are embedded inside the report.
            if (hasFileBeenScannedBefore)
            {
                PrintScan(fileReport);
            }
            else
            {
                ScanResult fileResult = await virusTotal.ScanFileAsync(eicar, "EICAR.txt");

                PrintScan(fileResult);
            }

            Console.WriteLine();

            string scanUrl = "http://www.google.com/";

            UrlReport urlReport = await virusTotal.GetUrlReportAsync(scanUrl);

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

            Console.WriteLine("URL has been scanned before: " + (hasUrlBeenScannedBefore ? "Yes" : "No"));

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

                PrintScan(urlResult);
            }
        }