<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      QQ空間的DOM XSS

      [摘要]傳統的依靠特征碼探測的Web漏洞掃描器是掃不到DOM XSS的, 為了更好的發現和修復漏洞, 所以有必要研究下DOM XSS的檢測。 一年多以前, 針對公司一些帶參數的HTML頁面我寫了...

      傳統的依靠特征碼探測的Web漏洞掃描器是掃不到DOM XSS的, 為了更好的發現和修復漏洞, 所以有必要研究下DOM XSS的檢測。

           一年多以前, 針對公司一些帶參數的HTML頁面我寫了一個vbs腳本來實現DOM XSS檢測。 大體思想是先使用爬蟲抓一些含有參數的HTML頁面(例如Google Hacking:inurl:html?url= site:xxx.com.cn), 然后在vbs中創建IE對象(InternetExplorer.Application)修改url中的參數訪問頁面, url參數的字符是“javascript:window.status="xsstest"”, 然后在vbs中調用IE對象的StatusTextChange事件, 如果StatusText等于xsstest就可以判斷出基于DOM的XSS。

          這個方案不是很好, 所以公司的DOM XSS一直沒有解決, 參考了一些業界的商業/免費漏洞掃描器, 這個問題都沒有解決。

          所以今天又舊話重提, 繼續來改進該方案。

          嗯, 請先學習一下預備知識, JavaScript的函數重載。 我們新的思路是利用函數重載, 自己構造代碼替換掉造成XSS的幾個JS函數, 然后檢查函數中的參數值, 發現特殊字符就大叫一聲:It is DOM XSS!

          先看一段模擬代碼:

      <title>DOM XSS Detect Demo</title>

      <script>

      //保存原來的document.getElementById

      sss = document.getElementById;

      //保存原來的document.write(ln)

      _echo = document.write;

      _echoln = document.writeln;

      //保存原來的eval

      _eval = eval;

      //保存原來的window.navigate

      _navigate = window.navigate

      var vs;

      function _document(){

      this.write = hookecho;

      this.writeln = hookecho;

      this.location = hooklocation;

      this.getElementById = _getElementById;

      this.navigate = hooknavigate;

      }

      function _getElementById(s){

      vs = s;

      setTimeout("GetinnerHTML();", 1000);

      return sss(s);

      }

      function GetinnerHTML(){

      var tmpString = sss(vs).innerHTML;

      if(tmpString.toLowerCase().indexOf("<hacker>")!=-1){

         alert("沒有過濾<>, 或許有XSS");

      }

      }

      function hookecho(s){

      var tmpString = s;

      if(tmpString.toLowerCase().indexOf("<hacker>")!=-1){

         alert("沒有過濾<>, 或許有XSS");

      }

      _echo(tmpString);

      }

      function hookeval(s){

      if(s.toLowerCase().indexOf("securitytest")!=-1){

         alert("eval可控, 存在XSS");

      }

      _eval(s);

      }

      function hooknavigate(s){

      alert(s);

      }

      var mydocument = new _document();

      document.write = mydocument.write;

      document.writeln = mydocument.writeln;

      document.getElementById = mydocument.getElementById;

      eval = hookeval;

      window.navigate = hookeval;

      </script>

      <div id="hi">ss</div>

      <script language="javascript">

      var g_url;

      function QueryList()

      {

         var url = window.location.href;

         var pos = url.indexOf("?");

         var suburl= url.substring(pos+1,url.length);

         var pos1 = suburl.indexOf("=");

         g_url = suburl.substring(pos1+1,url.length);

      }

      QueryList();

      </script>

      <script>eval( g_url);</script>

          嗯, 很好, 自己看代碼, url里面要構造我們的關鍵字哦。 我們實現了對函數document.write、document.writeln、eval的重載, 一旦代碼中調用這些函數就會先進入我們的代碼檢查是否被XSS。 innerHTML是屬性, 沒法重載, 所以我們先放過它, 然后用setTimeout查看改變為我們的特征字符沒有。

          等等, 轉向的函數window.navigate、屬性document.location等沒法重載啊, 沒關系, 前面不是說了用IE對象嗎, 在關聯的事件中檢查要轉向的值。

          最后一個問題, 這段JS要在整個頁面之前執行, 怎么弄?簡單, 你一定見過ARP劫持會話插入一段HTML代碼在頁面最前面吧——不是叫你ARP欺騙, 可以自己架一個HTTP道理, 把通過代理的HTTP請求都加一段script。

          基本上就是這樣, 效率肯定不敢保證, 也不敢保證一定能夠解決所有造成XSS的JS函數, 其實解析JS才是王道, 呃, 或許你以后可以再看到我或者別人寫這個題目。


      上面是電腦上網安全的一些基礎常識,學習了安全知識,幾乎可以讓你免費電腦中毒的煩擾。




      日韩精品一区二区三区高清