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

Enhance command_exists? method so that it falls to which in case the command fails #15296

Merged
merged 2 commits into from Jun 7, 2021

Conversation

pingport80
Copy link
Contributor

@pingport80 pingport80 commented Jun 3, 2021

Summary

This PR adds a small enhancement to the command_exists? method under post/common.rb. Currently it is using the command command to check if some command is present on the target system but in some cases that utility might not be present(see here for an example). So in that case it will fall to some other alternative like which.

This PR also removes a method pids which was removed in the PR #15199 but while refactoring it's code in the new process.rb the change was missed.

@wvu
Copy link
Contributor

wvu commented Jun 3, 2021

/me laughs in POSIX.

@smcintyre-r7
Copy link
Contributor

Totally out of scope for this PR, but at some point, we may want to consider some kind of caching to determine what commands are available on a remote system since it's unlikely to change (unless we're changing it I guess) and each query takes a round trip which slows things down.

@pingport80
Copy link
Contributor Author

That really sounds interesting and will be very useful. I guess for non-windows we can get using the dir method in every directory the PATH returns. For Powershell something like Get-Command, not sure about windows cmd.

@gwillcox-r7 gwillcox-r7 self-assigned this Jun 5, 2021
@gwillcox-r7 gwillcox-r7 added enhancement rn-enhancement release notes enhancement labels Jun 5, 2021
@gwillcox-r7
Copy link
Contributor

LGTM, will land this now.

@gwillcox-r7 gwillcox-r7 merged commit 06159dd into rapid7:master Jun 7, 2021
@gwillcox-r7
Copy link
Contributor

Release Notes

The command_exists? method inside post/common.rb has been updated to fall back to using the which command to check if a command exists on a target system if command -v fails to run successfully. This allows users to check whether a command exists or not on systems that might not contain a command command, such as ESXi.

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

Successfully merging this pull request may close these issues.

None yet

4 participants