Skip to content

Commit f6f2172

Browse files
committed
Support expressions for the irb command
1 parent 29a5194 commit f6f2172

File tree

1 file changed

+26
-2
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+26
-2
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class Core
9494
@@go_pro_opts = Rex::Parser::Arguments.new(
9595
"-h" => [ false, "Help banner." ])
9696

97+
@@irb_opts = Rex::Parser::Arguments.new(
98+
"-h" => [ false, "Help banner." ],
99+
"-e" => [ true, "Expression to evaluate." ])
100+
97101
# The list of data store elements that cannot be set when in defanged
98102
# mode.
99103
DefangedProhibitedDataStoreElements = [ "MsfModulePaths" ]
@@ -759,8 +763,8 @@ def cmd_info_tabs(str, words)
759763
def cmd_irb_help
760764
print_line "Usage: irb"
761765
print_line
762-
print_line "Drop into an interactive Ruby environment"
763-
print_line
766+
print_line "Execute commands in a Ruby environment"
767+
print @@irb_opts.usage()
764768
end
765769

766770
#
@@ -769,6 +773,26 @@ def cmd_irb_help
769773
def cmd_irb(*args)
770774
defanged?
771775

776+
expressions = []
777+
778+
# Parse the command options
779+
@@irb_opts.parse(args) do |opt, idx, val|
780+
case opt
781+
when '-e'
782+
expressions << val
783+
when '-h'
784+
cmd_irb_help
785+
return false
786+
end
787+
end
788+
789+
if !expressions.empty?
790+
expressions.each do |expression|
791+
eval(expression, binding)
792+
end
793+
return
794+
end
795+
772796
print_status("Starting IRB shell...\n")
773797

774798
begin

0 commit comments

Comments
 (0)