@@ -85,7 +85,10 @@ class Core
85
85
"-k" => [ true , "Keep (include) arg lines at start of output." ] ,
86
86
"-c" => [ false , "Only print a count of matching lines." ] )
87
87
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." ] )
89
92
90
93
@@irb_opts = Rex ::Parser ::Arguments . new (
91
94
"-h" => [ false , "Help banner." ] ,
@@ -105,6 +108,7 @@ def commands
105
108
"getg" => "Gets the value of a global variable" ,
106
109
"grep" => "Grep the output of another command" ,
107
110
"help" => "Help menu" ,
111
+ "history" => "Show commands history" ,
108
112
"irb" => "Drop into irb scripting mode" ,
109
113
"load" => "Load a framework plugin" ,
110
114
"quit" => "Exit the console" ,
@@ -133,6 +137,7 @@ def initialize(driver)
133
137
@cache_payloads = nil
134
138
@previous_module = nil
135
139
@module_name_stack = [ ]
140
+ @history_limit = 100
136
141
end
137
142
138
143
#
@@ -473,6 +478,43 @@ def cmd_exit(*args)
473
478
474
479
alias cmd_quit cmd_exit
475
480
481
+
482
+ def cmd_history ( *args )
483
+
484
+ limit = @history_limit
485
+ length = Readline ::HISTORY . length
486
+
487
+ @@history_opts . parse ( args ) do |opt , _idx , val |
488
+ case opt
489
+ when "-a"
490
+ limit = length
491
+ when "-n"
492
+ return cmd_history_help unless !val . nil? && val . match ( /\A [-+]?\d +\z / )
493
+ limit = val . to_i
494
+ limit = length if limit >= length
495
+ when "-h"
496
+ cmd_history_help
497
+ return false
498
+ end
499
+ end
500
+
501
+ start = length - limit
502
+ ( start ..length -1 ) . each do |pos |
503
+ print "#{ pos } #{ Readline ::HISTORY [ pos ] } \n "
504
+ end
505
+ end
506
+
507
+ def cmd_history_help
508
+ print_line "Usage: history [options]"
509
+ print_line
510
+ print_line "Shows the command history."
511
+ print_line "If -n is not set, it will only be shown the last #{ @history_limit } commands."
512
+ print_line
513
+ print @@history_opts . usage
514
+ end
515
+
516
+
517
+
476
518
def cmd_sleep_help
477
519
print_line "Usage: sleep <seconds>"
478
520
print_line
0 commit comments