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

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

Overview

Represents a library, e.g. kernel32.dll

Instance Attribute Summary collapse

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(library_path, consts_mgr) ⇒ Library

Returns a new instance of Library.


49
50
51
52
53
54
55
56
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/library.rb', line 49

def initialize(library_path, consts_mgr)
  @library_path = library_path

  # needed by LibraryHelper
  @consts_mgr = consts_mgr

  self.functions = {}
end

Instance Attribute Details

#functionsObject

Returns the value of attribute functions


46
47
48
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/library.rb', line 46

def functions
  @functions
end

#library_pathObject (readonly)

Returns the value of attribute library_path


47
48
49
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/library.rb', line 47

def library_path
  @library_path
end

Instance Method Details

#add_function(name, return_type, params, remote_name = nil, calling_conv = 'stdcall') ⇒ Object

Define a function for this library.

Every function argument is described by a tuple (type,name,direction)

Example:

add_function("MessageBoxW",   # name
  "DWORD",                    # return value
  [                           # params
 ["DWORD","hWnd","in"],
   ["PWCHAR","lpText","in"],
   ["PWCHAR","lpCaption","in"],
   ["DWORD","uType","in"],
  ])

Use remote_name when the actual library name is different from the ruby variable. You might need to do this for example when the actual func name is [email protected] or when you want to create an alternative version of an existing function.

When the new function is called it will return a list containing the return value and all inout params. See #call_function.


112
113
114
115
116
117
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/library.rb', line 112

def add_function(name, return_type, params, remote_name=nil, calling_conv='stdcall')
  if remote_name == nil
    remote_name = name
  end
  @functions[name] = LibraryFunction.new(return_type, params, remote_name, calling_conv)
end

#call_function(function, args, client) ⇒ Object

Perform a function call in this library on the remote system.

Returns a Hash containing the return value, the result of GetLastError(), and any inout parameters.

Raises an exception if function is not a known function in this library, i.e., it hasn't been defined in a Def.


75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/library.rb', line 75

def call_function(function, args, client)
  unless function.instance_of? LibraryFunction
    func_name = function.to_s

    unless known_function_names.include? func_name
      raise "Library-function #{func_name} not found. Known functions: #{PP.pp(known_function_names, '')}"
    end

    function = get_function(func_name)
  end

  return process_function_call(function, args, client)
end

#get_function(name) ⇒ Object


62
63
64
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/library.rb', line 62

def get_function(name)
  return functions[name]
end

#known_function_namesObject


58
59
60
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/library.rb', line 58

def known_function_names
  return functions.keys
end