java.lang.Object
com.aoapps.hodgepodge.net.IpReputation
Tracks IP reputation for use by any number of services.
The lifecycle:
init(java.net.InetAddress), returnsIpReputation.Connection- establishes a new context for tracking one specific service interaction.- Connection:
- Bad score decays once per hour.
- Blocking is done at a bad score of
REJECT_BAD_SCORE, limiting attempts (both serial and concurrent). - Bad score is capped to
MAX_BAD_SCOREfor a maximum of aUNBLOCK_HOURS-hour block.
Future ideas (in no particular order):
- Sortable columns in simple aoadmin-only web interface to view current statistics for the VNC tracker.
- Using hard-coded values; only make configurable when first needed.
- Concurrency through ConcurrentMap and AtomicInteger.
- Evict older records, with lower "bad" scores, when a fixed number of records are reached. (to limited maximum heap usage).
- Be able to remove blocks from the aoadmin interface.
- Track "Good" scores, too.
- Add a "boost" method, which would add some "Good" reputation from an external source, such as successful website login or access to remote console control panels. Have to consider consequences of this - don't want a bad guy with access to boost themselves unlimited service password attempts. Could limit to one boost per time period or session. However, the per-attempt delays might be sufficient to mitigate this already. Boost an be weaker than Connection.success(), and only apply to the /32 or /128.
- Track good/bad scores per different network ranges, both IPv4 and IPv6 supported:
- For IPv4, tracking /32 through /24, at every level (/32, /31, …, /25, /24).
- For IPv6, tracking /128 through /32, at every 4th level (/128, /124, …, /36, /32). Exact details to be determined later. Could be every 4th from /128 to /64, then others like /56, /48
- Scores are added and removed across all the levels.
- For allow/deny decision, check tightest range first (/32 or /128): if (bad - good) > deny_threshold, deny. If (bad - good) < allow_threshold, allow. Otherwise check the next level up. When allow levels checked and no threshold, would be UNCERTAIN (Link enum).
- At all prefixes, bad scores would have a maximum value where the decay would not block more than 24 hours.
- At all prefixes, good scores would have a maximum value where their reputation can persist longer, maybe a month?
- But scores for increasingly broader network ranges should have caps and decay such that the reputation effects do not last as long.
- Maybe the positive score decays more quickly by prefix. So a positive /32 could last up to 32 days, while the positive /24 could last much less time. Basically, either cap the max good score by prefix (preferred), or decay more quickly by prefix.
- Bound the downside of the difference. One good login could result in multiple bad attempts: 30 days reputation, slower decay, +2 good versus +1 bad, all multiple to the number of attempts that could be made. But, the number of attempts would remain bounded. A bad guy with one good login could use that to magnify their attempts. However, like the "boost" idea, the per-attempt delays might be sufficient to mitigate this already.
- Support IPv6 (including mapped IPv4 being converted to IPv4 internally)
- Support persistence. If storing in local filesystem, consider consequences of Tomcat parallel deployment. More enterprisey solution would be a reputation service that centralizes across multiple services, but this would begin to overlap the existing, and more complicated, AOServ IP Reputation system that blocks at edge routers.
- Bad scores decay more quickly, maybe once per hour and in a quantity scaled by (33-prefix) (/32 would decay one per hour, /31 would decay two per hour, /24 would decay 9 per hour /24 8 per hour).
- Good scores decay more slowly, maybe once per 10 hours or similar.
- Use this feature for other Java endpoints, such as aoserv-daemon, aoserv-master, and NOC RMI.
- When background clean-up is triggered, clean the immediate record being processed (if any), then delegate
background clean-up to the provided task executor. API users would have to pass-in the executor, which could
simply by
Thread::newor could be an unbouded executor from ao-concurrent. - Beyond reputation, add rate-limits per-host, and per-network prefix ranges. These rate limits would even affect those successfully performing the operations. The rate limit allowed could be affected by the currently effective good/bad scores.
- Use the reputation system for login forms and servlet filter for public facing sites. In particular, could integrate well with the rate limiting idea.
- Author:
- AO Industries, Inc.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionIpReputation(String logPrefix) Defaults toSystem.currentTimeMillis().IpReputation(String logPrefix, LongSupplier timeSource) -
Method Summary
Modifier and TypeMethodDescriptionGets a snapshot of the current reputation records with a badScore > 0.init(InetAddress address)
-
Constructor Details
-
IpReputation
- Parameters:
timeSource- Use the provided time source, useful for testing.
-
IpReputation
Defaults toSystem.currentTimeMillis().
-
-
Method Details
-
getRecordsSnapshot
Gets a snapshot of the current reputation records with a badScore > 0.- Returns:
- Unmodifiable snapshot map from address to bad score in insertion order.
-
init
-
