|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +$Id: fingerprint.py 1961 2010-10-11 13:52:32Z stamparm $ |
| 5 | +
|
| 6 | +This file is part of the sqlmap project, http://sqlmap.sourceforge.net. |
| 7 | +
|
| 8 | +Copyright (c) 2007-2010 Bernardo Damele A. G. <[email protected]> |
| 9 | +Copyright (c) 2006 Daniele Bellucci <[email protected]> |
| 10 | +
|
| 11 | +sqlmap is free software; you can redistribute it and/or modify it under |
| 12 | +the terms of the GNU General Public License as published by the Free |
| 13 | +Software Foundation version 2 of the License. |
| 14 | +
|
| 15 | +sqlmap is distributed in the hope that it will be useful, but WITHOUT ANY |
| 16 | +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 17 | +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 18 | +details. |
| 19 | +
|
| 20 | +You should have received a copy of the GNU General Public License along |
| 21 | +with sqlmap; if not, write to the Free Software Foundation, Inc., 51 |
| 22 | +Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 23 | +""" |
| 24 | + |
| 25 | +from lib.core.agent import agent |
| 26 | +from lib.core.common import formatDBMSfp |
| 27 | +from lib.core.common import formatFingerprint |
| 28 | +from lib.core.common import getHtmlErrorFp |
| 29 | +from lib.core.common import randomInt |
| 30 | +from lib.core.data import conf |
| 31 | +from lib.core.data import kb |
| 32 | +from lib.core.data import logger |
| 33 | +from lib.core.session import setDbms |
| 34 | +from lib.core.settings import SYBASE_ALIASES |
| 35 | +from lib.request import inject |
| 36 | +from lib.request.connect import Connect as Request |
| 37 | + |
| 38 | +from plugins.generic.fingerprint import Fingerprint as GenericFingerprint |
| 39 | + |
| 40 | +class Fingerprint(GenericFingerprint): |
| 41 | + def __init__(self): |
| 42 | + GenericFingerprint.__init__(self) |
| 43 | + |
| 44 | + def getFingerprint(self): |
| 45 | + value = "" |
| 46 | + wsOsFp = formatFingerprint("web server", kb.headersFp) |
| 47 | + |
| 48 | + if wsOsFp: |
| 49 | + value += "%s\n" % wsOsFp |
| 50 | + |
| 51 | + if kb.data.banner: |
| 52 | + dbmsOsFp = formatFingerprint("back-end DBMS", kb.bannerFp) |
| 53 | + |
| 54 | + if dbmsOsFp: |
| 55 | + value += "%s\n" % dbmsOsFp |
| 56 | + |
| 57 | + value += "back-end DBMS: " |
| 58 | + |
| 59 | + if not conf.extensiveFp: |
| 60 | + value += "Sybase" |
| 61 | + return value |
| 62 | + |
| 63 | + actVer = formatDBMSfp() |
| 64 | + blank = " " * 15 |
| 65 | + value += "active fingerprint: %s" % actVer |
| 66 | + |
| 67 | + if kb.bannerFp: |
| 68 | + banVer = kb.bannerFp["dbmsVersion"] |
| 69 | + banVer = formatDBMSfp([banVer]) |
| 70 | + value += "\n%sbanner parsing fingerprint: %s" % (blank, banVer) |
| 71 | + |
| 72 | + htmlErrorFp = getHtmlErrorFp() |
| 73 | + |
| 74 | + if htmlErrorFp: |
| 75 | + value += "\n%shtml error message fingerprint: %s" % (blank, htmlErrorFp) |
| 76 | + |
| 77 | + return value |
| 78 | + |
| 79 | + def checkDbms(self): |
| 80 | + if conf.dbms in SYBASE_ALIASES and kb.dbmsVersion and kb.dbmsVersion[0].isdigit(): |
| 81 | + setDbms("Sybase %s" % kb.dbmsVersion[0]) |
| 82 | + |
| 83 | + self.getBanner() |
| 84 | + |
| 85 | + if not conf.extensiveFp: |
| 86 | + kb.os = "Windows" |
| 87 | + |
| 88 | + return True |
| 89 | + |
| 90 | + infoMsg = "testing Sybase" |
| 91 | + logger.info(infoMsg) |
| 92 | + |
| 93 | + if conf.direct: |
| 94 | + result = True |
| 95 | + else: |
| 96 | + payload = agent.fullPayload(" AND tempdb_id()=tempdb_id()") |
| 97 | + result = Request.queryPage(payload) |
| 98 | + |
| 99 | + if result: |
| 100 | + logMsg = "confirming Sybase" |
| 101 | + logger.info(logMsg) |
| 102 | + |
| 103 | + payload = agent.fullPayload(" AND suser_id()=suser_id()") |
| 104 | + result = Request.queryPage(payload) |
| 105 | + |
| 106 | + if not result: |
| 107 | + warnMsg = "the back-end DMBS is not Sybase" |
| 108 | + logger.warn(warnMsg) |
| 109 | + |
| 110 | + return False |
| 111 | + |
| 112 | + setDbms("Sybase") |
| 113 | + |
| 114 | + self.getBanner() |
| 115 | + |
| 116 | + if not conf.extensiveFp: |
| 117 | + return True |
| 118 | + |
| 119 | + for version in range(12, 16): |
| 120 | + randInt = randomInt() |
| 121 | + query = " AND @@VERSION_NUMBER/1000=%d" % version |
| 122 | + payload = agent.fullPayload(query) |
| 123 | + result = Request.queryPage(payload) |
| 124 | + if result: |
| 125 | + kb.dbmsVersion = ["%d" % version] |
| 126 | + break |
| 127 | + |
| 128 | + return True |
| 129 | + else: |
| 130 | + warnMsg = "the back-end DMBS is not Sybase" |
| 131 | + logger.warn(warnMsg) |
| 132 | + |
| 133 | + return False |
0 commit comments