【问题标题】:Checking uploaded files for viruses检查上传的文件是否有病毒
【发布时间】:2016-11-28 11:32:20
【问题描述】:

我有一些申请。用户可以上传文件,我将其保存在磁盘上,并在用户需要时返回。我需要对上传的文件实施一些病毒防护。 我为这个问题找到了 3 个解决方案:

  1. 使用在线防病毒软件
  2. 在我的服务器上安装防病毒软件并从命令行检查上传的文件
  3. 通过 sdk 或 api 集成杀毒软件。

我不喜欢第一个解决方案,因为我将我的文件和私人信息发送给其他服务器。 我认为第二种解决方案是最好的,但我不知道如何正确实施。 最后一个解决方案很好,但我找不到任何有 java api 的优秀和著名的防病毒软件。

请给我一些解决这个问题的方向。 Mb 一些建议或文献。 最好的解决方法是什么?

【问题讨论】:

  • 标记为这主要是基于意见的,但我建议选项 #2,从您的应用程序作为一个孩子启动 AV 进程,然后检查孩子报告的退出代码(例如0 = 干净,1 = 受感染,或其他 - 检查文档),等等。
  • @ray 我发现了这个建议:“从应用程序的角度来看,您可以创建一个代理服务器,您可以在其中安装防病毒软件,将文件上传到此服务器,扫描并传输到您的目标服务器. " 但是为什么我们需要使用一些新的服务器呢?
  • 我想你可以做到这一点,如果你有正确设置它的基础设施和专业知识,但是如果你在你的服务器中安装了 AV,应用程序可以针对新文件启动 AV作为子进程。这看起来不是更简单吗?

标签: java antivirus antivirus-integration


【解决方案1】:

首先,你要检查你安装的杀毒软件提供了什么样的API。

如果提供了任何 Java API(如 AVG API),那么您必须按如下方式使用它:

public void scanFile(byte[] fileBytes, String fileName)
   throws IOException, Exception {
   if (scan) {
      AVClient avc = new AVClient(avServer, avPort, avMode);
      if (avc.scanfile(fileName, fileBytes) == -1) {
         throw new VirusException("WARNING: A virus was detected in
            your attachment: " + fileName + "<br>Please scan
            your system with the latest antivirus software with
            updated virus definitions and try again.");
      }
   }
}

如果安装的杀毒软件没有提供Java API,你仍然可以使用命令行调用它,如下:

String[] commands =  new String[5];
                  commands[0] = "cmd";
                  commands[1] = "/c";
                  commands[2] = "C:\\Program Files\\AVG\\AVG10\\avgscanx.exe";
                  commands[3] = "/scan=" + filename;
                  commands[4] = "/report=" + virusoutput;


                 Runtime rt = Runtime.getRuntime();
                 Process proc = rt.exec(commands);

有一篇有趣的文章供您参考:Implementing an Anti-Virus File Scan in JEE Applications

希望对你有所帮助。

【讨论】:

    【解决方案2】:

    在线 AntiVirus ClamAV:https://github.com/cdarras/clamav-client 是一个不错的选择。

    如果你使用 Linux/Mac,在线 AV 应该足够了。 如果您使用 Windows,您还应该在您的服务器上安装防病毒软件。

    【讨论】:

      猜你喜欢
      • 2013-07-19
      • 2013-09-13
      • 1970-01-01
      • 2015-09-21
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多