From dd6e75986d51d50ca53e0e32a4324fea807b69e6 Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Thu, 16 Mar 2017 23:48:39 -0500 Subject: [PATCH] add -l and -f flag simulation for pgrep, XXX rex handles flag opts poorly --- .../ui/console/command_dispatcher/stdapi/sys.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb index 35c3e598fd..189cdc8596 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb @@ -421,9 +421,20 @@ class Console::CommandDispatcher::Stdapi::Sys return true end - pids = processes.collect { |p| p['pid'] } - pids.each do | pid | - print_line(pid.to_s) + # XXX fix Rex parser to properly handle adjacent short flags + f_flag = args.include?('-f') || args.include?('-lf') || args.include?('-fl') + l_flag = args.include?('-l') || args.include?('-lf') || args.include?('-fl') + + processes.each do |p| + if l_flag + if f_flag + print_line("#{p['pid']} #{p['path']}") + else + print_line("#{p['pid']} #{p['name']}") + end + else + print_line("#{p['pid']}") + end end true end