55# By Andrew Horton aka urbanadventurer, MorningStar Security
66# Homepage: http://www.morningstarsecurity.com/research/bing-ip2hosts
77#
8+ # Version 0.4 Released December 19th, 2013. Updated to use nslookup, new usage, fixed tmp file issue
89# Version 0.3 Released September 21st, 2012. Updated because Bing mobile search changed.
910# Version 0.2 Released April 2nd, 2010
1011# Version 0.1 Released December 2nd, 2009 at Kiwicon III in New Zealand
1112#
1213# License: GPLv3
1314
14- VERSION=0.3
15+ VERSION=o.4
1516TMPDIR=/tmp
1617ANIMATION=1
1718OUTPUTIP=0
1819HTTPPREFIX=0
1920IP=
2021PREFIX=
22+ DEBUG=0
2123
2224if [ -z " $1 " ] || [ " $1 " == " -h" ] || [ " $1 " == " --help" ]; then
25+ echo -en ' \E[31m'
2326echo -e " bing-ip2hosts ($VERSION ) by Andrew Horton aka urbanadventurer
2427Homepage: http://www.morningstarsecurity.com/research/bing-ip2hosts
28+ "
29+ echo -en ' \033[0m'
2530
26- Find hostnames that share an IP address with your target which can be a hostname or
27- an IP address. This makes use of Microsoft Bing.com ability to seach by IP address,
28- e.g. \" IP:210.48.71.196\" .
31+ echo -e " Useful for web intelligence and attack surface mapping of vhosts during
32+ penetration tests. Find hostnames that share an IP address with your target
33+ which can be a hostname or an IP address. This makes use of Microsoft
34+ Bing.com ability to seach by IP address, e.g. \" IP:210.48.71.196\" .
2935
3036Usage: $0 [OPTIONS] <IP|hostname>
3137
@@ -66,8 +72,10 @@ single_page=
6672if [ ` echo " $1 " | egrep " (([0-9]+\.){3}[0-9]+)|\[[a-f0-9:]+\]" ` ]; then
6773 IP=" $1 "
6874else
69- IP=` resolveip -s " $1 " `
70- if [ " $? " != 0 ]; then
75+ # IP=`resolveip -s "$1"`
76+ IP=` nslookup " $1 " | egrep " ^Address: \w+\.\w+\.\w+\.\w+$" | tail -1| awk ' { print $2 }' `
77+ # dig -t a treshna.com +short
78+ if [ " $IP " == " " ]; then
7179 echo " Error: cannot resolve $1 to an IP"
7280 exit
7381 fi
@@ -86,12 +94,18 @@ while [ -z "$last_page_check" ] && [ -n "$how_many" ] && [ -z "$single_page" ];
8694 wget -q -O " $out " " $url "
8795
8896 last_page_check=` egrep -o ' <span class="sb_count" id="count">[0-9]+-([0-9]+) of (\1)' $out `
97+ if [ " $DEBUG " -eq 1 ]; then
98+ echo " Last Page Check: $last_page_check "
99+ fi
89100
90101 # if no results are found, how_many is empty and the loop will exit
91102 how_many=` egrep -o ' <span class="sb_count" id="count">[^<]+' $out | cut -d ' >' -f 2| cut -d ' ' -f 1-3`
92103
93104 # check for a single page of results
94105 single_page=` egrep -o ' <span class="sb_count" id="count">[0-9] results' $out `
106+ if [ $DEBUG -eq 1 ]; then
107+ echo " Single Page: $single_page "
108+ fi
95109
96110 # no captcha support or detection
97111 # pages will contain "Typing the characters in the picture above helps us ensure that a person, not a program, is performing a search"
@@ -101,8 +115,14 @@ while [ -z "$last_page_check" ] && [ -n "$how_many" ] && [ -z "$single_page" ];
101115
102116 uniq_hosts=` cat " $all_hosts " | cut -d ' /' -f 3 | tr ' [:upper:]' ' [:lower:]' | sort | uniq | wc -l`
103117
104- # rm -f "$out"
118+ if [ $DEBUG -eq 0 ]; then
119+ rm -f " $out "
120+ fi
121+
105122 let page=$page +1
123+ if [ $DEBUG -eq 1 ]; then
124+ echo " Page: $page "
125+ fi
106126done
107127
108128if [ $ANIMATION == 1 ]; then
111131
112132uniq_hosts=` cat " $all_hosts " | cut -d ' /' -f 3 | tr ' [:upper:]' ' [:lower:]' | sort | uniq`
113133
114- # rm -f "$all_hosts"
134+ if [ $DEBUG -eq 0 ]; then
135+ rm -f " $all_hosts "
136+ fi
115137
116138if [ $OUTPUTIP == 1 ]; then
117139 PREFIX=" $IP ,"
0 commit comments