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.

misc.lua 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. --[[
  2. Copyright (c) 2011-2016, 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 reconf = config['regexp']
  14. reconf['HTML_META_REFRESH_URL'] = {
  15. -- Requires options { check_attachements = true; }
  16. re = '/<meta\\s+http-equiv="refresh"\\s+content="\\d+\\s*;\\s*url=/{sa_raw_body}i',
  17. description = "Has HTML Meta refresh URL",
  18. score = 5.0,
  19. one_shot = true,
  20. group = 'HTML'
  21. }
  22. reconf['HAS_DATA_URI'] = {
  23. -- Requires options { check_attachements = true; }
  24. re = '/data:[^\\/]+\\/[^; ]+;base64,/{sa_raw_body}i',
  25. description = "Has Data URI encoding",
  26. group = 'HTML',
  27. one_shot = true,
  28. }
  29. reconf['DATA_URI_OBFU'] = {
  30. -- Requires options { check_attachements = true; }
  31. re = '/data:text\\/(?:plain|html);base64,/{sa_raw_body}i',
  32. description = "Uses Data URI encoding to obfuscate plain or HTML in base64",
  33. group = 'HTML',
  34. one_shot = true,
  35. score = 2.0
  36. }
  37. reconf['INTRODUCTION'] = {
  38. re = '/\\b(?:my name is\\b|(?:i am|this is)\\s+(?:mr|mrs|ms|miss|master|sir|prof(?:essor)?|d(?:octo)?r|rev(?:erend)?)(?:\\.|\\b))/{sa_body}i',
  39. description = "Sender introduces themselves",
  40. score = 2.0,
  41. one_shot = true,
  42. group = 'scams'
  43. }
  44. -- Message contains a link to a .onion URI (Tor hidden service)
  45. local onion_uri_v2 = '/[a-z0-9]{16}\\.onion?/{url}i'
  46. local onion_uri_v3 = '/[a-z0-9]{56}\\.onion?/{url}i'
  47. reconf['HAS_ONION_URI'] = {
  48. re = string.format('(%s | %s)', onion_uri_v2, onion_uri_v3),
  49. description = 'Contains .onion hidden service URI',
  50. score = 0.0,
  51. group = 'experimental'
  52. }
  53. local my_victim = [[/(?:victim|prey)/{words}]]
  54. local your_webcam = [[/webcam/{words}]]
  55. local your_onan = [[/(?:mast[ur]{2}bati(?:on|ng)|onanism|solitary)/{words}]]
  56. local password_in_words = [[/^pass(?:(?:word)|(?:phrase))$/i{words}]]
  57. local btc_wallet_address = [[/^[13][1-9A-Za-z]{25,34}$/]]
  58. local wallet_word = [[/^wallet$/{words}]]
  59. local broken_unicode = [[has_flag(bad_unicode)]]
  60. local list_unsub = [[header_exists(List-Unsubscribe)]]
  61. reconf['LEAKED_PASSWORD_SCAM'] = {
  62. re = string.format('%s{words} & (%s | %s | %s | %s | %s | %s | %s | lua:check_data_images)',
  63. btc_wallet_address, password_in_words, wallet_word,
  64. my_victim, your_webcam, your_onan, broken_unicode, list_unsub),
  65. description = 'Contains password word and BTC wallet address',
  66. functions = {
  67. check_data_images = function(task)
  68. local tp = task:get_text_parts() or {}
  69. for _,p in ipairs(tp) do
  70. if p:is_html() then
  71. local hc = p:get_html()
  72. if hc and hc:has_property('data_urls') then
  73. return true
  74. end
  75. end
  76. end
  77. return false
  78. end
  79. },
  80. score = 7.0,
  81. group = 'scams'
  82. }
  83. -- Special routine to validate bitcoin wallets
  84. -- Prepare base58 alphabet
  85. local fun = require "fun"
  86. local off = 0
  87. local base58_dec = fun.tomap(fun.map(
  88. function(c)
  89. off = off + 1
  90. return c,(off - 1)
  91. end,
  92. "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"))
  93. local id = rspamd_config:register_symbol{
  94. name = 'LEAKED_PASSWORD_SCAM_VALIDATED',
  95. callback = function(task)
  96. local rspamd_re = require "rspamd_regexp"
  97. local hash = require "rspamd_cryptobox_hash"
  98. if task:has_symbol('LEAKED_PASSWORD_SCAM') then
  99. -- Perform BTC wallet check (quite expensive)
  100. local wallet_re = rspamd_re.create_cached(btc_wallet_address)
  101. local seen_valid = false
  102. for _,tp in ipairs(task:get_text_parts()) do
  103. local words = tp:get_words('raw') or {}
  104. for _,word in ipairs(words) do
  105. if wallet_re:match(word) then
  106. -- We have something that looks like a BTC address
  107. local bytes = {}
  108. for i=1,25 do bytes[i] = 0 end
  109. -- Base58 decode loop
  110. fun.each(function(ch)
  111. local acc = base58_dec[ch] or 0
  112. for i=25,1,-1 do
  113. acc = acc + (58 * bytes[i]);
  114. bytes[i] = acc % 256
  115. acc = math.floor(acc / 256);
  116. end
  117. end, word)
  118. -- Now create a validation tag
  119. local sha256 = hash.create_specific('sha256')
  120. for i=1,21 do
  121. sha256:update(string.char(bytes[i]))
  122. end
  123. sha256 = hash.create_specific('sha256', sha256:bin()):bin()
  124. -- Compare tags
  125. local valid = true
  126. for i=1,4 do
  127. if string.sub(sha256, i, i) ~= string.char(bytes[21 + i]) then
  128. valid = false
  129. end
  130. end
  131. if valid then
  132. task:insert_result('LEAKED_PASSWORD_SCAM_VALIDATED', 1.0, word)
  133. seen_valid = true
  134. end
  135. end
  136. end
  137. end
  138. if not seen_valid then
  139. task:insert_result('LEAKED_PASSWORD_SCAM_INVALID', 1.0)
  140. end
  141. end
  142. end,
  143. score = 0.0,
  144. group = 'scams'
  145. }
  146. rspamd_config:register_symbol{
  147. type = 'virtual',
  148. name = 'LEAKED_PASSWORD_SCAM_INVALID',
  149. parent = id,
  150. score = 0.0,
  151. }
  152. rspamd_config:register_dependency('LEAKED_PASSWORD_SCAM_VALIDATED',
  153. 'LEAKED_PASSWORD_SCAM')