Class: Msf::Plugin::Wiki

Inherits:
Msf::Plugin show all
Defined in:
plugins/wiki.rb

Overview

This plugin extends the Rex::Text::Table class and provides commands that output database information for the current workspace in a wiki friendly format

Author:

  • Trenton Ivey

    • email: (“[email protected]”).gsub(/example/,“gmail”)

    • github: kn0

    • twitter: trentonivey

Defined Under Namespace

Classes: WikiCommandDispatcher

Instance Attribute Summary

Attributes inherited from Msf::Plugin

#opts

Attributes included from Framework::Offspring

#framework

Instance Method Summary collapse

Methods inherited from Msf::Plugin

#add_console_dispatcher, create, #flush, #input, #output, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #remove_console_dispatcher

Constructor Details

#initialize(framework, opts) ⇒ Wiki

Constructs a new instance of the plugin and registers the console dispatcher. It also extends Rex by adding the following methods:

* Rex::Text::Table.to_dokuwiki
* Rex::Text::Table.to_mediawiki


444
445
446
447
448
449
450
451
452
453
# File 'plugins/wiki.rb', line 444

def initialize(framework, opts)
  super

  # Extend Rex::Text::Table class so it can output wiki formats
  add_dokuwiki_to_rex
  add_mediawiki_to_rex

  # Add the console dispatcher
  add_console_dispatcher(WikiCommandDispatcher)
end

Instance Method Details

#add_dokuwiki_to_rexObject

Extends Rex tables to be able to create Dokuwiki tables



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'plugins/wiki.rb', line 490

def add_dokuwiki_to_rex
  Rex::Text::Table.class_eval do
    def to_dokuwiki
      str = prefix.dup
      # Print the header if there is one. Use headeri to determine wiki paragraph level
      if header
        level = '=' * headeri
        str << level + header + level + "\n"
      end
      # Add the column names to the top of the table
      columns.each do |col|
        str << '^ ' + col.to_s + ' '
      end
      str << "^\n" unless columns.count.eql? 0
      # Fill out the rest of the table with rows
      rows.each do |row|
        row.each do |val|
          cell = val.to_s
          cell = "<nowiki>#{cell}</nowiki>" if cell.include? '|'
          str << '| ' + cell + ' '
        end
        str << "|\n" unless rows.count.eql? 0
      end
      return str
    end
  end
end

#add_mediawiki_to_rexObject

Extends Rex tables to be able to create Mediawiki tables



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'plugins/wiki.rb', line 521

def add_mediawiki_to_rex
  Rex::Text::Table.class_eval do
    def to_mediawiki
      str = prefix.dup
      # Print the header if there is one. Use headeri to determine wiki
      # headline level. Mediawiki does headlines a bit backwards so that
      # the header level isn't limited. This results in the need to 'flip'
      # the headline length to standardize it.
      if header
        if headeri <= 6
          level = '=' * (-headeri + 7)
          str << "#{level} #{header} #{level}"
        else
          str << header.to_s
        end
        str << "\n"
      end
      # Setup the table with some standard formatting options
      str << "{|class=\"wikitable\"\n"
      # Output formated column names as the first row
      unless columns.count.eql? 0
        str << '!'
        str << columns.join('!!')
        str << "\n"
      end
      # Add the rows to the table
      unless rows.count.eql? 0
        rows.each do |row|
          str << "|-\n|"
          # Try and prevent formatting tags from causing problems
          bad = ['&', '<', '>', '"', "'", '/']
          r = row.join('|| ')
          r.each_char do |c|
            if bad.include? c
              str << Rex::Text.html_encode(c)
            else
              str << c
            end
          end
          str << "\n"
        end
      end
      # Finish up the table
      str << '|}'
      return str
    end
  end
end

#cleanupObject

The cleanup routine removes the methods added to Rex by the plugin initialization and then removes the console dispatcher



459
460
461
462
463
464
465
# File 'plugins/wiki.rb', line 459

def cleanup
  # Cleanup methods added to Rex::Text::Table
  Rex::Text::Table.class_eval { undef :to_dokuwiki }
  Rex::Text::Table.class_eval { undef :to_mediawiki }
  # Deregister the console dispatcher
  remove_console_dispatcher('Wiki')
end

#descObject

This method returns a brief description of the plugin. It should be no more than 60 characters, but there are no hard limits.



478
479
480
# File 'plugins/wiki.rb', line 478

def desc
  'Outputs stored database values from the current workspace into DokuWiki or MediaWiki format'
end

#nameObject

Returns the plugin’s name.



470
471
472
# File 'plugins/wiki.rb', line 470

def name
  'wiki'
end