You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1.A visitor is lured to the evil page. It doesn't matter how.
14
-
2.The page has a harmless-looking link on it (like "get rich now" or "click here, very funny").
15
-
3.Over that link the evil page positions a transparent `<iframe>`with`src`from facebook.com, in such a way that the "Like" button is right above that link. Usually that's done with `z-index`.
16
-
4.In attempting to click the link, the visitor in fact clicks the button.
<div>...And you're cool (I'm a cool hacker actually)!</div>
45
+
<div>...你会变帅(我才是帅黑客😜)!</div>
46
46
```
47
47
48
-
The full demo of the attack:
48
+
完整的攻击示例如下:
49
49
50
50
[codetabs src="clickjacking-visible" height=160]
51
51
52
-
Here we have a half-transparent `<iframe src="facebook.html">`, and in the example we can see it hovering over the button. A click on the button actually clicks on the iframe, but that's not visible to the user, because the iframe is transparent.
As a result, if the visitor is authorized on Facebook ("remember me" is usually turned on), then it adds a "Like". On Twitter that would be a "Follow" button.
55
54
56
-
Here's the same example, but closer to reality, with `opacity:0` for `<iframe>`:
All we need to attack -- is to position the `<iframe>` on the evil page in such a way that the button is right over the link. That's usually possible with CSS.
```smart header="Clickjacking is for clicks, not for keyboard"
63
-
The attack only affects mouse actions.
63
+
```smart header="点击劫持作用于点击事件,而非键盘事件"
64
+
此攻击仅影响鼠标操作。
64
65
65
-
Technically, if we have a text field to hack, then we can position an iframe in such a way that text fields overlap each other. So when a visitor tries to focus on the input he sees on the page, he actually focuses on the input inside the iframe.
The top page (belonging to the hacker) sets a handler to it, and when the `iframe`tries to change `top.location`the visitor gets a message asking him whether he wants to leave.
return"Want to leave without learning all the secrets (he-he)?";
99
100
};
100
101
```
101
102
102
-
In most cases the visitor would answer negatively, because he doesn't know about the iframe, all he can see is the top page, leading him to think there is no reason to leave. So `top.location`won't change!
So we can add the iframe with `sandbox="allow-scripts allow-forms"`. That would relax the restrictions, permitting scripts and forms. But we omit `allow-top-navigation`so that changing `top.location`is forbidden.
So there are other solutions... For instance, we can "cover" the page with a `<div>` with `height: 100%; width: 100%;`, so that it intercepts all clicks. That `<div>`should disappear if `window == top`or if we figure out that we don't need the protection.
//there will be an error if top window is from the different origin
176
-
//but that's ok here
176
+
//如果顶层 window 来自不同的域,会报错
177
+
//但是此处并没有报错
177
178
if (top.document.domain==document.domain) {
178
179
protector.remove();
179
180
}
180
181
</script>
181
182
```
182
183
183
-
The demo:
184
+
演示如下:
184
185
185
186
[codetabs src="protector"]
186
187
187
-
## Summary
188
+
## 总结
188
189
189
-
Clickjacking is a way to "trick" users into clicking on a malicious site without even knowing what's happening. That's dangerous if there are important click-activated actions.
190
+
点击劫持是一种 “欺骗” 用户在不知情下点击恶意站点的方式。如果是重要的点击操作,这是非常危险的。
190
191
191
-
A hacker can post a link to his evil page in a message, or lure visitors to his page by some other means. There are many variations.
From one perspective -- the attack is "not deep": all a hacker is doing is intercepting a single click. But from another perspective, if the hacker knows that after the click another control will appear, then he may use cunning messages to coerce the user into clicking on them as well.
The attack is quite dangerous, because when we engineer the UI we usually don't anticipate that a hacker may click on behalf of the visitor. So vulnerabilities can be found in totally unexpected places.
0 commit comments