用过期证书对PE签名

admin 2022年7月21日18:50:53评论100 views字数 4176阅读13分55秒阅读模式

网上有人会提供一些过期证书,若这些证书未被颁发机构吊销,只是过期,可以回调系统时间到证书有效期范围,然后用这种证书对PE签名,在回调的时间节点进行某些测试动作。

参[7],看雪上有人提供了几个过期证书。我只测了其中的cs20160224_w.pfx,该证书已被证书颁发机构吊销,其他几个未测试。

云海给我一个过期证书,假设名为some.pfx。下面说说如何回调系统时间后对PE签名。我不搞黑产、不玩驱动,所以这块完全没有研究过,临时折腾两下,描述可能有错漏,请指正。

首先要解决一个问题,回调到哪个时间节点?假设已有pfx文件,如何知道其有效期?若pfx文件无密码保护,直接右键,选"打开",即可查看,不要双击。但我拿到手的pfx文件都有密码保护,此时没有缺省的GUI查看手段,只能命令行可看。

certutil.exe -p <pass> -dump <.pfx>
certutil.exe -v -p <pass> -dump <.pfx>

openssl pkcs12 -info -password pass:<pass> -in <.pfx>
openssl pkcs12 -info -password pass:<pass> -in <.pfx> | openssl x509 -text -noout

推荐用certutil查看pfx文件,而不是openssl。假设下面是certutil查看some.pfx时的输出

================ Certificate 0 ================
================ Begin Nesting Level 1 ================
Element 0:
...
 NotBefore: 2011/9/2 8:00
 NotAfter: 2014/9/2 7:59
Subject: CN=NVIDIA Corporation
...
----------------  End Nesting Level 1  ----------------
...
================ Certificate 1 ================
================ Begin Nesting Level 1 ================
Element 1:
...
 NotBefore: 2010/2/8 8:00
 NotAfter: 2020/2/8 7:59
Subject: CN=VeriSign Class 3 Code Signing 2010 CA
...
----------------  End Nesting Level 1  ----------------
...
================ Certificate 2 ================
================ Begin Nesting Level 1 ================
Element 2:
...
 NotBefore: 2006/11/8 8:00
 NotAfter: 2021/11/8 7:59
Subject: CN=VeriSign Class 3 Public Primary Certification Authority - G5
...
----------------  End Nesting Level 1  ----------------

要将系统时间回调到"Element 0"的[NotBefore,NotAfter]区间,不要管"Element 1"、"Element 2",后两者范围只会比前者大。

假设系统时间已经回调至合适的节点,手头有some.pfx和待签名的any.dll,可以用signtool.exe进行签名操作,参[8],我用VS 2019/Win10 SDK中的signtool。

signtool.exe sign /a /f some.pfx /p <pass> any.dll

若系统时间不满足要求,签名时会报错

SignTool Error: No certificates were found that met all the given criteria.

假设已用some.pfx对any.dll签名过,可以GUI查看签名信息。

右键打开any.dll的Properties
  Digital Signatures
    Signature list

此处一般有三列,Name of signer、Digest Algorithm、Timestamp。正常签名的第三列Timestamp有值,即签名时间。用过期证书签名时,因为不敢联网校验时间,最终Timestamp为空。

在Signature list中选中签名,查看详情。

Details
  General
    Digital Signature Information
      This digital signature is OK (其他信息均表示签名无效)
    Signer information
      Signing time
        Not available (正常签名此处有值,未联网校验时间时此处为空)
    Countersignatures
      空 (正常签名此处有值,未联网校验时间时此处为空)
    View Certificate
      General
        Valid from 9/2/2011 to 9/2/2014 (Element 0)
      Certification Path (一般有个三级的树)
        VeriSign (Element 2)
          VeriSign Class 3 Code Signing 2010 CA (Element 1)
            NVIDIA Corporation (Element 0)
              Certificate status
                This certificate is OK (其他信息均表示证书无效)

Certification Path一般有个三级的树,为叙述方便,本文约定,从上至下分别为一级、二级、三级。分别选中每一级,可以View Certificate查看该级证书细节。三级证书的View Certificate是灰的,因为General中已经显示过了。分别选中每一级证书,还可以查看Certificate status,看到"This certificate is OK"就行,其他信息均表示证书无效。这三级证书的状态并不同步,各是各的,很可能一级证书有效,二级、三级证书均已过期失效。

针对过期证书回调系统时间,必须盯住三级证书,也就是certutil输出中的"Element 0",盯住它的[NotBefore,NotAfter],回调系统时间使之落在前述区间。

若some.pfx未过期,正常签名操作类似这种

signtool.exe sign /a /f some.pfx /p <pass> /t http://timestamp.digicert.com any.dll

/t参数就是联网校验时间用的,将来any.dll有签名时间,Countersignatures不为空。

但手头的some.pfx已过期,本机可以回调系统时间,时间戳服务器仍然是现实时间,对any.dll签名时不敢指定/t参数,导致将来any.dll没有签名时间,Countersignatures为空。

假设已用过期的some.pfx对any.dll签名过,恢复正常系统时间,在2022年检查any.dll,不再显示"This digital signature is OK",而是"A required certificate is not within its validity period when verifying against the current system clock or the timestamp in the signed file"。2022年的any.dll签名无效,因为2022年二级证书、三级证书均过期了,各自的Certificate status均为"This certificate has expired or is not yet valid"。

注意,若一级证书、二级证书未过期,只是三级证书过期,三级证书的Certificate status仍有可能是"This certificate is OK",三级证书仍可能被判定有效,PE签名仍可能被判定有效。

看sysinternals的livekd64.exe,签名时间是2020.4.27,一级证书、二级证书未过期,三级证书有效期是2020.3.5-2021.3.4,已过期,但三级证书的Certificate status仍显示"This certificate is OK",同时仍显示"This digital signature is OK"。没研究过其中的逻辑,猜测因为签名时间落在三级证书有效期内,尽管2022年三级证书过期了,仍判定证书有效,进而判定签名有效。

但是,对any.dll签名时没法指定/t参数,any.dll没有签名时间,在2022年检查any.dll,三级证书过期就算无效,进而判定签名无效。可以回调至2014.7.16检查any.dll,此时判定其签名有效。

假设在某个时间节点判定any.dll签名有效,即使其没有签名时间,可以在该时间节点用any.dll进行某些测试动作。本节用DLL举例,SYS类似。

[7] 送几个过期的数字签名给大家调试驱动用 - 醉後的温柔 [2022-05-01]
    https://bbs.pediy.com/thread-272573.htm

[8] Using SignTool to Sign a File
    https://docs.microsoft.com/en-us/windows/win32/seccrypto/using-signtool-to-sign-a-file


原文始发于微信公众号(青衣十三楼飞花堂):用过期证书对PE签名

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年7月21日18:50:53
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   用过期证书对PE签名http://cn-sec.com/archives/1190656.html

发表评论

匿名网友 填写信息