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.

compromised_hosts.lua 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. local reconf = config['regexp']
  2. local rspamd_regexp = require 'rspamd_regexp'
  3. local util = require 'rspamd_util'
  4. reconf['HAS_PHPMAILER_SIG'] = {
  5. re = "X-Mailer=/^PHPMailer/Hi || Content-Type=/boundary=\"b[123]_/Hi",
  6. description = "PHPMailer signature",
  7. group = "compromised_hosts"
  8. }
  9. reconf['PHP_SCRIPT_ROOT'] = {
  10. re = "X-PHP-Originating-Script=/^0:/Hi",
  11. description = "PHP Script executed by root UID",
  12. score = 1.0,
  13. group = "compromised_hosts"
  14. }
  15. reconf['HAS_X_POS'] = {
  16. re = "header_exists('X-PHP-Originating-Script')",
  17. description = "Has X-PHP-Originating-Script header",
  18. group = "compromised_hosts"
  19. }
  20. reconf['HAS_X_PHP_SCRIPT'] = {
  21. re = "header_exists('X-PHP-Script')",
  22. description = "Has X-PHP-Script header",
  23. group = "compromised_hosts"
  24. }
  25. -- X-Source:
  26. -- X-Source-Args: /usr/sbin/proxyexec -q -d -s /var/run/proxyexec/cagefs.sock/socket /bin/cagefs.server
  27. -- X-Source-Dir: silvianimberg.com:/public_html/wp-content/themes/ultimatum
  28. reconf['HAS_X_SOURCE'] = {
  29. re = "header_exists('X-Source') || header_exists('X-Source-Args') || header_exists('X-Source-Dir')",
  30. description = "Has X-Source headers",
  31. group = "compromised_hosts"
  32. }
  33. -- X-Authenticated-Sender: accord.host-care.com: sales@cortaflex.si
  34. rspamd_config.HAS_X_AS = {
  35. callback = function (task)
  36. local xas = task:get_header('X-Authenticated-Sender')
  37. if not xas then return false end
  38. local _,_,auth = xas:find('[^:]+:%s(.+)$')
  39. if auth then
  40. -- TODO: see if we can parse an e-mail address from auth
  41. -- and see if it matches the from address or not
  42. return true, auth
  43. else
  44. return true
  45. end
  46. end,
  47. description = 'Has X-Authenticated-Sender header',
  48. group = "compromised_hosts",
  49. score = 0.0
  50. }
  51. -- X-Get-Message-Sender-Via: accord.host-care.com: authenticated_id: sales@cortaflex.si
  52. rspamd_config.HAS_X_GMSV = {
  53. callback = function (task)
  54. local xgmsv = task:get_header('X-Get-Message-Sender-Via')
  55. if not xgmsv then return false end
  56. local _,_,auth = xgmsv:find('authenticated_id: (.+)$')
  57. if auth then
  58. -- TODO: see if we can parse an e-mail address from auth
  59. -- and see if it matches the from address or not.
  60. return true, auth
  61. else
  62. return true
  63. end
  64. end,
  65. description = 'Has X-Get-Message-Sender-Via: header',
  66. group = "compromised_hosts",
  67. score = 0.0,
  68. }
  69. -- X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
  70. -- X-AntiAbuse: Primary Hostname - accord.host-care.com
  71. -- X-AntiAbuse: Original Domain - swaney.com
  72. -- X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
  73. -- X-AntiAbuse: Sender Address Domain - dropbox.com
  74. reconf['HAS_X_ANTIABUSE'] = {
  75. re = "header_exists('X-AntiAbuse')",
  76. description = "Has X-AntiAbuse headers",
  77. group = "compromised_hosts"
  78. }
  79. reconf['X_PHP_EVAL'] = {
  80. re = "X-PHP-Script=/eval\\(\\)\\'d/Hi || X-PHP-Originating-Script=/eval\\(\\)\\'d/Hi",
  81. description = "Message sent using eval'd PHP",
  82. score = 4.0,
  83. group = "compromised_hosts"
  84. }
  85. reconf['HAS_WP_URI'] = {
  86. re = '/\\/wp-[^\\/]+\\//Ui',
  87. description = "Contains WordPress URIs",
  88. one_shot = true,
  89. group = "compromised_hosts"
  90. }
  91. reconf['WP_COMPROMISED'] = {
  92. re = '/\\/wp-(?:content|includes)[^\\/]+\\//Ui',
  93. description = "URL that is pointing to a compromised WordPress installation",
  94. one_shot = true,
  95. group = "compromised_hosts"
  96. }
  97. reconf['PHP_XPS_PATTERN'] = {
  98. re = 'X-PHP-Script=/^[^\\. ]+\\.[^\\.\\/ ]+\\/sendmail\\.php\\b/Hi',
  99. description = "Message contains X-PHP-Script pattern",
  100. group = "compromised_hosts"
  101. }
  102. reconf['HAS_XAW'] = {
  103. re = "header_exists('X-Authentication-Warning')",
  104. description = "Has X-Authentication-Warning header",
  105. group = "compromised_hosts"
  106. }
  107. -- X-Authentication-Warning: localhost.localdomain: www-data set sender to info@globalstock.lv using -f
  108. reconf['XAW_SERVICE_ACCT'] = {
  109. re = "X-Authentication-Warning=/\\b(?:www-data|anonymous|ftp|apache|nobody|guest|nginx|web|www) set sender to\\b/Hi",
  110. description = "Message originally from a service account",
  111. score = 1.0,
  112. group = "compromised_hosts"
  113. }
  114. reconf['ENVFROM_SERVICE_ACCT'] = {
  115. re = "check_smtp_data('from',/^(?:www-data|anonymous|ftp|apache|nobody|guest|nginx|web|www)@/i)",
  116. description = "Envelope from is a service account",
  117. score = 1.0,
  118. group = "compromised_hosts"
  119. }
  120. reconf['HIDDEN_SOURCE_OBJ'] = {
  121. re = "X-PHP-Script=/\\/\\..+/Hi || X-PHP-Originating-Script=/(?:^\\d+:|\\/)\\..+/Hi || X-Source-Args=/\\/\\..+/Hi",
  122. description = "UNIX hidden file/directory in path",
  123. score = 2.0,
  124. group = "compromised_hosts"
  125. }
  126. local hidden_uri_re = rspamd_regexp.create_cached('/(?!\\/\\.well[-_]known\\/)(?:^\\.[A-Za-z0-9]|\\/'..
  127. '\\.[A-Za-z0-9]|\\/\\.\\.\\/)/i')
  128. rspamd_config.URI_HIDDEN_PATH = {
  129. callback = function (task)
  130. local urls = task:get_urls(false)
  131. if (urls) then
  132. for _, url in ipairs(urls) do
  133. if (not (url:is_subject() and url:is_html_displayed())) then
  134. local path = url:get_path()
  135. if (hidden_uri_re:match(path)) then
  136. -- TODO: need url:is_schemeless() to improve this
  137. return true, 1.0, url:get_text()
  138. end
  139. end
  140. end
  141. end
  142. end,
  143. description = 'Message contains URI with a hidden path',
  144. score = 1.0,
  145. group = 'compromised_hosts',
  146. }
  147. reconf['MID_RHS_WWW'] = {
  148. re = "Message-Id=/@www\\./Hi",
  149. description = "Message-ID from www host",
  150. score = 0.5,
  151. group = "compromised_hosts"
  152. }
  153. rspamd_config.FROM_SERVICE_ACCT = {
  154. callback = function (task)
  155. local re = rspamd_regexp.create_cached('/^(?:www-data|anonymous|ftp|apache|nobody|guest|nginx|web|www)@/i');
  156. -- From
  157. local from = task:get_from(2)
  158. if (from and from[1]) then
  159. if (re:match(from[1].addr)) then return true end
  160. end
  161. -- Sender
  162. local sender = task:get_header('Sender')
  163. if sender then
  164. local s = util.parse_mail_address(sender, task:get_mempool())
  165. if (s and s[1]) then
  166. if (re:match(s[1].addr)) then return true end
  167. end
  168. end
  169. -- Reply-To
  170. local replyto = task:get_header('Reply-To')
  171. if replyto then
  172. local rt = util.parse_mail_address(replyto, task:get_mempool())
  173. if (rt and rt[1]) then
  174. if (re:match(rt[1].addr)) then return true end
  175. end
  176. end
  177. end,
  178. description = "Sender/From/Reply-To is a service account",
  179. score = 1.0,
  180. group = "compromised_hosts"
  181. }
  182. reconf['WWW_DOT_DOMAIN'] = {
  183. re = "From=/@www\\./Hi || Sender=/@www\\./Hi || Reply-To=/@www\\./Hi || check_smtp_data('from',/@www\\./i)",
  184. description = "From/Sender/Reply-To or Envelope is @www.domain.com",
  185. score = 0.5,
  186. group = "compromised_hosts"
  187. }