<html>
  <head><title>WebApp.aspx</title></head>
 
  <body bgColor="#ccffff">
<script LANGUAGE="javascript">alert("xss");</script>  </body>
</html>
这是一个网页,运行后会弹出XSS对话框。我用<script LANGUAGE="javascript">alert("xss");</script>的编码替换它,
<html>
  <head><title>WebApp.aspx</title></head>
 
  <body bgColor="#ccffff">
&#x3C;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x20;&#x4C;&#x41;&#x4E;&#x47;&#x55;&#x41;&#x47;&#x45;&#x3D;&#x22;&#x6A;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x22;&#x3E;&#x61;&#x6C;&#x65;&#x72;&#x74;&#x28;&#x22;&#x78;&#x73;&#x73;&#x22;&#x29;&#x3B;&#x3C;&#x2F;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3E;
  </body>
</html>
这时网页运行后只是显示<script LANGUAGE="javascript">alert("xss");</script>,而不是运行它。我试了只编码alert("xss");好像也没用,哪位高手知道??

解决方案 »

  1.   

    这是html编码,放在BODY里当然只是显示出来而已
    lz想要什么效果呢?
      

  2.   

    我想让他编码后会运行这个javascript,弹出XSS对话框,有什么办法吗
      

  3.   

    先要把不相干的代码去除,然后用eval解析
      

  4.   

    能不能给个例子,我就想编码这句话<script LANGUAGE="javascript">alert("xss"); </script>
      

  5.   

    <html> 
      <head> <title>WebApp.aspx </title>
      <script>
       function window_onload(){
         var str = document.body.innerText;
              alert("body中字符串:"+str);
         str = str.replace(/<script[^>]*>([^<]*)<\/script>/gi,"$1");
              alert("获取js语句:"+str);
         eval(str);
       }
      </script>
      </head>   <body bgColor="#ccffff" onload="window_onload()"> 
    &#x3C;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x20;&#x4C;&#x41;&#x4E;&#x47;&#x55;&#x41;&#x47;&#x45;&#x3D;&#x22;&#x6A;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x22;&#x3E;&#x61;&#x6C;&#x65;&#x72;&#x74;&#x28;&#x22;&#x78;&#x73;&#x73;&#x22;&#x29;&#x3B;&#x3C;&#x2F;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3E; 
      </body> 
    </html> 
      

  6.   

    楼上的意思是你把<script LANGUAGE="javascript">eval(alert("xss");) </script>编码,然后看看效果。
      

  7.   

    <html> 
      <head> <title>WebApp.aspx </title> </head> 
    <script>
    window.onload=function(){
     var s=document.getElementById('dvScript').innerHTML.replace(/&lt;/gi,'<').replace(/&gt;/gi,'>');
     var code=/<script[^>]*>([\s\S]+?)<\/script>/.exec(s);
     if(code)eval(code[1]);//运行代码
    }
    </script>
      <body bgColor="#ccffff"> 
    <div id="dvScript">
    &#x3C;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x20;&#x4C;&#x41;&#x4E;&#x47;&#x55;&#x41;&#x47;&#x45;&#x3D;&#x22;&#x6A;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x22;&#x3E;&#x61;&#x6C;&#x65;&#x72;&#x74;&#x28;&#x22;&#x78;&#x73;&#x73;&#x22;&#x29;&#x3B;&#x3C;&#x2F;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3E; </script>
      </body> 
    </html> 
      

  8.   

    为什么这样弹不出?
    <html> 
      <head> <title>WebApp.aspx </title>  </head>   <body bgColor="#ccffff" onload="window_onload()"> 
    <script language="javascript">
    eval('&#x3C;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x20;&#x4C;&#x41;&#x4E;&#x47;&#x55;&#x41;&#x47;&#x45;&#x3D;&#x22;&#x6A;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x22;&#x3E;&#x61;&#x6C;&#x65;&#x72;&#x74;&#x28;&#x22;&#x78;&#x73;&#x73;&#x22;&#x29;&#x3B;&#x3C;&#x2F;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3E;')
    </script> 
      </body> 
    </html> 
      

  9.   

    LZ要知道 显示 和 运行 是两个不同的感念,要想显示则需要正确编码(包括可以运行的字符更需要编码,否则被执行),想要运行则需要符合HTML的语法。好象难说清楚了,核心就是要执行的代码被编码后就只能显示为人类可识别的,而不是执行,要执行就不能对其编码
      

  10.   

    function addLoadEvent(func) {
      var oldonload = window.onload;
      if (typeof window.onload != 'function') {
        window.onload = func;
      } else {
        window.onload = function() {
          if (oldonload) {
            oldonload();
          }
          func();
        }
      }
    }addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
    addLoadEvent(function() {
      /* more code to run on page load */ 
    });
      

  11.   

    10楼的代码和6楼的有什么区别,10楼的弹不出xss对话框
      

  12.   

    <script>
    document.write('&#x3C;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x20;&#x4C;&#x41;&#x4E;&#x47;&#x55;&#x41;&#x47;&#x45;&#x3D;&#x22;&#x6A;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x22;&#x3E;&#x61;&#x6C;&#x65;&#x72;&#x74;&#x28;&#x22;&#x78;&#x73;&#x73;&#x22;&#x29;&#x3B;&#x3C;&#x2F;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3E;'.replace(/&#(x[a-z0-9]+)\;/ig,function($0,$1){return String.fromCharCode('0'+$1)}));
    </script>
      

  13.   

    <script> 
    document.write('&#x3C;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x20;&#x4C;&#x41;&#x4E;&#x47;&#x55;&#x41;&#x47;&#x45;&#x3D;&#x22;&#x6A;&#x61;&#x76;&#x61;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x22;&#x3E;&#x61;&#x6C;&#x65;&#x72;&#x74;&#x28;&#x22;&#x78;&#x73;&#x73;&#x22;&#x29;&#x3B;&#x3C;&#x2F;&#x73;&#x63;&#x72;&#x69;&#x70;&#x74;&#x3E;'.replace(/&#(x[a-z0-9]+)\;/ig,function($0,$1){return String.fromCharCode('0'+$1)}));
    </script>