cert_util.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码
def remove_windows_ca(name):
        import ctypes
        import ctypes.wintypes
        class CERT_CONTEXT(ctypes.Structure):
            _fields_ = [
                ('dwCertEncodingType', ctypes.wintypes.DWORD),
                ('pbCertEncoded', ctypes.POINTER(ctypes.wintypes.BYTE)),
                ('cbCertEncoded', ctypes.wintypes.DWORD),
                ('pCertInfo', ctypes.c_void_p),
                ('hCertStore', ctypes.c_void_p),]
        try:
            crypt32 = ctypes.WinDLL(b'crypt32.dll'.decode())
            store_handle = crypt32.CertOpenStore(10, 0, 0, 0x4000 | 0x20000, b'ROOT'.decode())
            pCertCtx = crypt32.CertEnumCertificatesInStore(store_handle, None)
            while pCertCtx:
                certCtx = CERT_CONTEXT.from_address(pCertCtx)
                certdata = ctypes.string_at(certCtx.pbCertEncoded, certCtx.cbCertEncoded)
                cert =  OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, certdata)
                if hasattr(cert, 'get_subject'):
                    cert = cert.get_subject()
                cert_name = next((v for k, v in cert.get_components() if k == 'CN'), '')
                if cert_name and name == cert_name:
                    crypt32.CertDeleteCertificateFromStore(crypt32.CertDuplicateCertificateContext(pCertCtx))
                pCertCtx = crypt32.CertEnumCertificatesInStore(store_handle, pCertCtx)
        except Exception as e:
            logging.warning('CertUtil.remove_windows_ca failed: %r', e)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号