扫描上传的文件 C# ASP.net

7
我正在尝试对上传的文件进行病毒扫描。 我无法控制安装的病毒扫描器,因为该产品由多个方面提供宿主服务,使用不同的扫描器。
我尝试了下面的库,但对于eicar文件它总是返回VirusNotFound。 https://antivirusscanner.codeplex.com/ 您知道其他解决方案吗?

你可以使用 VirusTotal API。 - Sarvesh Mishra
4个回答

5

1
这个解决方案是否会将文件发送到第三方服务? - zolty13

2

我使用了这个库来进行 .net 开发(它使用 VirusTotal 的公共 API):

https://github.com/Genbox/VirusTotal.NET

这是一个来自 Github 上的小例子:

static void Main(string[] args)
{
    VirusTotal virusTotal = new VirusTotal("INSERT API KEY HERE");

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

    FileInfo fileInfo = new FileInfo("testfile.txt");

    //Create a new file
    File.WriteAllText(fileInfo.FullName, "This is a test file!");

     //Check if the file has been scanned before.
    Report fileReport = virusTotal.GetFileReport(fileInfo).First();
    bool hasFileBeenScannedBefore = fileReport.ResponseCode == 1;

    if (hasFileBeenScannedBefore)
    {
        Console.WriteLine(fileReport.ScanId);
    }
    else
    {
        ScanResult fileResults = virusTotal.ScanFile(fileInfo);
        Console.WriteLine(fileResults.VerboseMsg);
    }
}

这里有一个完整的示例: https://github.com/Genbox/VirusTotal.NET/blob/master/VirusTotal.NET%20Client/Program.cs

0

0

我刚刚尝试了各种方法,但有些并没有起作用。 然后我决定使用ESET NOD32命令行工具。

对我来说它很好用:

 public bool Scan(string filename)
    {

        var result = false;
        try
        {
            Process process = new Process();

            var processStartInfo = new ProcessStartInfo(@"C:/Program Files/ESET/ESET Security/ecls.exe")
            {
                Arguments = $" \"{filename}\"",
                CreateNoWindow = true,
                ErrorDialog = false,
                WindowStyle = ProcessWindowStyle.Hidden,
                UseShellExecute = false
            };

            process.StartInfo = processStartInfo;
            process.Start();
            process.WaitForExit();
            if (process.ExitCode == 0) //if it doesn't exist virus ,it returns 0 ,if not ,it returns 1    
            {
                result = true;
            }
        }
        catch (Exception)
        { //nothing;
        }
        

        return result;
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接