rapid7/metasploit-framework — pull request #1080 by kernelsmith (2012-11-19 18:55:08+00:00)
Title: Console alias plugin

# console alias plugin PR writeup

I converted my msfconsole aliasing code into a plugin so that msfconsole internals would not have changes requiring deep review and avoiding any dragons thar be. It actually made for a better solution I believe and also makes it much more portable.

Usage: alias [options] [name [value]]

OPTIONS:

-c Clear an alias (* to clear all).
-f Force an alias assignment.
-h Help banner.

Example:
msf > load alias
[*] Successfully loaded plugin: alias
msf > alias s sessions -l -v
msf > alias si sessions -i
msf > alias sk sessions -K
msf > alias -f sk sessions -k
msf > alias

Current Aliases
===============

Alias Name Alias Value
---------- -----------
alias s sessions -l -v
alias si sessions -i
alias sk sessions -k

msf > alias -c *
[*] Cleared all aliases

msf > alias n00b rm -rf /
[-] You cannot use rm -rf / as the value for an alias, sorry
msf > alias -f n00b rm -rf /
[-] You cannot use rm -rf / as the value for an alias, sorry
msf > alias i ifconfig
msf > alias ifconfig sessions
[-] ifconfig already exists as a system command, use -f to force override
msf > alias -f ifconfig sessions
msf > alias

Current Aliases
===============

Alias Name Alias Value
---------- -----------
alias i ifconfig
alias ifconfig sessions

msf > i

Active sessions
===============

No active sessions.

msf > alias -c ifconfig
[*] Cleared alias ifconfig
msf > i
[*] exec: ifconfig

The output format is copy pasteable into an rc file (thanks for the idea egypt), and the plugin exposes the aliases method so the framework or other plugins can get the list of active plugins by calling pluginobj.aliases. Useful if we want to add the aliases to what gets saved using the save command etc.

Basically anything can be aliased, even shell commands, and using -f to force for overriding, except a few safe "words" like 'alias', 'rm -rf' and msfconsole etc. An alias can't have the name alias otherwise a user could end up in a state where one cannot unalias an overaliased core command like 'set'.

Aliases will tab complete, and the alias command will tab complete with any loaded command or current alias (you can also alias an alias)

This is super handy (see http://pastebin.com/rrS06amv) and can even be used to "translate" msfconsole commands into other (ASCII-based) languages (see http://pastebin.com/tMYWwSGH)