NSS刷题 js前端修改 os.path.join漏洞

打算刷一遍nssweb题(任重道远)

前面很简单 都是签到题

这里主要记录一下没想到的题目

GDOUCTF 2023hate eat snake js前端修改

这里 是对js的处理

有弹窗 说明可能存在 alert

我们去看看js

这里进行了判断 如果 getScore>-0x1e9* 我们结合上面 我觉得是60

然后我们去看看定义

找到了定义分数的方法 我们可以通过前端定义

Snake.prototype.getScore = () => 100

来设定我们的分数为100

NISACTF 2022babyupload os.path.join漏洞

这里通过源代码可以获取备份文件

复制代码
from flask import Flask, request, redirect, g, send_from_directory
import sqlite3
import os
import uuid

app = Flask(__name__)

SCHEMA = """CREATE TABLE files (
id text primary key,
path text
);
"""


def db():
    g_db = getattr(g, '_database', None)
    if g_db is None:
        g_db = g._database = sqlite3.connect("database.db")
    return g_db


@app.before_first_request
def setup():
    os.remove("database.db")
    cur = db().cursor()
    cur.executescript(SCHEMA)


@app.route('/')
def hello_world():
    return """<!DOCTYPE html>
<html>
<body>
<form action="/upload" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="file">
    <input type="submit" value="Upload File" name="submit">
</form>
<!-- /source -->
</body>
</html>"""


@app.route('/source')
def source():
    return send_from_directory(directory="/var/www/html/", path="www.zip", as_attachment=True)


@app.route('/upload', methods=['POST'])
def upload():
    if 'file' not in request.files:
        return redirect('/')
    file = request.files['file']
    if "." in file.filename:
        return "Bad filename!", 403
    conn = db()
    cur = conn.cursor()
    uid = uuid.uuid4().hex
    try:
        cur.execute("insert into files (id, path) values (?, ?)", (uid, file.filename,))
    except sqlite3.IntegrityError:
        return "Duplicate file"
    conn.commit()

    file.save('uploads/' + file.filename)
    return redirect('/file/' + uid)


@app.route('/file/<id>')
def file(id):
    conn = db()
    cur = conn.cursor()
    cur.execute("select path from files where id=?", (id,))
    res = cur.fetchone()
    if res is None:
        return "File not found", 404

    # print(res[0])

    with open(os.path.join("uploads/", res[0]), "r") as f:
        return f.read()


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80)

读取完毕后发现 不允许有后缀

并且读取文件是通过

复制代码
    # print(res[0])

    with open(os.path.join("uploads/", res[0]), "r") as f:
        return f.read()

这里来进行的

这里主要是 os.path.join 存在一个漏洞

复制代码
第一个以"/"开头的参数开始拼接,之前的参数全部丢弃,当有多个时,从最后一个开始

这个时候 我们如果输入 /flag 就会读取/flag 生成 uuid 那么这个时候的flag其实就是原本存储的文件

所以我们可以实现文件读取

NISACTF 2022level-up create_function代码注入

这里也挺有意思的 记录一下

通过前面的 MD5 sha1 绕过

我们可以到第五关

复制代码
<?php
//sorry , here is true last level
//^_^
error_reporting(0);
include "str.php";

$a = $_GET['a'];
$b = $_GET['b'];
if(preg_match('/^[a-z0-9_]*$/isD',$a)){
    show_source(__FILE__);
}
else{
    $a('',$b);
}

这种格式我们就可以想到可能是create_function

我们来了解一下

复制代码
$a('',$b);

我们对 $b输入注入

}system('tac /flag');//

这样源代码是什么呢

复制代码
create_function('',a)

会被构造为

function fT() {
    a;
  }

这个时候我们输入构造

function fT() {
    }system('tac /flag');//
  }

这个时候 就构造闭合 实现了注入

然后前面的正则是不允许字母数字下划线开头 所以我们构造 \

相关推荐
用户970161501682 分钟前
浏览器切到后台后,AI 给我的代码就失效了:我拿 3 个模型测了 6 个定时器坑
前端·代码规范
蓝星空20007 分钟前
GPT Image 2.5 生图模型已上线,支持 Flare 与 Sunburst 型号选择
前端·gpt·aigc·image2·imagen
小溪学编程7 分钟前
Java ListIterator 接口详解:双向遍历与列表修改的利器
java·开发语言·windows
影视飓风TIM8 分钟前
C++11 新特性:Lambda表达式、std::function与std::bind
开发语言·c++
sbjdhjd12 分钟前
在 8 字符、字母数字过滤与 PHP 版本差异下复盘临时文件命令执行链 | (8字符绕过)
android·java·开发语言·安全·web安全·数据挖掘·php
何何____19 分钟前
js常见继承方法详解
前端·javascript
parade岁月24 分钟前
Tailwind CSS 加入 Shopify,正在用 Tailwind 的项目要不要调整?
前端
梨想橙汁36 分钟前
Vue2 快速入门:环境搭建、模板语法、指令系统全解
前端·vue.js
King of fraud40 分钟前
HTML 页面的 CSS 选择器详解
前端·css·html
lichenyang45342 分钟前
ASCF 元服务如何区分“后台恢复”与“携参拉起”:后台标记 + 参数指纹方案
前端