Password Spraying Attack & Defense
Last updated
Last updated
To apply this scenario in your home lab, you need the following:
✅ Windows Server (Domain Controller - DC)
✅ Windows Client (Domain-Joined Machine)
✅ Ubuntu Machine (Elasticsearch & Kibana)
✅ Ubuntu Machine (TheHive)
Before initiating the attack, we must install Winlogbeat on the Windows server to collect logs and send them to Elasticsearch.
Please review this for the installation: https://faresbltagy.gitbook.io/footprintinglabs/weinnovate-training/build-elk-lab/set-up-winlogbeat-and-filebeat-for-log-collection
Below is the winlogbeat.yaml
configuration file:
Password spraying is a type of brute-force attack where an attacker tries a single, common password against multiple user accounts before moving on to another password and repeating the process. This technique is used to avoid account lockout policies that trigger after a certain number of failed login attempts.
Before initiating a Password Spraying attack simulation, it is essential to enable auditing for both successful and failed login attempts.
To conduct this attack and analyze the resulting logs, we will install and utilize the DomainPasswordSpray.ps1
tool.
After installing the tool, let's proceed to execute the attack against the domain Main.local
.
Before analyzing the logs in ELK, let's first review the events that occurred from PowerShell.
Now, let's access the ELK logs and filter for event code 4625.
Let's add additional columns, such as 'hostname' and 'username', to enhance our data set.
We need to establish a threshold rule that triggers an alert when the count of unique usernames surpasses a specified limit within a defined timeframe, with grouping based on the hostname field.
Next, we need to scroll down to proceed with creating the rule.
This rule triggers an alert when five authentication failure events occur for different usernames on the same hostname in five minutes.
This rule means:
At each execution (every 1 minute), the rule analyzes data collected over the last 5 minutes (the look-back time).
For example, if the rule runs at 5:21 PM, it will check data from 5:16 PM to 5:21 PM. Then, at 5:22 PM, it will check data from 5:17 PM to 5:22 PM, and so forth.
For password spray detection, the rule interval should be set to match or be shorter than the look-back time for continuous monitoring, ensuring no attacks are missed. However, if system resources are limited, increasing the interval to 5-10 minutes with a look-back time of 10-30 minutes balances performance and detection timeliness. For practice, let's configure the rule to run every minute with a loopback time of five minutes.
Next, let's rerun the attack and check if an alert was triggered.
Let's proceed with reviewing the alerts.
To automatically forward this alert to Tines, a Gold license is required. However, since we do not have one, we cannot utilize Tines' webhook URL for this purpose. Instead, we will send an HTTP request to retrieve alerts from the ELK stack and schedule this request to run every 10 minutes to check for new alerts.
Before proceeding, we need to create an API key with the necessary privileges to retrieve alerts.
We can retrieve the alerts triggered in ELK by accessing the following URL:
https://192.168.204.146:9200/.kibana_alerting_cases/_search?_source=alert&filter_path=hits.hits._source.alert
First, we will send a GET request to this URL using the previously generated API key.
Let's begin our workflow on Tines by sending an HTTP request to retrieve alerts from this endpoint. However, before proceeding, we need to use Ngrok to expose the ELK stack publicly, allowing Tines to send HTTP requests to it.
We are now able to retrieve the alerts. Let's proceed.
Now, let's run the HTTP request.
Let's schedule this request to run every 10 minutes to check for new alerts.
We have received the alerts and can forward them to any desired destination. Now, let's utilize this alert to send a notification to our Telegram bot and create a case in TheHive.
To set up a Telegram bot, please refer to the following guide: Telegram Bot Setup.
Let's rerun the workflow to verify if any output is received in our Telegram bot.
We also want to create a case in TheHive using the alert information.
We need to use Ngrok here as well because TheHive is hosted on our local machine. This allows us to expose TheHive's URL publicly, enabling Tines to send HTTP requests for case creation.
The following elements must be added to ensure the case is successfully created in TheHive.
WWe also require the API key to create a case on TheHive. To obtain it, please visit the following URL: https://faresbltagy.gitbook.io/footprintinglabs/build-home-lab-soc-automation/automate-everything-with-shuffle.
Now, let's rerun the workflow to verify whether the case is created successfully.
You may include a summary and MITRE tags to enhance the case's informativeness.