我正在构建一个Web应用程序,需要扫描用户上传的文件以查找病毒。
有没有经验在此方面建设应用程序的人可以提供有关如何启动和运行此类应用程序的信息?我猜想杀毒软件包具有访问其功能的API,但好像很难获得详细信息。
请注意,该应用程序是用C#编写的。
使用前重要提示: 请注意服务条款协议。您将授予其对所有内容的完全访问权限:“当您上传或提交内容时,您授予VirusTotal(及我们合作方)使用、编辑、托管、存储、复制、修改、创建衍生作品、传播、发布、公开执行、公开展示并分发此类内容的全球性、免版税、不可撤销和可转让许可证。”
与使用本地杀毒软件程序(从而将您的程序绑定到特定的杀毒软件产品并要求您的客户安装该杀毒软件产品)相比,您可以使用VirusTotal.com的服务。
该网站提供免费服务,即将您的文件输入到多个杀毒产品中,并返回详细报告,报告包含来自扫描过程的相关信息。通过这种方式,您的解决方案不再绑定到特定的杀毒软件产品(尽管您绑定到Internet可用性)。
该网站还提供应用程序编程接口,允许以编程方式接近其扫描引擎。
这里是用于此API的VirusTotal.NET库
这里是他们API的详细文档
这里是他们界面示例的Python文档
因为没有代码的回答是不完整的,这是直接从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 ....
}
免责声明
我与他们无任何关系。我写这篇答案只是因为它似乎是对这些四年前的答案的一个好的更新。
您可以使用 IAttachmentExecute API。
Windows 操作系统提供了通用的 API,用于调用已安装的杀毒软件(当然,需要支持该 API 的杀毒软件)。 但是,用于调用杀毒软件的 API 只提供 COM 接口样式,不支持 IDispatch。 因此,从任何 .NET 语言和脚本语言中调用此 API 都太困难了。
从此处下载此库,或者从“NuGet”中添加对您的 VS 项目的引用 AntiVirusScanner
例如,以下代码可以扫描文件:
var scanner = new AntiVirus.Scanner();
var result = scanner.ScanAndClean(@"c:\some\file\path.txt");
Console.WriteLine(result); // console output is "VirusNotFound".
我会直接调用系统来运行一个独立的进程来进行扫描。有许多来自不同供应商的命令行杀毒引擎。
var result = process.Start();
然后在做一些 process.StartInfo
的事情之后 MessageBox.Show(result);
? :D” - Momoro许多病毒扫描器都拥有API。我曾经集成过的一个是Sophos。我相信Norton也有API,而McAfee没有(它曾经有过)。您想使用哪种病毒软件?您可以查看Metascan,因为它允许与许多不同的扫描器集成,但需要支付年度许可证费用。:-P
我也有这个需求。我使用了提供按需扫描的clamAv防病毒软件,通过将文件发送到其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;
}
txt
文件中使用以下字符串:
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
不好意思打个广告,但你可能想要查看https://scanii.com,它基本上是一种作为(REST)服务的恶意软件/病毒检测工具。另外,请确保你阅读并理解virustotal的API条款(https://www.virustotal.com/en/documentation/public-api/)——他们非常明确地禁止商业使用。
我建议采用这种方法:
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 );
}
}
}
}
我们尝试了两种选项:
在一个小型 Linux 容器上安装 clamav-daemon
,并使用 ".NET" 库 "nClam" 与其交互。虽然这种方法可以正常工作,但 Clam AV 错过了很多(非常多!)病毒,特别是隐藏在 MS Office 文件中的危险宏。此外,ClamAV 病毒数据库必须始终保持在内存中,这需要大约 3.5GB 的内存,而这需要一个相当昂贵的云虚拟机。
最终使用 Windows Defender 通过 MpCmdRun.exe
CLI API。请参见答案此处
你可以尝试使用DevDragon.io。
它是一个带有API和.NET客户端DevDragon.Antivirus.Client的Web服务,您可以从NuGet获取。对于1MB文件,扫描时间少于200毫秒。
更多文档请参见: https://github.com/Dev-Dragon/Antivirus-Client
声明:我为他们工作。