Skip to content

Commit 3d38d46

Browse files
committed
Add extra version checking methods
Added the ability to check style.css for theme versions as version tagging in style.css is a requirement of WordPress theme development. Also updated existing readme checking to allow for a nil fixed_version parameter in scenarios where all versions are vulnerable in an EOL product.
1 parent c820431 commit 3d38d46

File tree

1 file changed

+79
-10
lines changed

1 file changed

+79
-10
lines changed

lib/msf/http/wordpress/version.rb

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,79 @@ def wordpress_version
4343
# Checks a readme for a vulnerable version
4444
#
4545
# @param [String] plugin_name The name of the plugin
46-
# @param [String] fixed_version The version the vulnerability was fixed in
46+
# @param [String] fixed_version Optional, the version the vulnerability was fixed in
4747
# @param [String] vuln_introduced_version Optional, the version the vulnerability was introduced
4848
#
4949
# @return [ Msf::Exploit::CheckCode ]
50-
def check_plugin_version_from_readme(plugin_name, fixed_version, vuln_introduced_version = nil)
50+
def check_plugin_version_from_readme(plugin_name, fixed_version = nil, vuln_introduced_version = nil)
5151
check_version_from_readme(:plugin, plugin_name, fixed_version, vuln_introduced_version)
5252
end
5353

54+
# Checks the style.css file for a vulnerable version
55+
#
56+
# @param [String] theme_name The name of the theme
57+
# @param [String] fixed_version Optional, the version the vulnerability was fixed in
58+
# @param [String] vuln_introduced_version Optional, the version the vulnerability was introduced
59+
#
60+
# @return [ Msf::Exploit::CheckCode ]
61+
def check_theme_version_from_style(theme_name, fixed_version = nil, vuln_introduced_version = nil)
62+
style_uri = normalize_uri(wordpress_url_themes, theme_name, 'style.css')
63+
res = send_request_cgi(
64+
'uri' => style_uri,
65+
'method' => 'GET'
66+
)
67+
68+
# No style.css file present
69+
return Msf::Exploit::CheckCode::Unknown if res.nil? || res.code != 200
70+
71+
# Try to extract version from style.css
72+
# Example line:
73+
# Version: 1.5.2
74+
version = res.body.to_s[/(?:Version):\s*([0-9a-z.-]+)/i, 1]
75+
76+
# style.css present, but no version number
77+
return Msf::Exploit::CheckCode::Detected if version.nil?
78+
79+
vprint_status("#{peer} - Found version #{version} of the theme")
80+
81+
if fixed_version.nil?
82+
if vuln_introduced_version.nil?
83+
# All versions are vulnerable
84+
return Msf::Exploit::CheckCode::Appears
85+
elsif Gem::Version.new(version) >= Gem::Version.new(vuln_introduced_version)
86+
# Newer or equal to the version it was introduced
87+
return Msf::Exploit::CheckCode::Appears
88+
else
89+
return Msf::Exploit::CheckCode::Safe
90+
end
91+
else
92+
# Version older than fixed version
93+
if Gem::Version.new(version) < Gem::Version.new(fixed_version)
94+
if vuln_introduced_version.nil?
95+
# All previous versions are vulnerable
96+
return Msf::Exploit::CheckCode::Appears
97+
# vuln_introduced_version provided, check if version is newer
98+
elsif Gem::Version.new(version) >= Gem::Version.new(vuln_introduced_version)
99+
return Msf::Exploit::CheckCode::Appears
100+
else
101+
# Not in range, nut vulnerable
102+
return Msf::Exploit::CheckCode::Safe
103+
end
104+
# version newer than fixed version
105+
else
106+
return Msf::Exploit::CheckCode::Safe
107+
end
108+
end
109+
end
110+
54111
# Checks a readme for a vulnerable version
55112
#
56113
# @param [String] theme_name The name of the theme
57-
# @param [String] fixed_version The version the vulnerability was fixed in
114+
# @param [String] fixed_version Optional, the version the vulnerability was fixed in
58115
# @param [String] vuln_introduced_version Optional, the version the vulnerability was introduced
59116
#
60117
# @return [ Msf::Exploit::CheckCode ]
61-
def check_theme_version_from_readme(theme_name, fixed_version, vuln_introduced_version = nil)
118+
def check_theme_version_from_readme(theme_name, fixed_version = nil, vuln_introduced_version = nil)
62119
check_version_from_readme(:theme, theme_name, fixed_version, vuln_introduced_version)
63120
end
64121

@@ -114,21 +171,33 @@ def check_version_from_readme(type, name, fixed_version, vuln_introduced_version
114171

115172
vprint_status("#{peer} - Found version #{version} of the #{type}")
116173

117-
# Version older than fixed version
118-
if Gem::Version.new(version) < Gem::Version.new(fixed_version)
174+
if fixed_version.nil?
119175
if vuln_introduced_version.nil?
120176
# All versions are vulnerable
121177
return Msf::Exploit::CheckCode::Appears
122-
# vuln_introduced_version provided, check if version is newer
123178
elsif Gem::Version.new(version) >= Gem::Version.new(vuln_introduced_version)
179+
# Newer or equal to the version it was introduced
124180
return Msf::Exploit::CheckCode::Appears
125181
else
126-
# Not in range, nut vulnerable
127182
return Msf::Exploit::CheckCode::Safe
128183
end
129-
# version newer than fixed version
130184
else
131-
return Msf::Exploit::CheckCode::Safe
185+
# Version older than fixed version
186+
if Gem::Version.new(version) < Gem::Version.new(fixed_version)
187+
if vuln_introduced_version.nil?
188+
# All versions are vulnerable
189+
return Msf::Exploit::CheckCode::Appears
190+
# vuln_introduced_version provided, check if version is newer
191+
elsif Gem::Version.new(version) >= Gem::Version.new(vuln_introduced_version)
192+
return Msf::Exploit::CheckCode::Appears
193+
else
194+
# Not in range, nut vulnerable
195+
return Msf::Exploit::CheckCode::Safe
196+
end
197+
# version newer than fixed version
198+
else
199+
return Msf::Exploit::CheckCode::Safe
200+
end
132201
end
133202
end
134203
end

0 commit comments

Comments
 (0)