<dd id="sga4y"><optgroup id="sga4y"></optgroup></dd>
<nav id="sga4y"><code id="sga4y"></code></nav>
  • <optgroup id="sga4y"></optgroup>

    原文地址:http://drops.wooyun.org/tips/2014

    0x00 背景


    下面圖中的eecs.cc為筆者自建的一臺具有私有根的DNS服務器,且對外開放了區域傳送權限,故有結果:cc區域傳送成功。該圖只是一個實驗驗證,下面文章正式開始!

    2014051922562284748.png

    0x01 尋找域名


    從互聯網上尋找全球Top1000Web站點列表。

    搜尋,發現 http://www.domainvader.com/website/top-sites.php 站點有需要的信息。

    處理過程如下:

    ·此處共計1000個統計頁面,每個頁面有1000個站點信息,故依次抓取這1000個html文檔; 
    ·使用grep結合正則表達式從這1000個文檔之中過濾出我們需要的域名,共計1000000個。 
    

    代碼如下:

    其中,grab.sh的參數threads意思為并發GET進程數,視雙方通訊鏈路狀態而定,默認為1,如果鏈路很好,可適當提高,但不宜過高,以防GET請求超時。?

    grab.sh:

    #!bash
    #!/bin/bash
    declare x
    declare threads=1
    # process concurrency
    declare mod
    
    for x in `seq 1 1000`
    do
      echo "http://www.domainvader.com/website/top-${x}000-sites.php"
      time GET "http://www.domainvader.com/website/top-${x}000-sites.php" > $x.html &
      mod=$(( x%threads ))
      if [ "$mod" -eq "0" ]
      then
        wait
      fi
    done
    

    translate.sh:

    #!bash
    #!/bin/bash
    
    declare x
    declare l
    
    if [ -r "top100_0000sites.txt" ]
    then
      rm -f top100_0000sites.txt
    fi
    
    touch top100_0000sites.txt
    
    for x in `seq 1 1000`
    do
      echo "analyzing ${x}.html..."
    # check if readable
      if ! [ -r "${x}.html" ]
      then
        echo "file ${x}.html doesn't exist or aren't readable :("
        echo "file top100_0000sites.txt collect total `cat top100_0000sites.txt | wc -l` websites"
        exit 1
      fi
      l=`grep -Eo --color 'target="_blank">(http://([A-Za-z0-9_-]+)(\.([A-Za-z0-9_-])+)+)' ${x}.html | wc -l` 
    # check content if been entirely grabbed
      if [ "$l" -ne "1000" ]
      then
        echo "file ${x}.html's content is not entire :( please check"
        echo "file top100_0000sites.txt collect total `cat top100_0000sites.txt | wc -l` websites"
        exit 1
      fi
      grep -Eo --color 'target="_blank">(http://([A-Za-z0-9_-]+)(\.([A-Za-z0-9_-])+)+)' ${x}.html | grep -Eo --color '(([A-Za-z0-9_-]+)(\.([A-Za-z0-9_-])+)+)$' >> top100_0000sites.txt
    done
      echo "done :)"
      echo "file top100_0000sites.txt collect total `cat top100_0000sites.txt | wc -l` websites" 
    

    最終效果圖:

    2014051923095424447.png

    0x02 DNS區域傳送權限自動檢測


    有如下命題:

    #!bash
    

    ??? if?dig?@${ns}?${d}?axfr?|?grep?-E?--color?'IN[[:space:]]+A|IN[[:space:]]+NS'?&>/dev/null

    ?? ?then?

    ? ????echo?"nice!?a?hole"

    ? ??fi

    上述命題是整個檢測程序的核心所在,這個命題是成立的。

    dns_transfer_check.sh?代碼如下:

    其中,threads為并發數,默認設置為40,由于一個域名很可能對應多個ns,觀察得到實際并發數大概為threads*3?,domainFileList為參與檢測的域名列表文件,可自定義之。

    #!bash
    #!/bin/bash
    
    declare d
    declare s=0
    declare ns_str
    declare ns
    declare mod
    declare threads=40
    # process concurrency
    declare domainFileList="top100_0000sites.txt"
    
    for d in `cat $domainFileList`
    do
      s=$(( s+1  ))
      echo "${s} : ${d}"
      ns_str=`dig -t ns ${d} | grep -E --color 'IN.*NS.*[[:space:]]([A-Za-z0-9_-]+)(\.([A-Za-z0-9_-])+)+\.' | awk  '{print $5}' | grep -Eo --color '([A-Za-z0-9_-]+)(\.([A-Za-z0-9_-])+)+'`
      for ns in $ns_str
      do
        echo $ns
        if dig @${ns} ${d} axfr | grep -E --color 'IN[[:space:]]+A|IN[[:space:]]+NS' &>/dev/null ; then echo "nice! transfer done! :) rank: $s  domain: $d  ns: $ns  ---->" ; fi & 
      done
      mod=$(( s%threads ))
      if [ "$mod" -eq 0 ] 
      then
        wait
      fi
    done
    

    程序結束。

    #!bash
    #?nohup?bash?dns_transfer_check.sh?&>log?&
    

    運行一夜之后,掃描到了前19212個站點,然后使用grep、awk、sed等工具處理之,得到滿意結果。

    WooYun: 全球Top1000Websites中存在DNS區域傳送漏洞的網站列表

    dns_domain_check.zip

    這是所有資料的鏈接。重點是dns_transfer_check.sh與域名列表,讀者可按照自己的需要自定義參數使用。

    除了world_top1000000,還包含了china_top500與china_top1344_entertainment站點列表 :)?

    希望這篇文章能幫助大家!

    97av