Back to Intelligence

Linux PAM Abuse: Detecting XMRig Cryptominers Hiding as Low-Privilege Users

SA
Security Arsenal Team
July 31, 2026
6 min read

Security Operations Centers (SOCs) have long relied on a simple heuristic: if a resource-intensive process like a cryptominer runs, it usually requires root privileges to install and persist. Consequently, many alerting rules are tuned to flag high CPU usage or suspicious binaries running with UID 0. Attackers know this.

Recent intelligence indicates that cryptomining crews—specifically those deploying XMRig—are evolving their tactics. Instead of maintaining root access, they are actively abusing Pluggable Authentication Modules (PAM) to drop privileges and impersonate low-privileged users (e.g., www-data, nobody, or standard user accounts). This technique allows them to blend into normal operational noise, effectively hiding in plain sight while consuming system resources. This post breaks down the mechanics of this evasion and provides the detection logic necessary to catch it.

Technical Analysis

The Threat: Operators are leveraging the Linux PAM subsystem to achieve persistence and execution without maintaining a root shell. By injecting commands or binaries into PAM configuration files (typically located in /etc/pam.d/), attackers ensure their payload is executed every time a user authenticates or a service restarts.

The Mechanics:

  1. Initial Compromise: Attackers gain initial access (often via unpatched services or credential theft) and obtain root temporarily.
  2. PAM Modification: Instead of deploying a systemd service or cron job—common IOC sources—they modify PAM configuration files (e.g., /etc/pam.d/common-auth or /etc/pam.d/sshd). They may use the pam_exec.so module to spawn a malicious shell script or binary.
  3. Privilege Dropping: The payload (XMRig) is executed specifically to run as a non-root user. This is often achieved by the malicious script switching users via su or simply inheriting the context of the authenticated user triggering the PAM module.
  4. Evasion: Because XMRig runs as a standard user, it bypasses SOC rules configured to alert on "Root Process CPU Anomalies" or "SUID Binary Modifications." Furthermore, the network traffic looks like standard user activity rather than system-daemon traffic.

Affected Products & Platforms:

  • Platform: Linux distributions utilizing PAM (Ubuntu, Debian, CentOS, RHEL, etc.).
  • Malware: XMRig (Monero cryptominer).
  • Exploitation Status: Confirmed active exploitation in the wild.

Detection & Response

Sigma Rules

YAML
---
title: Linux PAM Configuration Modification
id: 8a4d2c91-5f6e-4b8a-9c1d-2e3f4a5b6c7d
status: experimental
description: Detects modifications to PAM configuration directories which may indicate persistence mechanism abuse.
references:
 - https://attack.mitre.org/techniques/T1543/003/
author: Security Arsenal
date: 2026/04/06
tags:
 - attack.persistence
 - attack.t1543.003
logsource:
  category: file_change
  product: linux
detection:
  selection:
    TargetFilename|contains: '/etc/pam.d/'
  condition: selection
falsepositives:
  - Legitimate administrative changes to authentication policies
level: high
---
title: XMRig Execution as Non-Root User
id: 9b5e3d02-6g7f-5c9b-0d2e-3f4g5a6b7c8e
status: experimental
description: Detects execution of XMRig or common miner names by non-root users, indicating evasion techniques.
references:
 - https://attack.mitre.org/techniques/T1059/004/
author: Security Arsenal
date: 2026/04/06
tags:
 - attack.execution
 - attack.t1059.004
logsource:
  category: process_creation
  product: linux
detection:
  selection:
    Image|endswith:
      - '/xmrig'
      - '/miner'
    User|contains:
      - 'www-data'
      - 'nobody'
      - 'ubuntu'
      - 'daemon'
  filter:
    User|contains: 'root'
  condition: selection and not filter
falsepositives:
  - Authorized benchmarking by developers
level: high
---
title: Suspicious Outbound Connection to Mining Pool
id: 0c6f4e13-7h8g-6d0c-1e3f-4g5h6a7b8c9d
status: experimental
description: Detects network connections to known mining ports (commonly 3333, 14444, 8080) initiated by non-system binaries.
references:
 - https://attack.mitre.org/techniques/T1071/001/
author: Security Arsenal
date: 2026/04/06
tags:
 - attack.command_and_control
 - attack.t1071.001
logsource:
  category: network_connection
  product: linux
detection:
  selection_ports:
    DestinationPort:
      - 3333
      - 14444
      - 8080
      - 3357
  selection_process:
    Image|notcontains:
      - '/usr/bin'
      - '/usr/sbin'
      - '/bin'
  condition: all of selection_*
falsepositives:
  - Legitimate traffic to services running on non-standard ports
level: medium

KQL (Microsoft Sentinel / Defender)

KQL — Microsoft Sentinel / Defender
// Hunt for XMRig processes running under non-root accounts
DeviceProcessEvents
| where Timestamp > ago(7d)
| where ProcessName has "xmrig" or FileName has "xmrig"
| where AccountName != "root" and AccountName !contains "SYSTEM"
| project Timestamp, DeviceName, AccountName, ProcessCommandLine, InitiatingProcessFileName
| order by Timestamp desc

// Hunt for file modifications in /etc/pam.d/
DeviceFileEvents
| where Timestamp > ago(7d)
| where FolderPath startswith @"/etc/pam.d/"
| project Timestamp, DeviceName, ActionType, FileName, InitiatingProcessAccountName, InitiatingProcessCommandLine
| where ActionType in ("FileModified", "FileCreated")

Velociraptor VQL

VQL — Velociraptor
-- Hunt for XMRig execution artifacts and PAM tampering
SELECT 
  Pid, 
  Name, 
  Username, 
  CommandLine, 
  Exe
FROM pslist()
WHERE Name =~ 'xmrig'
   OR CommandLine =~ 'stratum+tcp'

-- Check for recent modifications to PAM configuration files
SELECT 
  FullPath, 
  Mtime, 
  Size, 
  Mode
FROM glob(globs="/etc/pam.d/*")
WHERE Mtime > now() - 7 * 86400  

-- Hunt for network connections associated with mining pools
SELECT 
  Family, 
  RemoteAddr, 
  RemotePort, 
  Pid, 
  Username
FROM netstat()
WHERE RemotePort IN (3333, 14444, 3357, 8080)
   AND Username != "root"

Remediation Script (Bash)

Bash / Shell
#!/bin/bash
# Remediation script for PAM abuse and Cryptomining removal
# Must be run as root

LOG_FILE="/var/log/pam_remediation.log"
echo "Starting PAM and Cryptominer remediation: $(date)" > $LOG_FILE

# 1. Identify and kill XMRig processes running under non-root users
echo "[+] Hunting for XMRig processes..." | tee -a $LOG_FILE
PIDS=$(pgrep -f xmrig)
if [ -n "$PIDS" ]; then
  echo "[!] Found XMRig PIDs: $PIDS" | tee -a $LOG_FILE
  for PID in $PIDS; do
    # Verify user is not root before killing (safety check)
    USER=$(ps -o user= -p $PID)
    if [ "$USER" != "root" ]; then
      echo "[+] Killing process $PID running as $USER" | tee -a $LOG_FILE
      kill -9 $PID
    fi
  done
else
  echo "[-] No XMRig processes found." | tee -a $LOG_FILE
fi

# 2. Locate and remove known malicious binaries
# Common locations where users might have write access or temp dirs
echo "[+] Scanning for malicious binaries..." | tee -a $LOG_FILE
find /tmp /var/tmp /dev/shm -name "xmrig" -exec rm -f {} \; 2>/dev/null

# 3. Audit PAM configurations for pam_exec abuse
echo "[+] Auditing /etc/pam.d/ for suspicious entries..." | tee -a $LOG_FILE
# Look for 'pam_exec.so' which is often used to launch scripts
if grep -r "pam_exec.so" /etc/pam.d/ | grep -v "^#" > /tmp/pam_audit.txt; then
  echo "[!] Potential pam_exec entries found. Review /tmp/pam_audit.txt manually." | tee -a $LOG_FILE
  # Automated restoration of backups is risky, alerting admin is preferred.
else
  echo "[-] No obvious pam_exec abuse detected." | tee -a $LOG_FILE
fi

echo "Remediation complete. Please review /var/log/pam_remediation.log and /tmp/pam_audit.txt."

Remediation

Immediate Actions:

  1. Isolate Hosts: If active mining is detected, isolate the affected Linux host from the network to prevent credential dumping or lateral movement, even if the miner itself appears "non-destructive."
  2. Process Termination: Use the provided Bash script or manually kill xmrig processes. Pay close attention to the parent process—identifying how the miner started (e.g., via SSH session or cron) is crucial for ensuring it doesn't restart.

Hardening & Prevention:

  1. Lock Down PAM Permissions: Ensure that /etc/pam.d/ and its contents are owned by root and are not writable by non-privileged users. bash chown root:root /etc/pam.d/* chmod 644 /etc/pam.d/*

  2. Implement File Integrity Monitoring (FIM): Enable FIM on /etc/pam.d/ and /etc/passwd. Any modification to these files outside of a documented change window should trigger a critical alert.

  3. User Behavior Analytics: Tune UEBA or CPU monitoring alerts to look for percentage usage spikes from any user, not just root. A single www-data user consuming 90% of a CPU core is just as abnormal as root doing so.

  4. Audit Logs: Ensure Linux auditing (auditd) is enabled and watching for writes to system configuration files.

Related Resources

Security Arsenal Managed SOC Services AlertMonitor Platform Book a SOC Assessment soc-mdr Intel Hub

Is your security operations ready?

Get a free SOC assessment or see how AlertMonitor cuts through alert noise with automated triage.