Scan uploaded files C# ASP.net
Asked Answered
T

4

9

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?

Turnaround answered 22/9, 2016 at 11:45 Comment(1)
You can use virus total apiStern
T
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

Turnaround answered 27/9, 2016 at 9:41 Comment(1)
Does this solution send files to third party services?Aluino
L
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

Lilalilac answered 22/9, 2016 at 11:58 Comment(0)
V
0

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

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

Valera answered 22/9, 2016 at 12:8 Comment(0)
P
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;
        }
Precedential answered 15/5, 2022 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.