-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
Add favorite
module feature and show favorites
command for msfconsole
#14201
Conversation
Notes
|
Thanks for the PR @kalba-security 👍 I'm still a bit new to the workflow side of things on Metasploit, but it would be great to know how often this command might be used by an average user. From my own personal experience I've mostly been reaching for previous modules within linux's ctrl+r reverse search capabilities, or after using the metasploit's For context - adding an additional core command to Metasploit requires a bit more effort than normal to get it shipped - both in terms of documentation considerations, educating the community about the additional functionality, future maintenance effort, manual/automated testing, edge case handling etc, so from my perspective I just want to be sure that this is something that will benefit most users if it's provided as an out of the box command with metasploit-framework ! :) |
Thanks for the question @adfoster-r7 ! I actually came up with the idea for this feature as a way to improve my workflow during penetration tests. I would personally be using this feature all the time for at least the following reasons:
While not everyone may find this feature as useful as I do, I think many users would benefit from it, which I imagine is also the reason that the PR has received likes from several people at Rapid 7 :) Please let me know what you think about all of this! |
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 this is a useful addition, and from the small bit of testing I've done so far, this is working as well. I do have some suggestions, where the main one is related to the addition / deletion logic.
The logic for adding and deleting a favorite module seems to be interweaved both within cmd_favorite()
and cmd_favorite_process()
. It might be helpful to separate those two features of the command into their own separate methods, especially if further additions to this command are being considered. This is untested and is just an example of what I mean:
def cmd_favorite(*args)
if args.empty?
unless active_module
print_error('No module has been chosen to favorite')
return
end
cmd_favorite_add(active_module)
return
end
if args.include?('-D')
args.delete('-D')
cmd_favorite_del(args, true)
return
end
if args.include?('-d')
args.delete('-d')
cmd_favorite_del(args)
return
end
cmd_favorite_add(args)
end
def cmd_favorite_del(module, delete_all = false)
if delete_all
# check if fav_module file exists and delete it
return
end
# handle deleting individual favorite module(s)
...
end
def cmd_favorite_add(module)
# logic for adding favorites
...
end
… functions; improve syntax and error handling
Thanks for the suggestions, @space-r7! Great to hear that you also think this could be a nice feature. I was starting to think this PR had been forgotten. |
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've a few more suggestions, mostly centered around utilizing the Rex::Parser::Arguments
class. Let me know if you have any questions!
…-D' delete file to '-c' for clearing the contents, change helper method names, add helper method 'favorite_check_fav_modules'
Thanks for the great suggestions @space-r7 ! I have implemented all of them, and made the following additional improvements:
I tried to test all different scenarios and didn't run into any errors. Please let me know if you'd like me to make any final changes. Looking forward to seeing this get landed! |
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.
The bulk of the remaining suggestions are really just re-ordering / moving around some logic and changing up some wording. This pr might be hanging around a little longer, as I'll be on research rotation, but I think this is almost done. Please let me know if you have any questions!
…help banner when user input is invalid, do not use parse
Hi @space-r7, thanks for the additional suggestions! I did struggle quite a bit with |
Just wanted to give an update on this. I've done some testing on this this week although it's unlikely that I'll get done with it / land it today. I'll resume work on it next rotation. The changes look good to me. Thanks! |
Thanks for the update @space-r7 ! Can you say anything more about the expected timeline for landing this? If not, that's fine, I'm just curious. :) |
Will try and get back to this on the 1st. |
Submitted https://github.com/kalba-security/metasploit-framework/pull/3 to your branch. Please let me know if that looks good to you, thanks! |
Thanks! I'll test this on Saturday. Probably won't have time before. |
@space-r7 I tested the changes locally and everything looks and works great, so I just merged it. So feel free to land this :) |
Release NotesAdded a new |
For future reference, I added a small wiki page that details the usage of this command: https://github.com/rapid7/metasploit-framework/wiki/How-to-use-the-Favorite-command. |
Thanks for working with me on this @space-r7 and for adding the wiki!! |
About
This change adds a new feature to
msfconsole
that allows users to create, view, edit and delete a list of favorite modules. The list is by default stored in the.msf4
folder in a file calledfav_modules
. The feature adds two new module commands:favorite
, which can be used to add modules tofav_modules
, to delete modules from it, and to delete thefav_modules
file altogether.show
command calledshow favorites
, which can be used to view all favorited modules in the same output format as othershow
commands.Demo
I've made a short demo video of the feature in action. Check it out here
The
favorite
module commandAdding modules
favorite
followed by the module name(s). It is not always necessary to add the module type at the beginning, eg:favorite
without arguments, eg:Deleting modules
favorite
with the-d
flag, eg:fav_modules
file altogether, runfavorite
with the-D
flag, eg:Errors and warnings
favorite
is run without arguments but there is not active module, an error message is printedfav_modules
, the module will not be added and a warning will be printedfav_modules
, or iffav_modules
does not exist,favorite
will do nothingfav_modules
even though it doesn't exist,favorite
will do nothing-D
and-d
flags are used together, or if the-D
flag is used together with a module name,favorite
will delete thefav_modules
file and returnThe
show favorites
commandshow favorites
can be used to view the list of favorited modules stored in thefav_modules
file, eg:fav_modules
file is empty or does not exist,show favorites
will print an error messagePotential future addition: access via
use <index>
While msfconsole allows users to access modules listed in search results via the index number, eg
use 5
, this feature is not available for the results of any of theshow
commands. However, if this feature is ever added, it will be immediately available forshow favorites
as well, since this command supports the same output format as othershow
commands likeshow post