2008-10-15 19:38:22 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
2008-10-15 19:56:32 +04:00
|
|
|
$Id$
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-10-14 18:41:14 +04:00
|
|
|
Copyright (c) 2006-2010 sqlmap developers (http://sqlmap.sourceforge.net/)
|
2010-10-15 03:18:29 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
|
2008-12-12 22:06:31 +03:00
|
|
|
import sys
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
from optparse import OptionError
|
|
|
|
from optparse import OptionGroup
|
|
|
|
from optparse import OptionParser
|
2010-05-21 13:35:36 +04:00
|
|
|
from optparse import SUPPRESS_HELP
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-05-28 15:48:44 +04:00
|
|
|
from lib.core.convert import utf8decode
|
2008-10-15 19:38:22 +04:00
|
|
|
from lib.core.data import logger
|
|
|
|
from lib.core.settings import VERSION_STRING
|
|
|
|
|
|
|
|
def cmdLineParser():
|
|
|
|
"""
|
|
|
|
This function parses the command line parameters and arguments
|
|
|
|
"""
|
|
|
|
|
2008-12-12 22:06:31 +03:00
|
|
|
usage = "%s [options]" % sys.argv[0]
|
2008-10-15 19:38:22 +04:00
|
|
|
parser = OptionParser(usage=usage, version=VERSION_STRING)
|
|
|
|
|
|
|
|
try:
|
2009-04-22 15:48:07 +04:00
|
|
|
parser.add_option("-v", dest="verbose", type="int", default=1,
|
2008-12-18 00:35:04 +03:00
|
|
|
help="Verbosity level: 0-5 (default 1)")
|
|
|
|
|
2008-12-04 20:40:03 +03:00
|
|
|
# Target options
|
|
|
|
target = OptionGroup(parser, "Target", "At least one of these "
|
|
|
|
"options has to be specified to set the source "
|
|
|
|
"to get target urls from.")
|
|
|
|
|
2010-03-27 02:23:25 +03:00
|
|
|
target.add_option("-d", dest="direct", help="Direct "
|
|
|
|
"connection to the database")
|
|
|
|
|
2008-12-04 20:40:03 +03:00
|
|
|
target.add_option("-u", "--url", dest="url", help="Target url")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2008-12-04 20:40:03 +03:00
|
|
|
target.add_option("-l", dest="list", help="Parse targets from Burp "
|
2010-01-10 00:08:47 +03:00
|
|
|
"or WebScarab proxy logs")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-01-14 23:42:45 +03:00
|
|
|
target.add_option("-r", dest="requestFile",
|
|
|
|
help="Load HTTP request from a file")
|
|
|
|
|
2008-12-04 20:40:03 +03:00
|
|
|
target.add_option("-g", dest="googleDork",
|
|
|
|
help="Process Google dork results as target urls")
|
2008-11-20 20:56:09 +03:00
|
|
|
|
2008-12-04 20:40:03 +03:00
|
|
|
target.add_option("-c", dest="configFile",
|
|
|
|
help="Load options from a configuration INI file")
|
2010-01-14 23:42:45 +03:00
|
|
|
|
2008-12-04 20:40:03 +03:00
|
|
|
# Request options
|
|
|
|
request = OptionGroup(parser, "Request", "These options can be used "
|
|
|
|
"to specify how to connect to the target url.")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
request.add_option("--method", dest="method", default="GET",
|
2009-04-22 15:48:07 +04:00
|
|
|
help="HTTP method, GET or POST (default GET)")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
request.add_option("--data", dest="data",
|
|
|
|
help="Data string to be sent through POST")
|
|
|
|
|
|
|
|
request.add_option("--cookie", dest="cookie",
|
|
|
|
help="HTTP Cookie header")
|
|
|
|
|
2010-01-14 23:42:45 +03:00
|
|
|
request.add_option("--cookie-urlencode", dest="cookieUrlencode",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2010-03-03 16:49:24 +03:00
|
|
|
help="URL Encode generated cookie injections")
|
2010-01-14 23:42:45 +03:00
|
|
|
|
|
|
|
request.add_option("--drop-set-cookie", dest="dropSetCookie",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2010-01-02 05:02:12 +03:00
|
|
|
help="Ignore Set-Cookie header from response")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
request.add_option("--user-agent", dest="agent",
|
|
|
|
help="HTTP User-Agent header")
|
|
|
|
|
|
|
|
request.add_option("-a", dest="userAgentsFile",
|
|
|
|
help="Load a random HTTP User-Agent "
|
|
|
|
"header from file")
|
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
request.add_option("--referer", dest="referer",
|
|
|
|
help="HTTP Referer header")
|
|
|
|
|
2008-12-09 00:24:24 +03:00
|
|
|
request.add_option("--headers", dest="headers",
|
2009-04-22 15:48:07 +04:00
|
|
|
help="Extra HTTP headers newline separated")
|
2008-12-09 00:24:24 +03:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
request.add_option("--auth-type", dest="aType",
|
2010-03-12 15:23:05 +03:00
|
|
|
help="HTTP authentication type "
|
2010-01-07 16:09:14 +03:00
|
|
|
"(Basic, Digest or NTLM)")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
request.add_option("--auth-cred", dest="aCred",
|
2010-03-12 15:23:05 +03:00
|
|
|
help="HTTP authentication credentials "
|
2010-01-07 16:09:14 +03:00
|
|
|
"(name:password)")
|
2010-07-30 16:49:25 +04:00
|
|
|
|
2010-01-07 15:59:09 +03:00
|
|
|
request.add_option("--auth-cert", dest="aCert",
|
2010-03-12 15:23:05 +03:00
|
|
|
help="HTTP authentication certificate ("
|
2010-01-07 15:59:09 +03:00
|
|
|
"key_file,cert_file)")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
request.add_option("--proxy", dest="proxy",
|
|
|
|
help="Use a HTTP proxy to connect to the target url")
|
|
|
|
|
2010-08-19 02:45:00 +04:00
|
|
|
request.add_option("--proxy-cred", dest="pCred",
|
2010-10-15 14:28:34 +04:00
|
|
|
help="HTTP proxy authentication credentials "
|
2010-08-19 02:45:00 +04:00
|
|
|
"(name:password)")
|
2010-09-27 17:23:29 +04:00
|
|
|
|
|
|
|
request.add_option("--ignore-proxy", dest="ignoreProxy", action="store_true",
|
|
|
|
default=False, help="Ignore system default HTTP proxy")
|
2010-03-03 19:19:17 +03:00
|
|
|
|
2010-10-17 04:07:53 +04:00
|
|
|
request.add_option("--delay", dest="delay", type="float", default=0,
|
2008-11-09 19:57:47 +03:00
|
|
|
help="Delay in seconds between each HTTP request")
|
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
request.add_option("--timeout", dest="timeout", type="float", default=30,
|
2008-12-04 20:40:03 +03:00
|
|
|
help="Seconds to wait before timeout connection "
|
2008-12-19 23:48:33 +03:00
|
|
|
"(default 30)")
|
2008-12-04 20:40:03 +03:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
request.add_option("--retries", dest="retries", type="int", default=3,
|
|
|
|
help="Retries when the connection timeouts "
|
|
|
|
"(default 3)")
|
2010-01-10 00:08:47 +03:00
|
|
|
|
2010-01-09 23:44:50 +03:00
|
|
|
request.add_option("--scope", dest="scope",
|
2010-01-10 00:08:47 +03:00
|
|
|
help="Regexp to filter targets from provided proxy log")
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-04-16 16:44:47 +04:00
|
|
|
request.add_option("--safe-url", dest="safUrl",
|
|
|
|
help="Url address to visit frequently during testing")
|
|
|
|
|
|
|
|
request.add_option("--safe-freq", dest="saFreq", type="int", default=0,
|
|
|
|
help="Test requests between two visits to a given safe url")
|
|
|
|
|
2010-10-17 01:52:16 +04:00
|
|
|
# Optimization options
|
|
|
|
optimization = OptionGroup(parser, "Optimization", "These "
|
|
|
|
"options can be used to optimize the "
|
|
|
|
"performance of sqlmap.")
|
|
|
|
|
|
|
|
optimization.add_option("-o", dest="optimize",
|
|
|
|
action="store_true", default=False,
|
2010-10-23 01:13:12 +04:00
|
|
|
help="Turn on all optimization switches")
|
2010-10-17 01:52:16 +04:00
|
|
|
|
2010-10-17 03:50:13 +04:00
|
|
|
optimization.add_option("--predict-output", dest="predictOutput", action="store_true",
|
|
|
|
default=False, help="Predict common queries output")
|
2010-10-17 01:52:16 +04:00
|
|
|
|
|
|
|
optimization.add_option("--keep-alive", dest="keepAlive", action="store_true",
|
|
|
|
default=False, help="Use persistent HTTP(s) connections")
|
|
|
|
|
|
|
|
optimization.add_option("--null-connection", dest="nullConnection", action="store_true",
|
|
|
|
default=False, help="Retrieve page length without actual HTTP response body")
|
|
|
|
|
|
|
|
optimization.add_option("--threads", dest="threads", type="int", default=1,
|
2010-10-25 19:17:59 +04:00
|
|
|
help="Max number of concurrent HTTP(s) "
|
2010-10-23 01:13:12 +04:00
|
|
|
"requests (default 1)")
|
2010-10-17 01:52:16 +04:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
# Injection options
|
2008-12-12 22:06:31 +03:00
|
|
|
injection = OptionGroup(parser, "Injection", "These options can be "
|
|
|
|
"used to specify which parameters to test "
|
|
|
|
"for, provide custom injection payloads and "
|
|
|
|
"how to parse and compare HTTP responses "
|
|
|
|
"page content when using the blind SQL "
|
|
|
|
"injection technique.")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2008-12-04 20:40:03 +03:00
|
|
|
injection.add_option("-p", dest="testParameter",
|
|
|
|
help="Testable parameter(s)")
|
|
|
|
|
2008-12-05 18:34:13 +03:00
|
|
|
injection.add_option("--dbms", dest="dbms",
|
|
|
|
help="Force back-end DBMS to this value")
|
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
injection.add_option("--os", dest="os",
|
|
|
|
help="Force back-end DBMS operating system "
|
|
|
|
"to this value")
|
|
|
|
|
2008-12-09 00:24:24 +03:00
|
|
|
injection.add_option("--prefix", dest="prefix",
|
|
|
|
help="Injection payload prefix string")
|
|
|
|
|
|
|
|
injection.add_option("--postfix", dest="postfix",
|
|
|
|
help="Injection payload postfix string")
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
injection.add_option("--string", dest="string",
|
|
|
|
help="String to match in page when the "
|
|
|
|
"query is valid")
|
|
|
|
|
2008-12-05 18:34:13 +03:00
|
|
|
injection.add_option("--regexp", dest="regexp",
|
|
|
|
help="Regexp to match in page when the "
|
|
|
|
"query is valid")
|
|
|
|
|
|
|
|
injection.add_option("--excl-str", dest="eString",
|
2009-04-22 15:48:07 +04:00
|
|
|
help="String to be excluded before comparing "
|
|
|
|
"page contents")
|
2008-12-05 18:34:13 +03:00
|
|
|
|
|
|
|
injection.add_option("--excl-reg", dest="eRegexp",
|
2009-04-22 15:48:07 +04:00
|
|
|
help="Matches to be excluded before "
|
|
|
|
"comparing page contents")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-09-14 14:35:01 +04:00
|
|
|
injection.add_option("--threshold", dest="thold", type="float",
|
|
|
|
help="Page comparison threshold value (0.0-1.0)")
|
2010-08-10 23:53:29 +04:00
|
|
|
|
2010-10-12 23:41:29 +04:00
|
|
|
injection.add_option("--text-only", dest="textOnly",
|
|
|
|
action="store_true", default=False,
|
|
|
|
help="Compare pages based only on their textual content")
|
|
|
|
|
2010-10-13 02:45:25 +04:00
|
|
|
injection.add_option("--tamper", dest="tamper",
|
2010-10-17 02:31:16 +04:00
|
|
|
help="Use given script(s) for tampering injection data")
|
2010-10-13 02:45:25 +04:00
|
|
|
|
2008-11-12 03:36:50 +03:00
|
|
|
# Techniques options
|
|
|
|
techniques = OptionGroup(parser, "Techniques", "These options can "
|
|
|
|
"be used to test for specific SQL injection "
|
|
|
|
"technique or to use one of them to exploit "
|
|
|
|
"the affected parameter(s) rather than using "
|
|
|
|
"the default blind SQL injection technique.")
|
|
|
|
|
2010-10-25 02:05:14 +04:00
|
|
|
techniques.add_option("--error-test", dest="errorTest",
|
|
|
|
action="store_true", default=False,
|
2010-10-25 19:54:45 +04:00
|
|
|
help="Test for and use error based SQL injection")
|
|
|
|
|
|
|
|
techniques.add_option("--stacked-test", dest="stackedTest",
|
|
|
|
action="store_true", default=False,
|
|
|
|
help="Test for and use stacked queries (multiple "
|
|
|
|
"statements)")
|
2010-10-25 02:05:14 +04:00
|
|
|
|
2008-11-12 03:36:50 +03:00
|
|
|
techniques.add_option("--time-test", dest="timeTest",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2009-01-19 01:36:48 +03:00
|
|
|
help="Test for time based blind SQL injection")
|
2008-12-18 00:35:04 +03:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
techniques.add_option("--time-sec", dest="timeSec",
|
|
|
|
type="int", default=5,
|
|
|
|
help="Seconds to delay the DBMS response "
|
|
|
|
"(default 5)")
|
|
|
|
|
2008-11-12 03:36:50 +03:00
|
|
|
techniques.add_option("--union-test", dest="unionTest",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2010-10-25 19:54:45 +04:00
|
|
|
help="Test for and use UNION query (inband) SQL injection")
|
2008-11-12 03:36:50 +03:00
|
|
|
|
2008-12-22 00:39:53 +03:00
|
|
|
techniques.add_option("--union-tech", dest="uTech",
|
|
|
|
help="Technique to test for UNION query SQL injection")
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
# Fingerprint options
|
|
|
|
fingerprint = OptionGroup(parser, "Fingerprint")
|
|
|
|
|
|
|
|
fingerprint.add_option("-f", "--fingerprint", dest="extensiveFp",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2008-11-16 02:41:31 +03:00
|
|
|
help="Perform an extensive DBMS version fingerprint")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
# Enumeration options
|
|
|
|
enumeration = OptionGroup(parser, "Enumeration", "These options can "
|
|
|
|
"be used to enumerate the back-end database "
|
|
|
|
"management system information, structure "
|
|
|
|
"and data contained in the tables. Moreover "
|
2008-12-21 19:35:03 +03:00
|
|
|
"you can run your own SQL statements.")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
enumeration.add_option("-b", "--banner", dest="getBanner",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False, help="Retrieve DBMS banner")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
enumeration.add_option("--current-user", dest="getCurrentUser",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2008-10-15 19:38:22 +04:00
|
|
|
help="Retrieve DBMS current user")
|
|
|
|
|
|
|
|
enumeration.add_option("--current-db", dest="getCurrentDb",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2008-10-15 19:38:22 +04:00
|
|
|
help="Retrieve DBMS current database")
|
|
|
|
|
2008-12-18 23:41:11 +03:00
|
|
|
enumeration.add_option("--is-dba", dest="isDba",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2008-12-18 23:41:11 +03:00
|
|
|
help="Detect if the DBMS current user is DBA")
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
enumeration.add_option("--users", dest="getUsers", action="store_true",
|
2010-09-27 17:23:29 +04:00
|
|
|
default=False, help="Enumerate DBMS users")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
enumeration.add_option("--passwords", dest="getPasswordHashes",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2010-03-03 21:57:09 +03:00
|
|
|
help="Enumerate DBMS users password hashes")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
enumeration.add_option("--privileges", dest="getPrivileges",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2010-03-03 21:57:09 +03:00
|
|
|
help="Enumerate DBMS users privileges")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-03-25 18:46:06 +03:00
|
|
|
enumeration.add_option("--roles", dest="getRoles",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2010-03-25 18:46:06 +03:00
|
|
|
help="Enumerate DBMS users roles")
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
enumeration.add_option("--dbs", dest="getDbs", action="store_true",
|
2010-09-27 17:23:29 +04:00
|
|
|
default=False, help="Enumerate DBMS databases")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
enumeration.add_option("--tables", dest="getTables", action="store_true",
|
2010-09-27 17:23:29 +04:00
|
|
|
default=False, help="Enumerate DBMS database tables")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
enumeration.add_option("--columns", dest="getColumns", action="store_true",
|
2010-09-27 17:23:29 +04:00
|
|
|
default=False, help="Enumerate DBMS database table columns")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
enumeration.add_option("--dump", dest="dumpTable", action="store_true",
|
2010-09-27 17:23:29 +04:00
|
|
|
default=False, help="Dump DBMS database table entries")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
enumeration.add_option("--dump-all", dest="dumpAll", action="store_true",
|
2010-09-27 17:23:29 +04:00
|
|
|
default=False, help="Dump all DBMS databases tables entries")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-05-07 17:40:57 +04:00
|
|
|
enumeration.add_option("--search", dest="search", action="store_true",
|
2010-09-27 17:23:29 +04:00
|
|
|
default=False, help="Search column(s), table(s) and/or database name(s)")
|
2010-05-07 17:40:57 +04:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
enumeration.add_option("-D", dest="db",
|
|
|
|
help="DBMS database to enumerate")
|
|
|
|
|
|
|
|
enumeration.add_option("-T", dest="tbl",
|
|
|
|
help="DBMS database table to enumerate")
|
|
|
|
|
|
|
|
enumeration.add_option("-C", dest="col",
|
|
|
|
help="DBMS database table column to enumerate")
|
|
|
|
|
|
|
|
enumeration.add_option("-U", dest="user",
|
|
|
|
help="DBMS user to enumerate")
|
|
|
|
|
|
|
|
enumeration.add_option("--exclude-sysdbs", dest="excludeSysDbs",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2008-10-15 19:38:22 +04:00
|
|
|
help="Exclude DBMS system databases when "
|
|
|
|
"enumerating tables")
|
|
|
|
|
|
|
|
enumeration.add_option("--start", dest="limitStart", type="int",
|
2009-04-25 00:12:52 +04:00
|
|
|
help="First query output entry to retrieve")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
enumeration.add_option("--stop", dest="limitStop", type="int",
|
2009-04-25 00:12:52 +04:00
|
|
|
help="Last query output entry to retrieve")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-09-26 03:03:45 +04:00
|
|
|
enumeration.add_option("--first", dest="firstChar", type="int",
|
|
|
|
help="First query output word character to retrieve")
|
|
|
|
|
|
|
|
enumeration.add_option("--last", dest="lastChar", type="int",
|
|
|
|
help="Last query output word character to retrieve")
|
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
enumeration.add_option("--sql-query", dest="query",
|
2008-12-21 19:35:03 +03:00
|
|
|
help="SQL statement to be executed")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
enumeration.add_option("--sql-shell", dest="sqlShell",
|
2010-09-27 17:23:29 +04:00
|
|
|
action="store_true", default=False,
|
2008-10-15 19:38:22 +04:00
|
|
|
help="Prompt for an interactive SQL shell")
|
|
|
|
|
2010-09-30 16:35:45 +04:00
|
|
|
enumeration.add_option("--common-exists", dest="cExists", action="store_true",
|
|
|
|
default=False, help="Check existence of common tables")
|
|
|
|
|
|
|
|
enumeration.add_option("--exists", dest="tableFile",
|
|
|
|
help="Check existence of user specified tables")
|
|
|
|
|
2009-09-26 03:03:45 +04:00
|
|
|
# User-defined function options
|
|
|
|
udf = OptionGroup(parser, "User-defined function injection", "These "
|
|
|
|
"options can be used to create custom user-defined "
|
|
|
|
"functions.")
|
|
|
|
|
|
|
|
udf.add_option("--udf-inject", dest="udfInject", action="store_true",
|
2010-09-27 17:23:29 +04:00
|
|
|
default=False, help="Inject custom user-defined functions")
|
2009-09-26 03:03:45 +04:00
|
|
|
|
|
|
|
udf.add_option("--shared-lib", dest="shLib",
|
|
|
|
help="Local path of the shared library")
|
2008-12-09 00:24:24 +03:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
# File system options
|
|
|
|
filesystem = OptionGroup(parser, "File system access", "These options "
|
|
|
|
"can be used to access the back-end database "
|
2009-04-22 15:48:07 +04:00
|
|
|
"management system underlying file system.")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
filesystem.add_option("--read-file", dest="rFile",
|
2009-04-22 15:48:07 +04:00
|
|
|
help="Read a file from the back-end DBMS "
|
|
|
|
"file system")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
filesystem.add_option("--write-file", dest="wFile",
|
2009-04-22 15:48:07 +04:00
|
|
|
help="Write a local file on the back-end "
|
|
|
|
"DBMS file system")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
filesystem.add_option("--dest-file", dest="dFile",
|
|
|
|
help="Back-end DBMS absolute filepath to "
|
|
|
|
"write to")
|
2008-12-09 00:24:24 +03:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
# Takeover options
|
2010-03-12 02:54:07 +03:00
|
|
|
takeover = OptionGroup(parser, "Operating system access", "These "
|
|
|
|
"options can be used to access the back-end "
|
2009-04-22 15:48:07 +04:00
|
|
|
"database management system underlying "
|
|
|
|
"operating system.")
|
|
|
|
|
|
|
|
takeover.add_option("--os-cmd", dest="osCmd",
|
|
|
|
help="Execute an operating system command")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
takeover.add_option("--os-shell", dest="osShell",
|
|
|
|
action="store_true", default=False,
|
2009-04-22 15:48:07 +04:00
|
|
|
help="Prompt for an interactive operating "
|
|
|
|
"system shell")
|
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
takeover.add_option("--os-pwn", dest="osPwn",
|
|
|
|
action="store_true", default=False,
|
2009-04-22 15:48:07 +04:00
|
|
|
help="Prompt for an out-of-band shell, "
|
|
|
|
"meterpreter or VNC")
|
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
takeover.add_option("--os-smbrelay", dest="osSmb",
|
|
|
|
action="store_true", default=False,
|
2009-04-22 15:48:07 +04:00
|
|
|
help="One click prompt for an OOB shell, "
|
|
|
|
"meterpreter or VNC")
|
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
takeover.add_option("--os-bof", dest="osBof",
|
|
|
|
action="store_true", default=False,
|
2009-04-22 15:48:07 +04:00
|
|
|
help="Stored procedure buffer overflow "
|
|
|
|
"exploitation")
|
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
takeover.add_option("--priv-esc", dest="privEsc",
|
|
|
|
action="store_true", default=False,
|
2010-03-13 01:43:35 +03:00
|
|
|
help="Database process' user privilege escalation")
|
2009-04-22 15:48:07 +04:00
|
|
|
|
|
|
|
takeover.add_option("--msf-path", dest="msfPath",
|
|
|
|
help="Local path where Metasploit Framework 3 "
|
|
|
|
"is installed")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
takeover.add_option("--tmp-path", dest="tmpPath",
|
|
|
|
help="Remote absolute path of temporary files "
|
|
|
|
"directory")
|
2008-12-09 00:24:24 +03:00
|
|
|
|
2009-09-26 03:03:45 +04:00
|
|
|
# Windows registry options
|
2010-03-12 02:54:07 +03:00
|
|
|
windows = OptionGroup(parser, "Windows registry access", "These "
|
|
|
|
"options can be used to access the back-end "
|
2009-09-26 03:03:45 +04:00
|
|
|
"database management system Windows "
|
|
|
|
"registry.")
|
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
windows.add_option("--reg-read", dest="regRead",
|
|
|
|
action="store_true", default=False,
|
2009-09-26 03:03:45 +04:00
|
|
|
help="Read a Windows registry key value")
|
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
windows.add_option("--reg-add", dest="regAdd",
|
|
|
|
action="store_true", default=False,
|
2009-09-26 03:03:45 +04:00
|
|
|
help="Write a Windows registry key value data")
|
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
windows.add_option("--reg-del", dest="regDel",
|
|
|
|
action="store_true", default=False,
|
2009-09-26 03:03:45 +04:00
|
|
|
help="Delete a Windows registry key value")
|
|
|
|
|
|
|
|
windows.add_option("--reg-key", dest="regKey",
|
|
|
|
help="Windows registry key")
|
|
|
|
|
|
|
|
windows.add_option("--reg-value", dest="regVal",
|
|
|
|
help="Windows registry key value")
|
|
|
|
|
|
|
|
windows.add_option("--reg-data", dest="regData",
|
|
|
|
help="Windows registry key value data")
|
|
|
|
|
|
|
|
windows.add_option("--reg-type", dest="regType",
|
|
|
|
help="Windows registry key value type")
|
|
|
|
|
2010-10-16 03:26:48 +04:00
|
|
|
# Miscellaneous options
|
|
|
|
miscellaneous = OptionGroup(parser, "Miscellaneous")
|
2010-09-16 14:23:51 +04:00
|
|
|
|
2010-05-28 20:43:04 +04:00
|
|
|
miscellaneous.add_option("-x", dest="xmlFile",
|
|
|
|
help="Dump the data into an XML file")
|
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
miscellaneous.add_option("-s", dest="sessionFile",
|
|
|
|
help="Save and resume all data retrieved "
|
|
|
|
"on a session file")
|
2010-05-21 13:35:36 +04:00
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
miscellaneous.add_option("--flush-session", dest="flushSession",
|
|
|
|
action="store_true", default=False,
|
2010-03-04 16:01:18 +03:00
|
|
|
help="Flush session file for current target")
|
2010-05-21 13:35:36 +04:00
|
|
|
|
2010-10-10 22:56:43 +04:00
|
|
|
miscellaneous.add_option("--forms", dest="forms",
|
|
|
|
action="store_true", default=False,
|
|
|
|
help="Parse and test forms on target url")
|
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
miscellaneous.add_option("--eta", dest="eta",
|
|
|
|
action="store_true", default=False,
|
2009-04-22 15:48:07 +04:00
|
|
|
help="Display for each output the "
|
|
|
|
"estimated time of arrival")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
miscellaneous.add_option("--gpage", dest="googlePage", type="int",
|
2010-01-13 17:52:23 +03:00
|
|
|
help="Use google dork results from specified page number")
|
2010-01-02 05:02:12 +03:00
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
miscellaneous.add_option("--update", dest="updateAll",
|
|
|
|
action="store_true", default=False,
|
2010-03-03 16:59:29 +03:00
|
|
|
help="Update sqlmap")
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
miscellaneous.add_option("--save", dest="saveCmdline",
|
|
|
|
action="store_true", default=False,
|
2008-10-15 19:38:22 +04:00
|
|
|
help="Save options on a configuration INI file")
|
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
miscellaneous.add_option("--batch", dest="batch",
|
|
|
|
action="store_true", default=False,
|
2008-10-15 19:38:22 +04:00
|
|
|
help="Never ask for user input, use the default behaviour")
|
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
miscellaneous.add_option("--cleanup", dest="cleanup",
|
|
|
|
action="store_true", default=False,
|
2009-04-22 15:48:07 +04:00
|
|
|
help="Clean up the DBMS by sqlmap specific "
|
|
|
|
"UDF and tables")
|
2008-12-09 00:24:24 +03:00
|
|
|
|
2010-09-27 17:23:29 +04:00
|
|
|
miscellaneous.add_option("--replicate", dest="replicate",
|
|
|
|
action="store_true", default=False,
|
2010-09-24 17:20:51 +04:00
|
|
|
help="Replicate dumped data into a sqlite3 database")
|
2010-09-24 17:19:35 +04:00
|
|
|
|
2010-10-25 19:37:43 +04:00
|
|
|
miscellaneous.add_option("--check-payload", dest="checkPayload",
|
|
|
|
action="store_true", default=False,
|
|
|
|
help="IDS detection testing of injection payload")
|
|
|
|
|
2010-10-23 13:38:46 +04:00
|
|
|
miscellaneous.add_option("--beep", dest="beep",
|
|
|
|
action="store_true", default=False,
|
|
|
|
help="Alert with audio beep when sql injection found")
|
|
|
|
|
2010-05-21 13:35:36 +04:00
|
|
|
# Hidden and/or experimental options
|
|
|
|
parser.add_option("--profile", dest="profile", action="store_true",
|
2010-09-27 17:23:29 +04:00
|
|
|
default=False, help=SUPPRESS_HELP)
|
2010-05-21 13:35:36 +04:00
|
|
|
|
|
|
|
parser.add_option("--cpu-throttle", dest="cpuThrottle", type="int", default=10,
|
|
|
|
help=SUPPRESS_HELP)
|
|
|
|
|
2010-07-30 16:49:25 +04:00
|
|
|
parser.add_option("--smoke-test", dest="smokeTest", action="store_true",
|
2010-09-27 17:23:29 +04:00
|
|
|
default=False, help=SUPPRESS_HELP)
|
2010-07-30 16:49:25 +04:00
|
|
|
|
2010-09-15 17:59:55 +04:00
|
|
|
parser.add_option("--live-test", dest="liveTest", action="store_true",
|
2010-09-27 17:23:29 +04:00
|
|
|
default=False, help=SUPPRESS_HELP)
|
2010-09-15 17:59:55 +04:00
|
|
|
|
2008-12-04 20:40:03 +03:00
|
|
|
parser.add_option_group(target)
|
2008-10-15 19:38:22 +04:00
|
|
|
parser.add_option_group(request)
|
2010-10-17 01:52:16 +04:00
|
|
|
parser.add_option_group(optimization)
|
2008-10-15 19:38:22 +04:00
|
|
|
parser.add_option_group(injection)
|
2008-11-12 03:36:50 +03:00
|
|
|
parser.add_option_group(techniques)
|
2008-10-15 19:38:22 +04:00
|
|
|
parser.add_option_group(fingerprint)
|
|
|
|
parser.add_option_group(enumeration)
|
2009-09-26 03:03:45 +04:00
|
|
|
parser.add_option_group(udf)
|
2008-10-15 19:38:22 +04:00
|
|
|
parser.add_option_group(filesystem)
|
|
|
|
parser.add_option_group(takeover)
|
2009-09-26 03:03:45 +04:00
|
|
|
parser.add_option_group(windows)
|
2008-10-15 19:38:22 +04:00
|
|
|
parser.add_option_group(miscellaneous)
|
|
|
|
|
2010-10-14 00:54:18 +04:00
|
|
|
args = []
|
|
|
|
for arg in sys.argv:
|
|
|
|
try:
|
|
|
|
args.append(utf8decode(arg))
|
|
|
|
except:
|
|
|
|
args.append(unicode(arg, sys.getfilesystemencoding()))
|
|
|
|
(args, _) = parser.parse_args(args)
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-09-15 17:59:55 +04:00
|
|
|
if not args.direct and not args.url and not args.list and not args.googleDork and not args.configFile\
|
|
|
|
and not args.requestFile and not args.updateAll and not args.smokeTest and not args.liveTest:
|
2010-03-27 02:23:25 +03:00
|
|
|
errMsg = "missing a mandatory parameter ('-d', '-u', '-l', '-r', '-g', '-c' or '--update'), "
|
2008-10-15 19:38:22 +04:00
|
|
|
errMsg += "-h for help"
|
|
|
|
parser.error(errMsg)
|
|
|
|
|
|
|
|
return args
|
|
|
|
except (OptionError, TypeError), e:
|
|
|
|
parser.error(e)
|
|
|
|
|
|
|
|
debugMsg = "parsing command line"
|
|
|
|
logger.debug(debugMsg)
|