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 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. --[[
  2. Copyright (c) 2019, Vsevolod Stakhov <vsevolod@highsecure.ru>
  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())
  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.javascript then
  23. task:insert_result('PDF_JAVASCRIPT', 1.0, part:get_filename())
  24. suspicious_factor = suspicious_factor + 0.1
  25. if specific.openaction then
  26. suspicious_factor = suspicious_factor + 0.5
  27. end
  28. end
  29. if specific.suspicious then
  30. suspicious_factor = suspicious_factor + 0.7
  31. end
  32. if suspicious_factor > 0.5 then
  33. if suspicious_factor > 1.0 then suspicious_factor = 1.0 end
  34. task:insert_result('PDF_SUSPICIOUS', suspicious_factor, part:get_filename())
  35. end
  36. end
  37. local tags_processors = {
  38. pdf = process_pdf_specific
  39. }
  40. local function process_specific_cb(task)
  41. local parts = task:get_parts() or {}
  42. for _,p in ipairs(parts) do
  43. if p:is_specific() then
  44. local data = p:get_specific()
  45. if data and type(data) == 'table' and data.tag then
  46. if tags_processors[data.tag] then
  47. tags_processors[data.tag](task, p, data)
  48. end
  49. end
  50. end
  51. end
  52. end
  53. local id = rspamd_config:register_symbol{
  54. type = 'callback',
  55. name = 'SPECIFIC_CONTENT_CHECK',
  56. callback = process_specific_cb
  57. }
  58. rspamd_config:register_symbol{
  59. type = 'virtual',
  60. name = 'PDF_ENCRYPTED',
  61. parent = id,
  62. groups = {"content", "pdf"},
  63. }
  64. rspamd_config:register_symbol{
  65. type = 'virtual',
  66. name = 'PDF_JAVASCRIPT',
  67. parent = id,
  68. groups = {"content", "pdf"},
  69. }
  70. rspamd_config:register_symbol{
  71. type = 'virtual',
  72. name = 'PDF_SUSPICIOUS',
  73. parent = id,
  74. groups = {"content", "pdf"},
  75. }