Class: Rex::Post::Meterpreter::Extensions::Stdapi::Railgun::DLL::UnitTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/rex/post/meterpreter/extensions/stdapi/railgun/dll.rb.ut.rb

Defined Under Namespace

Classes: MockRailgunClient

Constant Summary collapse

TLV_TYPE_NAMES =
{
	TLV_TYPE_RAILGUN_SIZE_OUT => "TLV_TYPE_RAILGUN_SIZE_OUT",
	TLV_TYPE_RAILGUN_STACKBLOB => "TLV_TYPE_RAILGUN_STACKBLOB",
	TLV_TYPE_RAILGUN_BUFFERBLOB_IN => "TLV_TYPE_RAILGUN_BUFFERBLOB_IN", 
	TLV_TYPE_RAILGUN_BUFFERBLOB_INOUT => "TLV_TYPE_RAILGUN_BUFFERBLOB_INOUT",
	TLV_TYPE_RAILGUN_DLLNAME => "TLV_TYPE_RAILGUN_DLLNAME",
	TLV_TYPE_RAILGUN_FUNCNAME => "TLV_TYPE_RAILGUN_FUNCNAME",
}

Instance Method Summary collapse

Instance Method Details

#function_descriptionsObject

These are sample descriptions of functions to use for testing.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/dll.rb.ut.rb', line 87

def function_descriptions
	[
		{
			:platform => "x86/win32",
			:name => "LookupAccountSidA",
			:params => [
				["PCHAR","lpSystemName","in"],
				["LPVOID","Sid","in"],
				["PCHAR","Name","out"],
				["PDWORD","cchName","inout"],
				["PCHAR","ReferencedDomainName","out"],
				["PDWORD","cchReferencedDomainName","inout"],
				["PBLOB","peUse","out"],
			],
			:return_type => "BOOL",
			:dll_name => "advapi32",
			:ruby_args => [nil, 1371864, 100, 100, 100, 100, 1],
			:request_to_client => {
				TLV_TYPE_RAILGUN_SIZE_OUT => 201,
				TLV_TYPE_RAILGUN_STACKBLOB => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xD8\xEE\x14\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00d\x00\x00\x00\x03\x00\x00\x00\b\x00\x00\x00\x02\x00\x00\x00\xC8\x00\x00\x00",
				TLV_TYPE_RAILGUN_BUFFERBLOB_IN => "",
				TLV_TYPE_RAILGUN_BUFFERBLOB_INOUT => "d\x00\x00\x00\x00\x00\x00\x00d\x00\x00\x00\x00\x00\x00\x00",
				TLV_TYPE_RAILGUN_DLLNAME => "advapi32",
				TLV_TYPE_RAILGUN_FUNCNAME => "LookupAccountSidA"
			},
			:response_from_client => {
				TLV_TYPE_RAILGUN_BACK_BUFFERBLOB_INOUT => "\x06\x00\x00\x00\x00\x00\x00\x00\f\x00\x00\x00\x00\x00\x00\x00",
				TLV_TYPE_RAILGUN_BACK_BUFFERBLOB_OUT => "SYSTEM\x00AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANT AUTHORITY\x00AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\x05",
				TLV_TYPE_RAILGUN_BACK_RET => 1,
				TLV_TYPE_RAILGUN_BACK_ERR => 997
			},
			:returned_hash => {
				"GetLastError" => 997,
				"return" => true,
				"Name" => "SYSTEM",
				"ReferencedDomainName" => "NT AUTHORITY",
				"peUse" => "\x05",
				"cchName" => 6,
				"cchReferencedDomainName" => 12
			},
		},
		{
			:platform => 'x64/win64',
			:name => 'LookupAccountSidA',
			:params => [
				["PCHAR", "lpSystemName", "in"],
				["LPVOID", "Sid", "in"],
				["PCHAR", "Name", "out"],
				["PDWORD", "cchName", "inout"],
				["PCHAR", "ReferencedDomainName", "out"],
				["PDWORD", "cchReferencedDomainName", "inout"],
				["PBLOB", "peUse", "out"]
			],
			:return_type => 'BOOL',
			:dll_name => 'advapi32',
			:ruby_args => [nil, 1631552, 100, 100, 100, 100, 1],
			:request_to_client => {
				TLV_TYPE_RAILGUN_SIZE_OUT => 201,
				TLV_TYPE_RAILGUN_STACKBLOB => "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@\xE5\x18\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00d\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\b\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\xC8\x00\x00\x00\x00\x00\x00\x00",
				TLV_TYPE_RAILGUN_BUFFERBLOB_IN => "",
				TLV_TYPE_RAILGUN_BUFFERBLOB_INOUT => "d\x00\x00\x00\x00\x00\x00\x00d\x00\x00\x00\x00\x00\x00\x00",
				TLV_TYPE_RAILGUN_DLLNAME => 'advapi32',
				TLV_TYPE_RAILGUN_FUNCNAME => 'LookupAccountSidA',
			},
			:response_from_client => {
				TLV_TYPE_RAILGUN_BACK_BUFFERBLOB_INOUT => "\x06\x00\x00\x00\x00\x00\x00\x00\f\x00\x00\x00\x00\x00\x00\x00",
				TLV_TYPE_RAILGUN_BACK_BUFFERBLOB_OUT => "SYSTEM\x00AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANT AUTHORITY\x00AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\x05",
				TLV_TYPE_RAILGUN_BACK_RET => 1,
				TLV_TYPE_RAILGUN_BACK_ERR => 0,
			},
			:returned_hash => {
				"GetLastError"=>0,
				"return"=>true,
				"Name"=>"SYSTEM",
				"ReferencedDomainName"=>"NT AUTHORITY",
				"peUse"=>"\x05",
				"cchName"=>6,
				"cchReferencedDomainName"=>12
			},
		},
	]
end

#make_mock_client(platform = "x86/win32", target_request_tlvs = [], response_tlvs = []) ⇒ Object



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

def make_mock_client(platform = "x86/win32", target_request_tlvs = [], response_tlvs = [])
	check_request = lambda do |request|
		target_request_tlvs.each_pair do |type, target_value|
			assert_equal(target_value, request.get_tlv_value(type),
				"process_function_call should send to client appropriate #{TLV_TYPE_NAMES[type]}")
		end
	end

	return  MockRailgunClient.new(platform, response_tlvs, check_request)
end

#test_add_functionObject



59
60
61
62
63
64
65
66
67
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/dll.rb.ut.rb', line 59

def test_add_function
	function_descriptions.each do |func|
		dll = DLL.new(func[:dll_name], make_mock_client(func[:platform]), nil)
		dll.add_function(func[:name], func[:return_type], func[:params])

		assert(dll.functions.has_key?(func[:name]),
			"add_function should expand the list of available functions")
	end
end

#test_method_missingObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rex/post/meterpreter/extensions/stdapi/railgun/dll.rb.ut.rb', line 69

def test_method_missing
	function_descriptions.each do |func|
		client = make_mock_client(func[:platform], func[:request_to_client], func[:response_from_client])
		dll = DLL.new(func[:dll_name], client, nil)

		dll.add_function(func[:name], func[:return_type], func[:params])

		actual_returned_hash = dll.send(:method_missing, func[:name].to_sym, *func[:ruby_args])

		assert(func[:returned_hash].has_key?('GetLastError'),
			"process_function_call should add the result of GetLastError to the key GetLastError")

		assert_equal(func[:returned_hash], actual_returned_hash,
			"process_function_call convert function result to a ruby hash")
	end
end