2013-02-14 15:32:17 +04:00
|
|
|
#!/usr/bin/env python
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
"""
|
2016-01-06 02:06:12 +03:00
|
|
|
Copyright (c) 2006-2016 sqlmap developers (http://sqlmap.org/)
|
2010-10-15 03:18:29 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
2011-01-28 19:36:09 +03:00
|
|
|
from lib.core.common import Backend
|
|
|
|
from lib.core.common import Format
|
2012-06-21 14:09:10 +04:00
|
|
|
from lib.core.common import hashDBWrite
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.data import kb
|
|
|
|
from lib.core.data import logger
|
2012-06-21 14:09:10 +04:00
|
|
|
from lib.core.enums import HASHDB_KEYS
|
2011-04-23 20:25:09 +04:00
|
|
|
from lib.core.enums import OS
|
2011-01-24 14:04:32 +03:00
|
|
|
from lib.core.settings import SUPPORTED_DBMS
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
def setDbms(dbms):
|
|
|
|
"""
|
|
|
|
@param dbms: database management system to be set into the knowledge
|
|
|
|
base as fingerprint.
|
|
|
|
@type dbms: C{str}
|
|
|
|
"""
|
|
|
|
|
2012-06-21 14:09:10 +04:00
|
|
|
hashDBWrite(HASHDB_KEYS.DBMS, dbms)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2012-06-21 14:09:10 +04:00
|
|
|
_ = "(%s)" % ("|".join([alias for alias in SUPPORTED_DBMS]))
|
2016-03-10 17:42:01 +03:00
|
|
|
_ = re.search(r"\A%s( |\Z)" % _, dbms, re.I)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2012-06-21 14:09:10 +04:00
|
|
|
if _:
|
|
|
|
dbms = _.group(1)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2011-01-28 19:36:09 +03:00
|
|
|
Backend.setDbms(dbms)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2011-01-28 19:36:09 +03:00
|
|
|
logger.info("the back-end DBMS is %s" % Backend.getDbms())
|
2008-12-31 00:24:01 +03:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
def setOs():
|
|
|
|
"""
|
|
|
|
Example of kb.bannerFp dictionary:
|
|
|
|
|
|
|
|
{
|
|
|
|
'sp': set(['Service Pack 4']),
|
|
|
|
'dbmsVersion': '8.00.194',
|
|
|
|
'dbmsServicePack': '0',
|
|
|
|
'distrib': set(['2000']),
|
|
|
|
'dbmsRelease': '2000',
|
|
|
|
'type': set(['Windows'])
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2011-04-30 17:20:05 +04:00
|
|
|
infoMsg = ""
|
2009-04-22 15:48:07 +04:00
|
|
|
|
|
|
|
if not kb.bannerFp:
|
|
|
|
return
|
|
|
|
|
|
|
|
if "type" in kb.bannerFp:
|
2011-04-23 20:25:09 +04:00
|
|
|
Backend.setOs(Format.humanize(kb.bannerFp["type"]))
|
|
|
|
infoMsg = "the back-end DBMS operating system is %s" % Backend.getOs()
|
2009-04-22 15:48:07 +04:00
|
|
|
|
|
|
|
if "distrib" in kb.bannerFp:
|
2011-01-28 19:36:09 +03:00
|
|
|
kb.osVersion = Format.humanize(kb.bannerFp["distrib"])
|
2011-01-20 02:06:15 +03:00
|
|
|
infoMsg += " %s" % kb.osVersion
|
2009-04-22 15:48:07 +04:00
|
|
|
|
|
|
|
if "sp" in kb.bannerFp:
|
2011-01-28 19:36:09 +03:00
|
|
|
kb.osSP = int(Format.humanize(kb.bannerFp["sp"]).replace("Service Pack ", ""))
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2011-04-23 20:25:09 +04:00
|
|
|
elif "sp" not in kb.bannerFp and Backend.isOs(OS.WINDOWS):
|
2009-04-22 15:48:07 +04:00
|
|
|
kb.osSP = 0
|
|
|
|
|
2011-04-23 20:25:09 +04:00
|
|
|
if Backend.getOs() and kb.osVersion and kb.osSP:
|
2009-04-22 15:48:07 +04:00
|
|
|
infoMsg += " Service Pack %d" % kb.osSP
|
|
|
|
|
|
|
|
if infoMsg:
|
|
|
|
logger.info(infoMsg)
|
|
|
|
|
2012-06-21 14:09:10 +04:00
|
|
|
hashDBWrite(HASHDB_KEYS.OS, Backend.getOs())
|