Skip to content

Commit dafb56f

Browse files
committed
Merge branch 'dmaloney-r7-findpids' into rapid7
[Closes rapid7#950]
2 parents 12de87e + 4f9385a commit dafb56f

File tree

1 file changed

+66
-1
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi

1 file changed

+66
-1
lines changed

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

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ class Console::CommandDispatcher::Stdapi::Sys
4343
"-t" => [ true, "The registry value type (E.g. REG_SZ)." ],
4444
"-v" => [ true, "The registry value name (E.g. Stuff)." ],
4545
"-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" ])
4754

4855
#
4956
# List of supported commands.
@@ -274,6 +281,54 @@ def cmd_kill(*args)
274281
#
275282
def cmd_ps(*args)
276283
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
277332
if (processes.length == 0)
278333
print_line("No running processes were found.")
279334
else
@@ -284,6 +339,15 @@ def cmd_ps(*args)
284339
return true
285340
end
286341

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+
287351
#
288352
# Reboots the remote computer.
289353
#
@@ -595,6 +659,7 @@ def cmd_shutdown(*args)
595659
client.sys.power.shutdown
596660
end
597661

662+
598663
end
599664

600665
end

0 commit comments

Comments
 (0)