支持数据库(11种类别):
Mysql、Oracle、PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird, Sybase, SAP MaxDB 和 HSQLDB
===========================================================================================
Sqlmap注入技术:
1) 基于bool的盲注
2) 基于时间的盲注
3)基于错误的注入
4)基于UNION查询注入
5)堆查询注入
6)out-of-band 带外
===========================================================================================
更新sqlmap
python sqlmap.py --update
===========================================================================================
-v参数(需要配合其他参数一起使用)
0、只显示python错误以及严重的信息。 1、同时显示基本信息和警告信息。(默认) 2、同时显示debug信息。 3、同时显示注入的payload。 4、同时显示HTTP请求。 5、同时显示HTTP响应头。 6、同时显示HTTP响应页面。
===================================================================================
目标获取
需要测试的目标
1) 参数 -d
功能:直接连接到数据库
使用说明:直接连接到单数据库实例
实例:
sqlmap -v 2 -d "mysql://root:root@127.0.0.1:3306/security" -f --banner --dbs --users
2) 参数-u URL
功能:--url=URL Target URL (e.g. "http://www.site.com/vuln.php?id=1")
实例:
sqlmap -u "http://127.0.0.1/Less-1/?id=2" -f --banner --dbs --users
3) -l logfile参数
功能:直接把Burp proxy或者WebScarab proxy中的日志直接倒出来交给sqlmap来一个一个检测是否有注入
4) 参数-x sitemapurl
功能:参数为提供远程服务器sitemap文件,可能xml格式
5) 参数-m
功能:从文本文件中读取多个目标文件进行扫描
6)参数-r http/https请求文件
功能:从文件中读取http请求,如果是https,需要配合参数--force-ssl 或主机端口中指明443端口
POST /sugg?ifc=4&em=4 HTTP/1.1 User-Agent: SogPSI Host: s.wisdom.www.sog.com Accept: */* Accept-Encoding: gzip,deflate Proxy-Connection: Keep-Alive Content-Length: 555 Content-Type: application/x-www-form-urlencoded x ÍÇ¢k@
7)参数-g
功能:使用google搜索引擎提供的搜索结果GET参数并注入
sqlmap -g "inurl:\".php?id=1\""
8) 参数-c
====================================================================================================
请求
构造HTTP/HTTPS请求头
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 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-private=A.. HTTP authentication PEM private key file --ignore-401 Ignore HTTP Error 401 (Unauthorized) --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 --ignore-proxy Ignore system default proxy settings --tor Use Tor anonymity network --tor-port=TORPORT Set Tor proxy port other than default --tor-type=TORTYPE Set Tor proxy type (HTTP (default), SOCKS4 or SOCKS5) --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()")
1) 参数 --method
功能:用于指定http请求方法,PUT,GET, POST
2) 参数:--data
适用范围:POST方法
功能:对post方法中数据部分每个参数进行注入测试
实例:
sqlmap -u "http://10.1.20.4:8800" --data="loginsubmit=true&refer=%2F&pwlevel=1&username=admin&userpass=70991d0ce4c6438a713c073535b93c18&rcode=bckL" -f --banner --dbs
3) 参数:--param-del
功能:指定http请求中data指明部分区分各个参数之间的分隔符(; || , &等)
实例:
sqlmap -u "http://10.1.20.4:8800" --data="loginsubmit=true||refer=%2F||pwlevel=1||username=admin||userpass=70991d0ce4c6438a713c073535b93c18||rcode=bckL" --param-del="||" -f --banner --dbs
4)参数http cookie:--cookie,--cookie-del,--load-cookies
功能:主动测试cookies;被动测试web应用需要登陆的时候
测试条件:当--level的参数设定为2或者2以上的时候,sqlmap会尝试注入Cookie参数
5)参数agent:--user-agent 和--random-agent
功能: --user-agent 指定用户自定义的
--random-agent 数据来源 txt/user-agents.txt,任意选择其中一个 Mozilla或Opera
6) 参数referer: --referer=REFERER
功能:请求中伪造HTTP中的referer
测试条件:当--level参数设定为3或者3以上的时候会尝试对referer注入
7) 参数 header:--headers
-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")
8) 参数:--auth-type、 --auth-cred、--auth-private、--ignore-401
--auth-type=AUTH.. HTTP authentication type (Basic, Digest, NTLM or PKI)
--auth-cred=AUTH.. HTTP authentication credentials (name:password)
--auth-private=A.. HTTP authentication PEM private key file
--ignore-401 Ignore HTTP Error 401 (Unauthorized)
9) 参数--randomize
功能:可以设定某一个参数值在每一次请求中随机的变化,长度和类型会与提供的初始值一样
10)参数 --skip-urlencode
功能:根据参数位置,它的值默认将会被URL编码,但是有些时候后端的web服务器不遵守RFC标准,只接受不经过URL编码的值,这时候就需要用--skip-urlencode参数
11)参数:--eval
功能:在有些时候,需要根据某个参数的变化,而修改另个一参数,才能形成正常的请求,这时可以用--eval参数在每次请求时根据所写python代码做完修改后请求
12) 参数:--safe-url
, --safe-post
, --safe-req
and --safe-freq
功能:
=================================================================================================
优化
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)
1)参数:-o
功能:用于开启sqlmap开关,用于开启 --predict-output 、--keep-alive 、--null-connection
说明:需要配合 --threads=3
、--keep-alive 、--null-connection 任何一个或多个使用
2) 参数 --predict-output
功能:
说明:这个开关是不兼容--threads 开关项
3) 参数 --keep-alive
功能:保持长连接
说明:不能同--proxy 参数一起使用
4) 参数:--null-connection
功能:通过发送不含http body的用于检测http响应的大小,主要用于盲注中,用于sqlmap端节省带宽,提高注入检测速度
说明:不兼容 --text-only参数项
5) 参数 --threads
功能:主要应用在开启暴力爆破开关的情况下,并数据获取方式是通过任何sql盲注技术的情况下, 并发请求的最大数量被设置为10时,性能和站点可靠性的比较好
=================================================================================================
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 dynamic --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
--where=DUMPWHERE Use WHERE condition while table dumping
--start=LIMITSTART First query output entry to retrieve
--stop=LIMITSTOP Last query output 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
--charset=CHARSET Force character encoding used for data retrieval
--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 ",")
--dump-format=DU.. Format of dumped data (CSV (default), HTML or SQLITE)
--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
--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
--pivot-column=P.. Pivot column name
--save 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)
--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)
--page-rank Display page rank (PR) for Google dork results
--purge-output Safely remove all content from output directory
--smart Conduct thorough tests only if positive heuristic(s)
--sqlmap-shell Prompt for an interactive sqlmap shell
--wizard Simple wizard interface for beginner users
=================================================================================================
=================================================================================================
=================================================================================================
=================================================================================================
=================================================================================================
=================================================================================================
=================================================================================================
参考:
1 官网 http://sqlmap.org/
2 https://github.com/sqlmapproject/sqlmap/wiki/Usage