Repository navigation
Conversation
fix path traversal bug
|
Resolves #171 |
|
@kratz00 What do you think? |
| /* use GNU extension to return non-existing files to real_output_directory */ | ||
| realpath(output_directory, real_output_directory); | ||
| realpath(filename, real_filename); | ||
| strncat(real_output_directory, "/", PATH_MAX); |
There was a problem hiding this comment.
I think this could overflow real_output_directory as strncat will add a terminating null-character.
If I see it correctly this PR is intended to fix CVE-2015-1386, therefor it might make sense to clean-up/review the existing code which supposedly should already address it and most importantly double check the test in https://github.com/twogood/unshield/tree/main/test/v5/CVE-2015-1386
This is just shooting from the hip, I will have a deeper look as soon as possible.
There was a problem hiding this comment.
So it's the same CVE? I didn't notice. Strange that the old test case passes.
There was a problem hiding this comment.
Saw this and throwing in my two cents.
Looks like it should be strncat(..., PATH_MAX - 1) to avoid the null character causing an off-by-one.
Regarding CVE-2015-1386, #171 looks like a corner case that the original fix missed. In the PoC @eqawasm provided, they appear to be exploiting a common prefix between the real paths: /tm. Suffixing / to real_output_directory prevents the directory name from being misinterpreted as a file name.
There was a problem hiding this comment.
@carter-yagemann summed it up quite nicely 👍
I think the proposed patch for this corner case is not sufficient, even when fixing the off-by-one issue, here is why.
The reproductions steps in #171 can be simplified and do not even require root permissions:
git clone git@github.com:twogood/unshield.git
cd unshield
cmake -B build
cmake --build build
./build/src/unshield -d /tmp x test/v5/CVE-2015-1386/data1.cab
Cabinet: test/v5/CVE-2015-1386/data1.cab
extracting: /tmp/Bovine_Files/../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../../tmp/moo
-------- -------
1 files
real_filename will be always /tmp/moo, in case of this manipulated cabinet file.
For the strncmp call (see https://github.com/twogood/unshield/blob/main/src/unshield.c#L496), we only need to make sure to match the first four bytes at most by influencing the real_output_directory, this can be easily done by using the -d command line option.
In the /tn case adding the slash would work to solve the issue but not for the /tmp case.
fix path traversal bug
45b5365 to
fd84d79
Compare
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 31 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
What this change does: Adds a trailing slash to the canonical output directory before checking whether an extracted path stays inside it. That addresses the real shared-prefix case: Must fix: It also turns a canonical root output directory Check the directory separator boundary in the comparison without appending to the buffer (and handle root correctly), or append only after checking remaining capacity. Add regression cases for a shared-prefix sibling directory, a maximum-length output path, and root. Also check Verdict: High-value bug to fix, but do not merge this particular patch. The local macOS suite passes because the changed Branch update correction: The initial update used a force-pushed rebase. The original PR commits have now been restored as first-parent history with a merge commit, pushed normally without force. Both the original and previously rebased commits remain reachable. The reviewed file contents are unchanged. Review basis: main |
Restore the original contribution commits as the first-parent history. Keep the reviewed conflict resolutions and current main without rewriting published history again.
fix path traversal bug