-
Notifications
You must be signed in to change notification settings - Fork 4
[Fix] Patched RCE arising inside the "launchpad" library #1
Conversation
lib/local/instance.js
Outdated
@@ -90,11 +97,11 @@ Instance.prototype.stop = function (callback) { | |||
} catch (error) {} | |||
} else { | |||
if (this.options.command.indexOf('open') === 0) { | |||
command = 'osascript -e \'tell application "' + self.options.process + '" to quit\''; | |||
command = 'osascript -e \'tell application "' + safe(self.options.process) + '" to quit\''; | |||
debug('Executing shutdown AppleScript', command); | |||
exec(command); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the dangerous function exec()
should be avoided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @toufik-airane :),
I've replaced the exec
function with the execFile
one in order to avoid problems. I removed also the safe
function in the windows
case because I saw certain systems won't recognize the string inside as a argument (edge cases covered anyway by execFile
now introduced).
Regards,
Mik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you run the tests and update the description?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I updated the description of the fixes
applied and I retested the new code.
I saw I had missed a )
... however now it should be fixed well and running the POC I previously used it doesn't lead to RCE
or errors due to malformed syntax.
Regards,
Mik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/local/version.js
Outdated
@@ -18,7 +28,7 @@ module.exports = function(browser) { | |||
|
|||
debug('Retrieving version for windows executable', command); | |||
// Can't use Q.nfcall here unfortunately because of non 0 exit code | |||
exec(command, function(error, stdout) { | |||
exec(command.split(' ')[0], command.split(' ').slice(1), function(error, stdout) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please change this exec()
to execFile()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mik317 - once you have made the fix - we will get this merged - cheers! 🍰
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I just updated the fix as requested. In the meanwhile I also applied a minor fix
because I had inserted certain characters as blacklisted
that however could be part of a path
(not only of a filename
) :).
Regards,
Mik
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mik317 - awesome, thanks for making the changes!
Congratulations Mik317 - your fix has been selected! 🎉 Thanks for being part of the community & helping secure the world's open source code. |
- polymer-cli is imported twice, once in package.json and once in tools/node_tools/package.json. Only the latter is used by CI system. - Add patch 418sec/launchpad#1 for launchpad Fixes: 198040317 Change-Id: Ibdf877a1e24909904edfad50a12729abf25bd735
📊 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