All posts

Splunk SSH Alert

๐Ÿš€ 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:SS using strftime().
  • Constructs the Slack message with emojis for better readability.

๐Ÿ”” Configuring a Splunk Alert to Send Slack Notifications #

๐Ÿ› ๏ธ Step 1: Create a New Alert #

  1. Go to Splunk UI โ†’ Settings โ†’ Searches, Reports, and Alerts.
  2. Click Create New Alert.
  3. 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 #

  1. Enable Slack Alert action in Splunk.
  2. Set up a Slack Webhook URL (replace with your actual webhook):
https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK
  1. 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$"
}
  1. 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! ๐Ÿš€๐Ÿ”