Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path traversal bug in TarFileReader::extract #115

Closed
eqawasm opened this issue Apr 4, 2023 · 1 comment
Closed

Path traversal bug in TarFileReader::extract #115

eqawasm opened this issue Apr 4, 2023 · 1 comment

Comments

@eqawasm
Copy link

eqawasm commented Apr 4, 2023

Impact: 

The latest version bastet-v8.1.16 has a path traversal vulnerability that allows the attacker to create or write to files outside the current directory due to improper string comparisons between canonical paths.

 
How to reproduce: 

wget https://github.com/CauldronDevelopmentLLC/cbang/archive/refs/tags/bastet-v8.1.16.tar.gz
tar -xzf bastet-v8.1.16.tar.gz
cd cbang-bastet-v8.1.16/tests
scons
cd tarTests
# place poc.tar in this directory
./tar --extract poc.tar
# verify attack worked
cat ../tarTests.d/config

Root cause:

string a = SystemUtilities::getCanonicalPath(_path);
string b = SystemUtilities::getCanonicalPath(path);
if (!String::startsWith(b, a))
THROW("Tar path points outside of the extraction directory: " << path);
}

The root cause is the return true value in function startsWith in String.cpp that passes if condition in function TarFileReader::extract  in TarFileReader.cpp.

PoC image:

Extract poc.zip to obtain poc.tar: poc.zip

@jcoffland
Copy link
Member

I believe the above commit fixes the issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants