]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Antivirus: Allow to set fake eicar patterns for testing AV engines
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 17 Sep 2021 15:43:32 +0000 (16:43 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 17 Sep 2021 15:43:32 +0000 (16:43 +0100)
src/plugins/lua/antivirus.lua

index 56bd4b5205814a4fd53a75245e0b4f14f02c58c2..2ad5dc0297554bf6566aa5663ac5ffc9c0ae179e 100644 (file)
@@ -16,6 +16,7 @@ limitations under the License.
 
 local rspamd_logger = require "rspamd_logger"
 local lua_util = require "lua_util"
+local rspamd_util = require "rspamd_util"
 local lua_redis = require "lua_redis"
 local fun = require "fun"
 local lua_antivirus = require("lua_scanners").filter('antivirus')
@@ -63,12 +64,19 @@ antivirus {
     }
     # `whitelist` points to a map of IP addresses. Mail from these addresses is not scanned.
     whitelist = "/etc/rspamd/antivirus.wl";
+    # Replace content that exactly matches the following string to the EICAR pattern
+    # Useful for E2E testing when another party removes/blocks EICAR attachments
+    #eicar_fake_pattern = 'testpatterneicar';
   }
 }
 ]])
   return
 end
 
+-- Encode as base32 in the source to avoid crappy stuff
+local eicar_pattern = rspamd_util.decode_base32(
+    [[akp6woykfbonrepmwbzyfpbmibpone3mj3pgwbffzj9e1nfjdkorisckwkohrnfe1nt41y3jwk1cirjki4w4nkieuni4ndfjcktnn1yjmb1wn]]
+)
 
 local function add_antivirus_rule(sym, opts)
   if not opts.type then
@@ -135,7 +143,21 @@ local function add_antivirus_rule(sym, opts)
 
       fun.each(function(p)
         local content = p:get_content()
-        if content and #content > 0 then
+        local clen = #content
+        if content and clen > 0 then
+          if opts.eicar_fake_pattern then
+            if type(opts.eicar_fake_pattern) == 'string' then
+              -- Convert it to Rspamd text
+              local rspamd_text = require "rspamd_text"
+              opts.eicar_fake_pattern = rspamd_text.fromstring(opts.eicar_fake_pattern)
+            end
+
+            if clen == #opts.eicar_fake_pattern and content == opts.eicar_fake_pattern then
+              rspamd_logger.infox(task, 'found eicar fake replacement part in the part (filename="%s")',
+                p:get_filename())
+              content = eicar_pattern
+            end
+          end
           cfg.check(task, content, p:get_digest(), rule, p)
         end
       end, common.check_parts_match(task, rule))