How to Block Zero Day Threats in C# .Net Framework

Cloudmersive
2 min readAug 5, 2020

--

Zero day threats are the bogey men of the malware world, popping up where least expected to take down unprepared systems. Traditional definition-based virus scanning solutions are no help here, as these new custom-designed threats are not yet catalogued. In these cases, you need specialized tools, which is what we will be covering today.

To begin we will run this command for NuGet to install our client files.

Install-Package Cloudmersive.APIClient.NET.VirusScan -Version 3.0.3

Next up comes our function call, which will take in a variety of parameters that can be used to customize your zero-day threat needs.

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.VirusScan.Api;using Cloudmersive.APIClient.NET.VirusScan.Client;using Cloudmersive.APIClient.NET.VirusScan.Model;namespace Example{public class ScanFileAdvancedExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new ScanApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.var allowExecutables = true;  // bool? | Set to false to block executable files (program code) from being allowed in the input file.  Default is false (recommended). (optional)var allowInvalidFiles = true;  // bool? | Set to false to block invalid files, such as a PDF file that is not really a valid PDF file, or a Word Document that is not a valid Word Document.  Default is false (recommended). (optional)var allowScripts = true;  // bool? | Set to false to block script files, such as a PHP files, Pythong scripts, and other malicious content or security threats that can be embedded in the file.  Set to true to allow these file types.  Default is false (recommended). (optional)var allowPasswordProtectedFiles = true;  // bool? | Set to false to block password protected and encrypted files, such as encrypted zip and rar files, and other files that seek to circumvent scanning through passwords.  Set to true to allow these file types.  Default is false (recommended). (optional)var restrictFileTypes = restrictFileTypes_example;  // string | Specify a restricted set of file formats to allow as clean as a comma-separated list of file formats, such as .pdf,.docx,.png would allow only PDF, PNG and Word document files.  All files must pass content verification against this list of file formats, if they do not, then the result will be returned as CleanResult=false.  Set restrictFileTypes parameter to null or empty string to disable; default is disabled. (optional)try{// Advanced Scan a file for virusesVirusScanAdvancedResult result = apiInstance.ScanFileAdvanced(inputFile, allowExecutables, allowInvalidFiles, allowScripts, allowPasswordProtectedFiles, restrictFileTypes);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling ScanApi.ScanFileAdvanced: " + e.Message );}}}}

And that’s it!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet