daily pastebin goal
8%
SHARE
TWEET

Load Balancing Script

a guest Dec 7th, 2013 182 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     #!/bin/bash                                                    
  2.     # lbd (load balancing detector) detects if a given domain uses
  3.     # DNS and/or HTTP Load-Balancing (via Server: and Date: header and diffs between server answers)                                  
  4.     # Copyright (C) 2010 Stefan Behte                              
  5.     #                                                              
  6.     # This program is free software; you can redistribute it and/or
  7.     # modify it under the terms of the GNU General Public License  
  8.     # as published by the Free Software Foundation; either version 2                                                                  
  9.     # of the License, or (at your option) any later version.      
  10.     #                                                              
  11.     # This program is distributed in the hope that it will be useful,                                                                
  12.     # but WITHOUT ANY WARRANTY; without even the implied warranty of                                                                  
  13.     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     # GNU General Public License for more details.                
  15.     #                                                              
  16.     # You should have received a copy of the GNU General Public License
  17.     # along with this program; if not, write to the Free Software
  18.     # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  19.     #
  20.     # License: GNU General Public License, version 2
  21.     # http://www.gnu.org/licenses/gpl-2.0.html
  22.     #
  23.     # Contact me, if you have any new ideas, bugs/bugfixes, recommondations or questions!
  24.     # Please also contact me, if you just like the tool. :)
  25.     #  
  26.     # Stefan dot Behte at gmx dot net
  27.     #
  28.     # 0.1:  - initial release
  29.     # 0.2:  - fix license for fedora
  30.     #       - fix indenting
  31.     #
  32.      
  33.     QUERIES=50
  34.     DOMAIN=$1
  35.     METHODS=""
  36.      
  37.     echo
  38.     echo "lbd - load balancing detector 0.2 - Checks if a given domain uses load-balancing."
  39.     echo "                                    Written by Stefan Behte (http://ge.mine.nu)"
  40.     echo "                                    Proof-of-concept! Might give false positives."
  41.      
  42.     if [ "$1" = "" ]
  43.     then
  44.             echo "usage: $0 [domain]"
  45.             echo
  46.             exit -1
  47.     fi
  48.      
  49.     echo -e -n "\nChecking for DNS-Loadbalancing:"
  50.     NR=`host $DOMAIN | grep -c "has add"`
  51.      
  52.     if [ $NR -gt 1 ]
  53.     then
  54.             METHODS="DNS"
  55.             echo " FOUND"
  56.             host $DOMAIN | grep "has add"
  57.             echo
  58.     else
  59.             echo " NOT FOUND"
  60.     fi
  61.      
  62.     echo -e "Checking for HTTP-Loadbalancing ["Server"]: "
  63.     for ((i=0 ; i< $QUERIES ; i++))
  64.     do
  65.             printf "HEAD / HTTP/1.0\r\n\r\n" | nc $DOMAIN 80 > .nlog
  66.             S=`grep -i "Server:" .nlog | awk -F: '{print $2}'`
  67.      
  68.             if ! grep "`echo ${S}| cut -b2-`" .log &>/dev/null
  69.             then
  70.                     echo "${S}"
  71.             fi
  72.             cat .nlog >> .log
  73.     done
  74.      
  75.     NR=`sort .log | uniq | grep -c "Server:"`
  76.      
  77.     if [ $NR -gt 1 ]
  78.     then
  79.             echo " FOUND"
  80.             METHODS="$METHODS HTTP[Server]"
  81.     else
  82.             echo " NOT FOUND"
  83.     fi
  84.     echo
  85.     rm .nlog .log
  86.      
  87.      
  88.     echo -e -n "Checking for HTTP-Loadbalancing ["Date"]: "
  89.     D4=
  90.      
  91.     for ((i=0 ; i<$QUERIES ; i++))
  92.     do
  93.             D=`printf "HEAD / HTTP/1.0\r\n\r\n" | nc $DOMAIN 80 | grep "Date:" | awk '{print $6}'`
  94.             printf "$D, "
  95.            
  96.             Df=$(echo " $D" | sed -e 's/:0/:/g' -e 's/ 0/ /g')
  97.             D1=$(echo ${Df} | awk -F: '{print $1}')
  98.             D2=$(echo ${Df} | awk -F: '{print $2}')
  99.             D3=$(echo ${Df} | awk -F: '{print $3}')
  100.      
  101.             if [ "$D4" = "" ];  then   D4=0;  fi
  102.            
  103.             if [ $[ $D1 * 3600 + $D2 * 60 + $D3 ] -lt $D4 ]
  104.             then
  105.                     echo "FOUND"
  106.                     METHODS="$METHODS HTTP[Date]"
  107.                     break;
  108.             fi
  109.            
  110.             D4="$[ $D1 * 3600 + $D2 * 60 + $D3 ]"
  111.      
  112.             if [ $i -eq $[$QUERIES - 1] ]
  113.             then
  114.                     echo "NOT FOUND"
  115.             fi
  116.     done
  117.      
  118.      
  119.     echo -e -n "\nChecking for HTTP-Loadbalancing ["Diff"]: "
  120.     for ((i=0 ; i<$QUERIES ; i++))
  121.     do
  122.             printf "HEAD / HTTP/1.0\r\n\r\n" | nc $DOMAIN 80 | grep -v -e "Date:" -e "Set-Cookie" > .nlog
  123.            
  124.             if ! cmp .log .nlog &>/dev/null && [ -e .log ]
  125.             then
  126.                     echo "FOUND"
  127.                     diff .log .nlog | grep -e ">" -e "<"
  128.                     METHODS="$METHODS HTTP[Diff]"
  129.                     break;
  130.             fi
  131.            
  132.             cp .nlog .log
  133.            
  134.             if [ $i -eq $[$QUERIES - 1] ]
  135.             then
  136.                     echo "NOT FOUND"
  137.             fi
  138.     done
  139.      
  140.     rm .nlog .log
  141.      
  142.      
  143.     if [ "$METHODS" != "" ]
  144.     then
  145.             echo
  146.             echo $DOMAIN does Load-balancing. Found via Methods: $METHODS
  147.             echo
  148.     else
  149.             echo
  150.             echo $DOMAIN does NOT use Load-balancing.
  151.             echo
  152.     fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top