Skip to content

Commit 7152a1e

Browse files
committed
Added --dependences to show which sqlmap dependences are not available
1 parent 8485827 commit 7152a1e

6 files changed

Lines changed: 123 additions & 6 deletions

File tree

lib/core/common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,9 +1020,9 @@ def parseTargetDirect():
10201020
import pymssql
10211021

10221022
if not hasattr(pymssql, "__version__") or pymssql.__version__ < "1.0.2":
1023-
errMsg = "pymssql library on your system must be "
1024-
errMsg += "version 1.0.2 to work, get it from "
1025-
errMsg += "http://sourceforge.net/projects/pymssql/files/pymssql/1.0.2/"
1023+
errMsg = "'%s' third-party library must be " % data[1]
1024+
errMsg += "version >= 1.0.2 to work properly. "
1025+
errMsg += "Download from %s" % data[2]
10261026
raise sqlmapMissingDependence, errMsg
10271027

10281028
elif dbmsName == DBMS.MYSQL:
@@ -1040,7 +1040,7 @@ def parseTargetDirect():
10401040
except ImportError, _:
10411041
errMsg = "sqlmap requires '%s' third-party library " % data[1]
10421042
errMsg += "in order to directly connect to the database "
1043-
errMsg += "'%s'. Download from '%s'" % (dbmsName, data[2])
1043+
errMsg += "%s. Download from %s" % (dbmsName, data[2])
10441044
raise sqlmapMissingDependence, errMsg
10451045

10461046
def parseTargetUrl():

lib/core/option.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
from lib.request.rangehandler import HTTPRangeHandler
114114
from lib.request.redirecthandler import SmartRedirectHandler
115115
from lib.request.templates import getPageTemplate
116+
from lib.utils.dependences import checkDependences
116117
from lib.utils.google import Google
117118

118119
authHandler = urllib2.BaseHandler()
@@ -1743,6 +1744,7 @@ def init(inputOptions=advancedDict(), overrideOptions=False):
17431744
__saveCmdline()
17441745
__setRequestFromFile()
17451746
__cleanupOptions()
1747+
checkDependences()
17461748
__basicOptionValidation()
17471749
__setTorProxySettings()
17481750
__setMultipleTargets()

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
"replicate": "boolean",
175175
"tor": "boolean",
176176
"wizard": "boolean",
177+
"dependences": "boolean",
177178
"verbose": "integer"
178179
},
179180
}

lib/parse/cmdline.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,10 @@ def cmdLineParser():
537537
action="store_true", default=False,
538538
help="Simple wizard interface for beginner users")
539539

540+
miscellaneous.add_option("--dependences", dest="dependences",
541+
action="store_true", default=False,
542+
help="Show which sqlmap dependences are not available")
543+
540544
# Hidden and/or experimental options
541545
parser.add_option("--profile", dest="profile", action="store_true",
542546
default=False, help=SUPPRESS_HELP)
@@ -586,8 +590,8 @@ def cmdLineParser():
586590
(args, _) = parser.parse_args(args)
587591

588592
if not any([args.direct, args.url, args.logFile, args.bulkFile, args.googleDork, args.configFile, \
589-
args.requestFile, args.updateAll, args.smokeTest, args.liveTest, args.realTest, args.wizard]):
590-
errMsg = "missing a mandatory parameter ('-d', '-u', '-l', '-m', '-r', '-g', '-c', '--wizard' or '--update'), "
593+
args.requestFile, args.updateAll, args.smokeTest, args.liveTest, args.realTest, args.wizard, args.dependences]):
594+
errMsg = "missing a mandatory parameter (-d, -u, -l, -m, -r, -g, -c, --wizard, --update or --dependences), "
591595
errMsg += "-h for help"
592596
parser.error(errMsg)
593597

lib/utils/dependences.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
$Id$
5+
6+
Copyright (c) 2006-2011 sqlmap developers (http://sqlmap.sourceforge.net/)
7+
See the file 'doc/COPYING' for copying permission
8+
"""
9+
10+
from lib.core.data import conf
11+
from lib.core.data import logger
12+
from lib.core.enums import DBMS
13+
from lib.core.exception import sqlmapMissingDependence
14+
from lib.core.settings import DBMS_DICT
15+
from lib.core.settings import IS_WIN
16+
17+
def checkDependences():
18+
missing_libraries = set()
19+
20+
for dbmsName, data in DBMS_DICT.items():
21+
if data[1] is None:
22+
continue
23+
24+
try:
25+
if dbmsName in (DBMS.MSSQL, DBMS.SYBASE):
26+
import _mssql
27+
import pymssql
28+
29+
if not hasattr(pymssql, "__version__") or pymssql.__version__ < "1.0.2":
30+
errMsg = "'%s' third-party library must be " % data[1]
31+
errMsg += "version >= 1.0.2 to work properly. "
32+
errMsg += "Download from %s" % data[2]
33+
logger.error(errMsg)
34+
elif dbmsName == DBMS.MYSQL:
35+
import MySQLdb
36+
elif dbmsName == DBMS.PGSQL:
37+
import psycopg2
38+
elif dbmsName == DBMS.ORACLE:
39+
import cx_Oracle
40+
elif dbmsName == DBMS.SQLITE:
41+
import sqlite3
42+
elif dbmsName == DBMS.ACCESS:
43+
import pyodbc
44+
elif dbmsName == DBMS.FIREBIRD:
45+
import kinterbasdb
46+
except ImportError, _:
47+
errMsg = "sqlmap requires '%s' third-party library " % data[1]
48+
errMsg += "in order to directly connect to the database "
49+
errMsg += "%s. Download from %s" % (dbmsName, data[2])
50+
logger.error(errMsg)
51+
missing_libraries.add(data[1])
52+
53+
continue
54+
55+
debugMsg = "'%s' third-party library is found" % data[1]
56+
logger.debug(debugMsg)
57+
58+
try:
59+
import impacket
60+
debugMsg = "'python-impacket' third-party library is found"
61+
logger.debug(debugMsg)
62+
except ImportError, _:
63+
errMsg = "sqlmap requires 'python-impacket' third-party library for "
64+
errMsg += "out-of-band takeover feature. Download from "
65+
errMsg += "http://code.google.com/p/impacket/"
66+
logger.error(errMsg)
67+
missing_libraries.add('python-impacket')
68+
69+
try:
70+
import ntlm
71+
debugMsg = "'python-ntlm' third-party library is found"
72+
logger.debug(debugMsg)
73+
except ImportError, _:
74+
errMsg = "sqlmap requires 'python-ntlm' third-party library for "
75+
errMsg += "if you plan to attack a web application behind NTLM "
76+
errMsg += "authentication. Download from http://code.google.com/p/python-ntlm/"
77+
logger.error(errMsg)
78+
missing_libraries.add('python-ntlm')
79+
80+
try:
81+
import pysvn
82+
debugMsg = "'python-svn' third-party library is found"
83+
logger.debug(debugMsg)
84+
except ImportError, _:
85+
errMsg = "sqlmap requires 'python-svn' third-party library for "
86+
errMsg += "if you want to use the sqlmap update functionality. "
87+
errMsg += "Download from http://pysvn.tigris.org/"
88+
logger.error(errMsg)
89+
missing_libraries.add('python-svn')
90+
91+
if IS_WIN:
92+
try:
93+
import pyreadline
94+
debugMsg = "'python-pyreadline' third-party library is found"
95+
logger.debug(debugMsg)
96+
except ImportError, _:
97+
errMsg = "sqlmap requires 'pyreadline' third-party library to "
98+
errMsg += "be able to take advantage of the sqlmap TAB "
99+
errMsg += "completion and history support features in the SQL "
100+
errMsg += "shell and OS shell. Download from "
101+
errMsg += "http://ipython.scipy.org/moin/PyReadline/Intro"
102+
logger.error(errMsg)
103+
missing_libraries.add('python-pyreadline')
104+
105+
if len(missing_libraries) == 0:
106+
infoMsg = "all dependences are installed"

sqlmap.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,10 @@ tor = False
576576
# Valid: True or False
577577
wizard = False
578578

579+
# Show which sqlmap dependences are not available.
580+
# Valid: True or False
581+
dependences = False
582+
579583
# Verbosity level.
580584
# Valid: integer between 0 and 6
581585
# 0: Show only error and critical messages

0 commit comments

Comments
 (0)