Search code examples
azureantivirusazure-media-servicessymantec

Virus Scanning Uploaded files from Azure Web/Worker Role


We are designing an Azure Website which will allow users to Upload content(MP4,Docx...MSOffice Files) which can then be accessed.

Some video content we will encode to provide several differing quality formats, before it will be streamed (using Azure Media Services).

We need to add an intermediate step so we can scan uploaded files for potential virus risk. Is there functionality built into azure (or third party) which will allow us to call an API to scan content before processing it? We are ideally looking for an API rather than just a background service on a VM, so we can get feedback potentially for use in a web or worker role.

Had a quick look at Symantec Endpoint and Windows Defender but not sure these offer an API


Solution

  • I have successfully done this using the open source ClamAV. You don't specify what languages you are using, but as it's Azure I'll assume .Net.

    There is a .Net wrapper that should provide the API that you are looking for:

    https://github.com/tekmaven/nClam

    Here is some sample code (note: this is copied directly from the nClam GitHub repo page and reproduced here just to protect against link rot)

    using System;
    using System.Linq;
    using nClam;
    
    class Program
    {
        static void Main(string[] args)
        {
    
            var clam = new ClamClient("localhost", 3310);
            var scanResult = clam.ScanFileOnServer("C:\\test.txt");  //any file you would like!
    
            switch(scanResult.Result)
            {
                case ClamScanResults.Clean:
                    Console.WriteLine("The file is clean!");
                    break;
                case ClamScanResults.VirusDetected:
                    Console.WriteLine("Virus Found!");
                    Console.WriteLine("Virus name: {0}", scanResult.InfectedFiles.First().VirusName);
                    break;
                case ClamScanResults.Error:
                    Console.WriteLine("Woah an error occured! Error: {0}", scanResult.RawResult);
                    break;
            }
        }
    }
    

    There are also APIs available for refreshing the virus definition database. All the necessary ClamAV files can be included in the deployment package and any configuration can be put into the service start-up code.