Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/core/module/reference.rb
19500 views
1
# -*- coding: binary -*-
2
3
###
4
#
5
# A reference to some sort of information. This is typically a URL, but could
6
# be any type of referential value that people could use to research a topic.
7
#
8
###
9
class Msf::Module::Reference
10
11
#
12
# Serialize a reference from a string.
13
#
14
def self.from_s(str)
15
return self.new(str)
16
end
17
18
#
19
# Initializes a reference from a string.
20
#
21
def initialize(in_str)
22
self.str = in_str
23
end
24
25
#
26
# Compares references to see if they're equal.
27
#
28
def ==(tgt)
29
return (tgt.to_s == to_s)
30
end
31
32
#
33
# Returns the reference as a string.
34
#
35
def to_s
36
return self.str
37
end
38
39
#
40
# Serializes the reference instance from a string.
41
#
42
def from_s(in_str)
43
self.str = in_str
44
end
45
46
#
47
# The reference string.
48
#
49
attr_reader :str
50
51
protected
52
53
attr_writer :str # :nodoc:
54
55
end
56
57
###
58
#
59
# A reference to a website.
60
#
61
###
62
class Msf::Module::SiteReference < Msf::Module::Reference
63
64
#
65
# Class method that translates a URL into a site reference instance.
66
#
67
def self.from_s(str)
68
instance = self.new
69
70
if (instance.from_s(str) == false)
71
return nil
72
end
73
74
return instance
75
end
76
77
#
78
# Initializes a site reference from an array. ary[0] is the site and
79
# ary[1] is the site context identifier, such as CVE.
80
#
81
def self.from_a(ary)
82
return nil if (ary.length < 2)
83
84
self.new(ary[0], ary[1])
85
end
86
87
#
88
# Initialize the site reference.
89
# If you're updating the references, please also update:
90
# * tools/module_reference.rb
91
# * https://docs.metasploit.com/docs/development/developing-modules/module-metadata/module-reference-identifiers.html
92
#
93
def initialize(in_ctx_id = 'Unknown', in_ctx_val = '')
94
self.ctx_id = in_ctx_id
95
self.ctx_val = in_ctx_val
96
97
if in_ctx_id == 'CVE'
98
self.site = "https://nvd.nist.gov/vuln/detail/CVE-#{in_ctx_val}"
99
elsif in_ctx_id == 'CWE'
100
self.site = "https://cwe.mitre.org/data/definitions/#{in_ctx_val}.html"
101
elsif in_ctx_id == 'BID'
102
self.site = "http://www.securityfocus.com/bid/#{in_ctx_val}"
103
elsif in_ctx_id == 'MSB'
104
year = in_ctx_val[2..3]
105
century = year[0] == '9' ? '19' : '20'
106
self.site = "https://docs.microsoft.com/en-us/security-updates/SecurityBulletins/#{century}#{year}/#{in_ctx_val}"
107
elsif in_ctx_id == 'EDB'
108
self.site = "https://www.exploit-db.com/exploits/#{in_ctx_val}"
109
elsif in_ctx_id == 'US-CERT-VU'
110
self.site = "https://www.kb.cert.org/vuls/id/#{in_ctx_val}"
111
elsif in_ctx_id == 'ZDI'
112
self.site = "http://www.zerodayinitiative.com/advisories/ZDI-#{in_ctx_val}"
113
elsif in_ctx_id == 'WPVDB'
114
self.site = "https://wpscan.com/vulnerability/#{in_ctx_val}"
115
elsif in_ctx_id == 'PACKETSTORM'
116
self.site = "https://packetstormsecurity.com/files/#{in_ctx_val}"
117
elsif in_ctx_id == 'URL'
118
self.site = in_ctx_val.to_s
119
elsif in_ctx_id == 'LOGO'
120
self.site = "Logo: #{in_ctx_val}"
121
elsif in_ctx_id == 'SOUNDTRACK'
122
self.site = "Soundtrack: #{in_ctx_val}"
123
elsif in_ctx_id == 'ATT&CK'
124
match = in_ctx_val.match(/\A(?<category>[A-Z]+)(?<id>[\d.]+)\z/)
125
path = Msf::Mitre::Attack::Categories::PATHS[match[:category]]
126
id_path = match[:id].gsub('.', '/')
127
self.site = "https://attack.mitre.org/#{path}/#{match[:category]}#{id_path}/"
128
else
129
self.site = in_ctx_id
130
self.site += " (#{in_ctx_val})" if (in_ctx_val)
131
end
132
end
133
134
#
135
# Returns the absolute site URL.
136
#
137
def to_s
138
return site || ''
139
end
140
141
#
142
# Serializes a site URL string.
143
#
144
def from_s(str)
145
if (/(http:\/\/|https:\/\/|ftp:\/\/)/.match(str))
146
self.site = str
147
self.ctx_id = 'URL'
148
self.ctx_val = self.site
149
else
150
return false
151
end
152
153
return true
154
end
155
156
#
157
# The site being referenced.
158
#
159
attr_reader :site
160
#
161
# The context identifier of the site, such as CVE.
162
#
163
attr_reader :ctx_id
164
#
165
# The context value of the reference, such as MS02-039
166
#
167
attr_reader :ctx_val
168
169
protected
170
171
attr_writer :site, :ctx_id, :ctx_val
172
173
end
174
175