Skip to content

Commit f906aa3

Browse files
David MaloneyDavid Maloney
authored andcommitted
Adds a new findpids command to meterpreter
findpids calls client.sys.process.get_processes like ps but then filters out any processes that do not match one of the process names supplied as arguments to the command. `findpids explorer.exe notepad.exe` will return all processes named explorer.exe or notepad.exe Allows for quick searching for the pid you want. ideal for migration
1 parent a07f521 commit f906aa3

File tree

1 file changed

+30
-0
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi

1 file changed

+30
-0
lines changed

lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def commands
5858
"getuid" => "Get the user that the server is running as",
5959
"kill" => "Terminate a process",
6060
"ps" => "List running processes",
61+
"findpids" => "Find Processes by name",
6162
"reboot" => "Reboots the remote computer",
6263
"reg" => "Modify and interact with the remote registry",
6364
"rev2self" => "Calls RevertToSelf() on the remote machine",
@@ -75,6 +76,7 @@ def commands
7576
"getuid" => [ "stdapi_sys_config_getuid" ],
7677
"kill" => [ "stdapi_sys_process_kill" ],
7778
"ps" => [ "stdapi_sys_process_get_processes" ],
79+
"findpids" => [ "stdapi_sys_process_get_processes" ],
7880
"reboot" => [ "stdapi_sys_power_exitwindows" ],
7981
"reg" => [
8082
"stdapi_registry_load_key",
@@ -284,6 +286,34 @@ def cmd_ps(*args)
284286
return true
285287
end
286288

289+
def cmd_findpids(*args)
290+
if args.empty? or args.include? "-h"
291+
print_line "You must supply one or more process name to search for"
292+
print_line "e.g. findpids explorer.exe notepad.exe"
293+
return true
294+
end
295+
processes = client.sys.process.get_processes
296+
if (processes.length == 0)
297+
print_line("No running processes were found.")
298+
else
299+
searched_procs = Rex::Post::Meterpreter::Extensions::Stdapi::Sys::ProcessList.new
300+
processes.each do |proc|
301+
if args.include? proc["name"]
302+
searched_procs << proc
303+
end
304+
end
305+
searched_procs.compact!
306+
if searched_procs.length == 0
307+
print_line("No running processes were found matching the supplied names.")
308+
else
309+
print_line
310+
print_line(searched_procs.to_table("Indent" => 1).to_s)
311+
print_line
312+
end
313+
end
314+
return true
315+
end
316+
287317
#
288318
# Reboots the remote computer.
289319
#

0 commit comments

Comments
 (0)