Class: Rex::Post::Meterpreter::Extensions::Stdapi::Railgun::MultiCaller

Inherits:
Object
  • Object
show all
Includes:
LibraryHelper
Defined in:
lib/rex/post/meterpreter/extensions/stdapi/railgun/multicall.rb

Overview

A easier way to call multiple functions in a single request

Instance Method Summary collapse

Methods included from LibraryHelper

#asciiz_to_str, #assemble_buffer, #param_to_number, #str_to_ascii_z, #str_to_uni_z, #uniz_to_str

Constructor Details

#initialize(client, parent, consts_mgr) ⇒ MultiCaller

Returns a new instance of MultiCaller.



44
45
46
47
48
49
50
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/multicall.rb', line 44

def initialize(client, parent, consts_mgr)
  @parent = parent
  @client = client

  # needed by LibraryHelper
  @consts_mgr = consts_mgr
end

Instance Method Details

#call(functions) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/multicall.rb', line 52

def call(functions)
  request = Packet.create_request(COMMAND_ID_STDAPI_RAILGUN_API_MULTI)
  function_results = []
  call_layouts          = []
  functions.each do |f|
    lib_name, function, args = f
    library = @parent.get_library(lib_name)

    unless library
      raise "Library #{lib_name} has not been loaded"
    end

    unless function.instance_of? LibraryFunction
      function = library.functions[function]
      unless function
        raise "Library #{lib_name} function #{function} has not been defined"
      end
    end

    raise "#{function.params.length} arguments expected. #{args.length} arguments provided." unless args.length == function.params.length

    group, layouts = library.build_packet_and_layouts(
      Rex::Post::Meterpreter::GroupTlv.new(TLV_TYPE_RAILGUN_MULTI_GROUP),
      function,
      args,
      @client.native_arch
    )
    request.tlvs << group
    call_layouts << layouts
  end

  call_results = []
  res = @client.send_request(request)
  res.each(TLV_TYPE_RAILGUN_MULTI_GROUP) do |val|
    call_results << val
  end

  functions.each do |f|
    lib_name, function, args = f
    library = @parent.get_library(lib_name)
    function = library.functions[function] unless function.instance_of? LibraryFunction
    function_results << library.build_response(call_results.shift, function, call_layouts.shift, @client)
  end

  function_results
end