๐ Splunk SSH Login Alert #
Monitoring SSH login activity is crucial for security. This guide walks you through setting up a Splunk alert that detects successful SSH logins and sends formatted Slack notifications with essential details.
๐ฏ Splunk Query to Detect Successful SSH Logins #
Use the following Splunk search query to detect successful SSH logins from /var/log/auth.log.
index=* "Accepted password for" OR "Accepted publickey for" source="/var/log/auth.log"
| rex field=_raw "Accepted (?<auth_method>\w+) for (?<user>\w+) from (?<ip>[\d\.]+) port (?<port>\d+)"
| eval formatted_time=strftime(_time, "%Y-%m-%d %H:%M:%S")
| table formatted_time host user ip auth_method port
| eval slack_message="๐ *Successful SSH Login Alert*\n๐ค *User:* `".user."`\n๐ฅ๏ธ *DEST Host:* `".host."`\n๐ *SRC IP:* `".ip."`\n๐ *Method:* `".auth_method."`\nโฐ *Time:* `".formatted_time."`"
๐ Explanation: #
- Filters logs to find SSH logins (password/public key authentication).
- Extracts key details using
rex(regex extraction):- ๐ค
user: Username - ๐
ip: Source IP - ๐
auth_method: Authentication method - ๐ฅ๏ธ
host: Destination machine
- ๐ค
- Formats the timestamp into
YYYY-MM-DD HH:MM:SSusingstrftime(). - Constructs the Slack message with emojis for better readability.
๐ Configuring a Splunk Alert to Send Slack Notifications #
๐ ๏ธ Step 1: Create a New Alert #
- Go to Splunk UI โ Settings โ Searches, Reports, and Alerts.
- Click Create New Alert.
- Set the Trigger Condition:
- Trigger if Number of Results > 0.
- Set an appropriate schedule (e.g., every 5 minutes).
๐ Step 2: Configure the Slack Alert Action #
- Enable Slack Alert action in Splunk.
- Set up a Slack Webhook URL (replace with your actual webhook):
https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK
- Use the following Slack message format:
{
"text": "๐ *Successful SSH Login Alert*\n๐ค *User:* $result.user$\n๐ฅ๏ธ *DEST Host:* $result.host$\n๐ *SRC IP:* $result.ip$\n๐ *Method:* $result.auth_method$\nโฐ *Time:* $result.formatted_time$"
}
- Save & Enable the Alert! ๐
โ Example Slack Notification Output #
When triggered, Slack will receive a message like this:
๐ Successful SSH Login Alert
๐ค User: james
๐ฅ๏ธ DEST Host: 10.10.10.10
๐ SRC IP: 10.10.10.100
๐ Method: publickey
โฐ Time: 2025-03-16 15:14:59
๐ฏ Final Thoughts #
By setting up this Splunk alert, you ensure real-time monitoring of SSH logins while improving security visibility. You can modify the query to:
โ
Include more details (e.g., failed logins, geolocation lookup).
โ
Trigger different actions (e.g., email alerts, automated responses).
๐น Now your Slack is your security dashboard! ๐๐