我目前在我的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
变量。根据给定的示例,它将提供文件是否在扫描之前被扫描。但我真正需要的是文件是否被感染。有人能给我一个解决方案吗?
发布于 2019-01-14 06:07:41
查看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")});
https://stackoverflow.com/questions/54176282
复制