Security Fix for Remote Code Execution - huntr.dev #124
+29
−7
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.
https://huntr.dev/app/users/Mik317 has fixed the Remote Code Execution vulnerability 🔨. Mik317 has been awarded $25 for fixing the vulnerability through the huntr bug bounty program 💵. Think you could fix a vulnerability like this?
Get involved at https://huntr.dev/
Q | A
Version Affected | ALL
Bug Fix | YES
Original Pull Request | 418sec#1
GitHub Issue URL | #123
Vulnerability README | https://github.com/418sec/huntr/blob/master/bounties/npm/launchpad/1/README.md
User Comments:
📊 Metadata *
Please enter the direct URL for this bounty on huntr.dev. This is compulsory and will help us process your bounty submission quicker.
Bounty URL: https://www.huntr.dev/app/bounties/open/1-npm-launchpad
⚙️ Description *
The issue arised in multiple locations, so I to validate the type of data the functions were going to use (like the
paths
) and since there were somemulti commands
I didn't use theexecFile
function, which should have had stored many new variables because we wouldn't have been to concatenate and return results that would have been used in a second/third command correlated to the first one executed. In this case I simply made a functionality thatdeletes every quote
from the variable, making impossible threat thevariables concatenated
as commands, but only asarguments
of the specific command.💻 Technical Description *
The fix has been applied in 3 different ways inside 3 different files, so I'll comment each one.
name
variable isconcatenated
inside the various commands without being sanitized. Since thename
is inside somesingle-quotes
it would have been useless split the 3 different commands inside 3 differentexecFile
that would have used more resources to store the content of the singular commands that should be concatenated again ... instead I introduced thesafe
function which deletes thequotes
from thename
in order to make it to be only an argument not escapable from quotes.Note I've used the
execFile
function later in this file in the following lines: https://github.com/Mik317/launchpad/blob/master/lib/local/instance.js#L104 and https://github.com/Mik317/launchpad/blob/master/lib/local/instance.js#L110, in order to avoidcommands
could be executed in a dangerous context.2. The 2' issue arised inside the following line: https://github.com/bitovi/launchpad/blob/master/lib/local/version.js#L21
In this case it I used
execFile
in order to avoid concatenation of other strings containing dangerous characters.Patched with:
In this case the first part of the
command
is taken ascommand to execute
(surely a path since thecommand
variable is made through), while the second part are the
arguments
.In this case the
browser path and filename
weren't checked completely, and even if the execution of malicious code would have been possible only if thedefault browser
of the victim has a badly craftedfilename
, I inserted a check to see if thepath+filename
pointing to the browser is a validpath
.The issue has been fixed through this function:
🐛 Proof of Concept (PoC) *
poc.js
file:node poc.js
HACKED
file will we created🔥 Proof of Fix (PoF) *
HACKED
file is NOT created anymore👍 User Acceptance Testing (UAT)
It doesn't introduce any error (at least using the module through the PoC I crafted)
Regards,
Mik