@@ -43,22 +43,42 @@ def wordpress_version
43
43
# Checks a readme for a vulnerable version
44
44
#
45
45
# @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
47
47
# @param [String] vuln_introduced_version Optional, the version the vulnerability was introduced
48
48
#
49
49
# @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 )
51
51
check_version_from_readme ( :plugin , plugin_name , fixed_version , vuln_introduced_version )
52
52
end
53
53
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
+ return extract_and_check_version ( res . body . to_s , :style , :theme , fixed_version , vuln_introduced_version )
72
+ end
73
+
54
74
# Checks a readme for a vulnerable version
55
75
#
56
76
# @param [String] theme_name The name of the theme
57
- # @param [String] fixed_version The version the vulnerability was fixed in
77
+ # @param [String] fixed_version Optional, the version the vulnerability was fixed in
58
78
# @param [String] vuln_introduced_version Optional, the version the vulnerability was introduced
59
79
#
60
80
# @return [ Msf::Exploit::CheckCode ]
61
- def check_theme_version_from_readme ( theme_name , fixed_version , vuln_introduced_version = nil )
81
+ def check_theme_version_from_readme ( theme_name , fixed_version = nil , vuln_introduced_version = nil )
62
82
check_version_from_readme ( :theme , theme_name , fixed_version , vuln_introduced_version )
63
83
end
64
84
@@ -77,7 +97,7 @@ def wordpress_version_helper(url, regex)
77
97
nil
78
98
end
79
99
80
- def check_version_from_readme ( type , name , fixed_version , vuln_introduced_version = nil )
100
+ def check_version_from_readme ( type , name , fixed_version = nil , vuln_introduced_version = nil )
81
101
case type
82
102
when :plugin
83
103
folder = 'plugins'
@@ -99,36 +119,73 @@ def check_version_from_readme(type, name, fixed_version, vuln_introduced_version
99
119
'uri' => readme_url ,
100
120
'method' => 'GET'
101
121
)
122
+ end
102
123
103
- # no Readme.txt present
104
- return Msf ::Exploit ::CheckCode ::Unknown if res . nil? || res . code != 200
124
+ if res . nil? || res . code != 200
125
+ # No readme.txt or Readme.txt present for plugin
126
+ return Msf ::Exploit ::CheckCode ::Unknown if type == :plugin
127
+
128
+ # Try again using the style.css file
129
+ return check_theme_version_from_style ( name , fixed_version , vuln_introduced_version ) if type == :theme
130
+ end
131
+
132
+ version_res = extract_and_check_version ( res . body . to_s , :readme , type , fixed_version , vuln_introduced_version )
133
+ if version_res == Msf ::Exploit ::CheckCode ::Detected && type == :theme
134
+ # If no version could be found in readme.txt for a theme, try style.css
135
+ return check_theme_version_from_style ( name , fixed_version , vuln_introduced_version )
136
+ else
137
+ return version_res
105
138
end
139
+ end
106
140
107
- # try to extract version from readme
108
- # Example line:
109
- # Stable tag: 2.6.6
110
- version = res . body . to_s [ /(?:stable tag|version):\s *(?!trunk)([0-9a-z.-]+)/i , 1 ]
141
+ def extract_and_check_version ( body , type , item_type , fixed_version = nil , vuln_introduced_version = nil )
142
+ case type
143
+ when :readme
144
+ # Try to extract version from readme
145
+ # Example line:
146
+ # Stable tag: 2.6.6
147
+ version = body [ /(?:stable tag|version):\s *(?!trunk)([0-9a-z.-]+)/i , 1 ]
148
+ when :style
149
+ # Try to extract version from style.css
150
+ # Example line:
151
+ # Version: 1.5.2
152
+ version = body [ /(?:Version):\s *([0-9a-z.-]+)/i , 1 ]
153
+ else
154
+ fail ( "Unknown file type #{ type } " )
155
+ end
111
156
112
- # readme present, but no version number
157
+ # Could not identify version number
113
158
return Msf ::Exploit ::CheckCode ::Detected if version . nil?
114
159
115
- vprint_status ( "#{ peer } - Found version #{ version } of the #{ type } " )
160
+ vprint_status ( "#{ peer } - Found version #{ version } of the #{ item_type } " )
116
161
117
- # Version older than fixed version
118
- if Gem ::Version . new ( version ) < Gem ::Version . new ( fixed_version )
162
+ if fixed_version . nil?
119
163
if vuln_introduced_version . nil?
120
164
# All versions are vulnerable
121
165
return Msf ::Exploit ::CheckCode ::Appears
122
- # vuln_introduced_version provided, check if version is newer
123
166
elsif Gem ::Version . new ( version ) >= Gem ::Version . new ( vuln_introduced_version )
167
+ # Newer or equal to the version it was introduced
124
168
return Msf ::Exploit ::CheckCode ::Appears
125
169
else
126
- # Not in range, nut vulnerable
127
170
return Msf ::Exploit ::CheckCode ::Safe
128
171
end
129
- # version newer than fixed version
130
172
else
131
- return Msf ::Exploit ::CheckCode ::Safe
173
+ # Version older than fixed version
174
+ if Gem ::Version . new ( version ) < Gem ::Version . new ( fixed_version )
175
+ if vuln_introduced_version . nil?
176
+ # All versions are vulnerable
177
+ return Msf ::Exploit ::CheckCode ::Appears
178
+ # vuln_introduced_version provided, check if version is newer
179
+ elsif Gem ::Version . new ( version ) >= Gem ::Version . new ( vuln_introduced_version )
180
+ return Msf ::Exploit ::CheckCode ::Appears
181
+ else
182
+ # Not in range, nut vulnerable
183
+ return Msf ::Exploit ::CheckCode ::Safe
184
+ end
185
+ # version newer than fixed version
186
+ else
187
+ return Msf ::Exploit ::CheckCode ::Safe
188
+ end
132
189
end
133
190
end
134
191
end
0 commit comments