Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/post/meterpreter/extensions/stdapi/railgun/multicall.rb
Views: 11792
# -*- coding: binary -*-1# Copyright (c) 2010, [email protected]2# All rights reserved.3#4# Redistribution and use in source and binary forms, with or without5# modification, are permitted provided that the following conditions are met:6# * Redistributions of source code must retain the above copyright7# notice, this list of conditions and the following disclaimer.8# * Redistributions in binary form must reproduce the above copyright9# notice, this list of conditions and the following disclaimer in the10# documentation and/or other materials provided with the distribution.11# * The names of the author may not be used to endorse or promote products12# derived from this software without specific prior written permission.13#14# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED16# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE17# DISCLAIMED. IN NO EVENT SHALL [email protected] BE LIABLE FOR ANY18# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES19# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;20# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND21# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS23# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2425require 'pp'26require 'enumerator'27require 'rex/post/meterpreter/extensions/stdapi/railgun/tlv'28require 'rex/post/meterpreter/extensions/stdapi/railgun/library_helper'29require 'rex/post/meterpreter/extensions/stdapi/railgun/buffer_item'3031module Rex32module Post33module Meterpreter34module Extensions35module Stdapi36module Railgun3738# A easier way to call multiple functions in a single request39class MultiCaller4041include LibraryHelper4243def initialize(client, parent, consts_mgr)44@parent = parent45@client = client4647# needed by LibraryHelper48@consts_mgr = consts_mgr49end5051def call(functions)52request = Packet.create_request(COMMAND_ID_STDAPI_RAILGUN_API_MULTI)53function_results = []54call_layouts = []55functions.each do |f|56lib_name, function, args = f57library = @parent.get_library(lib_name)5859unless library60raise "Library #{lib_name} has not been loaded"61end6263unless function.instance_of? LibraryFunction64function = library.functions[function]65unless function66raise "Library #{lib_name} function #{function} has not been defined"67end68end6970raise "#{function.params.length} arguments expected. #{args.length} arguments provided." unless args.length == function.params.length7172group, layouts = library.build_packet_and_layouts(73Rex::Post::Meterpreter::GroupTlv.new(TLV_TYPE_RAILGUN_MULTI_GROUP),74function,75args,76@client.native_arch77)78request.tlvs << group79call_layouts << layouts80end8182call_results = []83res = @client.send_request(request)84res.each(TLV_TYPE_RAILGUN_MULTI_GROUP) do |val|85call_results << val86end8788functions.each do |f|89lib_name, function, args = f90library = @parent.get_library(lib_name)91function = library.functions[function] unless function.instance_of? LibraryFunction92function_results << library.build_response(call_results.shift, function, call_layouts.shift, @client)93end9495function_results96end97# process_multi_function_call9899end # MultiCall100101end; end; end; end; end; end102103104