summaryrefslogtreecommitdiffstats
path: root/rules/regexp/compromised_hosts.lua
blob: 6159fbcccc70804fdc957f5d6250be07cb18cc08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
local reconf = config['regexp']
local rspamd_regexp = require 'rspamd_regexp'

reconf['HAS_PHPMAILER_SIG'] = {
  re = "X-Mailer=/^PHPMailer/Hi || Content-Type=/boundary=\"b[123]_/Hi",
  description = "PHPMailer signature",
  group = "compromised_hosts"
}

reconf['PHP_SCRIPT_ROOT'] = {
  re = "X-PHP-Originating-Script=/^0:/Hi",
  description = "PHP Script executed by root UID",
  score = 2.0,
  group = "compromised_hosts"
}

reconf['HAS_X_POS'] = {
  re = "header_exists('X-PHP-Originating-Script')",
  description = "Has X-PHP-Originating-Script header",
  group = "compromised_hosts"
}

reconf['HAS_X_PHP_SCRIPT'] = {
  re = "header_exists('X-PHP-Script')",
  description = "Has X-PHP-Script header",
  group = "compromised_hosts"
}

-- X-Source:
-- X-Source-Args: /usr/sbin/proxyexec -q -d -s /var/run/proxyexec/cagefs.sock/socket /bin/cagefs.server
-- X-Source-Dir: silvianimberg.com:/public_html/wp-content/themes/ultimatum
reconf['HAS_X_SOURCE'] = {
  re = "header_exists('X-Source') || header_exists('X-Source-Args') || header_exists('X-Source-Dir')",
  description = "Has X-Source headers",
  group = "compromised_hosts"
}

-- X-Authenticated-Sender: accord.host-care.com: sales@cortaflex.si
rspamd_config.HAS_X_AS = {
  callback = function (task)
    local xas = task:get_header('X-Authenticated-Sender')
    if not xas then return false end
    local _,_,auth = xas:find('[^:]+:%s(.+)$')
    if auth then
      -- TODO: see if we can parse an e-mail address from auth
      --       and see if it matches the from address or not
      return true, auth
    else
      return true
    end
  end,
  description = 'Has X-Authenticated-Sender header',
  group = "compromised_hosts"
}

-- X-Get-Message-Sender-Via: accord.host-care.com: authenticated_id: sales@cortaflex.si
rspamd_config.HAS_X_GMSV = {
  callback = function (task)
    local xgmsv = task:get_header('X-Get-Message-Sender-Via')
    if not xgmsv then return false end
    local _,_,auth = xgmsv:find('authenticated_id: (.+)$')
    if auth then
      -- TODO: see if we can parse an e-mail address from auth
      --       and see if it matches the from address or not.
      return true, auth
    else
      return true
    end
  end,
  description = 'Has X-Get-Message-Sender-Via: header',
  group = "compromised_hosts"
}

-- X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
-- X-AntiAbuse: Primary Hostname - accord.host-care.com
-- X-AntiAbuse: Original Domain - swaney.com
-- X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]
-- X-AntiAbuse: Sender Address Domain - dropbox.com
reconf['HAS_X_ANTIABUSE'] = {
  re = "header_exists('X-AntiAbuse')",
  description = "Has X-AntiAbuse headers",
  group = "compromised_hosts"
}

reconf['PHP_EVALD_CODE'] = {
  re = "X-PHP-Script=/eval\\(\\)\\'d/Hi || X-PHP-Originating-Script=/eval\\(\\)\\'d/Hi",
  description = "Message sent using eval'd PHP",
  score = 5.0,
  group = "compromised_hosts"
}

reconf['HAS_WP_URI'] = {
  re = '/\\/wp-[^\\/]+\\//Ui',
  description = "Contains WordPress URIs",
  group = "compromised_hosts"
}

reconf['WP_COMPROMISED'] = {
  re = '/\\/wp-(?!content|includes)[^\\/]+\\//Ui',
  description = "URL that is pointing to a compromised WordPress installation",
  score = 5.0,
  group = "compromised_hosts"
}

reconf['PHP_XPS_PATTERN'] = {
  re = 'X-PHP-Script=/^[^\\. ]+\\.[^\\.\\/ ]+\\/sendmail\\.php\\b/Hi',
  description = "Message contains X-PHP-Script pattern",
  score = 5.0,
  group = "compromised_hosts"
}

reconf['HAS_XAW'] = {
  re = "header_exists('X-Authentication-Warning')",
  description = "Has X-Authentication-Warning header",
  group = "compromised_hosts"
}

-- X-Authentication-Warning: localhost.localdomain: www-data set sender to info@globalstock.lv using -f
reconf['XAW_SERVICE_ACCT'] = {
  re = "X-Authentication-Warning=/\\b(?:www-data|anonymous|ftp|apache|nobody|guest|nginx|web|www) set sender to\\b/Hi",
  description = "Message originally from a service account",
  score = 1.0,
  group = "compromised_hosts"
}

reconf['ENVFROM_SERVICE_ACCT'] = {
  re = "check_smtp_data('from',/^(?:www-data|anonymous|ftp|apache|nobody|guest|nginx|web|www)@/i)",
  description = "Envelope from is a service account",
  score = 1.0,
  group = "compromised_hosts"
}

reconf['HIDDEN_SOURCE_OBJ'] = {
  re = "X-PHP-Script=/\\/\\..+/Hi || X-PHP-Originating-Script=/(?:^\\d+:|\\/)\\..+/Hi || X-Source-Args=/\\/\\..+/Hi",
  description = "UNIX hidden file/directory in path",
  score = 2.0,
  group = "compromised_hosts"
}

reconf['URI_HIDDEN_PATH'] = {
  re = "/\\/\\..+/U",
  description = "URL contains a UNIX hidden file/directory",
  score = 1.0,
  group = "compromised_hosts"
}

reconf['MID_RHS_WWW'] = {
  re = "Message-Id=/@www\\./Hi",
  description = "Message-ID from www host",
  score = 0.5,
  group = "compromised_hosts"
}

rspamd_config.FROM_SERVICE_ACCT = {
  callback = function (task)
    local re = rspamd_regexp.create_cached('/^(?:www-data|anonymous|ftp|apache|nobody|guest|nginx|web|www)@/i');
    -- From
    local from = task:get_from(2)
    if (from and from[1]) then
      if (re:match(from[1].addr)) then return true end
    end
    -- Sender
    local sender = task:get_header('Sender')
    if sender then
      local s = util.parse_mail_address(sender)
      if (s and s[1]) then
        if (re:match(s[1].addr)) then return true end
      end
    end
    -- Reply-To
    local replyto = task:get_header('Reply-To')
    if replyto then
      local rt = util.parse_mail_address(replyto)
      if (rt and rt[1]) then
        if (re:match(rt[1].addr)) then return true end
      end
    end
  end,
  description = "Sender/From/Reply-To is a service account",
  score = 1.0,
  group = "compromised_hosts"
}

reconf['WWW_DOT_DOMAIN'] = {
  re = "From=/@www\\./Hi || Sender=/@www\\./Hi || Reply-To=/@www\\./Hi || check_smtp_data('from',/@www\\./i)",
  description = "From/Sender/Reply-To or Envelope is @www.domain.com",
  score = 0.5,
  group = "compromised_hosts"
}