Skip to content

XSS 攻击

因为 XSS 攻击在现在几乎很难做到,所以要暂时代入 20 年前的网络环境情景中

反射型

假设某系统的 web 页面可以进行在线转账,转账的方式是通过 cookie + url 拼接,如:

txt
http://example.com/transfer?target=00001&money=100

target 和 money 是通过输入框输入的:

html

<form>
    <input type="text" id="target">
    <label for="target">转账目标</label>

    <input type="text" id="money">
    <label for="money">转账金额</label>

    <button onclick="submit()"></button>
</form>

<script>
    function submit() {
        // 获取输入值,拼接 URL,并且转向 URL
        let target = document.getElementById('target').value
        let money = document.getElementById('money').value
        // 由于 cookie 是自动携带的
        // 所以凭借 cookie, target, money 就可以完成转账 
        document.location.search = "?target=" + target + "&money=" + money
    }
</script>

此时有好事者,发现此站点有弱点,然后制造了一条带有脚本的 URL:

txt
http://example.com/transfer?target=00001&money=100