]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Virustotal: Fix checks
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Nov 2019 15:05:28 +0000 (15:05 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Nov 2019 15:05:28 +0000 (15:05 +0000)
Issue: #3141

lualib/lua_scanners/virustotal.lua

index 8775100ba356254e9ee72b8b02b99411f9061dcc..6bbdf94fd1767927ead499777b9b3751dc7c5154 100644 (file)
@@ -130,7 +130,7 @@ local function virustotal_check(task, content, digest, rule)
 
           if res then
             local obj = parser:get_object()
-            if not obj.positives then
+            if not obj.positives or type(obj.positives) ~= 'number' then
               if obj.response_code then
                 if obj.response_code == 0 then
                   cached = 'OK'
@@ -153,35 +153,36 @@ local function virustotal_check(task, content, digest, rule)
                 task:insert_result(rule.symbol_fail, 1.0, 'Bad JSON reply: no `positives` element')
                 return
               end
-            end
-            if obj.positives < rule.minimum_engines then
-              lua_util.debugm(rule.name, task, '%s: hash %s has not enough hits: %s where %s is min',
-                  rule.log_prefix, obj.positives, rule.minimum_engines)
-              -- TODO: add proper hashing!
-              cached = 'OK'
             else
-              if obj.positives > rule.full_score_engines then
-                dyn_score = 1.0
+              if obj.positives < rule.minimum_engines then
+                lua_util.debugm(rule.name, task, '%s: hash %s has not enough hits: %s where %s is min',
+                    rule.log_prefix, obj.positives, rule.minimum_engines)
+                -- TODO: add proper hashing!
+                cached = 'OK'
               else
-                local norm_pos = obj.positives - rule.minimum_engines
-                dyn_score = norm_pos / (rule.full_score_engines - rule.minimum_engines)
-              end
+                if obj.positives > rule.full_score_engines then
+                  dyn_score = 1.0
+                else
+                  local norm_pos = obj.positives - rule.minimum_engines
+                  dyn_score = norm_pos / (rule.full_score_engines - rule.minimum_engines)
+                end
 
-              if dyn_score < 0 or dyn_score > 1 then
-                dyn_score = 1.0
+                if dyn_score < 0 or dyn_score > 1 then
+                  dyn_score = 1.0
+                end
+                local sopt = string.format("%s:%s/%s",
+                    hash, obj.positives, obj.total)
+                common.yield_result(task, rule, sopt, dyn_score)
+                cached = sopt
               end
-              local sopt = string.format("%s:%s/%s",
-                  hash, obj.positives, obj.total)
-              common.yield_result(task, rule, sopt, dyn_score)
-              cached = sopt
             end
           else
+            -- not res
             rspamd_logger.errx(task, 'invalid JSON reply: %s, body: %s, headers: %s',
                 json_err, body, headers)
             task:insert_result(rule.symbol_fail, 1.0, 'Bad JSON reply: ' .. json_err)
             return
           end
-
         end
 
         if cached then