Skip to content

Commit e724974

Browse files
authored
Added the history command
Added the "history" command to see a list of commands used before. ``` msf exploit(handler) > history -n 4 2344 set PAYLOAD windows/meterpreter/reverse_tcp 2345 set LHOST 10.0.1.109 2346 exploit 2347 history -n 4 msf exploit(handler) > history -h Usage: history [options] Show the command history OPTIONS: -a Show length commands in history -h Help banner. -n <opt> Show the last n commands msf exploit(handler) > ```
1 parent 4906b8a commit e724974

File tree

1 file changed

+42
-1
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+42
-1
lines changed

lib/msf/ui/console/command_dispatcher/core.rb

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ class Core
8585
"-k" => [ true, "Keep (include) arg lines at start of output." ],
8686
"-c" => [ false, "Only print a count of matching lines." ])
8787

88-
88+
@@history_opts = Rex::Parser::Arguments.new(
89+
"-h" => [ false, "Help banner." ],
90+
"-a" => [ false, "Show all commands in history" ],
91+
"-n" => [ true, "Show the last n commands" ])
8992

9093
@@irb_opts = Rex::Parser::Arguments.new(
9194
"-h" => [ false, "Help banner." ],
@@ -105,6 +108,7 @@ def commands
105108
"getg" => "Gets the value of a global variable",
106109
"grep" => "Grep the output of another command",
107110
"help" => "Help menu",
111+
"history" => "Show commands history",
108112
"irb" => "Drop into irb scripting mode",
109113
"load" => "Load a framework plugin",
110114
"quit" => "Exit the console",
@@ -473,6 +477,43 @@ def cmd_exit(*args)
473477

474478
alias cmd_quit cmd_exit
475479

480+
481+
def cmd_history(*args)
482+
483+
limit = 100
484+
length = Readline::HISTORY.length
485+
486+
@@history_opts.parse(args) do |opt, _idx, val|
487+
case opt
488+
when "-a"
489+
limit = length
490+
when "-n"
491+
return cmd_history_help unless val.match /\A[-+]?\d+\z/
492+
limit = val.to_i
493+
limit = length if limit >= length
494+
when "-h"
495+
cmd_history_help
496+
return false
497+
end
498+
end
499+
500+
start = length - limit
501+
(start..length-1).each do |pos|
502+
print "#{pos} #{Readline::HISTORY[pos]}\n"
503+
end
504+
end
505+
506+
def cmd_history_help
507+
print_line "Usage: history [options]"
508+
print_line
509+
print_line "Shows the command history."
510+
print_line "If -n is not set, it will only be shown the last 100 commands"
511+
print_line
512+
print @@history_opts.usage
513+
end
514+
515+
516+
476517
def cmd_sleep_help
477518
print_line "Usage: sleep <seconds>"
478519
print_line

0 commit comments

Comments
 (0)