]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Project] Lua_magic: Support ole documents recognition
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 7 Sep 2019 14:11:21 +0000 (15:11 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 7 Sep 2019 14:11:21 +0000 (15:11 +0100)
lualib/lua_magic/init.lua
lualib/lua_magic/patterns.lua
lualib/lua_magic/types.lua
src/lua/lua_text.c

index 98d4845eb24cfd9c0be842360290aca963c2d5b7..59e2a6e36eea7021f251f1176c5cdc6bf009dec3 100644 (file)
@@ -140,7 +140,7 @@ local function match_chunk(chunk, input, tlen, offset, trie, processed_tbl, log_
     if not res[ext] then
       res[ext] = 0
     end
-    if match.weight then
+    if weight then
       res[ext] = res[ext] + weight
     else
       res[ext] = res[ext] + 1
index 003073cabad527f83de939f9b0a2866d344cf51e..9bb6df1825c8583417f987cfb8aee1c7a9b46b7f 100644 (file)
@@ -19,6 +19,8 @@ limitations under the License.
 -- This module contains most common patterns
 --]]
 
+local heuristics = require "lua_magic/heuristics"
+
 local patterns = {
   pdf = {
     -- These are alternatives
@@ -82,6 +84,17 @@ local patterns = {
       }
     }
   },
+  -- MS Office format, needs heuristic
+  ole = {
+    matches = {
+      {
+        hex = [[d0cf11e0a1b11ae1]],
+        relative_position = 0,
+        weight = 60,
+        heuristic = heuristics.ole_format_heuristic
+      }
+    }
+  },
   -- MS Exe file
   exe = {
     matches = {
index b3af668c8c8c2aa62e44363ea6e754b9a7f3d501..96c4952a8c14191684738cd64db940970163d01e 100644 (file)
@@ -130,6 +130,27 @@ local types = {
     ct = 'application/x-shockwave-flash',
     type = 'image',
   },
+  -- Ole files
+  ole = {
+    ct = 'application/octet-stream',
+    type = 'msoffice'
+  },
+  doc = {
+    ct = 'application/msword',
+    type = 'msoffice'
+  },
+  xls = {
+    ct = 'application/vnd.ms-excel',
+    type = 'msoffice'
+  },
+  ppt = {
+    ct = 'application/vnd.ms-powerpoint',
+    type = 'msoffice'
+  },
+  msi = {
+    ct = 'application/x-msi',
+    type = 'executable'
+  },
   -- other
   pgp = {
     ct = 'application/encrypted',
index e095b8c4333cd98df1f27fed8f7391e64f95bd60..68897019da4629f9ef786df6cb5ca222e4e52e2b 100644 (file)
@@ -98,6 +98,7 @@ static const struct luaL_reg textlib_m[] = {
                LUA_INTERFACE_DEF (text, take_ownership),
                LUA_INTERFACE_DEF (text, save_in_file),
                LUA_INTERFACE_DEF (text, span),
+               LUA_INTERFACE_DEF (text, at),
                {"write", lua_text_save_in_file},
                {"__len", lua_text_len},
                {"__tostring", lua_text_str},