Files
metasploit-gs/lib/msf/core/module/reference.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

169 lines
3.7 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
2005-06-05 00:03:23 +00:00
###
#
2005-11-15 15:11:43 +00:00
# A reference to some sort of information. This is typically a URL, but could
# be any type of referential value that people could use to research a topic.
2005-06-05 00:03:23 +00:00
#
###
class Msf::Module::Reference
2005-11-15 15:11:43 +00:00
#
# Serialize a reference from a string.
#
2005-06-05 00:03:23 +00:00
def self.from_s(str)
return self.new(str)
end
2013-08-30 16:28:33 -05:00
2005-11-15 15:11:43 +00:00
#
# Initializes a reference from a string.
#
2005-06-05 00:03:23 +00:00
def initialize(in_str)
self.str = in_str
end
2013-08-30 16:28:33 -05:00
2005-07-10 00:16:48 +00:00
#
2018-08-27 12:03:54 -05:00
# Compares references to see if they're equal.
2005-07-10 00:16:48 +00:00
#
def ==(tgt)
return (tgt.to_s == to_s)
end
2013-08-30 16:28:33 -05:00
2005-11-15 15:11:43 +00:00
#
# Returns the reference as a string.
#
2005-06-05 00:03:23 +00:00
def to_s
return self.str
end
2013-08-30 16:28:33 -05:00
2005-11-15 15:11:43 +00:00
#
# Serializes the reference instance from a string.
#
2005-06-05 00:03:23 +00:00
def from_s(in_str)
self.str = in_str
end
2013-08-30 16:28:33 -05:00
2005-11-15 15:11:43 +00:00
#
# The reference string.
#
2005-06-05 00:03:23 +00:00
attr_reader :str
protected
2005-11-15 15:11:43 +00:00
attr_writer :str # :nodoc:
2005-06-05 00:03:23 +00:00
end
###
#
# A reference to a website.
#
###
class Msf::Module::SiteReference < Msf::Module::Reference
#
2005-11-15 15:11:43 +00:00
# Class method that translates a URL into a site reference instance.
2005-06-05 00:03:23 +00:00
#
def self.from_s(str)
instance = self.new
2013-08-30 16:28:33 -05:00
2005-06-05 00:03:23 +00:00
if (instance.from_s(str) == false)
return nil
end
2013-08-30 16:28:33 -05:00
2005-06-05 00:03:23 +00:00
return instance
end
2013-08-30 16:28:33 -05:00
2005-11-15 15:11:43 +00:00
#
# Initializes a site reference from an array. ary[0] is the site and
2016-09-20 14:27:59 -05:00
# ary[1] is the site context identifier, such as CVE.
2005-11-15 15:11:43 +00:00
#
2005-06-05 00:33:38 +00:00
def self.from_a(ary)
return nil if (ary.length < 2)
2013-08-30 16:28:33 -05:00
2005-06-05 00:33:38 +00:00
self.new(ary[0], ary[1])
end
2013-08-30 16:28:33 -05:00
2005-06-05 00:03:23 +00:00
#
2005-11-15 15:11:43 +00:00
# Initialize the site reference.
2014-11-05 09:57:13 -06:00
# If you're updating the references, please also update:
# * tools/module_reference.rb
# * https://docs.metasploit.com/docs/development/developing-modules/module-metadata/module-reference-identifiers.html
2005-06-05 00:03:23 +00:00
#
def initialize(in_ctx_id = 'Unknown', in_ctx_val = '')
self.ctx_id = in_ctx_id
self.ctx_val = in_ctx_val
2013-08-30 16:28:33 -05:00
if in_ctx_id == 'CVE'
self.site = "https://nvd.nist.gov/vuln/detail/CVE-#{in_ctx_val}"
elsif in_ctx_id == 'CWE'
2015-05-02 10:11:17 -05:00
self.site = "https://cwe.mitre.org/data/definitions/#{in_ctx_val}.html"
elsif in_ctx_id == 'BID'
2014-10-02 23:03:31 +02:00
self.site = "http://www.securityfocus.com/bid/#{in_ctx_val}"
elsif in_ctx_id == 'MSB'
2019-05-23 07:00:23 -05:00
year = in_ctx_val[2..3]
century = year[0] == '9' ? '19' : '20'
self.site = "https://docs.microsoft.com/en-us/security-updates/SecurityBulletins/#{century}#{year}/#{in_ctx_val}"
elsif in_ctx_id == 'EDB'
2015-05-02 10:11:17 -05:00
self.site = "https://www.exploit-db.com/exploits/#{in_ctx_val}"
elsif in_ctx_id == 'US-CERT-VU'
2017-01-01 21:26:01 -06:00
self.site = "https://www.kb.cert.org/vuls/id/#{in_ctx_val}"
elsif in_ctx_id == 'ZDI'
2014-10-02 23:03:31 +02:00
self.site = "http://www.zerodayinitiative.com/advisories/ZDI-#{in_ctx_val}"
elsif in_ctx_id == 'WPVDB'
2021-02-08 17:48:54 +01:00
self.site = "https://wpscan.com/vulnerability/#{in_ctx_val}"
elsif in_ctx_id == 'PACKETSTORM'
self.site = "https://packetstormsecurity.com/files/#{in_ctx_val}"
elsif in_ctx_id == 'URL'
self.site = in_ctx_val.to_s
elsif in_ctx_id == 'LOGO'
self.site = "Logo: #{in_ctx_val}"
2018-07-17 19:10:30 -05:00
elsif in_ctx_id == 'SOUNDTRACK'
self.site = "Soundtrack: #{in_ctx_val}"
2005-06-05 00:03:23 +00:00
else
self.site = in_ctx_id
self.site += " (#{in_ctx_val})" if (in_ctx_val)
2005-06-05 00:03:23 +00:00
end
end
2013-08-30 16:28:33 -05:00
2005-06-05 00:03:23 +00:00
#
2005-11-15 15:11:43 +00:00
# Returns the absolute site URL.
2005-06-05 00:03:23 +00:00
#
def to_s
return site || ''
end
2013-08-30 16:28:33 -05:00
2005-06-05 00:03:23 +00:00
#
2005-11-15 15:11:43 +00:00
# Serializes a site URL string.
2005-06-05 00:03:23 +00:00
#
def from_s(str)
if (/(http:\/\/|https:\/\/|ftp:\/\/)/.match(str))
self.site = str
self.ctx_id = 'URL'
self.ctx_val = self.site
2005-06-05 00:03:23 +00:00
else
return false
end
2013-08-30 16:28:33 -05:00
2005-06-05 00:03:23 +00:00
return true
end
2013-08-30 16:28:33 -05:00
2005-11-15 15:11:43 +00:00
#
# The site being referenced.
#
attr_reader :site
#
2016-09-20 14:27:59 -05:00
# The context identifier of the site, such as CVE.
2005-11-15 15:11:43 +00:00
#
attr_reader :ctx_id
#
# The context value of the reference, such as MS02-039
#
attr_reader :ctx_val
2005-06-05 00:03:23 +00:00
protected
attr_writer :site, :ctx_id, :ctx_val
2005-06-05 00:03:23 +00:00
end