adds ability to use '!$' in msfconsole just like in bash #816

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
5 participants
Contributor

kernelsmith commented Sep 20, 2012

usage:
msf > set SRVHOST 192..168.101.102
SRVHOST => 192..168.101.102
msf > set LHOST !$
LHOST => 192..168.101.102
msf > set ReverseListenerBindAddress !$
ReverseListenerBindAddress => 1.1.1.1

History will reflect the replaced value, not the '!$'

kernelsmith added some commits Sep 20, 2012

kernelsmith adds ability to use '!$' in msfconsole just like in bash
usage:
msf > set SRVHOST 192..168.101.102
SRVHOST => 192..168.101.102
msf > set LHOST !$
LHOST => 192..168.101.102
msf >
1f4898f
kernelsmith update history so consecutive uses of !$ work properly
update the history file itself so consecutive uses of !$ don't return
'!$' instead of replaced value
7ec885d

@brandonprry brandonprry commented on the diff Nov 9, 2012

lib/rex/ui/text/dispatcher_shell.rb
@@ -417,6 +417,20 @@ def run_command(dispatcher, method, arguments)
if(blocked_command?(method))
print_error("The #{method} command has been disabled.")
else
+ # check for and replace '!$'
+ his_len = Readline::HISTORY.length
+ spot = arguments.index('!$')
+ if spot
+ if his_len < 1
+ print_error('No commands in history to use for !$ substitution')
+ return self.busy = false
+ else
+ arguments[spot] = parse_line(Readline::HISTORY[his_len-2]).last
@brandonprry

brandonprry Nov 9, 2012

Contributor

What happens if I am not using readline?

@mcfakepants

mcfakepants Nov 12, 2012

Contributor

This needs to be addressed for sure. Windows platforms, IIRC, have readline problems.

@brandonprry brandonprry commented on the diff Nov 9, 2012

lib/rex/ui/text/dispatcher_shell.rb
@@ -417,6 +417,20 @@ def run_command(dispatcher, method, arguments)
if(blocked_command?(method))
print_error("The #{method} command has been disabled.")
else
+ # check for and replace '!$'
+ his_len = Readline::HISTORY.length
+ spot = arguments.index('!$')
+ if spot
+ if his_len < 1
+ print_error('No commands in history to use for !$ substitution')
+ return self.busy = false
+ else
+ arguments[spot] = parse_line(Readline::HISTORY[his_len-2]).last
+ # we use -2 above because -1 is the last one in history, which is actually the currently executing command
+ # update the history file itself so consecutive uses of !$ don't return '!$' instead of replaced value
+ Readline::HISTORY[his_len-1] = "#{method} #{arguments.join(' ')}"
@brandonprry

brandonprry Nov 9, 2012

Contributor

Lots of dependence on readline here

Contributor

mcfakepants commented Nov 12, 2012

:+1

Contributor

mcfakepants commented Nov 12, 2012

👍

Sorry, I'm spewing graffiti all over @kernelsmith 's PR.

Contributor

jlee-r7 commented Nov 20, 2012

History replacement is a large and complex beast. I'm hesitant to take such a small piece of it, but I really miss this particular small piece. I guess what I'm saying is it'd be lovely if you could add support for the various other history expansions, especially !^, !*, and !:<n>.

Contributor

jlee-r7 commented Nov 20, 2012

Contributor

kernelsmith commented Nov 26, 2012

I'll rework it to add more history expansions and see what I can do about the readline dependencies.

Contributor

bperry-r7 commented Jan 12, 2013

Closed due to inactivity. Please resubmit when the above changes have been made. :)

bperry-r7 closed this Jan 12, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment