]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Archives: Distinguish compressed headers and encrypted archives
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 22 May 2019 14:06:32 +0000 (15:06 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 22 May 2019 14:06:32 +0000 (15:06 +0100)
src/libmime/archives.c
src/libmime/archives.h
src/lua/lua_task.c
src/plugins/lua/mime_types.lua

index 9c0336ac85be62a7c29e26f9cf9f4b9349127f45..c19991eb6516cb1e5c255cbe64f1d7888acfd945 100644 (file)
@@ -1590,7 +1590,8 @@ rspamd_7zip_read_next_section (struct rspamd_task *task,
                 * In fact, headers are just packed, but we assume it as
                 * encrypted to distinguish from the normal archives
                 */
-               arch->flags |= RSPAMD_ARCHIVE_ENCRYPTED;
+               msg_debug_archive ("7zip: encoded header, needs to be uncompressed");
+               arch->flags |= RSPAMD_ARCHIVE_CANNOT_READ;
                p = NULL; /* Cannot get anything useful */
                break;
        case kArchiveProperties:
index e4e7b8b031bca080a3a53a61aaedf14c33af10cd..6abfb857a9edb0edee1813287a3501d56ab07470 100644 (file)
@@ -27,6 +27,7 @@ enum rspamd_archive_type {
 
 enum rspamd_archive_flags {
        RSPAMD_ARCHIVE_ENCRYPTED = (1u << 0u),
+       RSPAMD_ARCHIVE_CANNOT_READ = (1u << 1u),
 };
 
 enum rspamd_archive_file_flags {
index 2529b88d6dc9e7792883352f6e1545318d339e91..e58ff17c78c1ee7578b4260183e609b416fc7834 100644 (file)
@@ -1171,6 +1171,7 @@ LUA_FUNCTION_DEF (archive, get_type);
 LUA_FUNCTION_DEF (archive, get_files);
 LUA_FUNCTION_DEF (archive, get_files_full);
 LUA_FUNCTION_DEF (archive, is_encrypted);
+LUA_FUNCTION_DEF (archive, is_unreadable);
 LUA_FUNCTION_DEF (archive, get_filename);
 LUA_FUNCTION_DEF (archive, get_size);
 
@@ -1179,6 +1180,7 @@ static const struct luaL_reg archivelib_m[] = {
        LUA_INTERFACE_DEF (archive, get_files),
        LUA_INTERFACE_DEF (archive, get_files_full),
        LUA_INTERFACE_DEF (archive, is_encrypted),
+       LUA_INTERFACE_DEF (archive, is_unreadable),
        LUA_INTERFACE_DEF (archive, get_filename),
        LUA_INTERFACE_DEF (archive, get_size),
        {"__tostring", rspamd_lua_class_tostring},
@@ -5935,6 +5937,22 @@ lua_archive_is_encrypted (lua_State *L)
        return 1;
 }
 
+static gint
+lua_archive_is_unreadable (lua_State *L)
+{
+       LUA_TRACE_POINT;
+       struct rspamd_archive *arch = lua_check_archive (L);
+
+       if (arch != NULL) {
+               lua_pushboolean (L, (arch->flags & RSPAMD_ARCHIVE_CANNOT_READ) ? true : false);
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 1;
+}
+
 static gint
 lua_archive_get_size (lua_State *L)
 {
index 63641b7d03e99cd0e20c4aee842cfa687d0a576c..ccea74dc3012861fd6b8a65623ab8a039a44de63 100644 (file)
@@ -1037,13 +1037,20 @@ local function check_mime_type(task)
             if ext and settings.archive_exceptions[ext] then
               check = false
               logger.debugm("mime_types", task, "skip checking of %s as archive, %s is whitelisted",
-                filename, ext)
+                  filename, ext)
             end
           end
           local arch = p:get_archive()
 
           if arch:is_encrypted() then
-            task:insert_result(settings['symbol_encrypted_archive'], 1.0, filename)
+            task:insert_result(settings.symbol_encrypted_archive, 1.0, filename)
+            task:insert_result('MIME_TRACE', 0.0,
+                string.format("%s:%s", p:get_id(), '-'))
+          elseif arch:is_unreadable() then
+            task:insert_result(settings.symbol_encrypted_archive, 0.5, {
+              'compressed header',
+              filename,
+            })
             task:insert_result('MIME_TRACE', 0.0,
                 string.format("%s:%s", p:get_id(), '-'))
           end