@@ -30,6 +30,10 @@ def initialize(shell)
30
30
self . bgjob_id = 0
31
31
end
32
32
33
+ @@irb_opts = Rex ::Parser ::Arguments . new (
34
+ "-h" => [ false , "Help banner." ] ,
35
+ "-e" => [ true , "Expression to evaluate." ] )
36
+
33
37
@@load_opts = Rex ::Parser ::Arguments . new (
34
38
"-l" => [ false , "List all available extensions" ] ,
35
39
"-h" => [ false , "Help menu." ] )
@@ -322,15 +326,43 @@ def cmd_interact(*args)
322
326
323
327
alias cmd_interact_tabs cmd_close_tabs
324
328
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
+
325
336
#
326
337
# Runs the IRB scripting shell
327
338
#
328
339
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
331
352
332
353
session = client
333
354
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
+
334
366
Rex ::Ui ::Text ::IrbShell . new ( binding ) . run
335
367
end
336
368
0 commit comments