sqlmap支持
MySQL
Oracle
PostgreSQL
Microsoft SQL Server
Microsoft Access
IBM DB2
SQLite
Firebird
Sybase
SAP MaxDB
等数据库的各种安全漏洞检测。
sqlmap支持五种不同的注入模式:
1、基于布尔的盲注,即可以根据返回页面判断条件真假的注入;
2、基于时间的盲注,即不能根据页面返回内容判断任何信息,用条件语句查看时间延迟语句是否执行(即页面返回时间是否增加)来判断;
3、基于报错注入,即页面会返回错误信息,或者把注入的语句的结果直接返回在页面中;
4、联合查询注入,可以使用union的情况下的注入;
5、堆查询注入,可以同时执行多条语句的执行时的注入。
二、sqlmap下载安装及更新
Kali自带sqlmap直接使用
更新kali sqlmap
cd /usr/share
rm-rf sqlmap
git clone https://github.com/sqlmapproject/sqlmap
三、sqlmap参数详解
1、Options(选项)
#显示基本帮助信息并退出
-h, --help Show basic help message and exit
#显示高级帮助信息并退出-hh Show advanced help message and exit
#显示程序版本信息并退出--version Show program's version number and exit
#直接连接数据库的连接字符串-d DIRECT Connection string for direct database connection
#(1).当数据库管理系统是MySQL、Oracle、Microsoft SQL Server或PostgreSQL等时格式为:#dbms://username:password@dbms_ip:dbms_port/databse_name#sqlmap -d "mysql://root:root@192.168.128.159:3306/security"#(2).当数据库管理系统是SQLite、Microsoft Access或Firebird等时格式为:#dbms://databse_filepath
#从Burp或者WebScarab代理日志文件中分析目标-l LOGFILE Parse target(s) from Burp or WebScarab proxy log file#burpsuite记录日志 Setting---All---Project---Logging---Proxy Requests---保存位置#sqlmap -l proxy.log#常与--scope=SCOPE联合使用#sqlmap -l burp.log --scope="(www)?\.target\.(com|net|org)"
#将目标地址保存在文件中,一行为一个URL地址进行批量检测。-m BULKFILE Scan multiple targets given in a textual file#sqlmap -m url.txt#url.txt#www.target1.com/vuln1.php?q=foobar#www.target2.com/vuln2.asp?id=1#www.target3.com/vuln3/id/1*
#从文件加载HTTP请求-r REQUESTFILE Load HTTP request from a file#如果是非get、非post型注入,则须将参数设置为*,来指定注入,如Cookie:*#如果是https需要配合--force-ssl或者在Host后面加:443#sqlmap -r target.txt# GET /user.php?id=1 HTTP/1.1# Host: 192.168.56.101:8080# User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0# Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8# Accept-Language: zh-SG,en-US;q=0.7,en;q=0.3# Accept-Encoding: gzip, deflate# DNT: 1# Connection: close# Upgrade-Insecure-Requests: 1
#从谷歌中加载结果目标URL,只测试前100个结果-g GOOGLEDORK Process Google dork results as target URLs
#sqlmap -g "inurl:\".php?id=1\""
#从配置ini文件中加载选项-c CONFIGFILE Load options from a configuration INI file#sqlmap -c sqlmap.conf#参照/usr/share/sqlmap/sqlmap.conf进行填写
3、Request(请求)
These options can be used to specify how to connect to the target URL
#这些选项可以用来指定如何连接到目标URL
#http user-agent头的值 -A AGENT, --user-agent=USER-AGENT HTTP User-Agent header value
#sqlmap -u "www.xxx.com" -A "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"#sqlmap -u "www.xxx.com" --user-agent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"#默认情况下sqlmap的HTTP请求头中User-Agent值是:sqlmap/1.0-dev-xxxxxxx(http://sqlmap.org)
#强制使用给定的HTTP方法--method=METHOD Force usage of given HTTP method (e.g. PUT)#sqlmap -u "www.xxx.com" --method=PUT#请求方法包括GET POST DELETE HEAD OPTIONS PUT TRACE
#通过POST发送数据参数--data=DATA Data string to be sent through POST (e.g. "id=1")#sqlmap -u "www.xxx.com" --data="uname=1&password"
#指定用于分割参数的字符,默认即为&
--param-del=PARAM-DEL Character used for splitting parameter values (e.g. &)#sqlmap -u "www.xxx.com" --data="id=0;name=1" --param-del=";"
#用来分隔cookie的字符串值
--cookie-del=COOKIE-DEL Character used for splitting cookie values (e.g. ;)#sqlmap -u "www.xxx.com" --data="id=0;name=1" --cookie-del=";"
#暂无资料
--live-cookies=LIVE-COOKIES Live cookies file used for loading up-to-date values
#暂无资料
--load-cookies=LOAD-COOKIES File containing cookies in Netscape/wget format
#忽略响应中的Set-Cookie
--drop-set-cookie Ignore Set-Cookie header from response
#若HTTP响应头中有“Set-Cookie”,Sqlmap会自动设置“Set-Cookie”设置的cookie,并对这些cookie进行检测。若不想让Sqlmap这么做,添加参数“–drop-set-cookie”即可,这样,Sqlmap会忽略“Set-Cookie”
#使用代理服务器连接到目标URL--proxy=PROXY Use a proxy to connect to the target URL
#使用参数“–proxy”来设置一个HTTP(S)代理,格式是“http(s)://url:port”。#若代理需要认证,使用参数“–proxy-cred”来提供认证凭证,格式是“username:password”#sqlmap --proxy="127.0.0.1:1234"
#从文件加载代理列表
--proxy-file=PRO.. Load proxy list from a file#使用参数“–proxy-file”指定一个存储着代理列表的文件#Sqlmap会依次使用文件中的代理,当某个代理有任何连接问题时就会被弃用而换下一个代理。#sqlmap --proxy-file="proxy.txt"
#暂无资料
--proxy-freq=PRO.. Requests between change of proxy from a given list
#使用Tor匿名网络--tor Use Tor anonymity network
#sqlmap --tor
#设置Tor代理端口
--tor-port=TORPORT Set Tor proxy port other than default
#sqlmap --tor --tor-port 9050
#设置Tor代理类型 (HTTP,SOCKS4 or SOCKS5 (默认))
--tor-type=TORTYPE Set Tor proxy type(HTTP, SOCKS4 or SOCKS5 (default))#sqlmap --tor --tor-port 9050 --tor-type=SOCKS5
#检查Tor的是否正确使用
--check-tor Check to see if Tor is used properly
#要求高度的匿名性可以使用参数“–check-tor”,加上该参数后Sqlmap会确保所有流量都走Tor代理#sqlmap --check-tor
#设定两个HTTP(S)请求间的延迟--delay=DELAY Delay in seconds between each HTTP request
#设定为0.5的时候是半秒,默认是没有延迟的#sqlmap --delay=0.5
#设定一个HTTP(S)请求超过多久判定为超时--timeout=TIMEOUT Seconds to wait before timeout connection (default 30)#10表示10秒,默认是30秒
#当HTTP(S)超时时,可以设定重新尝试连接次数,默认是3次。--retries=RETRIES Retries when the connection timeouts (default 3)#sqlmap --retries=4
#暂无资料
--retry-on=RETRYON Retry request on regexp matching content (e.g. "drop")
#设定某一个参数值在每一次请求中随机的变化,值的类型和长度依照于原始值--randomize=RPARAM Randomly change value for given parameter(s)
#提供一个安全不错误的连接,每隔一段时间都会去访问一下#有时服务器检测到某个客户端错误请求过多会对其进行屏蔽,而Sqlmap的测试往往会产生大量错误请求,为避免被屏蔽,可以时不时的产生几个正常请求以迷惑服务器。
--safe-url=SAFEURL URL address to visit frequently during testing
#sqlmap --safe-url="www.xxx.com"
#提供一个安全不错误的连接,每次测试请求之后都会再访问一遍安全连接。
--safe-post=SAFE.. POST data to send to a safe URL
#sqlmap --safe-url="www.xxx.com" --safe-post="uname=1&passwd=1"
#从文件中载入安全HTTP请求
--safe-req=SAFER.. Load safe HTTP request from a file
#每次测试请求之后都会访问一下的安全URL
--safe-freq=SAFE.. Regular requests between visits to a safe URL
#sqlmap --safe-freq="www.xxx.com"
#跳过URL的有效载荷数据编码
--skip-urlencode Skip URL encoding of payload data
#Sqlmap默认会对URL进行URL编码,可以使用该参数关闭URL编码#sqlmap --skip-urlencode
#指定包含token的隐藏字段名
--csrf-token=CSR.. Parameter used to hold anti-CSRF token
#现在有很多网站通过在表单中添加值为随机生成的token的隐藏字段来防止CSRF攻击,Sqlmap会自动识别出这种保护方式并绕过。但自动识别有可能失效,此时就要用到这两个参数#sqlmap --csrf-token="csrfmiddlewaretoken"
#从URL中提取token值
--csrf-url=CSRFURL URL address to visit for extraction of anti-CSRF token
#sqlmap --csrf-url="www.xxx.com"
#访问防止CSRF攻击网站时用到的HTTP方法
--csrf-method=CS.. HTTP method to use during anti-CSRF token page visit
#sqlmap --csrf-method=GET#请求方法包括GET POST DELETE HEAD OPTIONS PUT TRACE
#访问防止CSRF攻击网站时用到的POST数据
--csrf-data=CSRF.. POST data to send during anti-CSRF token page visit
#sqlmap --csrf-data="uname=1&passwd=1"
#强制使用SSL/HTTPS
--force-ssl Force usage of SSL/HTTPS
#sqlmap --force-ssl
#使用HTTP分块传输编码 (POST) 请求--chunked Use HTTP chunked transfer encoded (POST) requests
#使用HTTP参数污染的方法--hpp Use HTTP parameter pollution method
#在请求前执行python--eval=EVALCODE Evaluate provided Python code before the request (e.g."import hashlib;id2=hashlib.md5(id).hexdigest()")#sqlmap -u"http://www.target.com/vuln.php?id=1&hash=c4ca4238a0b923820dcc509a6f75849b"--eval="import hashlib;hash=hashlib.md5(id).hexdigest()"
4、Optimization(优化)
These options can be used to optimize the performance of sqlmap
#这些选项可用于优化sqlmap性能
#打开所有的优化开关-o Turn on all optimization switches
#添加此参数相当于同时添加下列三个优化参数:#–keep-alive#–null-connection#–threads=3 (如果没有设置一个更好的值)
#预测普通查询输出
--predict-output Predict common queries output
#使用持久HTTP(S)连接
--keep-alive Use persistent HTTP(s) connections
#该参数与“–proxy”矛盾
#检索页面长度,而不需要实际的HTTP响应体
--null-connection Retrieve page length without actual HTTP response body
#特殊的HTTP请求类型可以直接获得HTTP响应的大小而不用获得HTTP响应体。显然这在布尔型盲注中可以节约很大的带宽。
#最大并发HTTP请求数 (默认为1)--threads=THREADS Max number of concurrent HTTP(s) requests (default 1)
5、Injection(注入)
These options can be used to specify which parameters to test for,provide custom injection payloads and optional tampering scripts
#这些选项可用于指定要测试的参数、提供自定义注入有效载荷和可选的篡改脚本。
#跳过给定参数的测试--skip=SKIP Skip testing for given parameter(s)#sqlmap --skip="user-agent,referer"
#跳过测试不显示为动态的参数
--skip-static Skip testing parameters that not appear to be dynamic
#使用正则表达式排除参数进行测试(e.g. "ses")
--param-exclude=.. Regexp to exclude parameters from testing (e.g. "ses")
#暂无资料
--param-filter=P.. Select testable parameter(s) by place (e.g. "POST")
#强制后端的DBMS为此值--dbms=DBMS Force back-end DBMS to provided value
#sqlmap --dbms="MySQL 5.0"#sqlmap --dbms="Microsoft SQL Server 2005"#sqlmap --dbms="postgresql"#Sqlmap支持以下这些数据库管理系统:# MySQL# Oracle# PostgreSQL# Microsoft SQL Server# Microsoft Access# Firebird# SQLite# Sybase# SAP MaxDB# DB2#在添加“–dbms”参数的同时还添加了“–fingerprint”,Sqlmap只会在指定的数据库管理系统内进行指纹识别。
#使用给定的脚本篡改注入数据--tamper=TAMPER Use given script(s)for tampering injection data
6、Detection(检测)
These options can be used to customize the detection phase
#这些选项可以用来指定在SQL盲注时如何解析和比较HTTP响应页面的内容
--level=LEVEL Level of tests to perform (1-5, default 1)#sqlmap -u "www.xxx.com" --level=5#检测级别大于等于2时会检测cookie是否有注入#检测级别大于等于3时会检测User-Agent和Referer是否有注入#若不是很清楚注入点在哪里可以设置一个比较高的检测级别
#执行测试的风险(0-3,默认为1)--risk=RISK Risk of tests to perform (1-3, default 1)#风险等级2添加了基于时间的注入测试#风险等级3添加了OR测试#若注入点是在UPDATE语句中,使用OR测试可能会修改整个表的数据
#查询评估为True时匹配的字符串--string=STRING String to match when query is evaluated to True
#默认情况下在布尔型注入中Sqlmap通过比较返回页面内容来判断True或False。#但有时页面每次刷新都会不同#sqlmap --string="flag"
#查询评估为False时要匹配的字符串
--not-string=NOT.. String to match when query is evaluated to False
#sqlmap --not-string="slag"
#正则表达式在查询评估为True时匹配--regexp=REGEXP Regexp to match when query is evaluated to True
#查询评估为True时要匹配的HTTP代码--code=CODE HTTP code to match when query is evaluated to True
#HTTP状态码#https://www.runoob.com/http/http-status-codes.html#sqlmap --code=200
#在启发式为true的情况下执行全面测试--smart Perform thorough tests only if positive heuristic(s)
#仅根据文本内容比较页面
--text-only Compare pages based only on the textual content
#若是HTTP响应体中有许多诸如JavaScript之类的活动内容,专注于纯文本的检测#sqlmap --text-only="flag"
#根据标题比较页面--titles Compare pages based only on their titles
#sqlmap --titles="welcome"
7、Techniques(技术)
These options can be used to tweak testing of specific SQL injection
techniques
#这些选项可用于调整特定SQL注入技术的测试
#基于时间延迟注入中延时设置
--time-sec=TIMESEC Seconds to delay the DBMS response (default 5)#sqlmap --time-sec=10
#联合查询注入中列数设置
--union-cols=UCOLS Range of columns to testfor UNION query SQL injection
#sqlmap --union-cols=12-16
#联合查询注入中字符设置
--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
#sqlmap --union-from="users"
#DNS泄露攻击
--dns-domain=DNS.. Domain name used for DNS exfiltration attack
#搜索结果页面URL以获取二阶响应
--second-url=SEC.. Resulting page URL searched for second-order response
#从文件加载二阶HTTP请求
--second-req=SEC.. Load second-order HTTP request from file
8、Fingerprint(指纹)
#执行广泛的DBMS版本指纹
-f, --fingerprint Perform an extensive DBMS version fingerprint
9、Enumeration(枚举)
These options can be used to enumerate the back-end database management system information, structure and data contained in the tables
#这些选项可用于枚举表中包含的端到端数据库管理系统信息、结构和数据