7

CAT文件数字签名使用技巧

 3 years ago
source link: https://3gstudent.github.io/3gstudent.github.io/CAT%E6%96%87%E4%BB%B6%E6%95%B0%E5%AD%97%E7%AD%BE%E5%90%8D%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

0x00 前言


Windows系统中的重要文件常常会被添加数字签名,用来防止被篡改,部分白名单规则的判定也会基于数字签名。

本文作为数字签名研究系列文章的基础内容,介绍两种数字签名的添加方法,分析CAT文件数字签名的特点,并且纠正一名读者对我文章的回复,地址如下:

《利用xwizard.exe加载dll》

基于我的测试,个人认为:移动位置后,CAT文件数字签名不会失效

0x01 简介


本文将要介绍以下内容:

  • 生成证书的方法
  • 将数字签名添加在文件末尾的方法(Authenticode)
  • 将数字签名保存在CAT文件中的方法(catalog)
  • 使用CAT数字签名的文件特点

0x02 将数字签名添加在文件末尾的方法(Authenticode)


曾在隐写技巧的系列文章中研究过在数字签名中隐藏payload的方法,地址如下:

《隐写技巧——在PE文件的数字证书中隐藏Payload》

文中介绍过证书格式,在此不再赘述

向文件尾部添加数字签名后,可通过文件属性查看

C:\Windows\System32\consent.exe

自带微软数字签名,如下图

Alt text

可通过powershell验证数字签名:

Get-AuthenticodeSignature .\mimikatz.exe

也可以使用工具通过命令行查看数字签名

使用signtool.exe查看:

signtool.exe verify /v C:\Windows\System32\consent.exe
Alt text

使用sigcheck.exe查看:

sigcheck.exe -q C:\Windows\System32\consent.exe /accepteula
Alt text

注:

signtool.exe:

可用于查看文件的数字签名

安装Visual Studio后包含SDK,其中可找到signtool.exe,位于C:\Program Files\Microsoft SDKs\Windows\

进入开发人员工具的cmd可直接调用signtool.exe

Windows 7 SDK下载地址:

https://www.microsoft.com/en-us/download/details.aspx?id=8279

sigcheck.exe:

可用于查看文件的数字签名

下载地址:

https://docs.microsoft.com/zh-cn/sysinternals/downloads/sigcheck

本文相关文件已上传至github,地址如下:

https://github.com/3gstudent/signtools

生成测试证书的命令如下:

makecert -n "CN=Microsoft Windows Test" -r -sv Root.pvk Root.cer
cert2spc Root.cer Root.spc
pvk2pfx -pvk Root.pvk -pi 123456 -spc Root.spc -pfx Root.pfx -f

证书注册:

(管理员权限)

certmgr.exe -add -c Root.cer -s -r localmachine root

注:

细节可参考之前的文章《A dirty way of tricking users to bypass UAC》

签名mimikatz.exe:

signtool sign /f Root.pfx /p 123456 mimikatz.exe

显示数字签名正常,如下图

Alt text

0x03 将数字签名保存在CAT文件中的方法(catalog)


Windows系统中,有些文件通过文件属性无法获得其数字签名信息,但是这些文件也包含数字签名,这里的数字签名指的就是CAT(安全编录)文件数字签名(catalog signing)

资料可参考:

https://docs.microsoft.com/en-us/windows-hardware/drivers/install/catalog-files

签名流程的直观理解:

  • 将文件作sha1加密后得到的hash值保存在CAT文件中(一个CAT文件可保存多个文件hash)
  • 对该CAT文件添加数字签名
  • 将CAT文件添加到系统的安全编录数据库
  • 这些文件也就有了数字签名

C:\Windows\System32\catroot\{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\ntph.cat

属性-安全目录-项目详细信息-File,可以找到Hash值对应的文件

Alt text

通过文件属性无法查看CAT数字签名

.cat文件保存格式为ASN.1标准,直接通过记事本无法查看,需要解密,在线网址如下:

https://lapo.it/asn1js/

选择cat文件后即可解密显示完整格式

格式解析可参考:

https://support.microsoft.com/en-us/help/287547/object-ids-associated-with-microsoft-cryptography

C:\Windows\System32\xwizard.exe

自带CAT格式的数字签名,通过文件属性无法查看CAT数字签名

使用powershell无法获得CAT文件数字签名:

Get-AuthenticodeSignature C:\Windows\System32\xwizard.exe
Alt text

Win10系统能够获取CAT文件数字签名,Win7不可以

但可以使用signtool.exe和sigcheck.exe查看数字签名

使用signtool.exe查看:

signtool.exe verify /pa /a /v C:\Windows\System32\xwizard.exe
Alt text

使用sigcheck.exe查看:

sigcheck.exe -q C:\Windows\System32\xwizard.exe /accepteula
Alt text

下面介绍如何使用CAT文件数字签名

1、生成CAT文件

新建文本文档cat.txt,内容如下:

[CatalogHeader]
Name=makecat1.cat
[CatalogFiles]
<hash>ExeFile1=mimikatz.exe

注:

txt文件尾部需要一个空行,否则,在接下来的操作会报错,提示文件无法找到

Alt text

使用makecat.exe生成cat文件:

makecat -v cat.txt

2、使用证书为CAT文件添加签名

signtool sign /f Root.pfx /p 123456 makecat1.cat

注:

这里的证书使用的是0x02中生成的证书Root.pfx

3、将cat文件添加到系统的安全编录数据库

(管理员权限)

signtool catdb -v makecat1.cat

注:

删除使用 -r参数:signtool catdb -r makecat1.cat

如果未添加到系统的安全编录数据库,签名状态为unsigned,如下图

Alt text

添加到系统的安全编录数据库相当于在目录C:\Windows\System32\catroot\{F750E6C3-38EE-11D1-85E5-00C04FC295EE}添加文件makecat1.cat

删除等价于删除目录C:\Windows\System32\catroot\{F750E6C3-38EE-11D1-85E5-00C04FC295EE}下对应的CAT文件makecat1.cat

使用signtool.exe获取数字签名:

signtool.exe verify /pa /a mimikatz.exe

使用sigcheck.exe获取数字签名:

sigcheck.exe -q mimikatz.exe /accepteula

移动位置后,签名仍然有效

Alt text

验证结论:移动位置后,CAT文件数字签名不会失效

当然,利用带有CAT文件数字签名的xwizard.exe加载dll,在某种程度上说,能够绕过应用程序白名单的拦截。

0x04 小结


本文介绍了两种数字签名的添加方法,分析CAT文件数字签名的特点,对于可执行文件,通过Process Explorer可验证两种不同的数字签名

Alt text

LEAVE A REPLY


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK