xss-靶场

一、环境地址

XSS Game - Learning XSS Made Simple! | Created by PwnFunction

二、案例复现

案列1------Ma Spaghet!

复制代码
<!-- Challenge -->
<h2 id="spaghet"></h2>
<script>
    spaghet.innerHTML = (new URL(location).searchParams.get('somebody') || "Somebody") + " Toucha Ma Spaghet!"
</script>

这个脚本的功能是将页面中 ID 为 spaghet<h2> 元素的 innerHTML 设置为一个字符串,该字符串由 URL 查询参数 somebody 的值和文本 "Toucha Ma Spaghet!" 组合而成。如果 somebody 参数不存在,则使用默认值 "Somebody"。具体来说:

  1. new URL(location).searchParams.get('somebody'):获取 URL 查询参数 somebody 的值。
  2. || "Somebody":如果没有该查询参数,则使用默认值 "Somebody"。
  3. spaghet.innerHTML = ...:将拼接后的字符串赋值给 <h2> 元素的 innerHTML 属性。

element.innerHTML - Web API | MDN (mozilla.org)

解法

所以这道题的解法就很明了了,原因由上所说

https://sandbox.pwnfunction.com/warmups/ma-spaghet.html?somebody=\<img src=1 οnerrοr="alert(1337)">

本题应注意innerHTNL与innerText的区别

案例2------Jefff

复制代码
<!-- Challenge -->
<h2 id="maname"></h2>
<script>
    let jeff = (new URL(location).searchParams.get('jeff') || "JEFFF")
    let ma = ""
    eval(`ma = "Ma name ${jeff}"`)
    setTimeout(_ => {
        maname.innerText = ma
    }, 1000)
</script>

这个脚本的作用是将页面中 ID 为 maname 的 <h2> 元素的文本设置为 "Ma name " 后跟 URL 查询参数 jeff 的值,或者在没有该参数时使用默认值 "JEFFF"。具体步骤如下:

let jeff = (new URL(location).searchParams.get('jeff') || "JEFFF"):获取查询参数 jeff 的值,若不存在则使用默认值 "JEFFF"。

eval(ma = "Ma name {jeff}"):使用 eval 动态创建字符串 "Ma name {jeff}" 并将其赋值给变量 ma。

setTimeout(_ => { maname.innerText = ma }, 1000):在 1000 毫秒(1秒)后将 ma 的值设置为 <h2> 元素的文本内容,只执行一次

解法1

用分号;分割

https://sandbox.pwnfunction.com/warmups/jefff.html?jeff=aaa";alert(1337);"https://sandbox.pwnfunction.com/warmups/jefff.html?jeff=aaa";alert(1337);"[https://sandbox.pwnfunction.com/warmups/jefff.html?jeff=aaa";alert(1337);"](https://sandbox.pwnfunction.com/warmups/jefff.html?jeff=aaa";alert(1337);" "https://sandbox.pwnfunction.com/warmups/jefff.html?jeff=aaa\";alert(1337);\"")

解法2

用js中的特殊连接符(-)

https://sandbox.pwnfunction.com/warmups/jefff.html?jeff=aaa"-alert(1337);-"https://sandbox.pwnfunction.com/warmups/jefff.html?jeff=aaa"-alert(1337);-"[https://sandbox.pwnfunction.com/warmups/jefff.html?jeff=aaa"-alert(1337);-"](https://sandbox.pwnfunction.com/warmups/jefff.html?jeff=aaa"-alert(1337);-" "https://sandbox.pwnfunction.com/warmups/jefff.html?jeff=aaa\"-alert(1337);-\"")

案例3------Ugandan Knuckles

复制代码
<!-- Challenge -->
<div id="uganda"></div>
<script>
    let wey = (new URL(location).searchParams.get('wey') || "do you know da wey?");
    wey = wey.replace(/[<>]/g, '')
    uganda.innerHTML = `<input type="text" placeholder="${wey}" class="form-control">`
</script>

这个脚本的作用是将页面中 ID 为 uganda<div> 元素的内容设置为一个 <input> 元素。具体步骤如下:

  1. let wey = (new URL(location).searchParams.get('wey') || "do you know da wey?"):获取 URL 查询参数 wey 的值,如果没有则使用默认值 "do you know da wey?"
  2. wey = wey.replace(/[<>]/g, ''):从 wey 字符串中移除所有 <> 字符,以防止潜在的 HTML 注入。
  3. uganda.innerHTML = <input type="text" placeholder="${wey}" class="form-control">``:将 div 元素的 innerHTML 设置为一个 <input> 元素,其 placeholder 属性的值为处理后的 wey

解法

这道题的解法在于input的onfocus与autofocus属性(作用是聚焦,不过一个是手动对焦,一个是自动对焦)

案例4------Ah That's Hawt

javascript 复制代码
<!-- Challenge -->
<h2 id="will"></h2>
<script>
    smith = (new URL(location).searchParams.get('markassbrownlee') || "Ah That's Hawt")
    smith = smith.replace(/[\(\`\)\\]/g, '')
    will.innerHTML = smith
</script>

这个脚本的作用是将页面中 ID 为 will 的 <h2> 元素的 innerHTML 设置为一个处理过的字符串。具体步骤如下:

smith = (new URL(location).searchParams.get('markassbrownlee') || "Ah That's Hawt"):

从 URL 查询参数 markassbrownlee 中获取值。如果该参数不存在,则使用默认值 "Ah That's Hawt"。

smith = smith.replace(/[\(\)\]/g, '')`:

使用正则表达式从字符串 smith 中移除所有的 (、`、)、\ 字符(注,这里的符号我用逗号分隔的注意分辨)。这一步主要是为了清理字符串,以防止潜在的 HTML 注入或其他不安全字符。

will.innerHTML = smith:

将处理后的字符串 smith 赋值给 <h2> 元素的 innerHTML 属性。这将更新该 <h2> 元素的内容为 smith 的值。

解法

这道题过滤括号,反引号,反斜杠,采取location和编码绕过,%25url编码为%,%28编码为(,剩下的同理

https://sandbox.pwnfunction.com/warmups/thats-hawt.html?markassbrownlee=\<img src=1 οnerrοr=location="javascript:alert%25281337%2529">

相关推荐
dorisrv1 小时前
优雅的React表单状态管理
前端
蓝瑟2 小时前
告别重复造轮子!业务组件多场景复用实战指南
前端·javascript·设计模式
dorisrv2 小时前
高性能的懒加载与无限滚动实现
前端
韭菜炒大葱2 小时前
别等了!用 Vue 3 让 AI 边想边说,字字蹦到你脸上
前端·vue.js·aigc
StarkCoder2 小时前
求求你,别在 Swift 协程开头写 guard let self = self 了!
前端
清妍_2 小时前
一文详解 Taro / 小程序 IntersectionObserver 参数
前端
电商API大数据接口开发Cris2 小时前
构建异步任务队列:高效批量化获取淘宝关键词搜索结果的实践
前端·数据挖掘·api
符方昊2 小时前
如何实现一个MCP服务器
前端
喝咖啡的女孩2 小时前
React useState 解读
前端
渴望成为python大神的前端小菜鸟2 小时前
浏览器及其他 面试题
前端·javascript·ajax·面试题·浏览器