rapid7 / metasploit-framework

Metasploit Framework
https://www.metasploit.com/
Other
34.18k stars 13.98k forks source link

Improved bash-like recursive tab completion with modules #8033

Open Chiggins opened 7 years ago

Chiggins commented 7 years ago

Currently tab completion with module selection is kind of... lacking. Tab completion will work well for the module type, such as exploit, payload, etc, but then it will want to show all the possibilities for that module type, instead of recursing to the next "directory" under it.

msf > use exploit/[TAB]
Display all 1620 possibilities? (y or n)

What would be ideal is that from this point, it will tab complete for the payload platform..

msf > use exploit/win[TAB]
msf > use exploit/windows/

Onward, you can tab complete the service type (http, smb, ftp, etc), and then module name.

From what I'm gathering, the beginning of this fix would start in the method at modules.rb:867. (also, why are neither str or words being used at all in that method?)

I'm reporting this here for visibility. I've started poking into this issue, but framework is kind of confusing and it's taking me some time. @kernelsmith, any good helping hand ideas?

CC: @wvu-r7 @egypt

wvu commented 7 years ago

yes hello

kernelsmith commented 7 years ago

I think I can help

kernelsmith commented 7 years ago

@Chiggins as to why str and words aren't being used, even tho they are passed in, I can't say, but I'm guessing the original intent was to use them, but that intent got lost and it was easier to just return the full paths because they are already available just my enumerating the modules loaded into the framework object. I think we can "remedy" this tho

wvu commented 7 years ago

That method definition is cargo-culted everywhere, so it wouldn't surprise me if those values were never even intended to be used. We can definitely fix this.

kernelsmith commented 7 years ago

@Chiggins and I worked on it, and the problem at the moment is when you return any tab completion, something automatically adds a space to the end, which make it really painful to try to tab complete further... for example, w/our mods in place, you try use[tab][tab] you get a list of module types, life is good, you do use expl[tab][tab] you get back a prompt which has msf> use exploit_ where the '_' is actually a space, so you can't further tab complete w/o back spacing to get rid of the trailing space. I think it may come down to the Readline gem as there is a completion.append.character which is defined as the character that is automatically appended after the Readline.completion_proc is called, and AFAICT, I think that proc is the default tab_completion_proc in dispatcher_shell