CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/meterpreter/extensions/stdapi/railgun/multicall.rb
Views: 1904
1
# -*- coding: binary -*-
2
# Copyright (c) 2010, [email protected]
3
# All rights reserved.
4
#
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions are met:
7
# * Redistributions of source code must retain the above copyright
8
# notice, this list of conditions and the following disclaimer.
9
# * Redistributions in binary form must reproduce the above copyright
10
# notice, this list of conditions and the following disclaimer in the
11
# documentation and/or other materials provided with the distribution.
12
# * The names of the author may not be used to endorse or promote products
13
# derived from this software without specific prior written permission.
14
#
15
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
# DISCLAIMED. IN NO EVENT SHALL [email protected] BE LIABLE FOR ANY
19
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26
require 'pp'
27
require 'enumerator'
28
require 'rex/post/meterpreter/extensions/stdapi/railgun/tlv'
29
require 'rex/post/meterpreter/extensions/stdapi/railgun/library_helper'
30
require 'rex/post/meterpreter/extensions/stdapi/railgun/buffer_item'
31
32
module Rex
33
module Post
34
module Meterpreter
35
module Extensions
36
module Stdapi
37
module Railgun
38
39
# A easier way to call multiple functions in a single request
40
class MultiCaller
41
42
include LibraryHelper
43
44
def initialize(client, parent, consts_mgr)
45
@parent = parent
46
@client = client
47
48
# needed by LibraryHelper
49
@consts_mgr = consts_mgr
50
end
51
52
def call(functions)
53
request = Packet.create_request(COMMAND_ID_STDAPI_RAILGUN_API_MULTI)
54
function_results = []
55
call_layouts = []
56
functions.each do |f|
57
lib_name, function, args = f
58
library = @parent.get_library(lib_name)
59
60
unless library
61
raise "Library #{lib_name} has not been loaded"
62
end
63
64
unless function.instance_of? LibraryFunction
65
function = library.functions[function]
66
unless function
67
raise "Library #{lib_name} function #{function} has not been defined"
68
end
69
end
70
71
raise "#{function.params.length} arguments expected. #{args.length} arguments provided." unless args.length == function.params.length
72
73
group, layouts = library.build_packet_and_layouts(
74
Rex::Post::Meterpreter::GroupTlv.new(TLV_TYPE_RAILGUN_MULTI_GROUP),
75
function,
76
args,
77
@client.native_arch
78
)
79
request.tlvs << group
80
call_layouts << layouts
81
end
82
83
call_results = []
84
res = @client.send_request(request)
85
res.each(TLV_TYPE_RAILGUN_MULTI_GROUP) do |val|
86
call_results << val
87
end
88
89
functions.each do |f|
90
lib_name, function, args = f
91
library = @parent.get_library(lib_name)
92
function = library.functions[function] unless function.instance_of? LibraryFunction
93
function_results << library.build_response(call_results.shift, function, call_layouts.shift, @client)
94
end
95
96
function_results
97
end
98
# process_multi_function_call
99
100
end # MultiCall
101
102
end; end; end; end; end; end
103
104