@@ -43,7 +43,14 @@ class Console::CommandDispatcher::Stdapi::Sys
43
43
"-t" => [ true , "The registry value type (E.g. REG_SZ)." ] ,
44
44
"-v" => [ true , "The registry value name (E.g. Stuff)." ] ,
45
45
"-r" => [ true , "The remote machine name to connect to (with current process credentials" ] ,
46
- "-w" => [ false , "Set KEY_WOW64 flag, valid values [32|64]." ] )
46
+ "-w" => [ false , "Set KEY_WOW64 flag, valid values [32|64]." ] )
47
+
48
+ @@ps_opts = Rex ::Parser ::Arguments . new (
49
+ "-h" => [ false , "Help menu." ] ,
50
+ "-S" => [ true , "Filters processes on the process name using the supplied RegEx" ] ,
51
+ "-A" => [ true , "Filters processes on architecture (x86 or x86_64)" ] ,
52
+ "-s" => [ false , "Show only SYSTEM processes" ] ,
53
+ "-U" => [ true , "Filters processes on the user using the supplied RegEx" ] )
47
54
48
55
#
49
56
# List of supported commands.
@@ -274,6 +281,54 @@ def cmd_kill(*args)
274
281
#
275
282
def cmd_ps ( *args )
276
283
processes = client . sys . process . get_processes
284
+ @@ps_opts . parse ( args ) do |opt , idx , val |
285
+ case opt
286
+ when "-h"
287
+ cmd_ps_help
288
+ return true
289
+ when "-S"
290
+ print_line "Filtering on process name..."
291
+ searched_procs = Rex ::Post ::Meterpreter ::Extensions ::Stdapi ::Sys ::ProcessList . new
292
+ processes . each do |proc |
293
+ if val . nil? or val . empty?
294
+ print_line "You must supply a search term!"
295
+ return false
296
+ end
297
+ searched_procs << proc if proc [ "name" ] . match ( /#{ val } / )
298
+ end
299
+ processes = searched_procs
300
+ when "-A"
301
+ print_line "Filtering on arch..."
302
+ searched_procs = Rex ::Post ::Meterpreter ::Extensions ::Stdapi ::Sys ::ProcessList . new
303
+ processes . each do |proc |
304
+ next if proc [ 'arch' ] . nil? or proc [ 'arch' ] . empty?
305
+ if val . nil? or val . empty? or !( val == "x86" or val == "x86_64" )
306
+ print_line "You must select either x86 or x86_64"
307
+ return false
308
+ end
309
+ searched_procs << proc if proc [ "arch" ] == val
310
+ end
311
+ processes = searched_procs
312
+ when "-s"
313
+ print_line "Filtering on SYSTEM processes..."
314
+ searched_procs = Rex ::Post ::Meterpreter ::Extensions ::Stdapi ::Sys ::ProcessList . new
315
+ processes . each do |proc |
316
+ searched_procs << proc if proc [ "user" ] == "NT AUTHORITY\\ SYSTEM"
317
+ end
318
+ processes = searched_procs
319
+ when "-U"
320
+ print_line "Filtering on user name..."
321
+ searched_procs = Rex ::Post ::Meterpreter ::Extensions ::Stdapi ::Sys ::ProcessList . new
322
+ processes . each do |proc |
323
+ if val . nil? or val . empty?
324
+ print_line "You must supply a search term!"
325
+ return false
326
+ end
327
+ searched_procs << proc if proc [ "user" ] . match ( /#{ val } / )
328
+ end
329
+ processes = searched_procs
330
+ end
331
+ end
277
332
if ( processes . length == 0 )
278
333
print_line ( "No running processes were found." )
279
334
else
@@ -284,6 +339,15 @@ def cmd_ps(*args)
284
339
return true
285
340
end
286
341
342
+ def cmd_ps_help
343
+ print_line "Use the command with no arguments to see all running processes."
344
+ print_line "The following options can be used to filter those results:"
345
+
346
+ print_line @@ps_opts . usage
347
+ end
348
+
349
+
350
+
287
351
#
288
352
# Reboots the remote computer.
289
353
#
@@ -595,6 +659,7 @@ def cmd_shutdown(*args)
595
659
client . sys . power . shutdown
596
660
end
597
661
662
+
598
663
end
599
664
600
665
end
0 commit comments