DoS - Debian Packages - dpkg-deb leaves temporary files (feature flag)
The Debian Packages API uses dpkg-deb to extract package metadata, but if the package contains a non-writable directory, dpkg-deb cannot delete the extracted files, leaving them in /tmp. An attacker could upload a large package to gradually exhaust disk space, causing a denial of service.
GitLab
Originally disclosed on GitLab
- Fixed in 2.2 years
- Disclosed after 2.2 years
⚠️ Please read the process on how to fix security issues before starting to work on the issue. Vulnerabilities must be fixed in a security mirror.
HackerOne report #1970716 by zhutyra on 2023-05-03, assigned to @nmalcolm:
Report | Attachments | How To Reproduce
Report
The vulnerability is in the Debian Packages API which is gated behind a feature flag that's disabled by default.
When uploading a Debian package, information about this package is obtained using the dpkg-deb --field command.
A Debian package is an ar archive containing two tar archives. dpkg-deb must unpack these archives to get the required information.
If the archive contains a non-writable directory, then dpkg-deb cannot delete the extracted files at the end.
This can gradually exhaust the free disk space. Attached is a package containing two 5GB files.
Possible workaround
dpkg-deb extracts the data to the directory specified in the TMPDIR environment variable, so you can set it yourself and then delete the directory afterwards.
Steps to reproduce
Quick test
- Download the attached package dangling.deb
- Run the following command (on Debian system):
Bash dpkg-deb --field dangling.deb ## output: ## dpkg-deb: 'dangling.deb' contains no control component 'control' ## dpkg-deb: error: 1 requested control component is missing ## rm: cannot remove '/tmp/dpkg-deb.1wy1zI/dir/file1': Permission denied ## rm: cannot remove '/tmp/dpkg-deb.1wy1zI/dir/file2': Permission denied ## dpkg-deb: error while cleaning up: ## rm command for cleanup subprocess returned error exit status 1
Full test on your GitLab instance
-
Enable
Debian Packagesin your GitLab instance (Debian Linux)- On the server run
gitlab-rails consoleand enter following commands:Ruby Feature.enable(:debian_packages) Feature.enable(:debian_group_packages) # i'm not sure if this one is needed
- On the server run
-
Log in to your GitLab instance and go to any project page:
- Save the
Project IDnumber for later use
- Save the
-
Generate your personal token:
- In the upper-right corner, select your avatar.
- Select Edit profile.
- On the left sidebar, select Access Tokens.
- Enter a name and optional expiry date for the token.
- Select the desired scopes.
read_repositoryandwrite_repository- or just all :)
- Select Create personal access token.
- Save the token for later use
-
Download the attached package dangling.deb
-
In the directory with the package, run the following commands in a bash shell (change the marked values):
Bash GLHOST=http://yourinstance.com # change GLUSER=username # change GLPTOKEN=personal-token # change GLPROJID=project-id # change GLDISTRO=dist01 GLDEB=dangling.deb curl --request POST \ --header "PRIVATE-TOKEN: $GLPTOKEN" \ "$GLHOST/api/v4/projects/$GLPROJID/debian_distributions?codename=$GLDISTRO" ## output: {"id":...} curl --request PUT \ --user "$GLUSER:$GLPTOKEN" \ --upload-file $GLDEB \ "$GLHOST/api/v4/projects/$GLPROJID/packages/debian/$GLDEB?component=main&distribution=$GLDISTRO" ## output: {"message":"201 Created"} -
On the server check the
/tmp/dpkg-deb...directory- Extrated files should still be there (two 5GB files)
-
Wait
-
Visit
yourgitlabserver.comand see a500error
Impact
Denial of service due to running out of disk/temp space.
Attachments
Warning: Attachments received through HackerOne, please exercise caution!
How To Reproduce
Please add reproducibility information to this section:
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, dpkg-deb fails to clean up extracted files when the package contains a non-writable directory, leaving them in the temporary directory.
Impact
An attacker could cause a denial of service by exhausting disk space, but the vulnerable feature is behind a feature flag that is disabled by default.
What the attacker needed
Debian Packages feature flag enabled; Valid personal access token with write scope; Ability to upload a Debian package
How it was found
- Enable the Debian Packages feature flag on the GitLab instance.
- Log in and obtain a personal access token with repository write scope.
- Create a Debian distribution using the API.
- Upload the crafted Debian package to the Debian package endpoint.
- Check that the extracted files remain in /tmp/dpkg-deb...
- Wait until the disk fills and the GitLab instance returns a 500 error.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you upload a Debian package, the system uses a tool called dpkg-deb to read information from it. This tool unpacks the package into a temporary folder and then tries to delete the files. If the package contains a folder that cannot be written to, the deletion fails and the files stay on disk. By uploading a very large package, an attacker can fill up the disk and make the service unavailable.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.