You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

content.lua 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. --[[
  2. Copyright (c) 2022, Vsevolod Stakhov <vsevolod@rspamd.com>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ]]--
  13. local function process_pdf_specific(task, part, specific)
  14. local suspicious_factor = 0
  15. if specific.encrypted then
  16. task:insert_result('PDF_ENCRYPTED', 1.0, part:get_filename() or 'unknown')
  17. suspicious_factor = suspicious_factor + 0.1
  18. if specific.openaction then
  19. suspicious_factor = suspicious_factor + 0.5
  20. end
  21. end
  22. if specific.scripts then
  23. task:insert_result('PDF_JAVASCRIPT', 1.0, part:get_filename() or 'unknown')
  24. suspicious_factor = suspicious_factor + 0.1
  25. end
  26. if specific.suspicious then
  27. suspicious_factor = suspicious_factor + specific.suspicious
  28. end
  29. if suspicious_factor > 0.5 then
  30. if suspicious_factor > 1.0 then
  31. suspicious_factor = 1.0
  32. end
  33. task:insert_result('PDF_SUSPICIOUS', suspicious_factor, part:get_filename() or 'unknown')
  34. end
  35. if specific.long_trailer then
  36. task:insert_result('PDF_LONG_TRAILER', 1.0, string.format('%s:%d',
  37. part:get_filename() or 'unknown', specific.long_trailer))
  38. end
  39. if specific.many_objects then
  40. task:insert_result('PDF_MANY_OBJECTS', 1.0, string.format('%s:%d',
  41. part:get_filename() or 'unknown', specific.many_objects))
  42. end
  43. if specific.timeout_processing then
  44. task:insert_result('PDF_TIMEOUT', 1.0, string.format('%s:%.3f',
  45. part:get_filename() or 'unknown', specific.timeout_processing))
  46. end
  47. end
  48. local tags_processors = {
  49. pdf = process_pdf_specific
  50. }
  51. local function process_specific_cb(task)
  52. local parts = task:get_parts() or {}
  53. for _, p in ipairs(parts) do
  54. if p:is_specific() then
  55. local data = p:get_specific()
  56. if data and type(data) == 'table' and data.tag then
  57. if tags_processors[data.tag] then
  58. tags_processors[data.tag](task, p, data)
  59. end
  60. end
  61. end
  62. end
  63. end
  64. local id = rspamd_config:register_symbol {
  65. type = 'callback',
  66. name = 'SPECIFIC_CONTENT_CHECK',
  67. callback = process_specific_cb
  68. }
  69. rspamd_config:register_symbol {
  70. type = 'virtual',
  71. name = 'PDF_ENCRYPTED',
  72. parent = id,
  73. groups = { "content", "pdf" },
  74. }
  75. rspamd_config:register_symbol {
  76. type = 'virtual',
  77. name = 'PDF_JAVASCRIPT',
  78. parent = id,
  79. groups = { "content", "pdf" },
  80. }
  81. rspamd_config:register_symbol {
  82. type = 'virtual',
  83. name = 'PDF_SUSPICIOUS',
  84. parent = id,
  85. groups = { "content", "pdf" },
  86. }
  87. rspamd_config:register_symbol {
  88. type = 'virtual',
  89. name = 'PDF_LONG_TRAILER',
  90. parent = id,
  91. groups = { "content", "pdf" },
  92. }
  93. rspamd_config:register_symbol {
  94. type = 'virtual',
  95. name = 'PDF_MANY_OBJECTS',
  96. parent = id,
  97. groups = { "content", "pdf" },
  98. }
  99. rspamd_config:register_symbol {
  100. type = 'virtual',
  101. name = 'PDF_TIMEOUT',
  102. parent = id,
  103. groups = { "content", "pdf" },
  104. }