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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. reconf['LEAKED_PASSWORD_SCAM'] = {
  61. re = string.format('%s{words} & (%s | %s | %s | %s | %s | %s | lua:check_data_images)',
  62. btc_wallet_address, password_in_words, wallet_word,
  63. my_victim, your_webcam, your_onan, broken_unicode),
  64. description = 'Contains password word and BTC wallet address',
  65. functions = {
  66. check_data_images = function(task)
  67. local tp = task:get_text_parts() or {}
  68. for _,p in ipairs(tp) do
  69. if p:is_html() then
  70. local hc = p:get_html()
  71. if hc and hc:has_property('data_urls') then
  72. return true
  73. end
  74. end
  75. end
  76. return false
  77. end
  78. },
  79. score = 7.0,
  80. group = 'scams'
  81. }
  82. -- Special routine to validate bitcoin wallets
  83. -- Prepare base58 alphabet
  84. local fun = require "fun"
  85. local off = 0
  86. local base58_dec = fun.tomap(fun.map(
  87. function(c)
  88. off = off + 1
  89. return c,(off - 1)
  90. end,
  91. "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"))
  92. local id = rspamd_config:register_symbol{
  93. name = 'LEAKED_PASSWORD_SCAM_VALIDATED',
  94. callback = function(task)
  95. local rspamd_re = require "rspamd_regexp"
  96. local hash = require "rspamd_cryptobox_hash"
  97. if task:has_symbol('LEAKED_PASSWORD_SCAM') then
  98. -- Perform BTC wallet check (quite expensive)
  99. local wallet_re = rspamd_re.create_cached(btc_wallet_address)
  100. local seen_valid = false
  101. for _,tp in ipairs(task:get_text_parts()) do
  102. local words = tp:get_words('raw') or {}
  103. for _,word in ipairs(words) do
  104. if wallet_re:match(word) then
  105. -- We have something that looks like a BTC address
  106. local bytes = {}
  107. for i=1,25 do bytes[i] = 0 end
  108. -- Base58 decode loop
  109. fun.each(function(ch)
  110. local acc = base58_dec[ch] or 0
  111. for i=25,1,-1 do
  112. acc = acc + (58 * bytes[i]);
  113. bytes[i] = math.fmod(acc, 256);
  114. acc = math.modf(acc / 256);
  115. end
  116. end, fun.tail(word)) -- Tail due to first byte is version
  117. -- Now create a validation tag
  118. local sha256 = hash.create_specific('sha256')
  119. for i=1,21 do
  120. sha256:update(string.char(bytes[i]))
  121. end
  122. sha256 = hash.create_specific('sha256', sha256:bin()):bin()
  123. -- Compare tags
  124. local valid = true
  125. for i=1,4 do
  126. if string.sub(sha256, i, i) ~= string.char(bytes[21 + i]) then
  127. valid = false
  128. end
  129. end
  130. if valid then
  131. task:insert_result('LEAKED_PASSWORD_SCAM_VALIDATED', 1.0, word)
  132. seen_valid = true
  133. end
  134. end
  135. end
  136. end
  137. if not seen_valid then
  138. task:insert_result('LEAKED_PASSWORD_SCAM_INVALID', 1.0)
  139. end
  140. end
  141. end,
  142. score = 0.0,
  143. group = 'scams'
  144. }
  145. rspamd_config:register_symbol{
  146. type = 'virtual',
  147. name = 'LEAKED_PASSWORD_SCAM_INVALID',
  148. parent = id,
  149. score = 0.0,
  150. }
  151. rspamd_config:register_dependency('LEAKED_PASSWORD_SCAM_VALIDATED',
  152. 'LEAKED_PASSWORD_SCAM')