7

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?

Yolofy
  • 431
  • 1
  • 6
  • 13

4 Answers4

5

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

mmushtaq
  • 3,430
  • 7
  • 30
  • 47
Yolofy
  • 431
  • 1
  • 6
  • 13
2

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

Quentin Roger
  • 6,410
  • 2
  • 23
  • 36
0

Clam AV is pretty good. https://www.clamav.net/downloads

C# Api here: https://github.com/michaelhans/Clamson/

Artur Kedzior
  • 3,994
  • 1
  • 36
  • 58
0

I just tried various ways, But some didn't work. Then I decided to use ESET NOD32 command line tools .

It works fine for me:

 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;
        }
Javad Ghasemi
  • 222
  • 1
  • 4