Skip to content

Commit 762427b

Browse files
author
RageLtMan
committed
Clean up cmd_ps table output for Mettle
Mettle can run in all sorts of environments where some colums of a process table will be nil. The existing implementation compacts rows going into the table while providing filtering for the colum contents only by checking the output of the first row in the proc table. Check column filters against all rows to ensure proper table init. Check columns going into table for match against header. Do not compact nil values in the table rows - some things, like kthreads/workers dont have a path while other PIDs will.
1 parent bf67426 commit 762427b

File tree

1 file changed

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

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ def to_table(opts={})
395395
# ppid. Cut columns from the list if they aren't there. It is conceivable
396396
# that processes might have different columns, but for now assume that the
397397
# first one is representative.
398-
cols.delete_if { |c| !( first.has_key?(c.downcase) ) or first[c.downcase].nil? }
398+
cols.delete_if do |c|
399+
!(any? {|r| r.has_key?(c.downcase)}) or
400+
all? {|r| r[c.downcase].nil?}
401+
end
399402

400403
opts = {
401404
'Header' => 'Process List',
@@ -406,14 +409,15 @@ def to_table(opts={})
406409
tbl = Rex::Text::Table.new(opts)
407410
each { |process|
408411
tbl << cols.map { |c|
412+
next unless cols.any? {|h| h.downcase == c.downcase}
409413
col = c.downcase
410414
val = process[col]
411415
if col == 'session'
412416
val == 0xFFFFFFFF ? '' : val.to_s
413417
else
414418
val
415419
end
416-
}.compact
420+
}
417421
}
418422

419423
tbl

0 commit comments

Comments
 (0)