Skip to content

Commit f9642da

Browse files
committed
Support expressions for meterpreter's irb too
1 parent f6f2172 commit f9642da

File tree

1 file changed

+34
-2
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher

1 file changed

+34
-2
lines changed

lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def initialize(shell)
3030
self.bgjob_id = 0
3131
end
3232

33+
@@irb_opts = Rex::Parser::Arguments.new(
34+
"-h" => [ false, "Help banner." ],
35+
"-e" => [ true, "Expression to evaluate." ])
36+
3337
@@load_opts = Rex::Parser::Arguments.new(
3438
"-l" => [ false, "List all available extensions" ],
3539
"-h" => [ false, "Help menu." ])
@@ -322,15 +326,43 @@ def cmd_interact(*args)
322326

323327
alias cmd_interact_tabs cmd_close_tabs
324328

329+
def cmd_irb_help
330+
print_line "Usage: irb"
331+
print_line
332+
print_line "Execute commands in a Ruby environment"
333+
print @@irb_opts.usage()
334+
end
335+
325336
#
326337
# Runs the IRB scripting shell
327338
#
328339
def cmd_irb(*args)
329-
print_status("Starting IRB shell")
330-
print_status("The 'client' variable holds the meterpreter client\n")
340+
expressions = []
341+
342+
# Parse the command options
343+
@@irb_opts.parse(args) do |opt, idx, val|
344+
case opt
345+
when '-e'
346+
expressions << val
347+
when '-h'
348+
cmd_irb_help
349+
return
350+
end
351+
end
331352

332353
session = client
333354
framework = client.framework
355+
356+
if !expressions.empty?
357+
expressions.each do |expression|
358+
eval(expression, binding)
359+
end
360+
return
361+
end
362+
363+
print_status("Starting IRB shell")
364+
print_status("The 'client' variable holds the meterpreter client\n")
365+
334366
Rex::Ui::Text::IrbShell.new(binding).run
335367
end
336368

0 commit comments

Comments
 (0)