Linux Possible SSH Bypass for Non-User Account

 Original Source: [splunk source]
Name:Linux Possible SSH Bypass for Non-User Account
id:89a99108-8b70-4d05-ad3e-25a2e6a87d6f
version:1
date:None
author:Raven Tait, Splunk
status:production
type:Anomaly
Description:The following analytic detects a failed SSH password authentication followed by a successful password authentication for the same common non-user Linux account, source address, and endpoint within five seconds. This may indicate abuse of an authentication bypass or another weakness that allowed access to an account whose shadow entry is typically locked or passwordless. The account list is a cross-distribution heuristic; verify the account's shadow status for each image.
Data_source:
  • -Linux Messages Syslog
search:`linux_syslog`
("Failed password for" OR "Accepted password for")

| rex field=_raw "^(?<event_timestamp>\\w{3}\\s+\\d+\\s+\\d{2}:\\d{2}:\\d{2})\\s+(?<dest>\\S+)\\s+(?:\\S+\\s+)?sshd(?:-session)?(?:\\.pam)?\\[\\d+\\]:\\s+(?<auth_result>Failed|Accepted) password for (?:invalid user )?(?<user>\\S+) from (?<src_ip>\\S+) port (?<src_port>\\d+) ssh2"

| eval user=lower(user)

| where isnotnull(auth_result) AND in(user, "daemon", "bin", "sys", "sync", "shutdown", "halt", "games", "man", "lp", "mail", "news", "uucp", "operator", "www-data", "backup", "list", "irc", "gnats", "nobody", "_apt", "systemd-network", "systemd-resolve", "messagebus", "uuidd", "sshd", "ntp", "ftp", "chrony", "postfix", "redis", "mysql", "mariadb", "postgres", "alpine", "guest")

| eval event_priority=if(auth_result="Failed", 0, 1)

| sort 0 _time event_priority

| streamstats global=f window=1 current=f last(auth_result) as previous_auth_result last(_time) as failure_time by dest user src_ip

| where auth_result="Accepted" AND previous_auth_result="Failed" AND _time-failure_time<=5

| eval success_time=_time, elapsed_seconds=success_time-failure_time

| `security_content_ctime(failure_time)`
| `security_content_ctime(success_time)`

| table failure_time success_time elapsed_seconds dest user src_ip src_port

| `linux_possible_ssh_bypass_for_non_user_account_filter`


how_to_implement:To successfully implement this search, you need to ingest Linux syslog logs. These logs should be collected with the Splunk Add-on for Unix and Linux (https://splunkbase.splunk.com/app/833).
known_false_positives:A user may mistype a password before a legitimate login. Common account names may be unlocked or configured with a password on a particular image. Validate the account's shadow state and expected SSH access before escalating.
References:
  -https://attack.mitre.org/techniques/T1078/003/
  -https://attack.mitre.org/techniques/T1021/004/
  -https://sshhole.com/
drilldown_searches:
 name:'View the detection results for - "$dest$"'
 search:'%original_detection_search% | search dest = "$dest$"'
 earliest_offset:'$info_min_time$'
 latest_offset:'$info_max_time$'
 name:'View risk events for the last 7 days for - "$dest$"'
 search:'| from datamodel Risk.All_Risk | search normalized_risk_object IN ("$dest$") | stats count min(_time) as firstTime max(_time) as lastTime values(search_name) as "Search Name" values(risk_message) as "Risk Message" values(analyticstories) as "Analytic Stories" values(annotations._all) as "Annotations" values(annotations.mitre_attack.mitre_tactic) as "ATT&CK Tactics" by normalized_risk_object | `security_content_ctime(firstTime)` | `security_content_ctime(lastTime)`'
 earliest_offset:'7d'
 latest_offset:'0'
analytic_story:['Linux Privilege Escalation', 'SSHHole']

asset_type:Endpoint

mitre_attack_id:['T1078.003', 'T1021.004']

product:['Splunk Enterprise', 'Splunk Enterprise Security', 'Splunk Cloud']

category:endpoint

security_domain:endpoint

tags:

tests:
 name:'True Positive Test'
 attack_data:
  data: https://media.githubusercontent.com/media/splunk/attack_data/master/datasets/emerging_threats/sshhole/syslog.log
  source: /var/log/messages
  sourcetype: linux_messages_syslog
 test_type:'unit'
manual_test:None