@@ -11,16 +11,139 @@ class MetasploitModule < Msf::Post
11
11
12
12
def initialize ( info = { } )
13
13
super ( update_info ( info ,
14
- 'Name' => 'Railgun API Tests' ,
15
- 'Description' => %q{ This module will test railgun api functions} ,
16
- 'License' => MSF_LICENSE ,
17
- 'Author' => [ 'Spencer McIntyre' ] ,
18
- 'Platform' => [ 'windows' ]
19
- ) )
14
+ 'Name' => 'Railgun API Tests' ,
15
+ 'Description' => %q{ This module will test railgun api functions } ,
16
+ 'License' => MSF_LICENSE ,
17
+ 'Author' => [ 'Spencer McIntyre' ] ,
18
+ 'Platform' => [ 'linux' , 'windows' ]
19
+ ) )
20
20
end
21
21
22
- def test_api_function_calls
22
+ def init_railgun_defs
23
+ unless session . railgun . dlls . has_key? ( 'libc' )
24
+ session . railgun . add_dll ( 'libc' , 'libc.so.6' )
25
+ end
26
+ session . railgun . add_function (
27
+ 'libc' ,
28
+ 'calloc' ,
29
+ 'LPVOID' ,
30
+ [
31
+ [ 'SIZE_T' , 'nmemb' , 'in' ] ,
32
+ [ 'SIZE_T' , 'size' , 'in' ]
33
+ ] ,
34
+ nil ,
35
+ 'cdecl'
36
+ )
37
+ session . railgun . add_function (
38
+ 'libc' ,
39
+ 'getpid' ,
40
+ 'DWORD' ,
41
+ [ ] ,
42
+ nil ,
43
+ 'cdecl'
44
+ )
45
+ session . railgun . add_function (
46
+ 'libc' ,
47
+ 'inet_ntop' ,
48
+ 'LPVOID' ,
49
+ [
50
+ [ 'DWORD' , 'af' , 'in' ] ,
51
+ [ 'PBLOB' , 'src' , 'in' ] ,
52
+ [ 'PBLOB' , 'dst' , 'out' ] ,
53
+ [ 'DWORD' , 'size' , 'in' ]
54
+ ] ,
55
+ nil ,
56
+ 'cdecl'
57
+ )
58
+ session . railgun . add_function (
59
+ 'libc' ,
60
+ 'malloc' ,
61
+ 'LPVOID' ,
62
+ [ [ 'SIZE_T' , 'size' , 'in' ] ] ,
63
+ nil ,
64
+ 'cdecl'
65
+ )
66
+ session . railgun . add_function (
67
+ 'libc' ,
68
+ 'memfrob' ,
69
+ 'LPVOID' ,
70
+ [
71
+ [ 'PBLOB' , 'mem' , 'inout' ] ,
72
+ [ 'SIZE_T' , 'length' , 'in' ]
73
+ ] ,
74
+ nil ,
75
+ 'cdecl'
76
+ )
77
+ end
23
78
79
+ def test_api_function_calls_linux
80
+ return unless session . platform == 'linux'
81
+ init_railgun_defs
82
+ buffer = nil
83
+ buffer_size = 128
84
+ buffer_value = nil
85
+ it "Should include error information in the results" do
86
+ ret = true
87
+ result = session . railgun . libc . malloc ( 128 )
88
+ ret &&= result [ 'GetLastError' ] == 0
89
+ ret &&= result [ 'ErrorMessage' ] . is_a? String
90
+ end
91
+
92
+ it "Should support functions with no parameters" do
93
+ ret = true
94
+ result = session . railgun . libc . getpid ( )
95
+ ret &&= result [ 'GetLastError' ] == 0
96
+ ret &&= result [ 'return' ] == session . sys . process . getpid
97
+ end
98
+
99
+ it "Should support functions with literal parameters" do
100
+ ret = true
101
+ result = session . railgun . libc . calloc ( buffer_size , 1 )
102
+ ret &&= result [ 'GetLastError' ] == 0
103
+ buffer = result [ 'return' ]
104
+ ret &&= buffer != 0
105
+ end
106
+
107
+ it "Should support functions with in/out/inout parameter types" do
108
+ ret = true
109
+ # first test in/out parameter types
110
+ result = session . railgun . libc . inet_ntop ( 2 , "\x0a \x00 \x00 \x01 " , 128 , 128 )
111
+ ret &&= result [ 'GetLastError' ] == 0
112
+ ret &&= result [ 'return' ] != 0
113
+ ret &&= result [ 'dst' ] [ 0 ...8 ] == '10.0.0.1'
114
+ # then test the inout parameter type
115
+ result = session . railgun . libc . memfrob ( 'metasploit' , 10 )
116
+ ret &&= result [ 'GetLastError' ] == 0
117
+ ret &&= result [ 'return' ] != 0
118
+ ret &&= result [ 'mem' ] == 'GO^KYZFEC^'
119
+ end
120
+
121
+ it "Should support calling multiple functions at once" do
122
+ ret = true
123
+ multi_rail = [
124
+ [ 'libc' , 'getpid' , [ ] ] ,
125
+ [ 'libc' , 'memfrob' , [ 'metasploit' , 10 ] ]
126
+ ]
127
+ results = session . railgun . multi ( multi_rail )
128
+ ret &&= results . length == multi_rail . length
129
+ ret &&= results [ 0 ] [ 'return' ] == session . sys . process . getpid
130
+ ret &&= results [ 1 ] [ 'mem' ] == 'GO^KYZFEC^'
131
+ end
132
+
133
+ it "Should support writing memory" do
134
+ ret = true
135
+ buffer_value = Rex ::Text . rand_text_alphanumeric ( buffer_size )
136
+ ret &&= session . railgun . memwrite ( buffer , buffer_value , buffer_size )
137
+ end
138
+
139
+ it "Should support reading memory" do
140
+ ret = true
141
+ ret &&= session . railgun . memread ( buffer , buffer_size ) == buffer_value
142
+ end
143
+ end
144
+
145
+ def test_api_function_calls_windows
146
+ return unless session . platform == 'windows'
24
147
it "Should include error information in the results" do
25
148
ret = true
26
149
result = session . railgun . kernel32 . GetCurrentProcess ( )
@@ -70,43 +193,39 @@ def test_api_function_calls
70
193
ret &&= results [ 2 ] [ 'return' ] == session . sys . process . getpid
71
194
end
72
195
73
- it "Should support reading memory" do
74
- ret = true
75
- result = client . railgun . kernel32 . GetModuleHandleA ( 'kernel32' )
76
- ret &&= result [ 'GetLastError' ] == 0
77
- ret &&= result [ 'return' ] != 0
78
- return false unless ret
79
-
80
- handle = result [ 'return' ]
81
- mz_header = client . railgun . memread ( handle , 4 )
82
- ret &&= mz_header == "MZ\x90 \x00 "
83
- end
84
-
85
196
it "Should support writing memory" do
86
197
ret = true
87
- result = client . railgun . kernel32 . GetProcessHeap ( )
198
+ result = session . railgun . kernel32 . GetProcessHeap ( )
88
199
ret &&= result [ 'GetLastError' ] == 0
89
200
ret &&= result [ 'return' ] != 0
90
201
return false unless ret
91
202
92
203
buffer_size = 32
93
204
handle = result [ 'return' ]
94
- result = client . railgun . kernel32 . HeapAlloc ( handle , 0 , buffer_size )
205
+ result = session . railgun . kernel32 . HeapAlloc ( handle , 0 , buffer_size )
95
206
ret &&= result [ 'GetLastError' ] == 0
96
207
ret &&= result [ 'return' ] != 0
97
208
return false unless ret
98
209
99
210
buffer_value = Rex ::Text . rand_text_alphanumeric ( buffer_size )
100
211
buffer = result [ 'return' ]
101
- ret &&= client . railgun . memwrite ( buffer , buffer_value , buffer_size )
102
- ret &&= client . railgun . memread ( buffer , buffer_size ) == buffer_value
212
+ ret &&= session . railgun . memwrite ( buffer , buffer_value , buffer_size )
213
+ ret &&= session . railgun . memread ( buffer , buffer_size ) == buffer_value
103
214
104
- client . railgun . kernel32 . HeapFree ( handle , 0 , buffer )
215
+ session . railgun . kernel32 . HeapFree ( handle , 0 , buffer )
105
216
ret
106
217
end
107
218
108
- end
219
+ it "Should support reading memory" do
220
+ ret = true
221
+ result = session . railgun . kernel32 . GetModuleHandleA ( 'kernel32' )
222
+ ret &&= result [ 'GetLastError' ] == 0
223
+ ret &&= result [ 'return' ] != 0
224
+ return false unless ret
109
225
226
+ handle = result [ 'return' ]
227
+ mz_header = session . railgun . memread ( handle , 4 )
228
+ ret &&= mz_header == "MZ\x90 \x00 "
229
+ end
230
+ end
110
231
end
111
-
112
-
0 commit comments