Exemple #1
0
        /// <summary>
        /// Creates a scan request if the file exists in the virusTotal Database
        /// </summary>
        /// <returns></returns>
        public static async Task <ScanResults> CreateScanReqAsync()
        {
            ScanResults scanResults = null;

            using HttpResponseMessage response = await APIHelper.ApiClient.GetAsync("https://www.virustotal.com/api/v3/files/" + FileInfo.FileInfoInstance.MD5);

            if (response.IsSuccessStatusCode)
            {
                try
                {
                    //deserialize json into object
                    var jsonString = await response.Content.ReadAsStringAsync();

                    scanResults = ScanResults.FromJson(jsonString);
                    return(scanResults);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
            else
            {
                //File not found in virus total database.Need to upload it.
                if (!hasBeenUploaded)
                {
                    await UploadFileToVTotalAsync();

                    scanResults = await CreateScanReqAsync();
                }
            }
            return(scanResults);
        }
Exemple #2
0
        /// <summary>
        /// Async method to create an HTTPPost request to scan the file the user selected. Scan results are filtered and saved
        /// </summary>
        /// <returns></returns>
        private async Task GetScanResultsAsync()
        {
            ScanResults scanResults = null;

            do
            {
                scanResults = await UploadFile.CreateScanReqAsync();

                if (scanResults.Data.Attributes.LastAnalysisResults.Count > 72)
                {
                    break;
                }
                else
                {
                    // if results are still not of expected size, wait 10 seconds and request them again
                    await Task.Delay(10000);
                }
            } while (true);

            int malicious  = 0;
            int undetected = 0;
            int unknown    = 0;

            if (scanResults != null)
            {
                foreach (KeyValuePair <string, LastAnalysisResult> entry in scanResults.Data.Attributes.LastAnalysisResults)
                {
                    // categorize the outcome of the scan result
                    if ((int)entry.Value.Category == 0)
                    {
                        malicious++;
                    }
                    else if ((int)entry.Value.Category == 1)
                    {
                        unknown++;
                    }
                    else if ((int)entry.Value.Category == 2)
                    {
                        undetected++;
                    }
                    else if ((int)entry.Value.Category == 3)
                    {
                        unknown++;
                    }
                    else if ((int)entry.Value.Category == 4)
                    {
                        unknown++;
                    }
                }

                Func <ChartPoint, string> labelPoint   = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
                SeriesCollection          piechartData = new SeriesCollection
                {
                    new PieSeries
                    {
                        Title  = "Malicious",
                        Values = new ChartValues <double> {
                            malicious
                        },
                        DataLabels = true,
                        LabelPoint = labelPoint,
                        Fill       = System.Windows.Media.Brushes.Maroon
                    },
                    new PieSeries
                    {
                        Title  = "Undetected",
                        Values = new ChartValues <double> {
                            undetected
                        },
                        DataLabels = true,
                        LabelPoint = labelPoint,
                        Fill       = System.Windows.Media.Brushes.MediumBlue
                    },
                    new PieSeries
                    {
                        Title  = "Unknown",
                        Values = new ChartValues <double> {
                            unknown
                        },
                        DataLabels = true,
                        LabelPoint = labelPoint,
                        Fill       = System.Windows.Media.Brushes.Gray
                    }
                };

                pieChart1.Series = piechartData;
                CommunityVotesChart(scanResults.Data.Attributes.TotalVotes.Harmless, scanResults.Data.Attributes.TotalVotes.Malicious);
            }
        }