Reduce a vehicle-supplied MAVFTP file name to a file name before writ… - #3774
Open
nicholasaleks wants to merge 1 commit into
Open
nicholasaleks wants to merge 1 commit into
nicholasaleks wants to merge 1 commit into
Conversation
…ing it A MAVLink-FTP directory listing is attacker-controlled: MAVLink has no authentication, so whatever answers ListDirectory chooses the entry names. Both download handlers passed that name straight to Path.Combine() as the local file name. Path.Combine() returns path2 when path2 is rooted, and keeps ".." for the filesystem to resolve, so an entry named @"..\..\plugins\evil.cs" or @"C:\Program Files (x86)\Mission Planner\plugins\evil.cs" writes outside the folder the operator picked. Anything landing in plugins\ is Roslyn-compiled and executed by PluginLoader.LoadAll() on the next start. The upload path in this same file already calls Path.GetFileName() on its name for exactly this reason. The download path, which is the direction carrying untrusted input, did not. Apply the same reduction there, and skip an entry that cannot be represented as a file name rather than writing it somewhere else. The remote path is deliberately left alone: it is built separately from the tree node plus the entry name, and sanitising it would change which file is fetched.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A MAVLink-FTP directory listing is attacker-controlled: MAVLink has no authentication, so whatever answers ListDirectory chooses the entry names. Both download handlers passed that name straight to Path.Combine() as the local file name. Path.Combine() returns path2 when path2 is rooted, and keeps ".." for the filesystem to resolve, so an entry named @"....\plugins\evil.cs" or @"C:\Program Files (x86)\Mission Planner\plugins\evil.cs" writes outside the folder the operator picked. Anything landing in plugins\ is Roslyn-compiled and executed by PluginLoader.LoadAll() on the next start.
The upload path in this same file already calls Path.GetFileName() on its name for exactly this reason. The download path, which is the direction carrying untrusted input, did not. Apply the same reduction there, and skip an entry that cannot be represented as a file name rather than writing it somewhere else.
The remote path is deliberately left alone: it is built separately from the tree node plus the entry name, and sanitising it would change which file is fetched.
Related to: https://github.com/nicholasaleks/infected-drones/tree/main/MP-01_mavftp_plugin_rce