@@ -132,15 +132,15 @@ def __commentCheck(self):
132132
133133 return None
134134
135- # MySQL valid versions updated at 07 /2008
135+ # MySQL valid versions updated at 10 /2008
136136 versions = (
137137 (32200 , 32233 ), # MySQL 3.22
138138 (32300 , 32354 ), # MySQL 3.23
139139 (40000 , 40024 ), # MySQL 4.0
140140 (40100 , 40122 ), # MySQL 4.1
141- (50000 , 50067 ), # MySQL 5.0
142- (50100 , 50126 ), # MySQL 5.1
143- (60000 , 60006 ), # MySQL 6.0
141+ (50000 , 50072 ), # MySQL 5.0
142+ (50100 , 50129 ), # MySQL 5.1
143+ (60000 , 60008 ), # MySQL 6.0
144144 )
145145
146146 for element in versions :
@@ -202,6 +202,14 @@ def getFingerprint(self):
202202
203203
204204 def checkDbms (self ):
205+ """
206+ References for fingerprint:
207+
208+ * http://dev.mysql.com/doc/refman/5.0/en/news-5-0-x.html
209+ * http://dev.mysql.com/doc/refman/5.1/en/news-5-1-x.html
210+ * http://dev.mysql.com/doc/refman/6.0/en/news-6-0-x.html
211+ """
212+
205213 if conf .dbms in MYSQL_ALIASES and kb .dbmsVersion and kb .dbmsVersion [0 ].isdigit ():
206214 setDbms ("MySQL %s" % kb .dbmsVersion [0 ])
207215
@@ -229,38 +237,66 @@ def checkDbms(self):
229237
230238 return False
231239
232- query = "SELECT %s " % randInt
233- query += "FROM information_schema.TABLES "
234- query += "LIMIT 0, 1"
235-
236- if inject .getValue (query ) == randInt :
240+ # Determine if it is MySQL >= 5.0.0
241+ if inject .getValue ("SELECT %s FROM information_schema.TABLES LIMIT 0, 1" % randInt ) == randInt :
237242 setDbms ("MySQL 5" )
238243 self .has_information_schema = True
239244
240245 if not conf .extensiveFp :
241246 kb .dbmsVersion = [">= 5.0.0" ]
242247 return True
243248
244- self .currentDb = inject .getValue ("DATABASE()" )
245- if self .currentDb == inject .getValue ("SCHEMA()" ):
246- kb .dbmsVersion = [">= 5.0.2" , "< 5.1" ]
247-
248- query = "SELECT %s " % randInt
249- query += "FROM information_schema.PARTITIONS "
250- query += "LIMIT 0, 1"
251-
252- if inject .getValue (query ) == randInt :
253- kb .dbmsVersion = [">= 5.1" ]
249+ # Check if it is MySQL >= 6.0.3
250+ if inject .getValue ("SELECT %s FROM information_schema.PARAMETERS LIMIT 0, 1" % randInt ) == randInt :
251+ if inject .getValue ("SELECT %s FROM information_schema.PROFILING LIMIT 0, 1" % randInt ) == randInt :
252+ kb .dbmsVersion = [">= 6.0.5" ]
253+ else :
254+ kb .dbmsVersion = [">= 6.0.3" , "< 6.0.5" ]
255+
256+ # Or if it MySQL >= 5.1.2 and < 6.0.3
257+ elif inject .getValue ("MID(@@plugin_dir, 1, 1)" ):
258+ if inject .getValue ("SELECT %s FROM information_schema.PROFILING LIMIT 0, 1" % randInt ) == randInt :
259+ kb .dbmsVersion = [">= 5.1.28" , "< 6.0.3" ]
260+ elif inject .getValue ("MID(@@innodb_stats_on_metadata, 1, 1)" ):
261+ kb .dbmsVersion = [">= 5.1.17" , "< 5.1.28" ]
262+ elif inject .getValue ("SELECT %s FROM information_schema.REFERENTIAL_CONSTRAINTS LIMIT 0, 1" % randInt ) == randInt :
263+ kb .dbmsVersion = [">= 5.1.10" , "< 5.1.17" ]
264+ elif inject .getValue ("SELECT %s FROM information_schema.PROCESSLIST LIMIT 0, 1" % randInt ) == randInt :
265+ kb .dbmsVersion = [">= 5.1.7" , "< 5.1.10" ]
266+ elif inject .getValue ("SELECT %s FROM information_schema.PARTITIONS LIMIT 0, 1" % randInt ) == randInt :
267+ kb .dbmsVersion = ["= 5.1.6" ]
268+ elif inject .getValue ("SELECT %s FROM information_schema.PLUGINS LIMIT 0, 1" % randInt ) == randInt :
269+ kb .dbmsVersion = [">= 5.1.5" , "< 5.1.6" ]
270+ elif inject .getValue ("MID(@@table_open_cache, 1, 1)" ):
271+ kb .dbmsVersion = [">= 5.1.3" , "< 5.1.5" ]
272+ else :
273+ kb .dbmsVersion = ["= 5.1.2" ]
274+
275+ # Or if it is MySQL >= 5.0.0 and < 5.1.2
276+ elif inject .getValue ("MID(@@hostname, 1, 1)" ):
277+ kb .dbmsVersion = [">= 5.0.38" , "< 5.1.2" ]
278+ # NOTE: MySQL 5.0.12 introduced SLEEP() function
279+ # References:
280+ # * http://dev.mysql.com/doc/refman/5.0/en/news-5-0-12.html
281+ # * http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_sleep
282+ elif inject .getValue ("SELECT 1 FROM DUAL" ) == "1" :
283+ kb .dbmsVersion = [">= 5.0.11" , "< 5.0.38" ]
284+ elif inject .getValue ("DATABASE() LIKE SCHEMA()" ):
285+ kb .dbmsVersion = [">= 5.0.2" , "< 5.0.11" ]
254286 else :
255- kb .dbmsVersion = ["= 5.0.0 or 5.0.1" ]
287+ kb .dbmsVersion = [">= 5.0.0" , "<= 5.0.1" ]
288+
289+ # Otherwise assume it is MySQL < 5.0.0
256290 else :
257291 setDbms ("MySQL 4" )
258292 kb .dbmsVersion = ["< 5.0.0" ]
259293
260294 if not conf .extensiveFp :
261295 return True
262296
297+ # Check which version of MySQL , 5.0.0 it is
263298 coercibility = inject .getValue ("COERCIBILITY(USER())" )
299+
264300 if coercibility == "3" :
265301 kb .dbmsVersion = [">= 4.1.11" , "< 5.0.0" ]
266302 elif coercibility == "2" :
0 commit comments