[BUUCTF] 近日

这题学js

admin注册、登录不了
随便注册一个账号
拿不到flag
[BUUCTF] 近日permission denied

[BUUCTF] 近日

抓包伪造试试
修改token

[BUUCTF] 近日我以为这里可以,然而不是,依旧是permission denied

看源码
表单不是html和php
看看app.js
[BUUCTF] 近日

/**
 *  或许该用 koa-static 来处理静态文件
 *  路径该怎么配置?不管了先填个根目录XD
 */

function login() {
    const username = $("#username").val();
    const password = $("#password").val();
    const token = sessionStorage.getItem("token");
    $.post("/api/login", {username, password, authorization:token})
        .done(function(data) {
            const {status} = data;
            if(status) {
                document.location = "/home";
            }
        })
        .fail(function(xhr, textStatus, errorThrown) {
            alert(xhr.responseJSON.message);
        });
}

function register() {
    const username = $("#username").val();
    const password = $("#password").val();
    $.post("/api/register", {username, password})
        .done(function(data) {
            const { token } = data;
            sessionStorage.setItem('token', token);
            document.location = "/login";
        })
        .fail(function(xhr, textStatus, errorThrown) {
            alert(xhr.responseJSON.message);
        });
}

function logout() {
    $.get('/api/logout').done(function(data) {
        const {status} = data;
        if(status) {
            document.location = '/login';
        }
    });
}

function getflag() {
    $.get('/api/flag').done(function(data) {
        const {flag} = data;
        $("#username").val(flag);
    }).fail(function(xhr, textStatus, errorThrown) {
        alert(xhr.responseJSON.message);
    });
}

关键代码

  $.post("/api/login", {username, password, authorization:token})

根据提示,这是koa框架,单看这份源码是不够的,因此考察的是我们对于这个基于Nodejs的koa框架目录有一定的了解

├─src           应用目录(可设置)
│  ├─controller                 控制器
│  ├─config                      配置文件
│  ├─db                           数据库相关配置
    ├─ model                     各个数据模型
    ├─ index.js                   数据库配置页面
│  ├─middleWares           中间件
│  ├─routes                      路由
    ├─ index.js                   路由入口文件
    ├─ users.js                  用户路由
│  ├─service                    服务
│  ├─app.js                   入口文件

[BUUCTF] 近日

总体MVC框架
[BUUCTF] 近日

访问controllers/api.js发现处理逻辑

const crypto = require('crypto');
const fs = require('fs')
const jwt = require('jsonwebtoken')

const APIError = require('../rest').APIError;

module.exports = {
    'POST /api/register': async (ctx, next) => {
        const {username, password} = ctx.request.body;

        if(!username || username === 'admin'){
            throw new APIError('register error', 'wrong username');
        }

        if(global.secrets.length > 100000) {
            global.secrets = [];
        }

        const secret = crypto.randomBytes(18).toString('hex');
        const secretid = global.secrets.length;
        global.secrets.push(secret)

        const token = jwt.sign({secretid, username, password}, secret, {algorithm: 'HS256'});

        ctx.rest({
            token: token
        });

        await next();
    },

    'POST /api/login': async (ctx, next) => {
        const {username, password} = ctx.request.body;

        if(!username || !password) {
            throw new APIError('login error', 'username or password is necessary');
        }

        const token = ctx.header.authorization || ctx.request.body.authorization || ctx.request.query.authorization;

        const sid = JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString()).secretid;

        console.log(sid)

        if(sid === undefined || sid === null || !(sid < global.secrets.length && sid >= 0)) {
            throw new APIError('login error', 'no such secret id');
        }

        const secret = global.secrets[sid];

        const user = jwt.verify(token, secret, {algorithm: 'HS256'});

        const status = username === user.username && password === user.password;

        if(status) {
            ctx.session.username = username;
        }

        ctx.rest({
            status
        });

        await next();
    },

    'GET /api/flag': async (ctx, next) => {
        if(ctx.session.username !== 'admin'){
            throw new APIError('permission error', 'permission denied');
        }

        const flag = fs.readFileSync('/flag').toString();
        ctx.rest({
            flag
        });

        await next();
    },

    'GET /api/logout': async (ctx, next) => {
        ctx.session.username = null;
        ctx.rest({
            status: true
        })
        await next();
    }
};

关键代码

module.exports = {
    'POST /api/register': async (ctx, next) => {
    ·····
        const user = jwt.verify(token, secret, {algorithm: 'HS256'});
    ·····

应和之前的关键代码处,这里注册的认证方式是jwt-token
buu ikun那道题也是涉及到jwt认证问题

思路逻辑理清了
因为之前已经注册了,已经生成了jwt-token
直接回到登录页面,抓包修改authorization

https://jwt.io/

[BUUCTF] 近日
[BUUCTF] 近日

payload:

https://www.icode9.com/content-1-854191.html

[b01lers2020]Welcome to Earth

疯狂js跳转

知识点:
window.location.pathname

[BUUCTF] 近日

一开始就die了

http://a1e1a7e0-ba7e-4f2f-aa9b-6b8310ced2d6.node4.buuoj.cn/die/

一定有问题,删除/die/回到主页面

http://a1e1a7e0-ba7e-4f2f-aa9b-6b8310ced2d6.node4.buuoj.cn/

die的速度太快了,抓包查看源码

[BUUCTF] 近日直接在包里改

  • /chase/

[BUUCTF] 近日

  • /leftt/

[BUUCTF] 近日
懂html+css就知道,这个button会触发跳转到/die/

真正的提示在注释

  • /shoot/

[BUUCTF] 近日继续

  • /door/

[BUUCTF] 近日
这一页有很多选项,这时候就访问看一下详情
[BUUCTF] 近日查看源码,跟进door.js源码

[BUUCTF] 近日

[BUUCTF] 近日

  • /open/
    [BUUCTF] 近日
    [BUUCTF] 近日
    [BUUCTF] 近日
  • /fight/

[BUUCTF] 近日这里有action操作

审计以后了解到逻辑;
flag的顺序是由action值决定的

这么麻烦,
直接手动排序拼接

[BUUCTF] 近日

pctf{hey_boys_im_baaaaaaaaaack!}

[BUUCTF] 近日

[GYCTF2020]Ezsqli

上一篇:buuctf[第一章 web入门]常见的搜集


下一篇:支付宝PC端单笔支付同步回调session失效问题