forked from rapid7/metasploit-framework
/
web_vuln.rb
executable file
·191 lines (158 loc) · 4.45 KB
/
web_vuln.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# A Web Vulnerability found during a web scan or web audit.
#
# If you need to modify Mdm::WebVuln you can use ActiveSupport.on_load(:mdm_web_vuln) inside an initializer so that
# your patches are reloaded on each request in development mode for your Rails application.
#
# @example extending Mdm::WebVuln
# # config/initializers/mdm_web_vuln.rb
# ActiveSupport.on_load(:mdm_web_vuln) do
# def confidence_percentage
# "#{confidence}%"
# end
# end
class Mdm::WebVuln < ActiveRecord::Base
#
# CONSTANTS
#
# A percentage {#confidence} that the vulnerability is real and not a false positive. 0 is not allowed because there
# shouldn't be an {Mdm::WebVuln} record if there is 0% {#confidence} in the the finding.
CONFIDENCE_RANGE = 1 .. 100
# Default value for {#params}
DEFAULT_PARAMS = []
# Allowed {#method methods}.
METHODS = [
'GET',
# XXX I don't know why PATH is a valid method when it's not an HTTP Method/Verb
'PATH',
'POST'
]
# {#risk Risk} is rated on a scale from 0 (least risky) to 5 (most risky).
RISK_RANGE = 0 .. 5
#
# Associations
#
belongs_to :web_site, :class_name => 'Mdm::WebSite'
#
# Attributes
#
# @!attribute [rw] blame
# Who to blame for the vulnerability
#
# @return [String]
# @!attribute [rw] category
# Category of this vulnerability.
#
# @return [String]
# @!attribute [rw] confidence
# Percentage confidence scanner or auditor has that this vulnerability is not a false positive
#
# @return [Integer] 1% to 100%
# @!attribute [rw] description
# Description of the vulnerability
#
# @return [String, nil]
# @!attribute [rw] method
# HTTP Methods for request that found vulnerability. 'PATH' is also allowed even though it is not an HTTP Method.
#
# @return [String]
# @see METHODS
# @!attribute [rw] name
# Name of the vulnerability
#
# @return [String]
# @!attribute [rw] path
# Path portion of URL
#
# @return [String]
# @!attribute [rw] payload
# Web audit payload that gets executed by the remote server. Used for code injection vulnerabilities.
#
# @return [String, nil]
# @!attribute [rw] pname
# Name of parameter that demonstrates vulnerability
#
# @return [String]
# @!attribute [rw] proof
# String that proves vulnerability, such as a code snippet, etc.
#
# @return [String]
# @!attribute [rw] query
# The GET query.
#
# @return [String]
# @!attribute [rw] request
#
# @return [String]
# @!attribute [rw] risk
# {RISK_RANGE Risk} of leaving this vulnerability unpatched.
#
# @return [Integer]
#
# Validations
#
validates :category, :presence => true
validates :confidence,
:inclusion => {
:in => CONFIDENCE_RANGE
}
validates :method,
:inclusion => {
:in => METHODS
}
validates :name, :presence => true
validates :path, :presence => true
validates :pname, :presence => true
validates :proof, :presence => true
validates :risk,
:inclusion => {
:in => RISK_RANGE
}
validates :web_site, :presence => true
#
# Serializations
#
# @!attribute [rw] params
# Parameters sent as part of request
#
# @return [Array<Array<(String, String)>>] Array of parameter key value pairs
serialize :params, MetasploitDataModels::Base64Serializer.new(:default => DEFAULT_PARAMS)
#
# Methods
#
# Parameters sent as part of request.
#
# @return [Array<Array<(String, String)>>]
def params
normalize_params(
read_attribute(:params)
)
end
# Set parameters sent as part of request.
#
# @param params [Array<Array<(String, String)>>, nil] Array of parameter key value pairs
# @return [void]
def params=(params)
write_attribute(
:params,
normalize_params(params)
)
end
private
# Creates a duplicate of {DEFAULT_PARAMS} that is safe to modify.
#
# @return [Array] an empty array
def default_params
DEFAULT_PARAMS.dup
end
# Returns either the given params or {DEFAULT_PARAMS} if params is `nil`
#
# @param [Array<Array<(String, String)>>, nil] params
# @return [Array<<Array<(String, String)>>] params if not `nil`
# @return [nil] if params is `nil`
def normalize_params(params)
params || default_params
end
# switch back to public for load hooks
public
ActiveSupport.run_load_hooks(:mdm_web_vuln, self)
end