leonteale

Web-service-finder.sh

Nov 19th, 2013
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.41 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Gets the urls that return a status 200 on port 443 when given a list of ips.
  4. #
  5. # Usage: ./web-service-finder.sh ips.txt
  6. #
  7. # By: Leon Teale (leonteale.co.uk)
  8. #
  9.  
  10.  
  11. ## Check for correct usage
  12. if [ -z "$1" ];
  13.     then
  14.         echo ""
  15.         echo "please provide some ips for the script"
  16.         echo "   Usage: ./web-service-finder.sh ips.txt"
  17.         echo ""
  18.     else
  19.         echo ""
  20.  
  21. for ip in `cat $1`; do
  22.     echo "$ip";
  23.  
  24. #Perform nmap to only gather ips that have port 443 open else the script can hang.
  25. nmap $ip -p 443 -o /dev/null | egrep open; done | grep -B 1 open > temp.txt; cat temp.txt | grep '[^\.][0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}[^\.]' > ips443.txt;
  26.     for ip in `cat ips443.txt | sort -u`; do
  27.  
  28.         #Performs the last bit of the program using curl to grab the URL
  29.         curl -k -sL -w "%{http_code} %{url_effective}\\n" "https://$ip"; done | grep "200 https"
  30.  
  31. for ip in `cat $1`; do
  32.     echo "$ip";
  33.  
  34. #Perform nmap to only gather ips that have port 80 open else the script can hang.
  35. nmap $ip -p 80 -o /dev/null | egrep open; done | grep -B 1 open > temp.txt; cat temp.txt | grep '[^\.][0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}[^\.]' > ips80.txt;
  36.     for ip in `cat ips80.txt | sort -u`; do
  37.  
  38.         #Performs the last bit of the program using curl to grab the URL
  39.         curl -k -sL -w "%{http_code} %{url_effective}\\n" "http://$ip"; done | grep "200 http"
  40. fi
  41.  
  42.  
  43. #clean up
  44. rm ips80.txt
  45. rm ips443.txt
Advertisement
Add Comment
Please, Sign In to add comment