2019-05-08 13:47:52 +03:00
|
|
|
#!/usr/bin/env python
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
"""
|
2020-12-31 13:46:27 +03:00
|
|
|
Copyright (c) 2006-2021 sqlmap developers (http://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' 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
|
|
|
|
2020-03-03 16:40:40 +03:00
|
|
|
_ = "(%s)" % ('|'.join(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)
|
2016-05-30 11:32:49 +03:00
|
|
|
if kb.resolutionDbms:
|
|
|
|
hashDBWrite(HASHDB_KEYS.DBMS, kb.resolutionDbms)
|
|
|
|
|
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())
|