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

Add "search -u" to use a module if there's only one result #11652

Merged
merged 4 commits into from
Apr 1, 2019

Conversation

busterb
Copy link
Member

@busterb busterb commented Mar 29, 2019

This implements a feature request from a few years back, adding a numeric column to module search, as well as a '-u' option that automatically uses the first module that matches, or if the user specifies a number value, the nth module that matches.

Fixes #4336

Example:

msf5 > search -u cve-2013-0422

Matching Modules
================

   #  Name                                      Disclosure Date  Rank       Check  Description
   -  ----                                      ---------------  ----       -----  -----------
   1  exploit/multi/browser/java_jre17_jmxbean  2013-01-10       excellent  No     Java Applet JMX Remote Code Execution

Using exploit/multi/browser/java_jre17_jmxbean
msf5 exploit(multi/browser/java_jre17_jmxbean) > 

Counterexample:

msf5 exploit(multi/browser/java_jre17_jmxbean) > search cve-2013-0422 -u 1

Matching Modules
================

   #  Name                                      Disclosure Date  Rank       Check  Description
   -  ----                                      ---------------  ----       -----  -----------
   1  exploit/multi/browser/java_jre17_jmxbean  2013-01-10       excellent  No     Java Applet JMX Remote Code Execution


Using exploit/multi/browser/java_jre17_jmxbean
msf5 exploit(multi/browser/java_jre17_jmxbean) > search cve-2013-0422 -u 2

Matching Modules
================

   #  Name                                      Disclosure Date  Rank       Check  Description
   -  ----                                      ---------------  ----       -----  -----------
   1  exploit/multi/browser/java_jre17_jmxbean  2013-01-10       excellent  No     Java Applet JMX Remote Code Execution


Module #2 does not exist

…asy step

This implements a feature request from a few years back, adding a numeric column to module search, as well as a '-u' option that automatically uses the first module that matches, or if the user specifies a number value, the nth module that matches.
@busterb busterb changed the title add search-by-number support that allows 'use' on the module in one e… add search-by-number support that allows 'use' on the module in one step Mar 29, 2019
@h00die
Copy link
Contributor

h00die commented Mar 29, 2019

Is there a default sorting, if so what is it?
Specifying 'i choose x' (blindly, as this seems to be for scripting) seems rough since modules are always being added. Is another CVE-xxxx-xxxx likely to be added, no, but more open searches like 'wordpress' may change frequently.

Edit (after reading the use case):
It seems like you have pre-knowledge when doing this search. Personally I would always search xyz and look at my options before choosing, and then in that case I would most likely search xyz -u since its quicker than typing the long path or copy/paste. Blindly typing search wordpress -u and thinking it will give you something useful isn't likely to be very successful IMO

@busterb
Copy link
Member Author

busterb commented Mar 29, 2019

I was thinking you'd search foo, see the list of foos, then up-arrow and add -u 4 or whatever made sense. -u basically is 'I'm feeling lucky' or 'I know this should match one thing'

@busterb
Copy link
Member Author

busterb commented Mar 29, 2019

This could be improved with some sort of default sorting, but you're right in that there's no guarantee that '-u N' will continue resolving to a particular module over time, even if there is sorting. What do you think, is this a reasonable implementation, or should I try an entirely different approach?

@h00die
Copy link
Contributor

h00die commented Mar 29, 2019

I don't have a better answer than this. The only other thought that came to mind is somehow caching the search result then doing a search -u 1 or use -s 1 where it would use the cached search results. However, the search is so darn fast now-a-days that it isn't a big deal to perform the search twice.

I can see the tickets now though "i used some tutorial and it said search windows -u 12 and it loaded the wrong module"

@wvu
Copy link
Contributor

wvu commented Mar 30, 2019

If I were using this feature, I'd like to be able to do search -u on a term and use the only module that matches. If there are multiple results, I would like them displayed so I can use a specific one. Just my two cents.

I don't like the use-by-index approach. I agree with @h00die's consideration that tutorials will perpetuate the wrong information.

I would still keep the index column, though.

@wvu wvu self-assigned this Mar 31, 2019
@wvu wvu changed the title add search-by-number support that allows 'use' on the module in one step Add "search -u" to use a module if there's only one result Apr 1, 2019
@wvu
Copy link
Contributor

wvu commented Apr 1, 2019

e577b8f

@wvu wvu merged commit edca25d into rapid7:master Apr 1, 2019
wvu added a commit that referenced this pull request Apr 1, 2019
@wvu
Copy link
Contributor

wvu commented Apr 1, 2019

Release Notes

The -u option is now available in thesearch command in msfconsole. This option will automatically use a module if there is only one search result.

@jmartin-tech
Copy link
Contributor

Marking msf5 since this is not exposed in rpc and would require backport to work on 4.x.

jmartin-tech pushed a commit to jmartin-tech/metasploit-framework that referenced this pull request Jul 16, 2019
@tdoan-r7 tdoan-r7 added the rn-enhancement release notes enhancement label Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade to msfconsole search command (enhancement request).
5 participants