Detecting Suspicious IP Behavior and Impossible Travel
In this installment, we’ll demonstrate how you can leverage the same feature to detect impossible travel — aka an account connecting from two different locations, far from each other, in a short amount of time.
We will use the SSHD service again as an example for this article, but this feature can be used for any service logging authentication.
Requirements
Setup the acquisition (optional)
Same as in part one, in this article,we running the CrowdSec Security Engine in replay mode. If you want to use service mode, you need to set up the acquisition.
Install the SSHD collection
You can find the collection here.
Parse successful authentication
As already seen in part one, this is the parser node to parse successful SSH authentication:
Enrich event with IP geolocation
To detect that an account connected from two different locations in a short amount of time, we need information on the geolocation of the source IP address.
We can get this info by installing the geoip-enrich parser.
Note: You can skip this step if you have already installed this parser.
The scenario
Now we need to check that the IPs filled in our buckets are more than 1000km away from each other.
Here is the condition that we will use for our conditional bucket:
This condition checks that the buckets contain at least two events and that the distance between the IPs in those events is more than 1000km away. We can achieve that using the Distance() helper, which uses the Haversine formula to determine the distance between two points with their longitude and latitude.
Here is the full scenario that detects an account connecting from more than 1000km away since its last connection in 4 hours:
To make this scenario work, we must group the events by targeted user and only look at distinct IP addresses in the bucket.
Note: we set user as the scope for this scenario. If your profile configuration generates a decision only for alert with scope IP, triggering this scenario will not lead to any decision.
Bonus: Add context to the alert
With this scenario, the CrowdSec Security Engine will only log the user targeted by the attack. But it is also interesting to know from which IPs and countries the user logged in. To do that, I will use the new CrowdSec feature, called Alert Context. See more about this feature here.
To add the source IP addresses and the source countries, we need to run the following commands:
When you inspect an alert, you will be able to see all the source IPs and countries that have been poured into the bucket.
Test with CrowdSec replay mode
We can test this scenario with the CrowdSec replay mode to ensure everything works properly.
Here are some logs that represent two successful authentications from two different IPs, in 2 different countries, and in 2 hours intervals:
We can run the CrowdSec replay mode with the following command:
Tada! The impossible travel from the user root has been detected by CrowdSec!
Reference link
A.K
Comments
Post a Comment