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



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb', line 481

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