CVE-2023-2825: A Path Traversal Vulnerability in GitLab

A vulnerability has been discovered in GitLab that could allow an attacker to read arbitrary files on the server. The vulnerability, which has been assigned the CVE identifier CVE-2023-2825, affects GitLab Community and Enterprise Edition version 16.0.0.

Technical Details

The vulnerability is caused by a flaw in the way that GitLab handles the raw_url attribute of attachments. The raw_url attribute is a URL that can be used to access the attachment's raw contents.

When an attachment is uploaded to a public project nested within at least five groups, the raw_url attribute of the attachment is generated by concatenating the following components:

  • The base URL of the GitLab instance

  • The path to the attachment

  • The .raw suffix

The .raw suffix is not necessary for the vulnerability to be exploited. However, it was included in the original CVE identifier, which is why some people still refer to it as CVE-2023-2825.raw

The vulnerability occurs because the path to the attachment is not properly sanitized. This means that an attacker can manipulate the path to the attachment to access arbitrary files on the server.

For example, an attacker could upload an attachment with the filename ..%2Fetc%2Fpasswd. The raw_url for this attachment would be:

https://gitlab.example.com/api/v4/projects/my-project/attachments/..%2Fetc%2Fpasswd.raw

This URL can be used to access the etc/passwd file on the server.

The vulnerability is a path traversal vulnerability because it allows an attacker to traverse the file system by manipulating the path to the attachment.

Explanation of PoC

The GitHub repository for CVE-2023-2825 also includes a proof-of-concept exploit that can be used to exploit the vulnerability. The exploit is a simple Python script that can be used to upload an attachment with a malicious filename and then access the arbitrary file on the server.

Here's an explanation of the script's main components and flow:

  1. The script starts by importing necessary modules, including requests for making HTTP requests, random and string for generating random strings, urlparse for parsing URLs, and BeautifulSoup for parsing HTML.

  2. The ENDPOINT, USERNAME, and PASSWORD variables are defined to specify the GitLab instance URL, login credentials, and the target file to read.

  3. A session is created using requests.Session() to maintain cookies and session information.

  4. The csrf_token variable is used to store the Cross-Site Request Forgery (CSRF) token.

  5. The request function is defined to handle different types of HTTP requests, including handling CSRF tokens.

  6. The script retrieves the initial CSRF token by sending a GET request to the GitLab endpoint.

  7. The login process begins by sending a POST request to the /users/sign_in endpoint with the provided username and password.

  8. Once the login is successful, the script proceeds to create 11 groups with a generated prefix.

  9. For each group, a POST request is sent to the /groups endpoint with the necessary data to create the group.

  10. The response is parsed to extract the group ID, which is used as the parent ID for the next group.

  11. The script then creates a project by sending a POST request to the /projects endpoint with the required project data.

  12. The response URL is parsed to extract the repository path of the created project.

  13. An upload request is made to the /uploads endpoint of the project, simulating the file upload process.

  14. The uploaded file URL is extracted from the response and stored.

  15. Finally, an exploit path is constructed to perform a path traversal attack and fetch the /etc/passwd file from the GitLab instance. The exploit is executed by sending a GET request to the constructed path.

  16. The response containing the content of the /etc/passwd file is printed.

Mitigation

The vulnerability has been patched in GitLab 16.0.1. Users of GitLab 16.0.0 are advised to update to the latest version to protect themselves from this vulnerability.

In the meantime, there are a few things that you can do to mitigate the risk of this vulnerability:

  • Do not upload attachments to public projects nested within at least five groups.

  • If you must upload attachments to public projects nested within at least five groups, make sure that the attachments have filenames that do not contain malicious characters.

  • Use a web application firewall (WAF) to block malicious requests.

Conclusion

CVE-2023-2825 is a serious vulnerability that could allow an attacker to read arbitrary files on the server. By following the steps above, you can help to mitigate the risk of this vulnerability.

References

CVE-2021-3129 Proof of Concept: In-Depth Exploration of the Laravel Ignition RCE Vulnerability
CVE-2021-3129 Proof of Concept: In-Depth Exploration of the Laravel Ignition RCE Vulnerability
2024-02-14
James McGill
Cracking Containers: Understanding CVE-2024-21626 in runc
Cracking Containers: Understanding CVE-2024-21626 in runc
2024-02-18
James McGill
Unraveling Arbitrary Code Execution in Apache Commons Text (CVE-2022-42889) with PoC
Unraveling Arbitrary Code Execution in Apache Commons Text (CVE-2022-42889) with PoC
2024-01-13
James McGill
CVE-2023-32315: Understanding the Openfire Admin Console Path Traversal Vulnerability
CVE-2023-32315: Understanding the Openfire Admin Console Path Traversal Vulnerability
2024-02-07
James McGill
CVE-2024-23897: A Critical RCE Vulnerability in Jenkins
CVE-2024-23897: A Critical RCE Vulnerability in Jenkins
2024-01-29
James McGill
Demystifying CVE-2021-4034: Unpacking the Polkit pkexec RCE Vulnerability
Demystifying CVE-2021-4034: Unpacking the Polkit pkexec RCE Vulnerability
2024-01-21
James McGill