@@ -68,44 +68,7 @@ def check_theme_version_from_style(theme_name, fixed_version = nil, vuln_introdu
68
68
# No style.css file present
69
69
return Msf ::Exploit ::CheckCode ::Unknown if res . nil? || res . code != 200
70
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
71
+ return extract_and_check_version ( res . body . to_s , :style , :theme , fixed_version , vuln_introduced_version )
109
72
end
110
73
111
74
# Checks a readme for a vulnerable version
@@ -156,20 +119,70 @@ def check_version_from_readme(type, name, fixed_version, vuln_introduced_version
156
119
'uri' => readme_url ,
157
120
'method' => 'GET'
158
121
)
122
+ end
123
+
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
138
+ end
139
+ end
140
+
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
159
156
160
- # no Readme.txt present
161
- return Msf ::Exploit ::CheckCode ::Unknown if res . nil? || res . code != 200
157
+ version_res = extract_and_check_version ( res . body . to_s , :readme , type , fixed_version , vuln_introduced_version )
158
+ if version_res == Msf ::Exploit ::CheckCode ::Detected && type == :theme
159
+ # If no version could be found in readme.txt for a theme, try style.css
160
+ return check_theme_version_from_style ( name , fixed_version , vuln_introduced_version )
161
+ else
162
+ return version_res
162
163
end
164
+ end
163
165
164
- # try to extract version from readme
165
- # Example line:
166
- # Stable tag: 2.6.6
167
- version = res . body . to_s [ /(?:stable tag|version):\s *(?!trunk)([0-9a-z.-]+)/i , 1 ]
166
+ def extract_and_check_version ( body , type , item_type , fixed_version = nil , vuln_introduced_version = nil )
167
+ case type
168
+ when :readme
169
+ # Try to extract version from readme
170
+ # Example line:
171
+ # Stable tag: 2.6.6
172
+ version = body [ /(?:stable tag|version):\s *(?!trunk)([0-9a-z.-]+)/i , 1 ]
173
+ when :style
174
+ # Try to extract version from style.css
175
+ # Example line:
176
+ # Version: 1.5.2
177
+ version = body [ /(?:Version):\s *([0-9a-z.-]+)/i , 1 ]
178
+ else
179
+ fail ( "Unknown file type #{ type } " )
180
+ end
168
181
169
- # readme present, but no version number
182
+ # Could not identify version number
170
183
return Msf ::Exploit ::CheckCode ::Detected if version . nil?
171
184
172
- vprint_status ( "#{ peer } - Found version #{ version } of the #{ type } " )
185
+ vprint_status ( "#{ peer } - Found version #{ version } of the #{ item_type } " )
173
186
174
187
if fixed_version . nil?
175
188
if vuln_introduced_version . nil?
0 commit comments