Skip to content

Commit 6a8d54a

Browse files
committed
Land rapid7#8545, ps table output fixes
2 parents 04f0a55 + 283f36f commit 6a8d54a

File tree

1 file changed

+12
-12
lines changed
  • lib/rex/post/meterpreter/extensions/stdapi/sys

1 file changed

+12
-12
lines changed

lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,31 +390,31 @@ def to_table(opts={})
390390
return Rex::Text::Table.new(opts)
391391
end
392392

393-
cols = [ "PID", "PPID", "Name", "Arch", "Session", "User", "Path" ]
394-
# Arch and Session are specific to native Windows, PHP and Java can't do
395-
# ppid. Cut columns from the list if they aren't there. It is conceivable
396-
# that processes might have different columns, but for now assume that the
397-
# first one is representative.
398-
cols.delete_if { |c| !( first.has_key?(c.downcase) ) or first[c.downcase].nil? }
393+
column_headers = [ "PID", "PPID", "Name", "Arch", "Session", "User", "Path" ]
394+
column_headers.delete_if do |h|
395+
none? { |process| process.has_key?(h.downcase) } ||
396+
all? { |process| process[h.downcase].nil? }
397+
end
399398

400399
opts = {
401400
'Header' => 'Process List',
402401
'Indent' => 1,
403-
'Columns' => cols
402+
'Columns' => column_headers
404403
}.merge(opts)
405404

406405
tbl = Rex::Text::Table.new(opts)
407-
each { |process|
408-
tbl << cols.map { |c|
409-
col = c.downcase
406+
each do |process|
407+
tbl << column_headers.map do |header|
408+
col = header.downcase
409+
next unless process.keys.any? { |process_header| process_header == col }
410410
val = process[col]
411411
if col == 'session'
412412
val == 0xFFFFFFFF ? '' : val.to_s
413413
else
414414
val
415415
end
416-
}.compact
417-
}
416+
end
417+
end
418418

419419
tbl
420420
end

0 commit comments

Comments
 (0)