Skip to content

Commit 5596717

Browse files
committed
allow custom regex
1 parent 9678479 commit 5596717

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

lib/msf/http/wordpress/version.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ def check_theme_version_from_readme(theme_name, fixed_version = nil, vuln_introd
8585
# Checks a custom file for a vulnerable version
8686
#
8787
# @param [String] uripath The relative path of the file
88+
# @param [Regexp] regex The regular expression to extract the version. The first captured group must contain the version.
8889
# @param [String] fixed_version Optional, the version the vulnerability was fixed in
8990
# @param [String] vuln_introduced_version Optional, the version the vulnerability was introduced
9091
#
9192
# @return [ Msf::Exploit::CheckCode ]
92-
def check_version_from_custom_file(uripath, fixed_version = nil, vuln_introduced_version = nil)
93+
def check_version_from_custom_file(uripath, regex, fixed_version = nil, vuln_introduced_version = nil)
9394
res = send_request_cgi(
9495
'uri' => uripath,
9596
'method' => 'GET'
@@ -98,7 +99,7 @@ def check_version_from_custom_file(uripath, fixed_version = nil, vuln_introduced
9899
# file not found
99100
return Msf::Exploit::CheckCode::Unknown if res.nil? || res.code != 200
100101

101-
return extract_and_check_version(res.body.to_s, :custom, 'custom file', fixed_version, vuln_introduced_version)
102+
return extract_and_check_version(res.body.to_s, :custom, 'custom file', fixed_version, vuln_introduced_version, regex)
102103
end
103104

104105
private
@@ -156,7 +157,7 @@ def check_version_from_readme(type, name, fixed_version = nil, vuln_introduced_v
156157
end
157158
end
158159

159-
def extract_and_check_version(body, type, item_type, fixed_version = nil, vuln_introduced_version = nil)
160+
def extract_and_check_version(body, type, item_type, fixed_version = nil, vuln_introduced_version = nil, regex = nil)
160161
case type
161162
when :readme
162163
# Try to extract version from readme
@@ -169,7 +170,7 @@ def extract_and_check_version(body, type, item_type, fixed_version = nil, vuln_i
169170
# Version: 1.5.2
170171
version = body[/(?:Version):\s*([0-9a-z.-]+)/i, 1]
171172
when :custom
172-
version = body[/(?:Version):\s*([0-9a-z.-]+)/i, 1]
173+
version = body[regex, 1]
173174
else
174175
fail("Unknown file type #{type}")
175176
end

spec/lib/msf/http/wordpress/version_spec.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -253,76 +253,77 @@
253253
let(:wp_body) { nil }
254254
let(:wp_path) { '/test/' }
255255
let(:wp_fixed_version) { nil }
256+
let(:wp_regex) { /(?:Version):\s*([0-9a-z.-]+)/i }
256257

257258
context 'when no file is found' do
258259
let(:wp_code) { 404 }
259-
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Unknown) }
260+
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Unknown) }
260261
end
261262

262263
context 'when no version can be extracted from style' do
263264
let(:wp_code) { 200 }
264265
let(:wp_body) { 'invalid content' }
265-
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Detected) }
266+
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Detected) }
266267
end
267268

268269
context 'when version from style has arbitrary leading whitespace' do
269270
let(:wp_code) { 200 }
270271
let(:wp_fixed_version) { '1.0.1' }
271272
let(:wp_body) { 'Version: 1.0.0' }
272-
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Appears) }
273+
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Appears) }
273274
let(:wp_body) { 'Version:1.0.0' }
274-
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Appears) }
275+
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Appears) }
275276
end
276277

277278
context 'when installed version is vulnerable' do
278279
let(:wp_code) { 200 }
279280
let(:wp_fixed_version) { '1.0.1' }
280281
let(:wp_body) { 'Version: 1.0.0' }
281-
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Appears) }
282+
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Appears) }
282283
end
283284

284285
context 'when installed version is not vulnerable' do
285286
let(:wp_code) { 200 }
286287
let(:wp_fixed_version) { '1.0.1' }
287288
let(:wp_body) { 'Version: 1.0.2' }
288-
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Safe) }
289+
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Safe) }
289290
end
290291

291292
context 'when installed version is vulnerable (version range)' do
292293
let(:wp_code) { 200 }
293294
let(:wp_fixed_version) { '1.0.2' }
294295
let(:wp_introd_version) { '1.0.0' }
295296
let(:wp_body) { 'Version: 1.0.1' }
296-
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_fixed_version, wp_introd_version)).to be(Msf::Exploit::CheckCode::Appears) }
297+
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version, wp_introd_version)).to be(Msf::Exploit::CheckCode::Appears) }
297298
end
298299

299300
context 'when installed version is older (version range)' do
300301
let(:wp_code) { 200 }
301302
let(:wp_fixed_version) { '1.0.1' }
302303
let(:wp_introd_version) { '1.0.0' }
303304
let(:wp_body) { 'Version: 0.0.9' }
304-
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_fixed_version, wp_introd_version)).to be(Msf::Exploit::CheckCode::Safe) }
305+
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version, wp_introd_version)).to be(Msf::Exploit::CheckCode::Safe) }
305306
end
306307

307308
context 'when installed version is newer (version range)' do
308309
let(:wp_code) { 200 }
309310
let(:wp_fixed_version) { '1.0.1' }
310311
let(:wp_introd_version) { '1.0.0' }
311312
let(:wp_body) { 'Version: 1.0.2' }
312-
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_fixed_version, wp_introd_version)).to be(Msf::Exploit::CheckCode::Safe) }
313+
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version, wp_introd_version)).to be(Msf::Exploit::CheckCode::Safe) }
313314
end
314315

315316
context 'when installed version is newer (text in version number)' do
316317
let(:wp_code) { 200 }
317318
let(:wp_fixed_version) { '1.5.3' }
318319
let(:wp_body) { 'Version: 2.0.0-beta1' }
319-
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Safe) }
320+
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex, wp_fixed_version)).to be(Msf::Exploit::CheckCode::Safe) }
320321
end
321322

322323
context 'when all versions are vulnerable' do
323324
let(:wp_code) { 200 }
324325
let(:wp_body) { 'Version: 1.0.0' }
325-
it { expect(subject.send(:check_version_from_custom_file, wp_path)).to be(Msf::Exploit::CheckCode::Appears) }
326+
it { expect(subject.send(:check_version_from_custom_file, wp_path, wp_regex)).to be(Msf::Exploit::CheckCode::Appears) }
326327
end
327328
end
328329

0 commit comments

Comments
 (0)