@@ -45,6 +45,10 @@ class Console::CommandDispatcher::Stdapi::Sys
45
45
"-r" => [ true , "The remote machine name to connect to (with current process credentials" ] ,
46
46
"-w" => [ false , "Set KEY_WOW64 flag, valid values [32|64]." ] )
47
47
48
+ @@ps_opts = Rex ::Parser ::Arguments . new (
49
+ "-h" => [ false , "Help menu." ] ,
50
+ "-S" => [ true , "RegEx term(s) to filter results with " ] )
51
+
48
52
#
49
53
# List of supported commands.
50
54
#
@@ -58,7 +62,6 @@ def commands
58
62
"getuid" => "Get the user that the server is running as" ,
59
63
"kill" => "Terminate a process" ,
60
64
"ps" => "List running processes" ,
61
- "findpids" => "Find Processes by name" ,
62
65
"reboot" => "Reboots the remote computer" ,
63
66
"reg" => "Modify and interact with the remote registry" ,
64
67
"rev2self" => "Calls RevertToSelf() on the remote machine" ,
@@ -76,7 +79,6 @@ def commands
76
79
"getuid" => [ "stdapi_sys_config_getuid" ] ,
77
80
"kill" => [ "stdapi_sys_process_kill" ] ,
78
81
"ps" => [ "stdapi_sys_process_get_processes" ] ,
79
- "findpids" => [ "stdapi_sys_process_get_processes" ] ,
80
82
"reboot" => [ "stdapi_sys_power_exitwindows" ] ,
81
83
"reg" => [
82
84
"stdapi_registry_load_key" ,
@@ -276,6 +278,24 @@ def cmd_kill(*args)
276
278
#
277
279
def cmd_ps ( *args )
278
280
processes = client . sys . process . get_processes
281
+ @@ps_opts . parse ( args ) do |opt , idx , val |
282
+ case opt
283
+ when "-h"
284
+ cmd_ps_help
285
+ return true
286
+ when "-S"
287
+ print_line "Performing Search..."
288
+ searched_procs = Rex ::Post ::Meterpreter ::Extensions ::Stdapi ::Sys ::ProcessList . new
289
+ processes . each do |proc |
290
+ if val . nil? or val . empty?
291
+ print_line "You must supply a search term!"
292
+ return false
293
+ end
294
+ searched_procs << proc if proc [ "name" ] . match ( /#{ val } / )
295
+ end
296
+ processes = searched_procs
297
+ end
298
+ end
279
299
if ( processes . length == 0 )
280
300
print_line ( "No running processes were found." )
281
301
else
@@ -286,40 +306,14 @@ def cmd_ps(*args)
286
306
return true
287
307
end
288
308
289
- def cmd_findpids ( *args )
290
- if args . empty? or args . include? "-h"
291
- cmd_findpids_help
292
- return true
293
- end
294
- processes = client . sys . process . get_processes
295
- if ( processes . length == 0 )
296
- print_line ( "No running processes were found." )
297
- else
298
- searched_procs = Rex ::Post ::Meterpreter ::Extensions ::Stdapi ::Sys ::ProcessList . new
299
- processes . each do |proc |
300
- args . each do |arg |
301
- if proc [ "name" ] . match ( /#{ arg } / )
302
- searched_procs << proc
303
- break
304
- end
305
- end
306
- end
307
- searched_procs . compact!
308
- if searched_procs . length == 0
309
- print_line ( "No running processes were found matching the supplied names." )
310
- else
311
- print_line
312
- print_line ( searched_procs . to_table ( "Indent" => 1 ) . to_s )
313
- print_line
314
- end
315
- end
316
- return true
317
- end
318
-
319
- def cmd_findpids_help
320
- print_line "You must supply one or more process name to search for"
321
- print_line "e.g. findpids explorer.exe notepad.exe"
322
- print_line "You may also pass Regular Expressions: findpids *.svc.* *.dll.*"
309
+ def cmd_ps_help
310
+ print_line "Use the command with no arguments to see all running processes."
311
+ print_line "You may supply a search term to filter the results:"
312
+ print_line "\t ps -S explorer.exe"
313
+ print_line "\t Would return any processes named explorer.exe"
314
+ print_line "You may also pass Regular Expressions:"
315
+ print_line "\t ps -S *.svc.* "
316
+ print_line "Would return any processes with 'svc' in the name"
323
317
end
324
318
325
319
#
0 commit comments