]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Lua_magic: Add more file types
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Sep 2019 13:06:14 +0000 (14:06 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Sep 2019 13:06:14 +0000 (14:06 +0100)
lualib/lua_magic/patterns.lua
lualib/lua_magic/types.lua

index 354f8ec614ccea9b82a12fe73d45e18a7447da75..a52baa7900472627dcc2cfc39a81fb8320645bb4 100644 (file)
@@ -20,14 +20,12 @@ limitations under the License.
 --]]
 
 local patterns = {
-  {
-    -- MSDOS extension to match types table
-    ext = 'pdf',
+  pdf = {
     -- These are alternatives
     matches = {
       {
         string = [[%PDF-\d]],
-        position = 6, -- must be end of the match, as that's how hyperscan works
+        position = 6, -- must be end of the match, as that's how hyperscan works (or use relative_position)
         weight = 60,
       },
       {
@@ -41,6 +39,144 @@ local patterns = {
         weight = 60,
       },
     },
+  },
+  ps = {
+    matches = {
+      {
+        string = [[%!PS-Adobe]],
+        relative_position = 0,
+        weight = 60,
+      },
+    },
+  },
+  -- RTF document
+  rtf = {
+    matches = {
+      {
+        string = [[{\\rtf\d]],
+        position = 6,
+        weight = 60,
+      }
+    }
+  },
+  chm = {
+    matches = {
+      {
+        string = [[ITSF]],
+        relative_position = 0,
+        weight = 60,
+      }
+    }
+  },
+  djvu = {
+    matches = {
+      {
+        string = [[AT&TFORM]],
+        relative_position = 0,
+        weight = 60,
+      },
+      {
+        string = [[DJVM]],
+        relative_position = 0x0c,
+        weight = 60,
+      }
+    }
+  },
+  -- MS Exe file
+  exe = {
+    matches = {
+      {
+        string = [[MZ]],
+        relative_position = 0,
+        weight = 10,
+      },
+      -- PE part
+      {
+        string = [[PE\x{00}\x{00}]],
+        position = {'>=', 0x3c + 4},
+        weight = 40,
+      }
+    }
+  },
+  -- Archives
+  arj = {
+    matches = {
+      {
+        hex = '60EA',
+        relative_position = 0,
+        weight = 60,
+      },
+    }
+  },
+  ace = {
+    matches = {
+      {
+        string = [[\*\*ACE\*\*]],
+        position = 14,
+        weight = 60,
+      },
+    }
+  },
+  cab = {
+    matches = {
+      {
+        string = [[MSCF]],
+        relative_position = 0,
+        weight = 60,
+      },
+    }
+  },
+  -- Images
+  psd = {
+    matches = {
+      {
+        string = [[8BPS]],
+        relative_position = 0,
+        weight = 60,
+      },
+    }
+  },
+  ico = {
+    matches = {
+      {
+        hex = [[00000100]],
+        relative_position = 0,
+        weight = 60,
+      },
+    }
+  },
+  pcx = {
+    matches = {
+      {
+        hex = [[0A050108]],
+        relative_position = 0,
+        weight = 60,
+      },
+    }
+  },
+  pic = {
+    matches = {
+      {
+        hex = [[FF80C9C71A00]],
+        relative_position = 0,
+        weight = 60,
+      },
+    }
+  },
+  -- Other
+  pgp = {
+    matches = {
+      {
+        hex = [[A803504750]],
+        relative_position = 0,
+        weight = 60,
+      },
+      {
+        hex = [[2D424547494E20504750204D4553534147452D]],
+        relative_position = 0,
+        weight = 60,
+      },
+    }
   }
 }
 
index 746c87400b341dd8c80f9ac979c1ed4d172893e2..6672967157354f9059c6f8d59c3133877147aa5c 100644 (file)
@@ -22,17 +22,70 @@ limitations under the License.
 -- This table is indexed by msdos extension for convenience
 
 local types = {
+  -- exe
+  exe = {
+    ct = 'application/x-ms-application',
+    type = 'executable',
+  },
+  -- text
+  rtf = {
+    ct = "application/rtf",
+    type = 'text',
+  },
   pdf = {
     ct = 'application/pdf',
     type = 'binary',
   },
-  exe = {
-    ct = 'application/x-ms-application',
-    type = 'executable',
+  ps = {
+    ct = 'application/postscript',
+    type = 'binary',
+  },
+  chm = {
+    ct = 'application/chm',
+    type = 'binary',
+  },
+  djvu = {
+    ct = 'application/djvu',
+    type = 'binary',
+  },
+  -- archives
+  arj = {
+    ct = 'application/x-compressed',
+    type = 'archive',
+  },
+  cab = {
+    ct = 'application/x-compressed',
+    type = 'archive',
+  },
+  ace = {
+    ct = 'application/x-compressed',
+    type = 'archive',
+  },
+  -- images
+  psd = {
+    ct = 'image/psd',
+    type = 'image',
+  },
+  pcx = {
+    ct = 'image/pcx',
+    type = 'image',
+  },
+  pic = {
+    ct = 'image/pic',
+    type = 'image',
   },
   tiff = {
     ct = 'image/tiff',
     type = 'image',
+  },
+  ico = {
+    ct = 'image/ico',
+    type = 'image',
+  },
+  -- other
+  pgp = {
+    ct = 'application/encrypted',
+    type = 'encrypted'
   }
 }