Skip to content

Commit 9678479

Browse files
committed
check version from custom file
1 parent b6df023 commit 9678479

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

lib/msf/http/wordpress/version.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,25 @@ def check_theme_version_from_readme(theme_name, fixed_version = nil, vuln_introd
8282
check_version_from_readme(:theme, theme_name, fixed_version, vuln_introduced_version)
8383
end
8484

85+
# Checks a custom file for a vulnerable version
86+
#
87+
# @param [String] uripath The relative path of the file
88+
# @param [String] fixed_version Optional, the version the vulnerability was fixed in
89+
# @param [String] vuln_introduced_version Optional, the version the vulnerability was introduced
90+
#
91+
# @return [ Msf::Exploit::CheckCode ]
92+
def check_version_from_custom_file(uripath, fixed_version = nil, vuln_introduced_version = nil)
93+
res = send_request_cgi(
94+
'uri' => uripath,
95+
'method' => 'GET'
96+
)
97+
98+
# file not found
99+
return Msf::Exploit::CheckCode::Unknown if res.nil? || res.code != 200
100+
101+
return extract_and_check_version(res.body.to_s, :custom, 'custom file', fixed_version, vuln_introduced_version)
102+
end
103+
85104
private
86105

87106
def wordpress_version_helper(url, regex)
@@ -149,6 +168,8 @@ def extract_and_check_version(body, type, item_type, fixed_version = nil, vuln_i
149168
# Example line:
150169
# Version: 1.5.2
151170
version = body[/(?:Version):\s*([0-9a-z.-]+)/i, 1]
171+
when :custom
172+
version = body[/(?:Version):\s*([0-9a-z.-]+)/i, 1]
152173
else
153174
fail("Unknown file type #{type}")
154175
end

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,92 @@
238238
end
239239
end
240240

241+
242+
describe '#check_version_from_custom_file' do
243+
before :each do
244+
allow(subject).to receive(:send_request_cgi) do |opts|
245+
res = Rex::Proto::Http::Response.new
246+
res.code = wp_code
247+
res.body = wp_body
248+
res
249+
end
250+
end
251+
252+
let(:wp_code) { 200 }
253+
let(:wp_body) { nil }
254+
let(:wp_path) { '/test/' }
255+
let(:wp_fixed_version) { nil }
256+
257+
context 'when no file is found' do
258+
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+
end
261+
262+
context 'when no version can be extracted from style' do
263+
let(:wp_code) { 200 }
264+
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+
end
267+
268+
context 'when version from style has arbitrary leading whitespace' do
269+
let(:wp_code) { 200 }
270+
let(:wp_fixed_version) { '1.0.1' }
271+
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+
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+
end
276+
277+
context 'when installed version is vulnerable' do
278+
let(:wp_code) { 200 }
279+
let(:wp_fixed_version) { '1.0.1' }
280+
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+
end
283+
284+
context 'when installed version is not vulnerable' do
285+
let(:wp_code) { 200 }
286+
let(:wp_fixed_version) { '1.0.1' }
287+
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+
end
290+
291+
context 'when installed version is vulnerable (version range)' do
292+
let(:wp_code) { 200 }
293+
let(:wp_fixed_version) { '1.0.2' }
294+
let(:wp_introd_version) { '1.0.0' }
295+
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+
end
298+
299+
context 'when installed version is older (version range)' do
300+
let(:wp_code) { 200 }
301+
let(:wp_fixed_version) { '1.0.1' }
302+
let(:wp_introd_version) { '1.0.0' }
303+
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+
end
306+
307+
context 'when installed version is newer (version range)' do
308+
let(:wp_code) { 200 }
309+
let(:wp_fixed_version) { '1.0.1' }
310+
let(:wp_introd_version) { '1.0.0' }
311+
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+
end
314+
315+
context 'when installed version is newer (text in version number)' do
316+
let(:wp_code) { 200 }
317+
let(:wp_fixed_version) { '1.5.3' }
318+
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+
end
321+
322+
context 'when all versions are vulnerable' do
323+
let(:wp_code) { 200 }
324+
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+
end
327+
end
328+
241329
end

0 commit comments

Comments
 (0)