@@ -83,6 +83,8 @@ def commands
83
83
if client . passive_service && client . sock . type? == 'tcp-ssl'
84
84
c [ 'ssl_verify' ] = 'Modify the SSL certificate verification setting'
85
85
end
86
+
87
+ c [ 'pivot' ] = 'Manage pivot listeners'
86
88
end
87
89
88
90
if client . platform == 'windows' || client . platform == 'linux'
@@ -119,6 +121,151 @@ def name
119
121
'Core'
120
122
end
121
123
124
+ @@pivot_opts = Rex ::Parser ::Arguments . new (
125
+ '-t' => [ true , 'Pivot listener type' ] ,
126
+ '-i' => [ true , 'Identifier of the pivot to remove' ] ,
127
+ '-l' => [ true , 'Host address to bind to (if applicable)' ] ,
128
+ '-n' => [ true , 'Name of the listener entity (if applicable)' ] ,
129
+ '-a' => [ true , 'Architecture of the stage to generate' ] ,
130
+ '-p' => [ true , 'Platform of the stage to generate' ] ,
131
+ '-h' => [ false , 'View help' ]
132
+ )
133
+
134
+ @@pivot_supported_archs = [ ARCH_X64 , ARCH_X86 ]
135
+ @@pivot_supported_platforms = [ 'windows' ]
136
+
137
+ def cmd_pivot_help
138
+ print_line ( 'Usage: pivot <list|add|remove> [options]' )
139
+ print_line
140
+ print_line ( 'Manage pivot listeners on the target.' )
141
+ print_line
142
+ print_line ( @@pivot_opts . usage )
143
+ print_line
144
+ print_line ( 'Supported pivot types:' )
145
+ print_line ( ' - pipe (using named pipes over SMB)' )
146
+ print_line ( 'Supported arhiectures:' )
147
+ @@pivot_supported_archs . each do |a |
148
+ print_line ( ' - ' + a )
149
+ end
150
+ print_line ( 'Supported platforms:' )
151
+ print_line ( ' - windows' )
152
+ print_line
153
+ print_line ( "eg. pivot add -t pipe -l 192.168.0.1 -n msf-pipe -a #{ @@pivot_supported_archs . first } -p windows" )
154
+ print_line ( " pivot list" )
155
+ print_line ( " pivot remove -i 1" )
156
+ print_line
157
+ end
158
+
159
+ def cmd_pivot ( *args )
160
+ if args . length == 0 || args . include? ( '-h' )
161
+ cmd_pivot_help
162
+ return true
163
+ end
164
+
165
+ opts = { }
166
+ @@pivot_opts . parse ( args ) { |opt , idx , val |
167
+ case opt
168
+ when '-t'
169
+ opts [ :type ] = val
170
+ when '-i'
171
+ opts [ :guid ] = val
172
+ when '-l'
173
+ opts [ :lhost ] = val
174
+ when '-n'
175
+ opts [ :name ] = val
176
+ when '-a'
177
+ opts [ :arch ] = val
178
+ when '-p'
179
+ opts [ :platform ] = val
180
+ end
181
+ }
182
+
183
+ # first parameter is the command
184
+ case args [ 0 ]
185
+ when 'remove' , 'del' , 'delete' , 'rm'
186
+ unless opts [ :guid ]
187
+ print_error ( 'Pivot listener ID must be specified (-i)' )
188
+ return false
189
+ end
190
+
191
+ unless opts [ :guid ] =~ /^[0-9a-f]{32}/i && opts [ :guid ] . length == 32
192
+ print_error ( "Invalid pivot listener ID: #{ opts [ :guid ] } " )
193
+ return false
194
+ end
195
+
196
+ listener_id = [ opts [ :guid ] ] . pack ( 'H*' )
197
+ unless client . find_pivot_listener ( listener_id )
198
+ print_error ( "Unknown pivot listener ID: #{ opts [ :guid ] } " )
199
+ return false
200
+ end
201
+
202
+ Pivot . remove_listener ( client , listener_id )
203
+ print_good ( "Successfully removed pivot: #{ opts [ :guid ] } " )
204
+ when 'list' , 'show' , 'print'
205
+ tbl = Rex ::Text ::Table . new (
206
+ 'Header' => 'Currently active pivot listeners' ,
207
+ 'Indent' => 4 ,
208
+ 'Columns' => [ 'Id' , 'Detail' ] )
209
+
210
+ client . pivot_listeners . each do |k , v |
211
+ tbl << v . to_row
212
+ end
213
+ print_line ( "\n #{ tbl } \n " )
214
+ when 'add'
215
+ unless opts [ :type ]
216
+ print_error ( 'Pivot type must be specified (-t)' )
217
+ return false
218
+ end
219
+
220
+ unless opts [ :arch ]
221
+ print_error ( 'Architecture must be specified (-a)' )
222
+ return false
223
+ end
224
+ unless @@pivot_supported_archs . include? ( opts [ :arch ] )
225
+ print_error ( "Unknown or unsupported architecture: #{ opts [ :arch ] } " )
226
+ return false
227
+ end
228
+
229
+ unless opts [ :platform ]
230
+ print_error ( 'Platform must be specified (-p)' )
231
+ return false
232
+ end
233
+ unless @@pivot_supported_platforms . include? ( opts [ :platform ] )
234
+ print_error ( "Unknown or unsupported platform: #{ opts [ :platform ] } " )
235
+ return false
236
+ end
237
+
238
+ # currently only one pivot type supported, more to come we hope
239
+ case opts [ :type ]
240
+ when 'pipe'
241
+ pivot_add_named_pipe ( opts )
242
+ else
243
+ print_error ( "Unknown pivot type: #{ opts [ :type ] } " )
244
+ return false
245
+ end
246
+ else
247
+ print_error ( "Unknown command: #{ args [ 0 ] } " )
248
+ end
249
+ end
250
+
251
+ def pivot_add_named_pipe ( opts )
252
+ unless opts [ :lhost ]
253
+ print_error ( 'Pipe host must be specified (-l)' )
254
+ return false
255
+ end
256
+
257
+ unless opts [ :name ]
258
+ print_error ( 'Pipe name must be specified (-n)' )
259
+ return false
260
+ end
261
+
262
+ # reconfigure the opts so that they can be passed to the setup function
263
+ opts [ :pipe_host ] = opts [ :lhost ]
264
+ opts [ :pipe_name ] = opts [ :name ]
265
+ Pivot . create_named_pipe_listener ( client , opts )
266
+ print_good ( "Successfully created #{ opts [ :type ] } pivot." )
267
+ end
268
+
122
269
def cmd_sessions_help
123
270
print_line ( 'Usage: sessions <id>' )
124
271
print_line
0 commit comments