Class: Rex::Post::Meterpreter::Extensions::Stdapi::Sys::ProcessList

Inherits:
Array
  • Object
show all
Defined in:
lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb

Overview

Simple wrapper class for storing processes

Instance Method Summary collapse

Instance Method Details

#to_table(opts = {}) ⇒ Object

Create a Rex::Text::Table out of the processes stored in this list

opts is passed on to Rex::Text::Table.new, mostly unmolested

Note that this output is affected by Rex::Post::Meterpreter::Client#unicode_filter_encode


398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb', line 398

def to_table(opts={})
  if empty?
    return Rex::Text::Table.new(opts)
  end

  column_headers = [ "PID", "PPID", "Name", "Arch", "Session", "User", "Path" ]
  column_headers.delete_if do |h|
    none? { |process| process.has_key?(h.downcase) } ||
    all? { |process| process[h.downcase].nil? }
  end

  opts = {
    'Header' => 'Process List',
    'Indent' => 1,
    'Columns' => column_headers
  }.merge(opts)

  tbl = Rex::Text::Table.new(opts)
  each do |process|
    tbl << column_headers.map do |header|
      col = header.downcase
      next unless process.keys.any? { |process_header| process_header == col }
      val = process[col]
      if col == 'session'
        val == 0xFFFFFFFF ? '' : val.to_s
      else
        val
      end
    end
  end

  tbl
end