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


429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb', line 429

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