Class: Msf::Module

Inherits:
Object
  • Object
show all
Extended by:
Framework::Offspring
Includes:
Rex::Ui::Subscriber
Defined in:
lib/msf/core/module.rb

Overview

The module base class is responsible for providing the common interface that is used to interact with modules at the most basic levels, such as by inspecting a given module's attributes (name, dsecription, version, authors, etc) and by managing the module's data store.

Direct Known Subclasses

Auxiliary, Encoder, Exploit, Nop, Payload, Post

Defined Under Namespace

Modules: Deprecated, Failure, HasActions Classes: Author, AuxiliaryAction, Platform, PlatformList, Reference, SiteReference, Target

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes included from Rex::Ui::Subscriber::Input

#user_input

Attributes included from Rex::Ui::Subscriber::Output

#user_output

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Rex::Ui::Subscriber

#copy_ui, #init_ui, #reset_ui

Methods included from Rex::Ui::Subscriber::Input

#gets

Methods included from Rex::Ui::Subscriber::Output

#flush, #print, #print_debug

Constructor Details

#initialize(info = {}) ⇒ Module

Creates an instance of an abstract module using the supplied information hash.


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/msf/core/module.rb', line 113

def initialize(info = {})
  @module_info_copy = info.dup

  self.module_info = info
  generate_uuid

  set_defaults

  # Initialize module compatibility hashes
  init_compat

  # Fixup module fields as needed
  info_fixups

  # Transform some of the fields to arrays as necessary
  self.author = Author.transform(module_info['Author'])
  self.arch = Rex::Transformer.transform(module_info['Arch'], Array, [ String ], 'Arch')
  self.platform = PlatformList.transform(module_info['Platform'])
  self.references = Rex::Transformer.transform(module_info['References'], Array, [ SiteReference, Reference ], 'Ref')

  # Create and initialize the option container for this module
  self.options = OptionContainer.new
  self.options.add_options(info['Options'], self.class)
  self.options.add_advanced_options(info['AdvancedOptions'], self.class)
  self.options.add_evasion_options(info['EvasionOptions'], self.class)

  # Create and initialize the data store for this module
  self.datastore = ModuleDataStore.new(self)

  # Import default options into the datastore
  import_defaults

  self.privileged = module_info['Privileged'] || false
  self.license = module_info['License'] || MSF_LICENSE

  # Allow all modules to track their current workspace
  register_advanced_options(
    [
      OptString.new('WORKSPACE', [ false, "Specify the workspace for this module" ]),
      OptBool.new('VERBOSE',     [ false, 'Enable detailed status messages', false ])
    ], Msf::Module)

end

Class Attribute Details

.file_pathObject

The path from which the module was loaded.


80
81
82
# File 'lib/msf/core/module.rb', line 80

def file_path
  @file_path
end

.orig_clsObject

This attribute holds the non-duplicated copy of the module implementation. This attribute is used for reloading purposes so that it can be re-duplicated.


75
76
77
# File 'lib/msf/core/module.rb', line 75

def orig_cls
  @orig_cls
end

.refnameObject

The module's name that is assigned it it by the framework or derived from the path that the module is loaded from.


68
69
70
# File 'lib/msf/core/module.rb', line 68

def refname
  @refname
end

Instance Attribute Details

#archObject

The array of zero or more architectures.


896
897
898
# File 'lib/msf/core/module.rb', line 896

def arch
  @arch
end

#authorObject

The array of zero or more authors.


892
893
894
# File 'lib/msf/core/module.rb', line 892

def author
  @author
end

#datastoreObject

The module-specific datastore instance.


908
909
910
# File 'lib/msf/core/module.rb', line 908

def datastore
  @datastore
end

#errorObject

The last exception to occur using this module


935
936
937
# File 'lib/msf/core/module.rb', line 935

def error
  @error
end

#job_idObject

The job identifier that this module is running as, if any.


925
926
927
# File 'lib/msf/core/module.rb', line 925

def job_id
  @job_id
end

#licenseObject

The license under which this module is provided.


920
921
922
# File 'lib/msf/core/module.rb', line 920

def license
  @license
end

#module_storeObject

A generic hash used for passing additional information to modules


930
931
932
# File 'lib/msf/core/module.rb', line 930

def module_store
  @module_store
end

#optionsObject

The module-specific options.


912
913
914
# File 'lib/msf/core/module.rb', line 912

def options
  @options
end

#platformObject

The array of zero or more platforms.


900
901
902
# File 'lib/msf/core/module.rb', line 900

def platform
  @platform
end

#privilegedObject

Whether or not this module requires privileged access.


916
917
918
# File 'lib/msf/core/module.rb', line 916

def privileged
  @privileged
end

#referencesObject

The reference count for the module.


904
905
906
# File 'lib/msf/core/module.rb', line 904

def references
  @references
end

#uuidObject

A unique identifier for this module instance


940
941
942
# File 'lib/msf/core/module.rb', line 940

def uuid
  @uuid
end

Class Method Details

.cached?Boolean

Returns false since this is the real module


871
872
873
# File 'lib/msf/core/module.rb', line 871

def self.cached?
  false
end

.fullnameObject


36
37
38
# File 'lib/msf/core/module.rb', line 36

def fullname
  return type + '/' + refname
end

.is_usableObject

This method allows modules to tell the framework if they are usable on the system that they are being loaded on in a generic fashion. By default, all modules are indicated as being usable. An example of where this is useful is if the module depends on something external to ruby, such as a binary.


97
98
99
# File 'lib/msf/core/module.rb', line 97

def self.is_usable
  true
end

.rankObject

Returns this module's ranking.


47
48
49
# File 'lib/msf/core/module.rb', line 47

def rank
  (const_defined?('Rank')) ? const_get('Rank') : NormalRanking
end

.rank_to_hObject

Returns this module's ranking as a string for display.


61
62
63
# File 'lib/msf/core/module.rb', line 61

def rank_to_h
  rank_to_s.gsub('Rank', '').downcase
end

.rank_to_sObject

Returns this module's ranking as a string representation.


54
55
56
# File 'lib/msf/core/module.rb', line 54

def rank_to_s
  RankingName[rank]
end

.shortnameObject


40
41
42
# File 'lib/msf/core/module.rb', line 40

def shortname
  return refname.split('/')[-1]
end

.typeObject

Class method to figure out what type of module this is

Raises:

  • (NotImplementedError)

32
33
34
# File 'lib/msf/core/module.rb', line 32

def type
  raise NotImplementedError
end

Instance Method Details

#[](k) ⇒ Object

Read a value from the module store


878
879
880
# File 'lib/msf/core/module.rb', line 878

def [](k)
  self.module_store[k]
end

#[]=(k, v) ⇒ Object

Store a value into the module


885
886
887
# File 'lib/msf/core/module.rb', line 885

def []=(k,v)
  self.module_store[k] = v
end

#aliasObject

Returns the module's alias, if it has one. Otherwise, the module's name is returned.


330
331
332
# File 'lib/msf/core/module.rb', line 330

def alias
  module_info['Alias']
end

#arch?(what) ⇒ Boolean

Return whether or not the module supports the supplied architecture.


546
547
548
549
550
# File 'lib/msf/core/module.rb', line 546

def arch?(what)
  return true if (what == ARCH_ANY)

  return arch.index(what) != nil
end

#arch_to_sObject

Return a comma separated list of supported architectures, if any.


532
533
534
# File 'lib/msf/core/module.rb', line 532

def arch_to_s
  return arch.join(", ")
end

#author_to_sObject

Return a comma separated list of author for this module.


518
519
520
# File 'lib/msf/core/module.rb', line 518

def author_to_s
  return author.collect { |author| author.to_s }.join(", ")
end

#auxiliary?Boolean

Returns true if this module is an auxiliary module.


857
858
859
# File 'lib/msf/core/module.rb', line 857

def auxiliary?
  return (type == MODULE_AUX)
end

#checkObject

Checks to see if the target is vulnerable, returning unsupported if it's not supported.

This method is designed to be overriden by exploit modules.


354
355
356
# File 'lib/msf/core/module.rb', line 354

def check
  Msf::Exploit::CheckCode::Unsupported
end

#commObject

The default communication subsystem for this module. We may need to move this somewhere else.


577
578
579
# File 'lib/msf/core/module.rb', line 577

def comm
  return Rex::Socket::Comm::Local
end

#compatObject

Returns the hash that describes this module's compatibilities.


361
362
363
# File 'lib/msf/core/module.rb', line 361

def compat
  module_info['Compat'] || {}
end

#compatible?(mod) ⇒ Boolean

Returns whether or not this module is compatible with the supplied module.


439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
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
# File 'lib/msf/core/module.rb', line 439

def compatible?(mod)
  ch = nil

  # Invalid module?  Shoot, we can't compare that.
  return true if (mod == nil)

  # Determine which hash to used based on the supplied module type
  if (mod.type == MODULE_ENCODER)
    ch = self.compat['Encoder']
  elsif (mod.type == MODULE_NOP)
    ch = self.compat['Nop']
  elsif (mod.type == MODULE_PAYLOAD)
    ch = self.compat['Payload']
    if self.respond_to?("target") and self.target and self.target['Payload'] and self.target['Payload']['Compat']
      ch = ch.merge(self.target['Payload']['Compat'])
    end
  else
    return true
  end

  # Enumerate each compatibility item in our hash to find out
  # if we're compatible with this sucker.
  ch.each_pair do |k,v|

    # Get the value of the current key from the module, such as
    # the ConnectionType for a stager (ws2ord, for instance).
    mval = mod.module_info[k]

    # Reject a filled compat item on one side, but not the other
    if (v and not mval)
      dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{v}")
      return false
    end

    # Track how many of our values matched the module
    mcnt = 0

    # Values are whitespace separated
    sv = v.split(/\s+/)
    mv = mval.split(/\s+/)

    sv.each do |x|

      dlog("Checking compat [#{mod.refname} with #{self.refname}]: #{x} to #{mv.join(", ")}", 'core', LEV_3)

      # Verify that any negate values are not matched
      if (x[0,1] == '-' and mv.include?(x[1, x.length-1]))
        dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{x}, value was #{mval}", 'core', LEV_1)
        return false
      end

      mcnt += 1 if mv.include?(x)
    end

    # No values matched, reject this module
    if (mcnt == 0)
      dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{v}, value was #{mval}", 'core', LEV_1)
      return false
    end

  end

  dlog("Module #{mod.refname} is compatible with #{self.refname}", "core", LEV_1)


  # If we get here, we're compatible.
  return true
end

#debugging?Boolean

Returns true if this module is being debugged. The debug flag is set by setting datastore to 1|true|yes


620
621
622
# File 'lib/msf/core/module.rb', line 620

def debugging?
  (datastore['DEBUG'] || '') =~ /^(1|t|y)/i
end

#descriptionObject

Return the module's description.


337
338
339
# File 'lib/msf/core/module.rb', line 337

def description
  module_info['Description']
end

#disclosure_dateObject

Returns the disclosure date, if known.


344
345
346
# File 'lib/msf/core/module.rb', line 344

def disclosure_date
  date_str = Date.parse(module_info['DisclosureDate'].to_s) rescue nil
end

#each_arch(&block) ⇒ Object

Enumerate each architecture.


539
540
541
# File 'lib/msf/core/module.rb', line 539

def each_arch(&block)
  arch.each(&block)
end

#each_author(&block) ⇒ Object

Enumerate each author.


525
526
527
# File 'lib/msf/core/module.rb', line 525

def each_author(&block)
  author.each(&block)
end

#encoder?Boolean

Returns true if this module is an encoder module.


843
844
845
# File 'lib/msf/core/module.rb', line 843

def encoder?
  return (type == MODULE_ENCODER)
end

#exploit?Boolean

Returns true if this module is an exploit module.


829
830
831
# File 'lib/msf/core/module.rb', line 829

def exploit?
  return (type == MODULE_EXPLOIT)
end

#fail_with(reason, msg = nil) ⇒ Object

Support fail_with for all module types, allow specific classes to override

Raises:

  • (RuntimeError)

744
745
746
# File 'lib/msf/core/module.rb', line 744

def fail_with(reason, msg=nil)
  raise RuntimeError, "#{reason.to_s}: #{msg}"
end

#file_pathObject

The path to the file in which the module can be loaded from.


315
316
317
# File 'lib/msf/core/module.rb', line 315

def file_path
  self.class.file_path
end

#frameworkObject

Returns the class reference to the framework


86
87
88
# File 'lib/msf/core/module.rb', line 86

def framework
  return self.class.framework
end

#fullnameObject

Returns the module's framework full reference name. This is the short name that end-users work with (refname) plus the type of module prepended. Ex:

payloads/windows/shell/reverse_tcp


259
260
261
# File 'lib/msf/core/module.rb', line 259

def fullname
  return self.class.fullname
end

#import_defaults(clear_datastore = true) ⇒ Object

Imports default options into the module's datastore, optionally clearing all of the values currently set in the datastore.


595
596
597
598
599
600
601
602
603
604
605
# File 'lib/msf/core/module.rb', line 595

def import_defaults(clear_datastore = true)
  # Clear the datastore if the caller asked us to
  self.datastore.clear if clear_datastore

  self.datastore.import_options(self.options, 'self', true)

  # If there are default options, import their values into the datastore
  if (module_info['DefaultOptions'])
    self.datastore.import_options_from_hash(module_info['DefaultOptions'], true, 'self')
  end
end

#nameObject

Return the module's name from the module information hash.


322
323
324
# File 'lib/msf/core/module.rb', line 322

def name
  module_info['Name']
end

#nop?Boolean

Returns true if this module is a nop module.


850
851
852
# File 'lib/msf/core/module.rb', line 850

def nop?
  return (type == MODULE_NOP)
end

#orig_clsObject

Returns the unduplicated class associated with this module.


308
309
310
# File 'lib/msf/core/module.rb', line 308

def orig_cls
  return self.class.orig_cls
end

#ownerObject

Returns the username that instantiated this module, this tries a handful of methods to determine what actual user ran this module.


407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/msf/core/module.rb', line 407

def owner
  # Generic method to configure a module owner
  username = self.datastore['MODULE_OWNER'].to_s.strip

  # Specific method used by the commercial products
  if username.empty?
    username = self.datastore['PROUSER'].to_s.strip
  end

  # Fallback when neither prior method is available, common for msfconsole
  if username.empty?
    username = (ENV['LOGNAME'] || ENV['USERNAME'] || ENV['USER'] || "unknown").to_s.strip
  end

  username
end

#payload?Boolean

Returns true if this module is a payload module.


836
837
838
# File 'lib/msf/core/module.rb', line 836

def payload?
  return (type == MODULE_PAYLOAD)
end

#platform?(what) ⇒ Boolean

Checks to see if this module is compatible with the supplied platform


562
563
564
# File 'lib/msf/core/module.rb', line 562

def platform?(what)
  (platform & what).empty? == false
end

#platform_to_sObject

Return a comma separated list of supported platforms, if any.


555
556
557
# File 'lib/msf/core/module.rb', line 555

def platform_to_s
  return ((platform.all?) ? [ "All" ] : platform.names).join(", ")
end

#post?Boolean

Returns true if this module is an post-exploitation module.


864
865
866
# File 'lib/msf/core/module.rb', line 864

def post?
  return (type == MODULE_POST)
end

202
203
204
# File 'lib/msf/core/module.rb', line 202

def print_error(msg='')
  super(print_prefix + msg)
end

206
207
208
# File 'lib/msf/core/module.rb', line 206

def print_good(msg='')
  super(print_prefix + msg)
end

223
224
225
# File 'lib/msf/core/module.rb', line 223

def print_line(msg='')
  super(print_line_prefix + msg)
end

Overwrite the Subscriber print_line to do custom prefixes


219
220
221
# File 'lib/msf/core/module.rb', line 219

def print_line_prefix
  datastore['CustomPrintPrefix'] || framework.datastore['CustomPrintPrefix'] || ''
end

Overwrite the Subscriber print_(status|error|good) to do time stamps


180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/msf/core/module.rb', line 180

def print_prefix
  if (datastore['TimestampOutput'] =~ /^(t|y|1)/i) || (
    framework && framework.datastore['TimestampOutput'] =~ /^(t|y|1)/i
  )
    prefix = "[#{Time.now.strftime("%Y.%m.%d-%H:%M:%S")}] "

    xn ||= datastore['ExploitNumber']
    xn ||= framework.datastore['ExploitNumber']
    if xn.is_a?(Fixnum)
      prefix << "[%04d] " % xn
    end

    return prefix
  else
    return ''
  end
end

198
199
200
# File 'lib/msf/core/module.rb', line 198

def print_status(msg='')
  super(print_prefix + msg)
end

210
211
212
# File 'lib/msf/core/module.rb', line 210

def print_warning(msg='')
  super(print_prefix + msg)
end

#privileged?Boolean

Returns whether or not the module requires or grants high privileges.


569
570
571
# File 'lib/msf/core/module.rb', line 569

def privileged?
  return (privileged == true)
end

#rankObject

Returns the module's rank.


276
277
278
# File 'lib/msf/core/module.rb', line 276

def rank
  return self.class.rank
end

#rank_to_hObject

Returns the module's rank in display format.


290
291
292
# File 'lib/msf/core/module.rb', line 290

def rank_to_h
  return self.class.rank_to_h
end

#rank_to_sObject

Returns the module's rank in string format.


283
284
285
# File 'lib/msf/core/module.rb', line 283

def rank_to_s
  return self.class.rank_to_s
end

#refnameObject

Returns the module's framework reference name. This is the short name that end-users work with. Ex:

windows/shell/reverse_tcp


269
270
271
# File 'lib/msf/core/module.rb', line 269

def refname
  return self.class.refname
end

#register_parent(ref) ⇒ Object

Scans the parent module reference to populate additional information. This is used to inherit common settings (owner, workspace, parent uuid, etc).


428
429
430
431
432
433
# File 'lib/msf/core/module.rb', line 428

def register_parent(ref)
  self.datastore['WORKSPACE']    = (ref.datastore['WORKSPACE'] ? ref.datastore['WORKSPACE'].dup : nil)
  self.datastore['PROUSER']      = (ref.datastore['PROUSER']   ? ref.datastore['PROUSER'].dup   : nil)
  self.datastore['MODULE_OWNER'] = ref.owner.dup
  self.datastore['ParentUUID']   = ref.uuid.dup
end

#replicantObject

Creates a fresh copy of an instantiated module


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/msf/core/module.rb', line 160

def replicant

  obj = self.class.new
  self.instance_variables.each { |k|
    v = instance_variable_get(k)
    v = v.dup rescue v
    obj.instance_variable_set(k, v)
  }

  obj.datastore    = self.datastore.copy
  obj.user_input   = self.user_input
  obj.user_output  = self.user_output
  obj.module_store = self.module_store.clone
  obj
end

#search_filter(search_string) ⇒ Object

This provides a standard set of search filters for every module. The search terms are in the form of:

{
  "text" => [  [ "include_term1", "include_term2", ...], [ "exclude_term1", "exclude_term2"], ... ],
  "cve" => [  [ "include_term1", "include_term2", ...], [ "exclude_term1", "exclude_term2"], ... ]
}

Returns true on no match, false on match


643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
# File 'lib/msf/core/module.rb', line 643

def search_filter(search_string)
  return false if not search_string

  search_string += " "

  # Split search terms by space, but allow quoted strings
  terms = search_string.split(/\"/).collect{|t| t.strip==t ? t : t.split(' ')}.flatten
  terms.delete('')

  # All terms are either included or excluded
  res = {}

  terms.each do |t|
    f,v = t.split(":", 2)
    if not v
      v = f
      f = 'text'
    end
    next if v.length == 0
    f.downcase!
    v.downcase!
    res[f] ||=[   [],    []   ]
    if v[0,1] == "-"
      next if v.length == 1
      res[f][1] << v[1,v.length-1]
    else
      res[f][0] << v
    end
  end

  k = res

  refs = self.references.map{|x| [x.ctx_id, x.ctx_val].join("-") }
  is_server    = (self.respond_to?(:stance) and self.stance == "aggressive")
  is_client    = (self.respond_to?(:stance) and self.stance == "passive")

  [0,1].each do |mode|
    match = false
    k.keys.each do |t|
      next if k[t][mode].length == 0

      k[t][mode].each do |w|
        # Reset the match flag for each keyword for inclusive search
        match = false if mode == 0

        # Convert into a case-insensitive regex
        r = Regexp.new(Regexp.escape(w), true)

        case t
          when 'text'
            terms = [self.name, self.fullname, self.description] + refs + self.author.map{|x| x.to_s}
            if self.respond_to?(:targets) and self.targets
              terms = terms + self.targets.map{|x| x.name}
            end
            match = [t,w] if terms.any? { |x| x =~ r }
          when 'name'
            match = [t,w] if self.name =~ r
          when 'path'
            match = [t,w] if self.fullname =~ r
          when 'author'
            match = [t,w] if self.author.map{|x| x.to_s}.any? { |a| a =~ r }
          when 'os', 'platform'
            match = [t,w] if self.platform_to_s =~ r or self.arch_to_s =~ r
            if not match and self.respond_to?(:targets) and self.targets
              match = [t,w] if self.targets.map{|x| x.name}.any? { |t| t =~ r }
            end
          when 'port'
            match = [t,w] if self.datastore['RPORT'].to_s =~ r
          when 'type'
            match = [t,w] if Msf::MODULE_TYPES.any? { |modt| w == modt and self.type == modt }
          when 'app'
            match = [t,w] if (w == "server" and is_server)
            match = [t,w] if (w == "client" and is_client)
          when 'cve'
            match = [t,w] if refs.any? { |ref| ref =~ /^cve\-/i and ref =~ r }
          when 'bid'
            match = [t,w] if refs.any? { |ref| ref =~ /^bid\-/i and ref =~ r }
          when 'osvdb'
            match = [t,w] if refs.any? { |ref| ref =~ /^osvdb\-/i and ref =~ r }
          when 'edb'
            match = [t,w] if refs.any? { |ref| ref =~ /^edb\-/i and ref =~ r }
        end
        break if match
      end
      # Filter this module if no matches for a given keyword type
      if mode == 0 and not match
        return true
      end
    end
    # Filter this module if we matched an exclusion keyword (-value)
    if mode == 1 and match
      return true
    end
  end

  false
end

#share_datastore(ds) ⇒ Object

Overrides the class' own datastore with the one supplied. This is used to allow modules to share datastores, such as a payload sharing an exploit module's datastore.


586
587
588
589
# File 'lib/msf/core/module.rb', line 586

def share_datastore(ds)
  self.datastore = ds
  self.datastore.import_options(self.options)
end

#shortnameObject

Returns the module's framework short name. This is a possibly conflicting name used for things like console prompts.

reverse_tcp


301
302
303
# File 'lib/msf/core/module.rb', line 301

def shortname
  return self.class.shortname
end

#support_ipv6?Boolean

Indicates whether the module supports IPv6. This is true by default, but certain modules require additional work to be compatible or are hardcoded in terms of application support and should be skipped.


629
630
631
# File 'lib/msf/core/module.rb', line 629

def support_ipv6?
  true
end

#target_hostObject

Returns the address of the last target host (rough estimate)


368
369
370
371
372
373
374
375
376
377
378
# File 'lib/msf/core/module.rb', line 368

def target_host
  if(self.respond_to?('rhost'))
    return rhost()
  end

  if(self.datastore['RHOST'])
    return self.datastore['RHOST']
  end

  nil
end

#target_portObject

Returns the address of the last target port (rough estimate)


383
384
385
386
387
388
389
390
391
392
393
# File 'lib/msf/core/module.rb', line 383

def target_port
  if(self.respond_to?('rport'))
    return rport()
  end

  if(self.datastore['RPORT'])
    return self.datastore['RPORT']
  end

  nil
end

#typeObject

Return the module's abstract type.

Raises:

  • (NotImplementedError)

511
512
513
# File 'lib/msf/core/module.rb', line 511

def type
  raise NotImplementedError
end

#validateObject

This method ensures that the options associated with this module all have valid values according to each required option in the option container.


612
613
614
# File 'lib/msf/core/module.rb', line 612

def validate
  self.options.validate(self.datastore)
end

#vprint_debug(msg) ⇒ Object

Verbose version of #print_debug


244
245
246
# File 'lib/msf/core/module.rb', line 244

def vprint_debug(msg)
  print_debug(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
end

#vprint_error(msg) ⇒ Object

Verbose version of #print_error


232
233
234
# File 'lib/msf/core/module.rb', line 232

def vprint_error(msg)
  print_error(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
end

#vprint_good(msg) ⇒ Object

Verbose version of #print_good


236
237
238
# File 'lib/msf/core/module.rb', line 236

def vprint_good(msg)
  print_good(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
end

#vprint_line(msg) ⇒ Object

Verbose version of #print_line


240
241
242
# File 'lib/msf/core/module.rb', line 240

def vprint_line(msg)
  print_line(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
end

#vprint_status(msg) ⇒ Object

Verbose version of #print_status


228
229
230
# File 'lib/msf/core/module.rb', line 228

def vprint_status(msg)
  print_status(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
end

#vprint_warning(msg) ⇒ Object

Verbose version of #print_warning


248
249
250
# File 'lib/msf/core/module.rb', line 248

def vprint_warning(msg)
  print_warning(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
end

#workspaceObject

Returns the current workspace


398
399
400
401
# File 'lib/msf/core/module.rb', line 398

def workspace
  self.datastore['WORKSPACE'] ||
    (framework.db and framework.db.active and framework.db.workspace and framework.db.workspace.name)
end