Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scan uploaded files C# ASP.net

I'm trying to do a virus scan on uploaded files. I have no control over the installed virus scanner, the product hosted by multiple parties with different scanners.

I tried the following library but it always returns VirusNotFound on the eicar file. https://antivirusscanner.codeplex.com/

Do you know any other solutions?

like image 317
Yolofy Avatar asked Sep 22 '16 11:09

Yolofy


2 Answers

ClamAV has pretty bad detection scores. VirusTotal is not on premises.

I decided to create CLI wrappers for multiple scanners, nuget packages can be found here: https://www.nuget.org/packages?q=avscan

And its documentation and source code available at https://github.com/yolofy/AvScan

like image 91
Yolofy Avatar answered Sep 22 '22 17:09

Yolofy


I used this library for .net (It uses the VirusTotal public api):

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

A little example from 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);
    }
}

A full example can be found here :

https://github.com/Genbox/VirusTotal.NET/blob/master/VirusTotal.NET%20Client/Program.cs

like image 24
Quentin Roger Avatar answered Sep 18 '22 17:09

Quentin Roger