Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f700692

Browse files
committed
added missing files for Sybase
1 parent 4b641af commit f700692

8 files changed

Lines changed: 489 additions & 3 deletions

File tree

lib/controller/handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
from plugins.dbms.firebird.connector import Connector as FirebirdConn
5252
from plugins.dbms.maxdb import MaxDBMap
5353
from plugins.dbms.maxdb.connector import Connector as MaxDBConn
54-
#from plugins.dbms.sybase import SybaseMap
55-
#from plugins.dbms.sybase.connector import Connector as SybaseConn
54+
from plugins.dbms.sybase import SybaseMap
55+
from plugins.dbms.sybase.connector import Connector as SybaseConn
5656

5757
def setHandler():
5858
"""
@@ -71,7 +71,7 @@ def setHandler():
7171
( ACCESS_ALIASES, AccessMap, AccessConn ),
7272
( FIREBIRD_ALIASES, FirebirdMap, FirebirdConn ),
7373
( MAXDB_ALIASES, MaxDBMap, MaxDBConn ),
74-
# ( SYBASE_ALIASES, SybaseMap, SybaseConn ),
74+
( SYBASE_ALIASES, SybaseMap, SybaseConn ),
7575
)
7676

7777
for dbmsAliases, dbmsMap, dbmsConn in dbmsMap:

plugins/dbms/sybase/__init__.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
$Id: __init__.py 1505 2010-03-23 21:26:45Z inquisb $
5+
6+
This file is part of the sqlmap project, http://sqlmap.sourceforge.net.
7+
8+
Copyright (c) 2007-2009 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.settings import SYBASE_SYSTEM_DBS
26+
from lib.core.unescaper import unescaper
27+
28+
from plugins.dbms.sybase.enumeration import Enumeration
29+
from plugins.dbms.sybase.filesystem import Filesystem
30+
from plugins.dbms.sybase.fingerprint import Fingerprint
31+
from plugins.dbms.sybase.syntax import Syntax
32+
from plugins.dbms.sybase.takeover import Takeover
33+
from plugins.generic.misc import Miscellaneous
34+
35+
class SybaseMap(Syntax, Fingerprint, Enumeration, Filesystem, Miscellaneous, Takeover):
36+
"""
37+
This class defines Sybase methods
38+
"""
39+
40+
def __init__(self):
41+
self.excludeDbsList = SYBASE_SYSTEM_DBS
42+
43+
Syntax.__init__(self)
44+
Fingerprint.__init__(self)
45+
Enumeration.__init__(self)
46+
Filesystem.__init__(self)
47+
Miscellaneous.__init__(self)
48+
Takeover.__init__(self)
49+
50+
unescaper.setUnescape(SybaseMap.unescape)

plugins/dbms/sybase/connector.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
$Id$
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+
try:
26+
import _mssql
27+
import pymssql
28+
except ImportError, _:
29+
pass
30+
31+
from lib.core.convert import utf8encode
32+
from lib.core.data import conf
33+
from lib.core.data import logger
34+
from lib.core.exception import sqlmapConnectionException
35+
36+
from plugins.generic.connector import Connector as GenericConnector
37+
38+
class Connector(GenericConnector):
39+
"""
40+
Homepage: http://pymssql.sourceforge.net/
41+
User guide: http://pymssql.sourceforge.net/examples_pymssql.php
42+
API: http://pymssql.sourceforge.net/ref_pymssql.php
43+
Debian package: python-pymssql
44+
License: LGPL
45+
46+
Possible connectors: http://wiki.python.org/moin/SQL%20Server
47+
48+
Important note: pymssql library on your system MUST be version 1.0.2
49+
to work, get it from http://sourceforge.net/projects/pymssql/files/pymssql/1.0.2/
50+
"""
51+
52+
def __init__(self):
53+
GenericConnector.__init__(self)
54+
55+
def connect(self):
56+
self.initConnection()
57+
58+
try:
59+
self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout)
60+
except pymssql.OperationalError, msg:
61+
raise sqlmapConnectionException, msg
62+
63+
self.setCursor()
64+
self.connected()
65+
66+
def fetchall(self):
67+
try:
68+
return self.cursor.fetchall()
69+
except (pymssql.ProgrammingError, pymssql.OperationalError, _mssql.MssqlDatabaseException), msg:
70+
logger.log(8, msg)
71+
return None
72+
73+
def execute(self, query):
74+
try:
75+
self.cursor.execute(utf8encode(query))
76+
except (pymssql.OperationalError, pymssql.ProgrammingError), msg:
77+
logger.log(8, msg)
78+
except pymssql.InternalError, msg:
79+
raise sqlmapConnectionException, msg
80+
81+
def select(self, query):
82+
self.execute(query)
83+
value = self.fetchall()
84+
85+
try:
86+
self.connector.commit()
87+
except pymssql.OperationalError:
88+
pass
89+
90+
return value

plugins/dbms/sybase/enumeration.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
$Id: enumeration.py 1835 2010-08-31 14:25:37Z 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.data import conf
26+
from lib.core.data import logger
27+
from lib.core.exception import sqlmapUnsupportedFeatureException
28+
29+
from plugins.generic.enumeration import Enumeration as GenericEnumeration
30+
31+
class Enumeration(GenericEnumeration):
32+
def __init__(self):
33+
GenericEnumeration.__init__(self, "Sybase")
34+
35+
def getPasswordHashes(self):
36+
warnMsg = "on Sybase it is not possible to enumerate the user password hashes"
37+
logger.warn(warnMsg)
38+
39+
return {}

plugins/dbms/sybase/filesystem.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
$Id: filesystem.py 1505 2010-03-23 21:26:45Z inquisb $
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.exception import sqlmapUnsupportedFeatureException
26+
27+
from plugins.generic.filesystem import Filesystem as GenericFilesystem
28+
29+
class Filesystem(GenericFilesystem):
30+
def __init__(self):
31+
GenericFilesystem.__init__(self)
32+
33+
def readFile(self, rFile):
34+
errMsg = "on Sybase it is not possible to read files"
35+
raise sqlmapUnsupportedFeatureException, errMsg
36+
37+
def writeFile(self, wFile, dFile, fileType=None, confirm=True):
38+
errMsg = "on Sybase it is not possible to write files"
39+
raise sqlmapUnsupportedFeatureException, errMsg

plugins/dbms/sybase/fingerprint.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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

Comments
 (0)