= WFORCE_POLICY(8) Open-Xchange 2018 doctype: manpage
wforce_policy - Policy to run with wforce
The default policy that comes with wforce is necessarily simple. This policy is designed to be more feature-rich and customizable, and deployable ideally straight out of the box.
The wforce policy is designed to solve the following problems:
The policy has two main feature areas; policies which act based on user-behaviour (i.e. detecting abuse behaviour), and policies which act on other information such as blacklists or whitelists.
The behavioural policies are based on recording statistics using the in-memory stats DB, using behaviour over the last hour as the main metric. Additionally, a 24-hour DB is also used to track the behaviour of abusers who consistently exceed the thresholds of the one-hour policies, and to whom more draconian actions can be applied.
The file config/wforce_config.lua contains the default values for all the policies. Changes to the policies are not made by changing this file, instead a table with the modified policies is passed to the init function of the config object. This is shown in the following example from the default wforce.conf file:
local config = require("config.wforce_config")
-- override the default values with the supplied table - see config/wforce_config.lua
config.initConfig({})
The above example shows an empty table being passed, which means to accept all the defaults. To change some of the defaults, only the keys which need to be changed are passed. For example:
local override_config = {
wforce_1hr_policies = {
maxDiffBadPasswordsPerIP = {
enabled = false
}
},
general_policies = {
countryBlacklist = {
policy_params = {"NG"},
}
},
diffCountryWL = { "NO", "SE", "DK", "FI" }
}
config.initConfig(override_config)
You can also set configuration on a per-domain basis (the login name
will be parsed, and if it is of the form
local override_config = {
wforce_1hr_policies = {
maxDiffBadPasswordsPerIP = {
enabled = false
}
}
}
config.initDomainConfig("foo.com", override_config)
The initDomainConfig() command will first copy the default config
(including any changes made in initConfig()) before merging the
changes supplied. So, only changes from the default configuration need
to be supplied, as shown above. IP key prefix settings are an
exception: ipkey_v4_prefix and ipkey_v6_prefix are global-only and
cannot be overridden per domain.
Most policies are configured in the same way, as shown in the following example:
maxDiffBadPasswordsPerIPUser = {
enabled = true,
threshold = 3,
action = "tarpit",
action_value = 5,
policy_code = 503,
policy_text = "maxDiffBadPasswordsPerIPUser"
},
Not shown above:
The following one-hour policies can be enabled and configured. For each policy, the threshold at which the policy applies, and the action taken for that policy can be changed, as well as whether the policy itself is enabled or disabled.
Policy actions are as follows:
For more information on JA3 hashes, see the blog post that explains the concepts. For all intents and purposes, you can treat it as a stand-in for the particular client that the user is using (which could be a version of a valid client like Thunderbird, or a spambot for example).
The one-hour policies are checked in the order set by the wforce_1hr_policy_order config key. Unless tarpit override is enabled (see Tarpit Override below), the first matching policy decides the result, so the order matters when more than one policy matches. For example, 10 different bad passwords for one login from one IP exceed both maxDiffBadPasswordsPerUser (reject) and maxDiffBadPasswordsPerIPUser (tarpit), and the policy that is checked first decides whether the login is rejected or tarpitted.
The default order checks all the policies whose default action is reject first, then all the policies whose default action is tarpit. Within each half, the order goes from the widest aggregation (JA3) to the narrowest (IP/login):
To change the order, set wforce_1hr_policy_order with initConfig(), or with initDomainConfig() for one domain:
local override_config = {
wforce_1hr_policy_order = { "maxDiffBadPasswordsPerIPUser", "maxDiffBadPasswordsPerUser" }
}
config.initDomainConfig("foo.com", override_config)
Unlike other config keys, the list you set replaces the existing list; it is not merged with it. So a list that names only some of the policies does not keep the others in their default positions. Instead:
Why rejects first: without tarpit override, the first matching policy decides the result, so checking the rejects first means the strictest action wins, as it would with tarpit override enabled. With tarpit override enabled, the result is the same in any order, but every matching tarpit policy checked before a reject adds to the numTarpits counts that the twenty-four hour tarpit policies use. Checking the rejects first means a request that will be rejected stops before any tarpit policy is checked, so it is not also counted as a tarpit, and fewer policies are checked.
Why widest first within each half: a one-hour policy only rejects or delays the current request and leaves nothing behind, so within the rejects or within the tarpits the order only decides which policy is reported. The twenty-four hour and persistent reputation policies blacklist a key for an hour or longer, so for them the default order goes from the narrowest key to the widest (see Twenty-Four Hour Policy Order and Persistent Reputation Policy Order below).
The default order assumes the default actions. If you change a policy’s action, for example from tarpit to reject, consider moving it in wforce_1hr_policy_order too, or the reasoning above no longer holds for it.
The policy uses IP-derived keys in several places: IP-only statistics, IP/login tuple statistics, IP/JA3 tuple statistics, and the built-in IP, IP/login and IP/JA3 blacklist and whitelist entries managed by the policy. The network prefix used for these keys is controlled by the following configuration fields:
local override_config = {
ipkey_v4_prefix = 32,
ipkey_v6_prefix = 64
}
config.initConfig(override_config)
The defaults are /32 for IPv4 and /64 for IPv6. For example, with
ipkey_v4_prefix = 24, the IPv4 addresses 192.0.2.10 and
192.0.2.99 are treated as the same IP key for IP, IP/login and
IP/JA3 policy statistics, and for policy-managed blacklist and
whitelist entries.
These settings are global-only. Per-domain configurations created with
initDomainConfig() inherit the global ipkey_v4_prefix and
ipkey_v6_prefix values, and any ipkey_*_prefix values supplied in
a per-domain override are ignored.
This also affects reset behaviour. Resetting an IP/login or IP/JA3
tuple resets the prefixed tuple key, so resetting 192.0.2.99 with a
/24 IPv4 prefix also resets tuple statistics recorded for
192.0.2.10 with the same login or JA3 hash.
Note that the IPv6 default for these policy keys is now /64. This
is intentional: DDoS attacks that originate from IPv6 ranges can rotate
through large numbers of individual IPv6 addresses, causing the stats
DBs and policy-managed blacklist or whitelist DBs to become bloated
and much less effective when keyed by full /128 addresses.
Aggregating IPv6 keys by /64 makes these attacks visible and
actionable at the network level. In earlier versions, some IP-derived
keys effectively used the full IPv6 address (/128), especially for
tuple statistics and blacklist or whitelist entries. If you need the
previous exact-address behaviour for IPv6, set:
config.initConfig({
ipkey_v6_prefix = 128
})
Policies (all thresholds are applied over a rolling one-hour period):
maxDiffBadPasswordsPerIP - This counts the number of different failed passwords used in the last hour by a single IP address. The default threshold is 30, and the default action is “reject”.
maxDiffBadPasswordsPerUser - This counts the number of different failed passwords used in the last hour by a single user/login. The default threshold is 9, and the default action is “reject”.
maxDiffBadPasswordsPerIPUser - This counts the number of different failed passwords used in the last hour by a single user/login and IP address (i.e. both must match). The default threshold is 3, and the default action is “tarpit” for 5 seconds.
maxDiffBadPasswordsPerIPJA3 - This counts the number of different failed passwords used in the last hour by a single client (JA3 hash) and IP address (i.e. both must match). The default threshold is 15, and the default action is “tarpit” for 5 seconds.
maxDiffIPsPerUser - This counts the number of different IP addresses used in the last hour by a particular login. The default threshold is 10, and the default action is “reject”.
maxDiffLoginsPerIP - This counts the number of different usernames used in the last hour by a particular IP address. The default threshold is 20, and the default action is “reject”.
maxLoginsPerIP - This counts the total number of logins (successful or unsuccessful) in the last hour by an individual IP address. The default threshold is 600 (which equates to one login every 6 seconds), and the default action is “tarpit” for 5 seconds.
maxLoginsPerUser - This counts the total number of logins (successful or unsuccessful) in the last hour by a single user. The default threshold is 240 (which equates to one login every 15 seconds), and the default action is “tarpit” for 5 seconds.
maxFailedLoginsPerIP - This counts the total number of unsuccessful logins in the last hour by an individual IP address. The default threshold is 300 (which equates to one failed login every 12 seconds), and the default action is “tarpit” for 5 seconds.
maxFailedLoginsPerUser - This counts the total number of unsuccessful logins in the last hour by a single user. The default threshold is 120 (which equates to one failed login every 30 seconds), and the default action is “tarpit” for 5 seconds.
maxDiffCountriesPerUser - This counts the number of different countries that a user has logged in from (using the GeoIP Country DB) in the last hour. A whitelist of countries to ignore when tracking different countries can be configured. The default threshold is 3 (i.e. logging in from 4 different countries will trigger the policy), and the default action is “reject”.
badLoginPercentByIP - This calculates the percentage of bad logins by IP address. The percent failed threshold is set to 65 by default, with a minimum of three different login names, and a minimum number of 50 logins.
badLoginPercentByJA3 - This calculates the percentage of bad logins by client (JA3 hash). The percent failed threshold is set to 65 by default, with a minimum of 50 different login names, and a minimum number of 500 logins.
If the fail_type parameter is supplied by the client, then the following policies are also available:
The following policies track abuse over a 24 hour period. Note that all the following policies are based on counting rejections caused by the previous policies. Any policies that do not cause a reject action (for the reject policies), or a tarpit action (for the tarpit policies) will not be tracked (note that the blacklist* actions do generate a reject action).
In general the default actions for these policies will blacklist the offending IP/login address; the more frequent the abuse, the longer the blacklist will be applied for.
Although these policies track rejects over a 24-hour period, there are in fact two different thresholds for each policy. One threshold is for the current hour, and another is for the entire 24-hour period. The default action of the current hour policies is to blacklist for an hour, wherease the default action of the 24-hour policies is to blacklist for 24 hours. These values can all be configured of course if the administrator wants to choose different values.
maxRejectsPerHourPerIP - This counts the number of rejects for a given IP address in the current hour. The default threshold is 60, and the default action is “blacklistip” for one hour.
maxRejectsPerHourPerUser - This counts the number of rejects for a given username in the current hour. The default threshold is 30 and the default action is “blacklistlogin” for one hour.
maxRejectsPerHourPerIPUser - This counts the number of rejects for a given IP address/username tuple in the current hour. The default threshold is 15 and the default action is “blacklistiplogin” for one hour.
maxRejectsPerHourPerJA3 - This counts the number of rejects for a given JA3 hash in the current hour. The default threshold is 30 and the default action is “blacklistja3” for one hour.
maxRejectsPerHourPerIPJA3 - This counts the number of rejects for a given IP address/JA3 hash tuple in the current hour. The default threshold is 15 and the default action is “blacklistipja3” for one hour.
maxRejectsPerDayPerIP - This counts the number of rejects for a given IP address in the last 24 hours. The default threshold is 200, and the default action is “blacklistip” for 24 hours.
maxRejectsPerDayPerUser - This counts the number of rejects for a given username in the last 24 hours. The default threshold is 100, and the default action is “blacklistlogin” for 24 hours.
maxRejectsPerDayPerIPUser - This counts the number of rejects for a given IP address/username tuple in the last 24 hours. The default threshold is 50, and the default action is “blacklistiplogin” for 24 hours.
maxRejectsPerDayPerJA3 - This counts the number of rejects for a given JA3 hash in the last 24 hours. The default threshold is 100, and the default action is “blacklistja3” for 24 hours.
maxRejectsPerDayPerIPJA3 - This counts the number of rejects for a given IP address/JA3 hash tuple in the last 24 hours. The default threshold is 50, and the default action is “blacklistipja3” for 24 hours.
maxTarpitsPerHourPerIP - This counts the number of tarpits for a given IP address in the current hour. The default threshold is 120, and the default action is “blacklistip” for 30 mins.
maxTarpitsPerHourPerUser - This counts the number of tarpits for a given username in the current hour. The default threshold is 60 and the default action is “blacklistlogin” for 30 mins.
maxTarpitsPerHourPerIPUser - This counts the number of tarpits for a given IP address/username tuple in the current hour. The default threshold is 30 and the default action is “blacklistiplogin” for 30 mins.
maxTarpitsPerHourPerJA3 - This counts the number of tarpits for a given JA3 hash in the current hour. The default threshold is 60 and the default action is “blacklistja3” for 30 mins.
maxTarpitsPerHourPerIPJA3 - This counts the number of tarpits for a given IP address/JA3 tuple in the current hour. The default threshold is 30 and the default action is “blacklistipja3” for 30 mins.
maxTarpitsPerDayPerIP - This counts the number of tarpits for a given IP address in the last 24 hours. The default threshold is 400, and the default action is “blacklistip” for 24 hours.
maxTarpitsPerDayPerUser - This counts the number of tarpits for a given username in the last 24 hours. The default threshold is 200, and the default action is “blacklistlogin” for 24 hours.
maxTarpitsPerDayPerIPUser - This counts the number of tarpits for a given IP address/username tuple in the last 24 hours. The default threshold is 100, and the default action is “blacklistiplogin” for 24 hours.
maxTarpitsPerDayPerJA3 - This counts the number of tarpits for a given JA3 hash in the last 24 hours. The default threshold is 200, and the default action is “blacklistja3” for 24 hours.
maxTarpitsPerDayPerIPJA3 - This counts the number of tarpits for a given IP address/JA3 hash tuple in the last 24 hours. The default threshold is 120, and the default action is “blacklistipja3” for 24 hours.
Note that rejects or tarpits caused by the 24-hour policies themselves are not counted when calculating the above statistics.
With tarpit override enabled (see Tarpit Override), a request counts at most once as a tarpit, even if several one-hour tarpit policies match it, and it is not counted as a tarpit at all if a one-hour reject policy also matches it.
The twenty-four hour policies are checked in the order set by the wforce_24hr_policy_order config key. The policies for the last 24 hours (the maxRejectsPerDay and maxTarpitsPerDay policies) are always checked before the policies for the current hour (the maxRejectsPerHour and maxTarpitsPerHour policies); the list sets the order within each of those two groups.
Every twenty-four hour policy blacklists the key it counts, and the first matching policy decides which key that is. Each reject or tarpit from a one-hour policy counts towards all of the request’s keys at once (IP, login, IP/login, JA3 and IP/JA3), so policies with the same threshold can match on the same request. With the default thresholds, a single client trying one login from one IP exceeds maxRejectsPerHourPerIPUser and maxRejectsPerHourPerIPJA3 (both 15) on the same request.
The default order therefore goes from the narrowest key to the widest: IP/login, IP/JA3, login, JA3, IP. For the same key, the rejects policy comes before the tarpits policy. The reason is collateral damage. Blacklisting an IP/login blocks one account on one network. Blacklisting an IP blocks everyone behind it, which behind carrier-grade or corporate NAT can be many users. Blacklisting a login locks the real user out from everywhere, and blacklisting a JA3 blocks that client software on every network. Little protection is lost: if the attacker moves on to another login from the same IP and client, the IP/JA3 count is already over its threshold, so the next reject blacklists the IP/JA3 as well. The wider keys still have their own higher thresholds.
The default list is:
The default order assumes the default actions, where each policy blacklists the key it counts. If you change a policy’s action, for example to blacklist a wider key than the one it counts, consider moving it in wforce_24hr_policy_order too.
wforce_24hr_policy_order is set like wforce_1hr_policy_order (see One-Hour Policy Order), globally or per domain, and follows the same rules: the list you set replaces the existing list, policies not in the list are checked after it in order of policy name, and unknown names are ignored with a warning.
Non-behavioural policies are as follows:
The built-in blacklist check normally runs in wforce before the Lua policy engine is called. In order to disable this, and enable the blacklist to be checked from Lua instead, use the following configuration:
disableBuiltinBlacklists()
local override_config = {
checkBuiltInBlacklists = true
}
config.initConfig(override_config)
This can be useful if Lua-based whitelisting is used rather than the built-in whitelists (available only from wforce 2.1 onwards), since otherwise the built-in blacklist overrides the Lua-based whitelist.
The whitelist consists of a list of IP addresses (these can be in CIDR format), usernames and JA3 hashes that will be whitelisted. By default “127.0.0.0/8”, “192.168.0.0/16, “postmaster” and “abuse” will be whitelisted.
The IPs, usernames and JA3 hashes to be whitelisted can be configured in one of two ways.
Firstly by passing a table containing the required IPs and usernames to the “loadWhitelists()” function:
config.loadWhitelists({ip_wl = { "127.0.0.1/8" }, ipe_wl = { "127.0.2.1" }, login_wl = { "postmaster", "abuse" }, ja3_wl={"xxx"})
The ip_wl table contains the IP whitelist. The ipe_wl table contains a set of exceptions to the IP whitelist. The login_wl table contains the login whitelist. The ja3_wl table contains the login whitelist.
Secondly, they can be loaded from a file:
config.loadWhitelistsFromFile("whitelists.lua")
The file must have the following format:
ip_wl = { "127.0.0.0/8", "192.168.0.0/16" }
ipe_wl = { "127.0.2.1" }
login_wl = { "postmaster", "abuse" }
ja3_wl = { "xxx" }
If the whitelist is changed while wforce is running, it can be reloaded simply by typing “config.loadWhitelistsFromFile(filename)” at the wforce console (or running the console as follows: wforce -c -e “config.loadWhitelistsFromFile(filename)”.
You can check if an IP or login are in the whitelist from your own functions by using:
if (config.checkIPWhitelist(ip)) then XXX end
if (config.checkIPWhitelistExceptions(ip)) then XXX end
if (config.checkLoginWhitelist(login)) then XXX end
if (config.checkJA3Whitelist(login)) then XXX end
Remember that wforce will change working directory to that of the specified configuration file, so filenames can be relative to that point.
By default all policies that match will ‘short-circuit’ the policy decisions. The policies are checked in groups, in the following order: the allow prefunc, the RBLs, the general policies (e.g. countryBlacklist), the persistent reputation policies, the 24-hour policies, the one-hour policies, and finally the allow postfunc. Within their groups, the persistent reputation, 24-hour and one-hour policies are checked in the order set by persistent_reputation_policy_order, wforce_24hr_policy_order and wforce_1hr_policy_order (see the Policy Order sections), and a policy in an earlier group returns before a later group is checked. This means that a less restrictive policy action such as tarpit can be returned even though a later policy with an action of blocklist might also match. To prevent this, there is an option to continue processing if the action is tarpit, saving the current action and policy and replacing it only if a subsequent policy is more restrictive. For example if three policies would match, with actions of “tarpit 2 seconds”, “tarpit 5 seconds” and “blocklist for 1 day”, then the blocklist policy/action will be applied, even if the tarpit policies are evaluated first.
To enable tarpit override, set the “allow_tarpit_override” config key to true.
With tarpit override enabled, the 24-hour statistics count the action that the one-hour policies return, not every policy that matched: a request that matches several one-hour tarpit policies adds one to numTarpits, and a request that a one-hour policy rejects adds one to numRejects and nothing to numTarpits.
The concept of delayed whitelisting is supported; when this is enabled, then for whitelisted IPs, rather than short-circuiting the policy, the full policy is run and the log message that would have been generated is logged , prepended with “Whitelisted IP or login:”. This allows examination of the logs to see what whitelisted IPs or users are doing, and what policies they would hit if they were not whitelisted.
To enable delayed whitelisting, set the “delayWhitelisting” config key to true.
The IP graylist consists of a list of IP addresses (these can be in CIDR format) that will be graylisted. Graylisted IPs will never be rejected or blacklisted, only tarpitted.
The number of seconds that graylisted IPs will be tarpitted for is configured using the “graylist_tarpit_secs” configuration field, e.g.
config.initConfig({graylist_tarpit_secs=5})
The IPs to be graylisted can be configured in one of two ways.
Firstly by passing a table containing the required IPs to the “loadGraylist()” function:
config.loadGraylist({ip_gl = { "127.0.0.1/8" }})
Secondly, they can be loaded from a file:
config.loadGraylistFromFile("graylist.lua")
The file must have the following format:
ip_gl = { "127.0.0.0/8", "192.168.0.0/16" }
If the graylist is changed while wforce is running, it can be reloaded simply by typing “config.loadGraylistFromFile(filename)” at the wforce console (or running the console as follows: wforce -c -e “config.loadGraylistFromFile(filename)”.
You can check if an IP is in the graylist from your own functions by using:
if (config.checkIPGraylist(ip)) then XXX end
Remember that wforce will change working directory to that of the specified configuration file, so filenames can be relative to that point.
The suspect country list is a list of ISO Alpha-2 country codes. Requests from these countries are not blocked outright; instead, any policy that sets “suspect_multiplier” uses a scaled threshold (threshold * suspect_multiplier) for them. Policies without suspect_multiplier are unaffected.
For example, to halve the maxFailedLoginsPerIP threshold for suspect countries:
config.initConfig({ wforce_1hr_policies = {
maxFailedLoginsPerIP = { suspect_multiplier = 0.5 } -- 300 becomes 150
}})
The countries can be configured by passing a table to the “loadSuspectlists()” function:
config.loadSuspectlists({ country_sl = { "XX", "YY" } })
Or they can be loaded from a file:
config.loadSuspectlistsFromFile("suspectlist.lua")
The file must have the following format:
country_sl = { "XX", "YY" }
Calling either function replaces the current list, so it can be reloaded at the wforce console while wforce is running. Country codes in the list are converted to upper case when loaded.
You can check if a country is in the suspect list from your own functions by using:
if (config.checkCountrySuspectlist(cc)) then XXX end
“checkCountrySuspectlist()” expects an upper-case code, as returned by the GeoIP country lookup.
When a policy triggers, the allow response attributes include “suspect_multiplier”: the multiplier applied for that request (1 if none was applied).
Static lists of IP addresses (these can be in CIDR format), ASNs and countries to block can be configured in one of two ways.
The first is to pass them directly to the “loadBlacklists()” function:
config.loadBlacklists({ ip_bl = { "198.51.100.0/24" }, asn_bl = { "64496" }, country_bl = { "XX" } })
The second is to load them from a file, using the “loadBlacklistsFromFile()” function:
config.loadBlacklistsFromFile("blacklists.lua")
The file must have the following format. Include all three tables, and use an empty table for any list you do not use:
ip_bl = { "198.51.100.0/24" }
asn_bl = {}
country_bl = { "XX" }
To clear a list, set it to an empty table (for example “asn_bl = {}”) and reload the file. Do not just remove the table from the file: when the file is reloaded, a table that is missing from it keeps the entries it had from the previous load.
Each call replaces all three lists. The lists apply to all domains. They are checked as follows:
ipBlacklist and asnBlacklist are normal general policies, like countryBlacklist: they can be disabled, or given a different action, policy_code or policy_text, globally or per domain, and they follow testMode and whitelisting in the same way. For example, to only log matches of the ASN blacklist:
general_policies = {
asnBlacklist = {
action = "log"
}
}
If the lists are changed while wforce is running, they can be reloaded by typing “config.loadBlacklistsFromFile(filename)” at the wforce console.
The country blacklist consists of a list of countries that will be blacklisted by the policy. Any IPs matching those countries will be subject to the specified action. The default action is “reject”. The country list must be specified using the ISO Alpha-2 (i.e. 2-digit) country codes. The country codes are specified using the “policy_params” argument for the “countryBlacklist” policy, e.g.
countryBlacklist = {
enabled = true,
policy_params = { "NG", "JP", "US" }, -- A comma-separated list of 2-digit country codes that will be blacklisted
action = "reject",
policy_code = 551,
policy_text = "countryBlacklist"
}
The “maxLoginsPerSession” general policy counts allow requests per session over five minutes, and applies its action when a session has more than “threshold” allow requests. Sessions are identified by the “session_id” field of the allow request, which Dovecot sends. Allow requests without a session_id are not counted. The policy is disabled by default; to enable it:
general_policies = {
maxLoginsPerSession = {
enabled = true,
threshold = 4, -- more than 4 allow requests in 5 minutes
action = "reject",
policy_code = 3001,
policy_text = "maxLoginsPerSession"
}
}
The counts are kept in the “FiveMinDB” stats DB, which is replicated when replication is enabled. They are not cleared by the reset command, and expire after five minutes. The policy can be enabled or tuned per domain, like other policies.
Multiple RBLs can be configured, in order to reject connections from known-bad IPs. These are configured as follows:
wforce_enable_rbls = true,
wforce_rbls = {
spamhaus =
{ zone = "authbl.spamhaus.org",
ret = { "127.0.0.10" },
msg = "Your IP address is on the spamhaus auth blacklist, please visit https://www.spamhaus.org/lookup/"
},
mybl =
{ zone = "myisp.bl",
ret = { "127.0.0.2", "127.0.0.3" },
msg = "You have been blacklisted by myzone, please contact myisp support at https://myisp.net/support/blacklist"
}
}
It is possible to configure a custom fuction, which will be called whenever an IP matches an RBL zone. An example function follows:
local function processRBLBlock(lt, ret_msg, match_zone, match_ip, config)
return -1, ret_msg, "Remote IP matches RBL", {rbl_zone = match_zone, match_ip = match_ip}
end
Where the parameters are as follows:
It returns the following:
N.B. RBLs cannot be overridden on a per-domain basis - only the RBL configuration defined in initConfig() will be used.
There are policies which will track reputation of IP addresses and JA3 hashes persistently, by storing data about IPs/JA3 hashes which are blocklisted by the 24-hour policies in a Redis DB. Everytime an IP is blacklisted by a 24-hour policy, that information is recorded in Redis. A policy can then count the number of times that the IP address has been recorded in Redis, and if the count is above a threshold, blocklist the IP address for a longer period of time.
There are several configuration pre-requisites for Persistent Reputation; namely a working redis configuration and enabling the feature itself:
redis = {
redis_enabled = true,
redis_server = 'localhost'
},
enable_persistent_reputation = true
Once the above is enabled, the persistent reputation policies will start to be used. These consist of the following policies:
The default configuration is as follows:
persistent_reputation_policies = {
max24HourBlocklistsPerIP = {
enabled = true,
threshold = 14,
policy_params = 3456000, -- Keep the data about each block for 40 days
action = "blacklistip",
action_value = 2628000, -- Blocklist for a whole month
policy_code = 2001,
policy_text = "max24HourBlocklistsPerIP"
},
max24HourBlocklistsPerJA3 = {
enabled = true,
threshold = 14,
policy_params = 3456000, -- Keep each data item for 40 days
action = "blacklistja3",
action_value = 2592000, -- Blocklist for 30 days
policy_code = 2002,
policy_text = "max24HourBlocklistsPerJA3"
}
},
Note that the default action is to blocklist the IP/JA3 for a month; this reflects the fact that an IP address has to have been blocklisted more than 14 times in a 40 day period, which generally indicates a malicious IP. All of the above configuration parameters can adjusted to suit local requirements.
The persistent reputation policies are checked in the order set by the persistent_reputation_policy_order config key. Both policies have a threshold of 14 by default, so a single attacker can exceed both on the same request, and the first one checked decides whether the IP or the JA3 is blocklisted for a month. The default order is max24HourBlocklistsPerIP, then max24HourBlocklistsPerJA3, because blocklisting a JA3 blocks that client software on every network, while blocklisting an IP only affects that address (or its prefix, see IP Key Prefixes). If you change either policy’s action, consider changing the order too. The list is set like wforce_1hr_policy_order, globally or per domain, with the same rules.
The testMode config parameter can be set to true, in which the return value from the allow function will always be 0. Logging will be the same as if testMode was disabled, except that the key “test_mode=1” will be set in ret_attrs.
Wforce supports sending report data to external entities. Specifically now there is support for the following:
A typical configuration is for wforce to send all reports and allow commands to both Elasticsearch and trackalert, which is configured as follows (note that both are disabled by default):
elasticsearch = {
enabled = true,
commands = { "report", "allow"},
logstash_server = "http://127.0.0.1:8080",
webhook_secret = "secret",
webhook_basic_auth = "foo:bar"
},
trackalert = {
enabled = true,
trackalert_server = "http://127.0.0.1:8085",
webhook_secret = "secret",
webhook_basic_auth = "foo:bar"
}
The trackalert daemon will (optionally) cache information about previous successful logins in a Redis DB. This information can be queried by wforce in order to return a “suspiciousLogin: 1” field in the return data for allow requests, for example when a login is detected which uses a new device or IP address. The “suspiciousLogin” field can then be used by clients to perform extra checks, for example Second Factor Authentication.
To enable this behaviour in either daemon, configure the following, changing the values as appropriate (note that this is disabled by default):
redis = {
redis_enabled = true,
expire_secs = 5184000, -- 60 days expiry for redis cache entries
redis_server = "127.0.0.1", -- can also be a hostname
redis_username = "foo", -- optional if redis server is only configured with password
redis_password = "secret", -- optional is redis is configured with no authentication
redis_port = 6379,
},
check_suspicious_login = true
If you want to use the standardized policy framework described in this document, but you have some local customization you’d like to make, this is achieveable using several mechanisms. Ideally you will use the existing policy framework, because this has a lot of benefits in terms of logging, white/graylisting and reporting. To do this there are several hooks that enable you to add new policies, new fields to the stats db, and even write your own lua functions.
The easiest way to add a new policy is to use the addOneHourPolicy() function, which is part of the config.wforce_config module.
This function looks like:
config.addOneHourPolicy("policyName", "fieldName", "ip")
This will register a new policy, which acts on the field name specified, using the key specified. The field name can be an existing field in the one hour statss db, or a custom field (see addOneHourCustomField(). The key can be “ip”, “login” or “iplogin”.
By itself this function will not achieve anything however because it will not be enabled. To enable the policy, you’ll need to add all the configuration for that policy using initConfig(). For example:
config.addOneHourPolicy("myNewPolicyByIP", "myNewField", "ip")
local override_config = {
wforce_1hr_policies = {
myNewPolicyByIP = {
enabled = true,
threshold = 70,
action = "reject",
policy_code = 9001,
policy_text = "myNewPolicyByIP",
}
}
}
The above will cause a reject action if the value of “myNewField” goes above 70 for any IP address.
A new policy is checked after the policies in wforce_1hr_policy_order, and a warning is logged when it is enabled. To choose where it is checked, add it to wforce_1hr_policy_order (see One-Hour Policy Order). This also applies to addOneHourCustomPolicy().
When adding new policies it is often the case that a new field is required to be tracked in the stats db. The function addOneHourCustomField() can be used to do this, as follows:
addOneHourCustomField("fieldName", "int")
The second parameter can be “int”, “hll” or “countmin”.
The field will not be updated unless you write some Lua code to update it. This can be done using the “report prefunc” and “allow prefunc” hooks (see below).
If you require to perform some complex login in your policy, and not use a simple single field threshold, then you can create entirely custom policies using the addOneHourCustomPolicy() function. This is a hook that will run as part of the policy, and returns true if the policy matches and false if not. If returning true, a table is also returned with key-value pairs which will be added to the JSON returned to the client as well as being logged.
addOneHourCustomPolicy("policyName", custom_function)
local function badLoginPercent(hourdb, daydb, lt, policy, config)
local debugLog = config.debugLog
local statsdb = hourdb
local diff_logins = statsdb:twGet(lt.remote, "diffLogins")
local total_logins = statsdb:twGet(lt.remote, "numLogins")
local failed_logins = statsdb:twGet(lt.remote, "numFailedLogins")
local percent_failed = failed_logins/total_logins*100
local percent_success = 100 - percent_failed
local min_logins = policy.min_logins
local percent_failed_threshold = policy.percent_failed_threshold
local difflogins_threshold = policy.diff_logins_threshold
if tostring(percent_failed) == "-nan" or tostring(percent_failed) == "nan" then percent_failed=0 end;
if total_logins > min_logins and percent_failed > percent_failed_threshold and diff_logins > difflogins_threshold
then
if (debugLog) then infoLog("Combined threshold exceeded for policy badLoginPercent actual values are total logins ".. total_logins .. " percent failed " .. percent_failed .. " different logins ".. diff_logins, {}) end
return true, { percent_failed=percent_failed, diff_logins=diff_logins, total_logins=total_logins }
else
if (debugLog) then infoLog("Combined threshold NOT exceeded for policy badLoginPercent actual values are total logins ".. total_logins .. " percent failed " .. percent_failed .. " different logins ".. diff_logins, {}) end
return false
end
end
config.initConfig({
wforce_1hr_policies = {
badLoginPercentByIP = {
enabled = true,
percent_failed_threshold = 70,
diff_logins_threshold = 3,
action = "reject",
policy_code = 9010,
policy_text = "badLoginPercentByIP",
min_logins = 10
}
}
)
config.addOneHourCustomPolicy("policyName", custom_function)
Note that the above example badLoginPercentByIP is now a standard policy, incidently implemented using the custom policy framework.
The report prefunc is configured as follows:
report_prefunc = myReportFunction,
Where “myReportFunction” is a Lua function that is configured as follows:
function myReportFunction(lt)
-- Do the things a report function would normally do such as update statsdb fields
end
See the wforce documentation for more information on configuring report functions.
The allow prefunc is called before the rest of the policy, and is configured as follows:
allow_prefunc = myAllowFunction,
The allow postfunc is called after the rest of the policy, i.e. only if the return result would be 0, and is configured as follows:
allow_postfunc = myAllowFunction,
Where “myAllowFunction” is a Lua function that is configured as follows:
function myAllowFunction(lt)
-- do things
return 0, "", "", {}
end
For the allow prefunc, if the custom function returns any value other than 0 (i.e. “allow”), then the rest of the policy will not run.
See the wforce documentation for more information on configuring allow functions.
The file that contains the configuration defaults is called wforce_config.lua, which contains all the thresholds and actions for the various policies which can be enabled. These can be overridden on a global or per-domain basis with the initConfig() or initDomainConfig() functions.
Functions to load whitelists of IPs and logins are found in wforce_wl.lua.
The wforce.conf file may be modified, e.g. to add ACLs, Siblings, or modify the console crypto key, or the basic authentication password. This is also where the configuration can be overridden, and whitelists loaded.
The Lua “require” command is used to load all the policy files as Lua modules. To ensure this works correctly, wforce will change the working directory to the directory containing the wforce.conf file.
The policy consists of the following files. These will typically be installed in a manner which does not override the default configuration (e.g. in /etc/wforce/example-policy). In order to use the files as part of a standard install, they should be copied (not moved) to /etc/wforce (or wherever wforce is configured to read its configuration from by default). The directory layout must be preserved, otherwise the policy will fail (i.e. the wforce.lua file must be in a subdirectory relative to wforce.conf named “policy”).
File layout:
Files marked * are not designed to be edited by the administrator, so consider these read-only unless you really know what you are doing. Modifying them means that it will be very hard to upgrade to new versions of the policy.