Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NET病毒扫描API_C#_.net_Api_Antivirus - Fatal编程技术网

C# .NET病毒扫描API

C# .NET病毒扫描API,c#,.net,api,antivirus,C#,.net,Api,Antivirus,我正在构建一个web应用程序,在其中我需要扫描用户上传的文件以查找病毒 任何有过类似构建经验的人都可以提供关于如何启动和运行的信息吗?我猜杀毒软件包有API可以通过编程方式访问其功能,但似乎不容易掌握细节 仅供参考,该应用程序是用C#编写的。我可能只需要进行一个系统调用来运行一个独立的进程来进行扫描。有许多来自不同供应商的命令行AV引擎 根据我的经验,您可以使用COM与一些防病毒软件进行接口。但我的建议是更简单一点,只需在扫描后解析扫描结果。您只需启动扫描程序进程,将其指向要扫描的文件/文件夹,

我正在构建一个web应用程序,在其中我需要扫描用户上传的文件以查找病毒

任何有过类似构建经验的人都可以提供关于如何启动和运行的信息吗?我猜杀毒软件包有API可以通过编程方式访问其功能,但似乎不容易掌握细节


仅供参考,该应用程序是用C#编写的。

我可能只需要进行一个系统调用来运行一个独立的进程来进行扫描。有许多来自不同供应商的命令行AV引擎

根据我的经验,您可以使用COM与一些防病毒软件进行接口。但我的建议是更简单一点,只需在扫描后解析扫描结果。您只需启动扫描程序进程,将其指向要扫描的文件/文件夹,将扫描结果存储到文件中,或将stdout重定向到应用程序并解析结果。

各种病毒扫描程序都有API。我和Sophos整合在一起。我很确定诺顿也有API,而McAfee没有(以前是这样)。你想使用什么病毒软件?您可能希望签出,因为它将允许与许多不同的扫描仪集成,但需要每年支付许可证费用:-P

看一下。它使用COM,COM应该很容易与.NET进行接口。它特别指的是Internet Explorer和Microsoft Office,但我不明白为什么您不能使用按需扫描任何文件


所有在Windows上运行的现代扫描仪都应该了解此API。

使用前的重要注意事项: 注意TOS协议。您给予他们对所有内容的完全访问权:“当您上传或以其他方式提交内容时,您给予VirusTotal(以及我们的合作伙伴)使用、编辑、主持、存储、复制、修改、创建衍生作品、交流、发布、公开表演、公开展示和分发此类内容的全球免版税、不可撤销和可转让许可证。”

您可以使用的服务不是使用本地防病毒程序(从而将您的程序绑定到特定的防病毒产品,并请求您的客户安装该防病毒产品)

本网站提供免费服务,您的文件将作为众多防病毒产品的输入,您将收到一份详细的报告,其中包含扫描过程中产生的证据。通过这种方式,您的解决方案不再绑定到特定的防病毒产品(尽管您绑定到Internet可用性)

该网站还提供了一个应用程序编程接口,允许以编程方式访问其扫描引擎



由于没有代码就不完整,因此这是直接从VirusTotal.NET库附带的示例客户端获取的

static void Main(string[] args)
{
    VirusTotal virusTotal = new VirusTotal(ConfigurationManager.AppSettings["ApiKey"]);

    //Use HTTPS instead of HTTP
    virusTotal.UseTLS = true;

    //Create the EICAR test virus. See http://www.eicar.org/86-0-Intended-use.html
    FileInfo fileInfo = new FileInfo("EICAR.txt");
    File.WriteAllText(fileInfo.FullName, @"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*");

    //Check if the file has been scanned before.
    FileReport fileReport = virusTotal.GetFileReport(fileInfo);

    bool hasFileBeenScannedBefore = fileReport.ResponseCode == ReportResponseCode.Present;

    Console.WriteLine("File has been scanned before: " + (hasFileBeenScannedBefore ? "Yes" : "No"));

    //If the file has been scanned before, the results are embedded inside the report.
    if (hasFileBeenScannedBefore)
    {
        PrintScan(fileReport);
    }
    else
    {
        ScanResult fileResult = virusTotal.ScanFile(fileInfo);
        PrintScan(fileResult);
    }
    ... continue with testing a web site ....
}

免责声明
我与他们没有任何关系。我之所以写这个答案,是因为它似乎是对这些4年前的答案的一个很好的更新。

//Scan
//Scan  
string start = Console.ReadLine();  
System.Diagnostics.Process scanprocess = new System.Diagnostics.Process();  
sp.StartInfo.WorkingDirectory = @"<location of your antivirus>";  
sp.StartInfo.UseShellExecute = false;  
sp.StartInfo.FileName = "cmd.exe";  
sp.StartInfo.Arguments = @"/c antivirusscanx.exe /scan="+filePath;  
sp.StartInfo.CreateNoWindow = true;  
sp.StartInfo.RedirectStandardInput = true;    
sp.StartInfo.RedirectStandardError = true; sp.Start();  
string output = sp.StandardOutput.ReadToEnd();  
//Scan results  
System.Diagnostics.Process pr = new System.Diagnostics.Process();      
pr.StartInfo.FileName = "cmd.exe";  
pr.StartInfo.Arguments = @"/c echo %ERRORLEVEL%";   
pr.StartInfo.RedirectStandardInput = true;    
pr.StartInfo.RedirectStandardError = true; pr.Start();  
output = processresult.StandardOutput.ReadToEnd();  
pr.Close(); 
字符串start=Console.ReadLine(); System.Diagnostics.Process scanprocess=新的System.Diagnostics.Process(); sp.StartInfo.WorkingDirectory=@”; sp.StartInfo.UseShellExecute=false; sp.StartInfo.FileName=“cmd.exe”; sp.StartInfo.Arguments=@/c antivirusscanx.exe/scan=“+filePath; sp.StartInfo.CreateNoWindow=true; sp.StartInfo.RedirectStandardInput=true; sp.StartInfo.RedirectStandardError=true;sp.Start(); 字符串输出=sp.StandardOutput.ReadToEnd(); //扫描结果 System.Diagnostics.Process pr=新的System.Diagnostics.Process(); pr.StartInfo.FileName=“cmd.exe”; pr.StartInfo.Arguments=@“/c echo%ERRORLEVEL%”; pr.StartInfo.RedirectStandardInput=true; pr.StartInfo.RedirectStandardError=true;pr.Start(); output=processresult.StandardOutput.ReadToEnd(); pr.Close();
无耻的插件,但您可能想检查一下,它基本上是作为(REST)服务的恶意软件/病毒检测。另外,请确保您阅读并理解virustotal的API术语()——它们非常清楚不允许商业使用

您可以使用IAttachmentExecute API

Windows操作系统提供了调用已安装的防病毒软件的通用API(当然,所需的防病毒软件支持该API)。 但是,调用防病毒软件的API仅提供COM接口样式,不支持IDispatch。 因此,从任何.NET语言和脚本语言调用此API都太困难了

从此处下载此库或从“NuGet”添加对VS项目的引用

例如,下面的代码扫描文件:

var scanner = new AntiVirus.Scanner();
var result = scanner.ScanAndClean(@"c:\some\file\path.txt");
Console.WriteLine(result); // console output is "VirusNotFound".

您可以尝试使用DevDragon.io

它是一个web服务,具有API和.NET客户端DevDragon.Antivirus.client,您可以从NuGet获得。1MB文件的扫描速度低于200ms

此处有更多文档:


披露:我为他们工作。

我也有这个要求。我使用了clamAv anti-virus,它通过将文件发送到其tcp侦听端口来提供按需扫描。您可以使用
nClam
nuget包将文件发送到
clamav

var clam = new ClamClient("localhost", 3310);
var scanResult = clam.ScanFileOnServerAsync("C:\\test.txt"); //any file you would like!
switch (scanResult.Result.Result)
{
    case ClamScanResults.Clean:
        Console.WriteLine("The file is clean!");
        break;
    case ClamScanResults.VirusDetected:
        Console.WriteLine("Virus Found!");
        Console.WriteLine("Virus name: {0}", scanResult.Result.InfectedFiles[0].FileName);
        break;
    case ClamScanResults.Error:
        Console.WriteLine("Woah an error occured! Error: {0}", scanResult.Result.RawResult);
        break;
}
给出了一个简单而详细的示例。注意:-同步扫描方法在最新nuget中不可用。你必须像我上面所做的那样编写代码

要测试病毒,可以在
txt
文件中使用以下字符串

X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


我建议使用这种方法:

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: Apikey
            Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
            
            

            var apiInstance = new ScanApi();
            var inputFile = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // 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 viruses
                VirusScanAdvancedResult result = apiInstance.ScanFileAdvanced(inputFile, allowExecutables, allowInvalidFiles, allowScripts, allowPasswordProtectedFiles, restrictFileTypes);
                Debug.WriteLine(result);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling ScanApi.ScanFileAdvanced: " + e.Message );
            }
        }
    }
}
请注意,通过这种方式,您甚至可以控制是否过滤掉非病毒威胁有效负载,如可执行文件、脚本、加密/密码保护文件等


这种方法有一个自由层,也可以验证你上传的文件的内容。< /P>检查一下。这应该会有帮助。这一个是实实在在的,实际上是免费的:我相信API是C++的。不是。NET.COM。这意味着你可以使用它。