3

我目前在我的 C# MVC 项目中使用 VirusTotal.NET nuget 包来扫描上传的文件。我正在使用此处给出的相同示例https://github.com/Genbox/VirusTotal.NET

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 report = await virusTotal.GetFileReportAsync(eicar);

Console.WriteLine("Seen before: " + (report.ResponseCode == FileReportResponseCode.Present ? "Yes" : "No"));

我正在将上传文件的字节数组加载到eicar上述代码中的变量中。根据给定的示例,它将提供文件是否被扫描过。但我真正需要的是文件是否被感染。谁能建议我一个解决方案?

4

1 回答 1

5

查看UrlReport类,您返回的报告包含更多信息,而不仅仅是代码示例中的响应代码。有 3 个字段看起来很有趣:

/// <summary>
/// How many engines flagged this resource.
/// </summary>
public int Positives { get; set; }

/// <summary>
/// The scan results from each engine.
/// </summary>
public Dictionary<string, UrlScanEngine> Scans { get; set; }

/// <summary>
/// How many engines scanned this resource.
/// </summary>
public int Total { get; set; }

这可能会为您提供您正在寻找的结果。VirusTotal 实际上会返回多个扫描引擎的结果,其中一些可能会检测到病毒,而另一些可能不会。

Console.WriteLine($"{report.Positives} out of {report.Total} scan engines detected a virus.");

你可以用这些数据做任何你想做的事情,比如计算百分比:

var result = 100m * report.Positives / report.Total;
Console.WriteLine($"{result}% of scan engines detected a virus.");

或者只是将大多数正面扫描引擎结果视为整体正面结果:

var result = Math.Round(report.Positives / Convert.ToDecimal(report.Total));
Console.WriteLine($"Virus {(result == 0 ? "not detected": "detected")});
于 2019-01-14T06:07:40.553 回答