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

enum_commands: Cleanup #17334

Merged
merged 1 commit into from
Dec 20, 2022
Merged

enum_commands: Cleanup #17334

merged 1 commit into from
Dec 20, 2022

Conversation

bcoles
Copy link
Contributor

@bcoles bcoles commented Dec 4, 2022

  • Resolves Rubocop violations.
  • Adds documentation.
  • Adds Notes module meta information.
  • Changes the module name. "Gather Available Shell Commands" is a better fit for the Metasploit naming convention than "Testing commands needed in a function".

Also fixes a few bugs:

  • Prior to this PR, this module would crash if any of the searched paths didn't exist. For example:
[-] Post failed: Rex::Post::Meterpreter::RequestError stdapi_fs_ls: Operation failed: 1
[-] Call stack:
[-]   /root/Desktop/metasploit-framework/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb:62:in `entries'
[-]   /root/Desktop/metasploit-framework/lib/msf/core/post/file.rb:88:in `dir'
[-]   /root/Desktop/metasploit-framework/modules/post/linux/gather/enum_commands.rb:45:in `block in run'
[-]   /root/Desktop/metasploit-framework/modules/post/linux/gather/enum_commands.rb:44:in `each'
[-]   /root/Desktop/metasploit-framework/modules/post/linux/gather/enum_commands.rb:44:in `run'
[*] Post module execution completed
  • Duplicate paths were allowed, resulting in searching the same directory more than once.

  • BusyBox commands were unnecessarily printed twice.

  • BusyBox output was not parsed properly, resulting in messed up output. For example:

busybox 
	[
busybox  [[
busybox  acpid
busybox  adjtimex
busybox  ar
busybox  arch
busybox  arp
busybox  arping
busybox  ash
busybox  awk
busybox  basename
busybox  bc
busybox 
	blkdiscard
busybox  blockdev
busybox  brctl
busybox  bunzip2
...

This PR also adds unix to Platform. Not necessary, but there's no reason this module can't also run on UNIX sessions (ie, *NIX command sessions). Adding unix prevents a warning message.

Although untested, this module could likely be moved to post/multi as it should also work on Solaris, FreeBSD, Mac OSX, etc.

While find -executable could be used, my understanding is that this module is intended to be portable (find may not be available and -executable applies only to the user running the command, so this would skip "commands" which may be executable for other users). Thus the existing logic in this module has been left largely untouched.

@bcoles
Copy link
Contributor Author

bcoles commented Dec 4, 2022

As the output is quite large it may make more sense to store the output as loot.

@@ -0,0 +1,52 @@
## Vulnerable Application

This module will check which shell commands are available on a system.
Copy link
Contributor

@adfoster-r7 adfoster-r7 Dec 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a blocker: I think shell commands normally refers to inbuilt shell commands like cd/env/pwd etc; Potentially the module should've been called enum_path_binaries or similar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, although enum_path_binaries is not suitable either as the module searches outside of the system PATH. I'll leave it as is.

@adfoster-r7 adfoster-r7 merged commit a6605d3 into rapid7:master Dec 20, 2022
@adfoster-r7
Copy link
Contributor

Release Notes

Multiple improvements to modules/post/linux/gather/enum_commands - including fixing a crash when attempting to search a path that doesn't exist

@adfoster-r7 adfoster-r7 added the rn-fix release notes fix label Dec 20, 2022
@bcoles bcoles deleted the enum_commands branch December 21, 2022 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug module rn-fix release notes fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants