yo9gjx

goohost.sh

Apr 7th, 2012
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 20.33 KB | None | 0 0
  1. #!/bin/bash
  2. ###########################################################################
  3. # Simple script that tries to extracts hosts, subdomains, ip and mail from
  4. # a Google search against a specif domain or Google scraping if you prefere!
  5. # License: GPLv3
  6. # Name: goohost
  7. # Author: watakushi
  8. # Special thanks to: Danya & Roberto \n \n"
  9. ###########################################################################
  10.  
  11.  
  12. ###########################################################################
  13. # General stuff - usage - errors - parameters definition
  14. #
  15.  
  16.  
  17. let I=0 #Used in the while loop's Google queries
  18. METHOD="host" #Default mode is set to host
  19. let PAGES=5 #Default pages to download from Google
  20. let VERBOSITY=0 #Verbosity is set to off as default
  21. TMPRND=$RANDOM #Random number used for temporany files
  22. REGEXPRESULT='Results <b>[0-9,]*</b> - <b>[0-9,]*</b> of[" about "]+<b>[0-9,]*</b>' #REGEXP for extraxct the number of results from a query
  23. METHOD=host #Default method set to host
  24.  
  25. #Print the help banner and exit the script
  26. printhelpanddie () {
  27.    printf "\n"
  28.    printf "[*] goohost v.0.0.1 Beta \n"
  29.    printf "[*] Simple script that extracts hosts/subdomains, ip or emails for a specific domain with Google search \n"
  30.    printf "[*] Author: watakushi \n"
  31.    printf "[*] Thanks to: Johnny Long and GHDB for inspiration stuff \n"
  32.    printf "[*] Special thanks to: Danya & Roberto \n \n"
  33.    printf "[*] Usage: $0 -t domain.tld [-m <host|ip|mail> -p <1-20> -v] \n \n"
  34.    printf "[*] -t: target domain. Ex: backtrack.linux.org \n"
  35.    printf "[*] -m: method: <ip|host|mail>. Default value is set to host \n"
  36.    printf "[*]             host: raw google hosts and subdomains search \n"
  37.    printf "[*]             ip: raw google hosts and subdomains search and performs a reverse DNS resolution \n"
  38.    printf "[*]             mail:raw google email search \n"
  39.    printf "[*] -p: pages [1-20]. Max number of pages to download from Google. Default 5 \n"
  40.    printf "[*] -v: verbosity. Default is set to off \n"
  41.    printf "[*] Example: $0 -t backtrack-linux.com -m ip -p 10 -v \n \n"
  42.    exit 1
  43.    }
  44.  
  45. #Extract the number of results google gives from the query
  46. getresult () {
  47.    RESULT=$(grep -Eio "$REGEXPRESULT" /tmp/goohost$I-$TMPRND.log | cut -d"<" -f 6 | cut -d">" -f 2| tr -d ",")
  48.    return $RESULT
  49.    }
  50.  
  51.  
  52. while getopts "t:m:p:v" optname
  53.   do
  54.     case "$optname" in
  55.       "t")
  56.         DOMAIN=$OPTARG
  57.         ;;
  58.       "m")
  59.         METHOD=$OPTARG
  60.         ;;
  61.       "p")
  62.         let PAGES=$OPTARG
  63.         ;;
  64.       "v")
  65.         let VERBOSITY=1
  66.         ;;
  67.       "?")
  68.         echo "[!] Error: Unknown option!"
  69.         printhelpanddie
  70.         ;;
  71.       ":")
  72.         echo "[!] Error: Argument needed!"
  73.         printhelpanddie
  74.         ;;
  75.       *)
  76.         echo "[!] Error: Unknown error!!!"
  77.         printhelpanddie
  78.         ;;
  79.     esac
  80.   done
  81.  
  82.  
  83. #Check for write permissions and several tools used in the script
  84. if [ ! -x /usr/bin/wget ]; then
  85.   echo "[!] Error: /usr/bin/wget not found on this system!" 1>&2
  86.   exit 1
  87. fi
  88.  
  89. if [ ! -x /usr/bin/awk ]; then
  90.   echo "[!] Error: /usr/bin/awk not found on this system!" 1>&2
  91.   exit 1
  92. fi
  93.  
  94. if [ ! -x /bin/sed ]; then
  95.   echo "[!] Error: /bin/sed not found on this system!" 1>&2
  96.   exit 1
  97. fi
  98.  
  99. if [ ! -w /tmp ]; then
  100.   echo "[!] Error: Can't write in /tmp ! - Permission denied" 1>&2
  101.   exit 1
  102. fi
  103.  
  104. if [ ! -w ./ ]; then
  105.   echo "[!] Error: Can't write in ./ ! - Permission denied" 1>&2
  106.   exit 1
  107. fi
  108.  
  109. #Print usage if parameters are not passed to the script
  110. if [[ -z $DOMAIN ]] || [[ $METHOD != host && $METHOD != ip && $METHOD != mail  ]] ; then
  111.  
  112.    printhelpanddie
  113.  
  114. fi
  115.  
  116. #Use a regular expression based on the method option
  117. case "$METHOD" in
  118.  
  119.    host)
  120.       REGEXPQUERY='[a-zA-Z0-9\._-]+\.'$DOMAIN
  121.    ;;
  122.  
  123.    ip)
  124.       REGEXPQUERY='[a-zA-Z0-9\._-]+\.'$DOMAIN
  125.    ;;
  126.  
  127.    mail)
  128.       REGEXPQUERY="[a-zA-Z0-9._-]+@<em>$DOMAIN</em>"
  129.       QEMAIL="+$DOMAIN"
  130.    ;;
  131.  
  132. esac
  133.  
  134.  
  135. #Set the number of queries to do. Default value 5.
  136. if [[ $PAGES -lt 1 || $PAGES -gt 20 ]] ; then
  137.    echo "[-] Warning: Pages value not in the range 1-20. Default value used!" 1>&2
  138.    let PAGES=5
  139.    printf "\n"
  140. fi
  141.  
  142. #Check for DNS wildcards
  143. if [[ $(host idontexist.xxxxx$TMPRND.com | grep address) ]]; then
  144.    printf "\n"
  145.    echo "[-] Warning: DNS wildcard detected! With IP method you should have some false positive results." 1>&2
  146.    printf "\n"
  147. fi
  148.  
  149.  
  150. ###########################################################################
  151. # QUERY:0  Download the first google page with the site: parameter
  152. #
  153.  
  154. #Google Query
  155. case "$METHOD" in
  156.  
  157.    host)
  158.       GOOGLEQUERY0="http://www.google.com/search?num=100&q=site%3A$DOMAIN" #site:example.tld
  159.    ;;
  160.  
  161.    ip)
  162.       GOOGLEQUERY0="http://www.google.com/search?num=100&q=site%3A$DOMAIN" #site:example.tld
  163.    ;;
  164.  
  165.    mail)
  166.       GOOGLEQUERY0="http://www.google.com/search?num=100&q=site%3A$DOMAIN$QEMAIL" #example.tld site:example.tld
  167.    ;;
  168.  
  169. esac
  170.  
  171. #Download with wget the page
  172. wget -U "" "$GOOGLEQUERY0" -O /tmp/goohost$I-$TMPRND.log -q
  173.  
  174.  
  175. #Extract the hosts/emails and save in the result file
  176. grep -Eio $REGEXPQUERY  /tmp/goohost$I-$TMPRND.log > result-$TMPRND.log
  177.  
  178. #Extract the number of results google gives from the query
  179. getresult
  180.  
  181. #Verbosity
  182. if [ "$VERBOSITY" = "1" ]; then
  183.    printf "\n"
  184.    printf "Google Query n.$I \n"
  185.    echo $GOOGLEQUERY0
  186.    printf "\n"
  187.    printf "Results for query: $RESULT \n"
  188.    printf "\n"
  189.  
  190. fi
  191.  
  192. ###########################################################################
  193. # Start the loop, download the pages generated with different types of query
  194. #
  195.  
  196. while [[ "$RESULT" -ge "100"  &&  "$I" -lt $PAGES-1 ]]
  197. do
  198.  
  199.    let I=I+1
  200.  
  201.    case "$I" in
  202.  
  203.       1)
  204.          #Google Query
  205.          case "$METHOD" in
  206.  
  207.             host)
  208.                GOOGLEQUERY1="http://www.google.com/search?num=100&q=site%3A$DOMAIN+-inurl%3Awww.$DOMAIN" #site:example.tld -inurl:www.example.tld
  209.             ;;
  210.  
  211.             ip)
  212.                GOOGLEQUERY1="http://www.google.com/search?num=100&q=site%3A$DOMAIN+-inurl%3Awww.$DOMAIN" #site:example.tld -inurl:www.example.tld
  213.             ;;
  214.  
  215.             mail)
  216.                GOOGLEQUERY1="http://www.google.com/search?num=100&q=site%3A$DOMAIN$QEMAIL+mail" #site:example.tld example.tld mail
  217.             ;;
  218.  
  219.          esac
  220.  
  221.          #Download with wget the page
  222.          wget -U "" "$GOOGLEQUERY1" -O /tmp/goohost$I-$TMPRND.log -q
  223.  
  224.          #Extract the hosts/emails and save in the result file
  225.          grep -Eio $REGEXPQUERY /tmp/goohost$I-$TMPRND.log  >> result-$TMPRND.log
  226.  
  227.          #Extract the number of results google gives from the query
  228.          getresult
  229.  
  230.          #Verbosity
  231.          if [ "$VERBOSITY" = "1" ]; then
  232.             printf "\n"
  233.             printf "Google Query n.$I \n"
  234.             echo $GOOGLEQUERY1
  235.             printf "\n"
  236.             printf "Results for query: $RESULT \n"
  237.             printf "\n"
  238.          fi
  239.  
  240.          ;;
  241.  
  242.       2)
  243.  
  244.          #Google Query
  245.          case "$METHOD" in
  246.  
  247.             host)
  248.                GOOGLEQUERY2="http://www.google.com/search?num=100&q=*.site%3A$DOMAIN+-inurl%3Awww.$DOMAIN" #site:example.tld -inurl:www.example.tld
  249.             ;;
  250.  
  251.             ip)
  252.                GOOGLEQUERY2="http://www.google.com/search?num=100&q=*.site%3A$DOMAIN+-inurl%3Awww.$DOMAIN" #site:example.tld -inurl:www.example.tld
  253.             ;;
  254.  
  255.             mail)
  256.                GOOGLEQUERY2="http://www.google.com/search?num=100&q=$site%3A$DOMAIN$QEMAIL+mail&start=200" #site:example.tld example.tld mail
  257.             ;;
  258.  
  259.          esac
  260.  
  261.          #Download with wget the page
  262.          wget -U "" "$GOOGLEQUERY2" -O /tmp/goohost$I-$TMPRND.log -q
  263.  
  264.          #Extract the hosts/emails and save in the result file
  265.          grep -Eio $REGEXPQUERY /tmp/goohost$I-$TMPRND.log  >> result-$TMPRND.log
  266.  
  267.          #Extract the number of results google gives from the query
  268.          getresult
  269.  
  270.          #Verbosity
  271.          if [ "$VERBOSITY" = "1" ]; then
  272.             printf "\n"
  273.             printf "Google Query n.$I \n"
  274.             echo $GOOGLEQUERY2
  275.             printf "\n"
  276.             printf "Results for query: $RESULT \n"
  277.             printf "\n"
  278.          fi
  279.  
  280.  
  281.          # Generate TOP6 file and pass the values to the next queries
  282.          case "$METHOD" in
  283.  
  284.             host)
  285.                grep -Eio $REGEXPQUERY result-$TMPRND.log | sort | uniq -i -c | sort -n -r |  grep -Eio $REGEXPQUERY | sed -e "s/.$DOMAIN//g" > /tmp/top6-$TMPRND.log
  286.             ;;
  287.  
  288.             ip)
  289.                grep -Eio $REGEXPQUERY result-$TMPRND.log | sort | uniq -i -c | sort -n -r |  grep -Eio $REGEXPQUERY | sed -e "s/.$DOMAIN//g" > /tmp/top6-$TMPRND.log
  290.             ;;
  291.  
  292.             mail)
  293.                grep -Eio $REGEXPQUERY result-$TMPRND.log | sort | uniq -i -c | sort -n -r |  grep -Eio $REGEXPQUERY | cut -d"@" -f1 > /tmp/top6-$TMPRND.log
  294.             ;;
  295.  
  296.          esac
  297.  
  298.          ;;
  299.  
  300.       3)
  301.  
  302.          CURL1=$(awk NR==1 /tmp/top6-$TMPRND.log)
  303.          CURL2=$(awk NR==2 /tmp/top6-$TMPRND.log)
  304.          CURL3=$(awk NR==3 /tmp/top6-$TMPRND.log)
  305.          CURL4=$(awk NR==4 /tmp/top6-$TMPRND.log)
  306.          CURL5=$(awk NR==5 /tmp/top6-$TMPRND.log)
  307.          CURL6=$(awk NR==6 /tmp/top6-$TMPRND.log)
  308.  
  309.          #Google Query
  310.          case "$METHOD" in
  311.  
  312.             host)
  313.                GOOGLEQUERY3="http://www.google.com/search?num=100&q=site%3A$DOMAIN+-inurl%3A$CURL1+-inurl%3A$CURL2+-inurl%3A$CURL3+-inurl%3A$CURL4+-inurl%3A$CURL5+-inurl%3A$CURL6" #site:example.tlf -inurl:top1 -inurl:top2 -inurl:top3 -inurl:top4 -inurl:top5 -inurl:top6
  314.             ;;
  315.  
  316.             ip)
  317.                GOOGLEQUERY3="http://www.google.com/search?num=100&q=site%3A$DOMAIN+-inurl%3A$CURL1+-inurl%3A$CURL2+-inurl%3A$CURL3+-inurl%3A$CURL4+-inurl%3A$CURL5+-inurl%3A$CURL6" #site:example.tlf -inurl:top1 -inurl:top2 -inurl:top3 -inurl:top4 -inurl:top5 -inurl:top6
  318.             ;;
  319.  
  320.             mail)
  321.                GOOGLEQUERY3="http://www.google.com/search?num=100&q=$QEMAILsite%3A$DOMAIN+-intext%3A$CURL1+-intext%3A$CURL2+-intext%3A$CURL3+-intext%3A$CURL4+-intext%3A$CURL5+-intext%3A$CURL6" #site:example.tlf -intext:info
  322.             ;;
  323.  
  324.          esac
  325.  
  326.          #Download with wget the page
  327.          wget -U  "" "$GOOGLEQUERY3" -O /tmp/goohost$I-$TMPRND.log -q
  328.  
  329.          #Extract the hosts/emails and save in the result file
  330.          grep -Eio $REGEXPQUERY /tmp/goohost$I-$TMPRND.log >> result-$TMPRND.log
  331.  
  332.          #Extract the number of results google gives from the query
  333.          getresult
  334.  
  335.          #Verbosity
  336.          if [ "$VERBOSITY" = "1" ]; then
  337.             printf "\n"
  338.             printf "Google Query n.$I \n"
  339.             echo $GOOGLEQUERY3
  340.             printf "\n"
  341.             printf "Result for query: $RESULT \n"
  342.             #print the top 6 host from result-$TMPRND.log
  343.             printf "The TOP6 are: \n"
  344.             printf "$CURL1 $CURL2 $CURL3 $CURL4 $CURL5 $CURL6"
  345.             printf "\n"
  346.          fi
  347.  
  348.          ;;
  349.  
  350.       4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 )
  351.  
  352.          let START=($I-3)*100 #Google query top6 changed the start parameter
  353.  
  354.          #Google Query
  355.          case "$METHOD" in
  356.  
  357.             host)
  358.                GOOGLEQUERY3="http://www.google.com/search?num=100&start=$START&q=site%3A$DOMAIN+-inurl%3A$CURL1+-inurl%3A$CURL2+-inurl%3A$CURL3+-inurl%3A$CURL4+-inurl%3A$CURL5+-inurl%3A$CURL6" #site:example.tlf -inurl:top1 -inurl:top2 -inurl:top3 -inurl:top4 -inurl:top5 -inurl:top6
  359.             ;;
  360.  
  361.             ip)
  362.                GOOGLEQUERY3="http://www.google.com/search?num=100&start=$START&q=site%3A$DOMAIN+-inurl%3A$CURL1+-inurl%3A$CURL2+-inurl%3A$CURL3+-inurl%3A$CURL4+-inurl%3A$CURL5+-inurl%3A$CURL6" #site:example.tlf -inurl:top1 -inurl:top2 -inurl:top3 -inurl:top4 -inurl:top5 -inurl:top6
  363.             ;;
  364.  
  365.             mail)
  366.                GOOGLEQUERY3="http://www.google.com/search?num=100&start=$START&q=$QEMAILsite%3A$DOMAIN+-intext%3A$CURL1+-intext%3A$CURL2+-intext%3A$CURL3+-intext%3A$CURL4+-intext%3A$CURL5+-intext%3A$CURL6" #site:example.tlf -intext:info
  367.             ;;
  368.  
  369.          esac
  370.  
  371.          #Download with wget the page
  372.          wget -U  "" "$GOOGLEQUERY3" -O /tmp/goohost$I-$TMPRND.log -q
  373.  
  374.          #Extract the hosts/emails and save in the result file
  375.          grep -Eio $REGEXPQUERY /tmp/goohost$I-$TMPRND.log >> result-$TMPRND.log
  376.  
  377.          #Extract the number of results google gives from the query
  378.          getresult
  379.  
  380.          #Check how many pages to download with this query
  381.          let END=($RESULT/100) #Number of page to download
  382.  
  383.          if [[ $I -ge $END+3 ]]; then
  384.             let I=12
  385.          fi
  386.  
  387.  
  388.          #Verbosity
  389.          if [ "$VERBOSITY" = "1" ]; then
  390.             printf "\n"
  391.             printf "Google Query n.$I \n"
  392.             echo $GOOGLEQUERY3
  393.             printf "\n"
  394.             printf "Result for query: $RESULT \n"
  395.             #print the top 6 host from result-$TMPRND.log
  396.             printf "The TOP6 are: \n"
  397.             printf "$CURL1 $CURL2 $CURL3 $CURL4 $CURL5 $CURL6"
  398.             printf "\n"
  399.  
  400.          fi
  401.  
  402.          ;;
  403.  
  404.  
  405.       13)
  406.  
  407.          #Generate temporary file for the random query
  408.          case "$METHOD" in
  409.  
  410.             host)
  411.                sort -u result-$TMPRND.log | sed -e "s/.$DOMAIN//g" > /tmp/random-$TMPRND.log
  412.             ;;
  413.  
  414.             ip)
  415.                sort -u result-$TMPRND.log | sed -e "s/.$DOMAIN//g" > /tmp/random-$TMPRND.log
  416.             ;;
  417.  
  418.             mail)
  419.                sort -u result-$TMPRND.log | cut -d"@" -f1 > /tmp/random-$TMPRND.log
  420.             ;;
  421.  
  422.          esac
  423.  
  424.          highest=$(wc -l /tmp/random-$TMPRND.log | cut -d" " -f1 ) #Number of hosts present in the result file
  425.  
  426.          #################################################
  427.          #TODO: Exit from the case loop if highest is <= 0
  428.          #################################################
  429.          if [[ $highest -ge "1" ]]; then
  430.             R1=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  431.             R2=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  432.             R3=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  433.             R4=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  434.             R5=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  435.             R6=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  436.  
  437.             RURL1="$(awk "NR==$R1" /tmp/random-$TMPRND.log)"
  438.             RURL2="$(awk "NR==$R2" /tmp/random-$TMPRND.log)"
  439.             RURL3="$(awk "NR==$R3" /tmp/random-$TMPRND.log)"
  440.             RURL4="$(awk "NR==$R4" /tmp/random-$TMPRND.log)"
  441.             RURL5="$(awk "NR==$R5" /tmp/random-$TMPRND.log)"
  442.             RURL6="$(aewk "NR==$R6" /tmp/random-$TMPRND.log)"
  443.  
  444.  
  445.             #Google Query
  446.             case "$METHOD" in
  447.  
  448.                host)
  449.                   GOOGLEQUERY4="http://www.google.com/search?num=100&q=site%3A$DOMAIN+-inurl%3A$RURL1+-inurl%3A$RURL2+-inurl%3A$RURL3+-inurl%3A$RURL4+-inurl%3A$RURL5+-inurl%3A$RURL6" #site:example.tlf -inurl:random1 -inurl:random2 -inurl:random3 -inurl:random4 -inurl:random5 -inurl:random6
  450.                ;;
  451.  
  452.                ip)
  453.                   GOOGLEQUERY4="http://www.google.com/search?num=100&q=site%3A$DOMAIN+-inurl%3A$RURL1+-inurl%3A$RURL2+-inurl%3A$RURL3+-inurl%3A$RURL4+-inurl%3A$RURL5+-inurl%3A$RURL6" #site:example.tlf -inurl:random1 -inurl:random2 -inurl:random3 -inurl:random4 -inurl:random5 -inurl:random6
  454.                ;;
  455.  
  456.                mail)
  457.                   GOOGLEQUERY4="http://www.google.com/search?num=100&q=$QEMAILsite%3A$DOMAIN+-intext%3A$RURL1+-intext%3A$RURL2+-intext%3A$RURL3+-intext%3A$RURL4+-intext%3A$RURL5+-intext%3A$RURL6" #site:example.tlf example.tld -itext:random1 -intext:random2 -intext:random3 -intext:random4 -intext:random5 -intext:random6
  458.                ;;
  459.  
  460.             esac
  461.  
  462.             #Download with wget the page
  463.             wget -U  "" "$GOOGLEQUERY4" -O /tmp/goohost$I-$TMPRND.log -q
  464.  
  465.             #Extract the hosts/emails and save in the result file
  466.             grep -Eio $REGEXPQUERY /tmp/goohost$I-$TMPRND.log >> result-$TMPRND.log
  467.  
  468.             #Extract the number of results google gives from the query
  469.             getresult
  470.  
  471.             #Verbosity
  472.             if [ "$VERBOSITY" = "1" ]; then
  473.                printf "\n"
  474.                printf "Google Query n.$I \n"
  475.                echo $GOOGLEQUERY4
  476.                printf "\n"
  477.                printf "Result for query: $RESULT \n"
  478.                printf "Random hosts: $RURL1 $RURL2 $RURL3 $RURL4 $RURL5 $RURL6 \n"
  479.                printf "\n"
  480.             fi
  481.  
  482.          else
  483.             let I=20
  484.          fi
  485.  
  486.          ;;
  487.  
  488.       14 | 15 | 16 | 17 | 18 | 19)
  489.  
  490.          R1=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  491.          R2=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  492.          R3=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  493.          R4=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  494.          R5=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  495.          R6=$[ ( $RANDOM % ( $[ $highest - 1 ] + 1 ) ) + 1 ]
  496.  
  497.          RURL1="$(awk "NR==$R1" /tmp/random-$TMPRND.log)"
  498.          RURL2="$(awk "NR==$R2" /tmp/random-$TMPRND.log)"
  499.          RURL3="$(awk "NR==$R3" /tmp/random-$TMPRND.log)"
  500.          RURL4="$(awk "NR==$R4" /tmp/random-$TMPRND.log)"
  501.          RURL5="$(awk "NR==$R5" /tmp/random-$TMPRND.log)"
  502.          RURL6="$(awk "NR==$R6" /tmp/random-$TMPRND.log)"
  503.  
  504.          #Google Query
  505.          case "$METHOD" in
  506.  
  507.             host)
  508.                GOOGLEQUERY4="http://www.google.com/search?num=100&q=site%3A$DOMAIN+-inurl%3A$RURL1+-inurl%3A$RURL2+-inurl%3A$RURL3+-inurl%3A$RURL4+-inurl%3A$RURL5+-inurl%3A$RURL6" #site:example.tlf -inurl:random1 -inurl:random2 -inurl:random3 -inurl:random4 -inurl:random5 -inurl:random6
  509.             ;;
  510.  
  511.             ip)
  512.                GOOGLEQUERY4="http://www.google.com/search?num=100&q=site%3A$DOMAIN+-inurl%3A$RURL1+-inurl%3A$RURL2+-inurl%3A$RURL3+-inurl%3A$RURL4+-inurl%3A$RURL5+-inurl%3A$RURL6" #site:example.tlf -inurl:random1 -inurl:random2 -inurl:random3 -inurl:random4 -inurl:random5 -inurl:random6
  513.             ;;
  514.  
  515.             mail)
  516.                GOOGLEQUERY4="http://www.google.com/search?num=100&q=$QEMAILsite%3A$DOMAIN+-intext%3A$RURL1+-intext%3A$RURL2+-intext%3A$RURL3+-intext%3A$RURL4+-intext%3A$RURL5+-intext%3A$RURL6" #site:example.tlf example.tld -itext:random1 -intext:random2 -intext:random3 -intext:random4 -intext:random5 -intext:random6
  517.             ;;
  518.  
  519.          esac
  520.  
  521.          #Download with wget the page
  522.          wget -U  "" "$GOOGLEQUERY4" -O /tmp/goohost$I-$TMPRND.log -q
  523.  
  524.          #Extract the hosts/emails and save in the result file
  525.          grep -Eio $REGEXPQUERY /tmp/goohost$I-$TMPRND.log >> result-$TMPRND.log
  526.  
  527.          #Extract the number of results google gives from the query
  528.          getresult
  529.  
  530.          #Verbosity
  531.          if [ "$VERBOSITY" = "1" ]; then
  532.             printf "\n"
  533.             printf "Google Query n.$I \n"
  534.             echo $GOOGLEQUERY4
  535.             printf "\n"
  536.             printf "Result for query: $RESULT \n"
  537.             #print the top 6 host from result-$TMPRND.log
  538.             printf "Random hosts: $RURL1 $RURL2 $RURL3 $RURL4 $RURL5 $RURL6 \n"
  539.             printf "\n"
  540.          fi
  541.  
  542.          ;;
  543.  
  544.    esac
  545.  
  546. done
  547.  
  548. ###########################################################################
  549. # Generate output and report file
  550. #
  551.  
  552.  
  553. #Generate different report for different methods
  554. case "$METHOD" in
  555.  
  556.    host)
  557.  
  558.       printf "\n"
  559.       cat result-$TMPRND.log | sort -u > report-$TMPRND-$DOMAIN.txt
  560.       printf "Results saved in file report-$TMPRND-$DOMAIN.txt \n"
  561.       printf "$(wc -l report-$TMPRND-$DOMAIN.txt | cut -d" " -f1) results found! \n"
  562.       ;;
  563.  
  564.    ip)
  565.  
  566.       printf "\n"
  567.       for line in $(cat result-$TMPRND.log | sort -u); do
  568.          host $line | grep "has address" | cut -d" " -f1,4 >> report-$TMPRND-$DOMAIN.txt &
  569.       done
  570.       printf "Results saved in file report-$TMPRND-$DOMAIN.txt \n"
  571.       #printf "$(wc -l report-$TMPRND-$DOMAIN.txt | cut -d" " -f1) results found! \n"
  572.       ;;
  573.  
  574.    mail)
  575.  
  576.       printf "\n"
  577.       cat result-$TMPRND.log | sort -u | sed -e "s/<[^>]*>//g"  > report-$TMPRND-$DOMAIN.txt
  578.       printf "Results saved in file report-$TMPRND-$DOMAIN.txt \n"
  579.       printf "$(wc -l report-$TMPRND-$DOMAIN.txt | cut -d" " -f1) results found! \n"
  580.       ;;
  581.  
  582. esac
  583.  
  584. ###########################################################################
  585. # Delete temporary files
  586. #
  587.  
  588. rm -f result-$TMPRND.log 2> /dev/null
  589. rm -f /tmp/goohost*-$TMPRND.log 2> /dev/null
  590. rm -f /tmp/random-$TMPRND.log 2> /dev/null
  591. rm -f /tmp/top6-$TMPRND.log 2> /dev/null
Add Comment
Please, Sign In to add comment