Vulnerabilities in Pagure and OBS allowed for the compromise of packages in Fedora and openSUSE repositories

Security researchers from Fenrisk revealed vulnerabilities in the Pagure and OBS (Open Build Service) tools that could compromise the package building infrastructures of Fedora and openSUSE. The researchers demonstrated the possibility of executing an attack to run arbitrary code on servers using Pagure and OBS, which could be exploited to modify packages in the Fedora and openSUSE repositories.

The Pagure platform, used in Fedora for collaborative work with code and package metadata, has revealed 4 vulnerabilities. Exploiting these issues requires a Pagure account, which anyone can obtain (currently, there are 24,899 registered users on Pagure.io). Three of the issues allow reading files on the system, while one problem allows executing custom code on serwerze. The issues were identified on January 1, 2024, reported through bugzilla.redhat.com on April 25, 2024, and fixed in Pagure within 3 hours.

  • The vulnerabilities CVE-2024-4981 and CVE-2024-47515 are caused by improper handling of symbolic links in the file update and archive generation functions. These vulnerabilities allow reading the contents of local files on the server; for example, it is possible to access the contents of the file with Pagure administrator session parameters and gain access with their permissions. Exploiting the vulnerability in the _update_file_in_git() function involves creating a repository in Pagure; adding a commit with a new file made as a symbolic link to the desired system file; and opening this file for editing in the web interface.
  • The vulnerability (CVE-2024-4982) in the view_issue_raw_file() function allows escaping the base directory by specifying the characters "\/.." in the parameters of the requested Issue. This problem allows reading files on the system, depending on the access rights of the process under which the web interface runs. For example, to view the file \/etc\/passwd, one can access the page "http:\/\/pagure.local:5000\/your-repository\/issue\/raw\/.\.\/.\.\/.\.\/.\.\/.\/etc\/passwd".
  • Zagrożenie (CVE-2024-47516) w funkcji PagureRepo.log() umożliwia wstrzykiwanie własnych poleceń i wykonywanie kodu na serwerze. Problem polega na tym, że podczas przeglądania historii zmian pliku za pośrednictwem interfejsu webowego wywoływana jest komenda „git” z przekazanym identyfikatorem gałęzi w wierszu poleceń (np. „/usr/bin/git --pretty=oneline --abbrev-commit -- README.md”). Poprawność identyfikatora nie jest weryfikowana, dlatego można wprowadzić dowolną opcję wiersza poleceń, na przykład „--output=/tmp/foo.bar” do przekierowania wyjścia do pliku. Napastnik może nadpisać plik w systemie, wysyłając zapytanie w następującej postaci: http://pagure.local:5000/test/history/README.md?identifier=--output=/tmp/foo.bar

    Pagure działa z prawami użytkownika git, dlatego można nadpisać jedynie pliki tego użytkownika. Aby zrealizować swoje polecenia na serwerze, można skorzystać z usługi dostępu do repozytorium przez SSH, co skutkuje wykonaniem komendy „bash -c /usr/libexec/pagure/aclchecker.py”. Napastnik może wykorzystać tę lukę do nadpisania pliku „/srv/git/.bashrc”, który zostanie uruchomiony przez interpreter poleceń bash przy dostępie do repozytorium przez ssh.

    Atak polega na rejestracji w systemie Pagure, utworzeniu repozytorium, dodaniu do repozytorium pliku README.md z notatką do commit o treści „|| /bin/bash” oraz wysłaniu zapytania „http://pagure.local:5000/test/history/README.md?identifier=--output=/srv/git/.bashrc”. W tym procesie do pliku „/srv/git/.bashrc” zostanie zapisana linia o treści „34a5s43 || /bin/bash”. Aby uruchomić utworzony plik „/srv/git/.bashrc”, wystarczy połączyć się z repozytorium przez SSH, używając swojego konta. Wykonanie kodu z uprawnieniami użytkownika git na serwerze Pagure umożliwia kontrolowanie całej zawartości repozytoriów z pakietami.

Na platformie OBS (Open Build Service), używanej w openSUSE i niektórych innych dystrybucjach do budowania pakietów, odkryto jedną lukę (CVE-2024-22033), która umożliwia wykonanie własnego kodu na serwerze. Luka została zgłoszona 27 czerwca 2024 roku, przekazana projektowi openSUSE 29 czerwca, a naprawiona 10 lipca.

Vulnerability exists in the service "obs-service-download_url", where proper URL verification was missing when executing the wget utility from the script used to download the source code in OBS. An attacker can specify in the OBS service the configuration of the package being formed, where instead of the URL for downloading the code, a command-line option for wget can be indicated, for example: --output-document=\/tmp\/test tempfile

To bypass the error return when trying to run wget without a URL, the "download-manifest" option is provided in the example, which allows specifying a list of URLs in a separate file. The above example will lead to the execution of the command: \/usr\/bin\/wget -i \/srv\/obs\/service\/XXXXX\/src\/tempfile -4 --output-document=\/tmp\/test

which allows writing to the file \/tmp\/test the content downloaded from the link specified in the file \/srv\/obs\/service\/XXXXX\/src\/tempfile from the code uploaded by the attacker in OBS through the build.opensuse.org interface, which allows free registration. In addition to overwriting the file on the server, the attacker can also send any file to themselves by indicating the option "--post-file" instead of "--output-document", for example, "--post-file=\/etc\/passwd". Thus, the attacker can read and write files on the server, depending on the access rights under which the OBS service runs.

In order to turn the file writing capability into code execution on the server, researchers proposed a method consisting of two steps. Two steps are necessary, as the attacker can create a ".wgetrc" file with settings for wget, but this is insufficient for running commands. However, through ".wgetrc", conditions can be created for executing any program in the system, but without passing arguments to it. To run arbitrary code, it is proposed to launch the "prove" program, which processes the configuration file ".proverc", allowing the option "--exec" to execute any code.

Na pierwszym etapie, poprzez wymienione wcześniej manipulacje z «download-manifest», w domowym katalogu użytkownika «obsservicerun» tworzony jest plik «.proverc», zawierający komendy, które będą wykonane podczas uruchamiania procesu «prove». Na drugim etapie tworzony jest plik «.wgetrc» z parametrem «use-askpass=\/usr\/bin\/prove», którego efektem jest wywołanie «prove». Po pojawieniu się tych plików wystarczy stworzyć warunki do pobrania jakichkolwiek danych za pomocą wget, co sprowadzi się do uruchomienia kodu atakującego na serwerze z uprawnieniami użytkownika «obsservicerun». Uprawnienia użytkownika «obsservicerun» są wystarczające do wyciągnięcia z repozytoriów kluczy używanych przez użytkowników OBS do weryfikacji pakietów.

Uzupełnienie: Zespół SUSE Product Security uważa, że niebezpieczeństwo związane z luką w OBS jest przewartościowane, a oświadczenie badaczy, że problem ten umożliwia skompromitowanie wszystkich pakietów w dystrybucji openSUSE, jest nieprawdziwe. Zwrócono uwagę, że usługi w infrastrukturze build.opensuse.org uruchamiane są z wykorzystaniem izolowanych kontenerów, które są na nowo tworzone i nie zawierają krytycznych informacji. Zidentyfikowana luka oceniana jest jako niebezpieczna, ale niewystarczająca do kompromitacji infrastruktury budowlanej openSUSE i tworzonych pakietów. Ponadto wskazano, że działania w interfejsie OBS, opisane w przykładzie ataku, mogły być przeprowadzone tylko w lokalnej wersji OBS zainstalowanej na stacji roboczej programisty.

Źródło: opennet.ru

Kup solidny hosting stron z ochroną przed DDoS, serwery VPS VDS 🔥 Kup solidny hosting stron z ochroną przed DDoS, serwery VPS VDS | ProHoster