CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/core/module/reference.rb
Views: 1904
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
else
124
self.site = in_ctx_id
125
self.site += " (#{in_ctx_val})" if (in_ctx_val)
126
end
127
end
128
129
#
130
# Returns the absolute site URL.
131
#
132
def to_s
133
return site || ''
134
end
135
136
#
137
# Serializes a site URL string.
138
#
139
def from_s(str)
140
if (/(http:\/\/|https:\/\/|ftp:\/\/)/.match(str))
141
self.site = str
142
self.ctx_id = 'URL'
143
self.ctx_val = self.site
144
else
145
return false
146
end
147
148
return true
149
end
150
151
#
152
# The site being referenced.
153
#
154
attr_reader :site
155
#
156
# The context identifier of the site, such as CVE.
157
#
158
attr_reader :ctx_id
159
#
160
# The context value of the reference, such as MS02-039
161
#
162
attr_reader :ctx_val
163
164
protected
165
166
attr_writer :site, :ctx_id, :ctx_val
167
168
end
169
170