Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. #!/bin/bash
  2. # bing-ip2hosts - Enumerate hostnames from Bing.com for an IP address.
  3. # Bing.com is Microsoft's search engine which has an IP: search parameter.
  4. #
  5. # By Andrew Horton aka urbanadventurer, MorningStar Security
  6. # Homepage: http://www.morningstarsecurity.com/research/bing-ip2hosts
  7. #
  8. # Version 0.3 Released September 21st, 2012. Updated because Bing mobile search changed.
  9. # Version 0.2 Released April 2nd, 2010
  10. # Version 0.1 Released December 2nd, 2009 at Kiwicon III in New Zealand
  11. #
  12. # License: GPLv3
  13.  
  14. VERSION=0.3
  15. TMPDIR=/tmp
  16. ANIMATION=1
  17. OUTPUTIP=0
  18. HTTPPREFIX=0
  19. IP=
  20. PREFIX=
  21.  
  22. if [ -z "$1" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
  23. echo -e "bing-ip2hosts ($VERSION) by Andrew Horton aka urbanadventurer
  24. Homepage: http://www.morningstarsecurity.com/research/bing-ip2hosts
  25.  
  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\".
  29.  
  30. Usage: $0 [OPTIONS] <IP|hostname>
  31.  
  32. OPTIONS are:
  33. -n\t\tTurn off the progress indicator animation
  34. -t <DIR>\tUse this directory instead of /tmp. The directory must exist.
  35. -i\t\tOptional CSV output. Outputs the IP and hostname on each line, separated by a comma.
  36. -p\t\tOptional http:// prefix output. Useful for right-clicking in the shell.
  37. "
  38. exit 1
  39. fi
  40.  
  41. while getopts "nipt:" optionName; do
  42. case "$optionName" in
  43. n) ANIMATION=0;;
  44. t) TMPDIR="$OPTARG";;
  45. i) OUTPUTIP=1;;
  46. p) HTTPPREFIX=1;;
  47. [?]) echo "Error"; exit 1;;
  48. esac
  49. done
  50.  
  51. shift $(($OPTIND -1))
  52.  
  53. if [ -z "$1" ]; then
  54. echo "need an IP or hostname"
  55. exit 1
  56. fi
  57.  
  58. animation="/-\|"
  59. page=0
  60. last_page_check=
  61. how_many=1
  62. uniq_hosts=0
  63. single_page=
  64.  
  65. # if the parameter looks like an IP go ahead, otherwise resolve it
  66. if [ `echo "$1" | egrep "(([0-9]+\.){3}[0-9]+)|\[[a-f0-9:]+\]"` ]; then
  67. IP="$1"
  68. else
  69. IP=`resolveip -s "$1"`
  70. if [ "$?" != 0 ]; then
  71. echo "Error: cannot resolve $1 to an IP"
  72. exit
  73. fi
  74. fi
  75.  
  76. all_hosts=`mktemp -p $TMPDIR -t bing-ip2hosts.tmp.XXXXXX`
  77.  
  78. while [ -z "$last_page_check" ] && [ -n "$how_many" ] && [ -z "$single_page" ]; do
  79. if [ $ANIMATION == 1 ]; then
  80. echo -ne "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
  81. echo -en "[ $IP | Scraping $how_many | Found $uniq_hosts | ${animation: $(( $page % 4 )) :1} ]"
  82. fi
  83. url="http://www.bing.com/search?q=ip%3A$IP&go=&qs=n&first=${page}0&FORM=PERE"
  84.  
  85. out=`mktemp -p "$TMPDIR" -t bing-ip2hosts.tmp.XXXXXX`
  86. wget -q -O "$out" "$url"
  87.  
  88. last_page_check=`egrep -o '<span class="sb_count" id="count">[0-9]+-([0-9]+) of (\1)' $out`
  89.  
  90. # if no results are found, how_many is empty and the loop will exit
  91. how_many=`egrep -o '<span class="sb_count" id="count">[^<]+' $out|cut -d '>' -f 2|cut -d ' ' -f 1-3`
  92.  
  93. # check for a single page of results
  94. single_page=`egrep -o '<span class="sb_count" id="count">[0-9] results' $out`
  95.  
  96. # no captcha support or detection
  97. # pages will contain "Typing the characters in the picture above helps us ensure that a person, not a program, is performing a search"
  98.  
  99. vhosts=`cat "$out"| egrep -o "<h2><a href=\"[^\"]+" $out |cut -d '"' -f 2`
  100. echo -e "$vhosts" >> "$all_hosts"
  101.  
  102. uniq_hosts=`cat "$all_hosts" | cut -d '/' -f 3 | tr '[:upper:]' '[:lower:]' | sort | uniq | wc -l`
  103.  
  104. rm -f "$out"
  105. let page=$page+1
  106. done
  107.  
  108. if [ $ANIMATION == 1 ]; then
  109. echo
  110. fi
  111.  
  112. uniq_hosts=`cat "$all_hosts" | cut -d '/' -f 3 | tr '[:upper:]' '[:lower:]' | sort | uniq`
  113.  
  114. rm -f "$all_hosts"
  115.  
  116. if [ $OUTPUTIP == 1 ]; then
  117. PREFIX="$IP,"
  118. fi
  119. if [ $HTTPPREFIX == 1 ]; then
  120. PREFIX="$PREFIX""http://"
  121. fi
  122.  
  123. for h in `echo "$uniq_hosts"`
  124. do
  125. echo "$PREFIX$h"
  126. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement