| 1 | + | #!/usr/bin/env bash |
| 2 | + | BNR="G1s0MG0bWzMybSAga2F5b3MgKHRjcC5kaXJlY3QpICAbWzBtChtbNDBtG1szMm0gICAg4pae4paA4paWICDilpwgICAgICDilp7iloDilpYgICAbWzBtChtbNDBtG1szMm0gICAg4paM4pae4paM4paZ4paA4paQIOKWjCDilowgICDilpfilpggICAbWzBtChtbNDBtG1szMm0gICAg4pabIOKWjOKWjCDilpAg4paa4paE4paMICAg4paYICAgIBtbMG0KG1s0MG0bWzMybSAgICDilp3iloAg4paYICDilpjilpfiloTilpggICDilpggICAgG1swbQo=" |
| 3 | + | ############################ |
| 4 | + | # -------> kayos <-------- # |
| 5 | + | # git.tcp.direct/kayos # |
| 6 | + | # twitter.com/yunginnanet # |
| 7 | + | # github.com/yunginnanet # |
| 8 | + | ############################ |
| 9 | + | |
| 10 | + | # ________ |
| 11 | + | #/ \ |
| 12 | + | #| 0rly? | |
| 13 | + | #\__ __'\ |
| 14 | + | # |/ \\ |
| 15 | + | # \ \\ . |
| 16 | + | # |\\/| |
| 17 | + | # / " '\ |
| 18 | + | # . . . |
| 19 | + | # / ) | |
| 20 | + | # ' _.' | |
| 21 | + | # '-'/ \ |
| 22 | + | |
| 23 | + | # usage: ./0rly.sh website.com |
| 24 | + | |
| 25 | + | # uses findomain, runs whois on all the resolvable subs found |
| 26 | + | # sorts out cloudflare IPs, run rustscan on all non-cloudflare IPs |
| 27 | + | # generate HTML reports |
| 28 | + | |
| 29 | + | ###### known dependencies ###### |
| 30 | + | |
| 31 | + | #### most package managers: |
| 32 | + | # - nmap |
| 33 | + | # - xsltproc |
| 34 | + | |
| 35 | + | #### fancy shit: |
| 36 | + | # - rustscan |
| 37 | + | # --- with rust: https://crates.io/crates/rustscan (cargo install rustscan) |
| 38 | + | # --- without: https://github.com/RustScan/RustScan/releases/tag/2.0.1 |
| 39 | + | # - findomain |
| 40 | + | # --- with rust: https://crates.io/crates/findomain (cargo install findomain) |
| 41 | + | # --- without: https://github.com/Findomain/Findomain/releases/tag/3.1.0 |
| 42 | + | |
| 43 | + | ############################################################################### |
| 44 | + | |
| 45 | + | ####################### https://github.com/tlatsas/bash-spinner |
| 46 | + | |
| 47 | + | function _spinner() { |
| 48 | + | # $1 start/stop |
| 49 | + | # |
| 50 | + | # on start: $2 display message |
| 51 | + | # on stop : $2 process exit status |
| 52 | + | # $3 spinner function pid (supplied from stop_spinner) |
| 53 | + | |
| 54 | + | local on_success="DONE" |
| 55 | + | local on_fail="FAIL" |
| 56 | + | local white="\e[1;37m" |
| 57 | + | local green="\e[1;32m" |
| 58 | + | local red="\e[1;31m" |
| 59 | + | local nc="\e[0m" |
| 60 | + | |
| 61 | + | case $1 in |
| 62 | + | start) |
| 63 | + | # calculate the column where spinner and status msg will be displayed |
| 64 | + | let column=$(tput cols)-${#2}-8 |
| 65 | + | # display message and position the cursor in $column column |
| 66 | + | echo -ne ${2} |
| 67 | + | printf "%${column}s" |
| 68 | + | |
| 69 | + | # start spinner |
| 70 | + | i=1 |
| 71 | + | sp='\|/-' |
| 72 | + | delay=${SPINNER_DELAY:-0.15} |
| 73 | + | |
| 74 | + | while : |
| 75 | + | do |
| 76 | + | printf "\b${sp:i++%${#sp}:1}" |
| 77 | + | sleep $delay |
| 78 | + | done |
| 79 | + | ;; |
| 80 | + | stop) |
| 81 | + | if [[ -z ${3} ]]; then |
| 82 | + | echo "spinner is not running.." |
| 83 | + | exit 1 |
| 84 | + | fi |
| 85 | + | |
| 86 | + | kill $3 > /dev/null 2>&1 |
| 87 | + | |
| 88 | + | # inform the user uppon success or failure |
| 89 | + | echo -en "\b[" |
| 90 | + | if [[ $2 -eq 0 ]]; then |
| 91 | + | echo -en "${green}${on_success}${nc}" |
| 92 | + | else |
| 93 | + | echo -en "${red}${on_fail}${nc}" |
| 94 | + | fi |
| 95 | + | echo -e "]" |
| 96 | + | ;; |
| 97 | + | *) |
| 98 | + | echo "invalid argument, try {start/stop}" |
| 99 | + | exit 1 |
| 100 | + | ;; |
| 101 | + | esac |
| 102 | + | } |
| 103 | + | |
| 104 | + | function start_spinner { |
| 105 | + | # $1 : msg to display |
| 106 | + | _spinner "start" "${1}" & |
| 107 | + | # set global spinner pid |
| 108 | + | _sp_pid=$! |
| 109 | + | disown |
| 110 | + | } |
| 111 | + | |
| 112 | + | function stop_spinner { |
| 113 | + | # $1 : command exit status |
| 114 | + | _spinner "stop" $1 $_sp_pid |
| 115 | + | unset _sp_pid |
| 116 | + | } |
| 117 | + | |
| 118 | + | ################################################ |
| 119 | + | |
| 120 | + | rmap() { |
| 121 | + | sudo $HOME/.cargo/bin/rustscan --ulimit 10000 -a $1 -- -Pn -A -T Aggressive -oX $RESULTS/XML/$1.xml |
| 122 | + | sudo xsltproc $RESULTS/XML/$1.xml -o $RESULTS/HTML/$1.html |
| 123 | + | } |
| 124 | + | |
| 125 | + | |
| 126 | + | echo $BNR | base64 -d |
| 127 | + | |
| 128 | + | set -e |
| 129 | + | |
| 130 | + | RESULTS="$HOME/0rly/$1" |
| 131 | + | echo "Creating directory: $RESULTS" |
| 132 | + | echo "" |
| 133 | + | mkdir -p $RESULTS |
| 134 | + | if [ ! -f $HOME/0rly/resolvers.txt ]; then |
| 135 | + | echo -e "\e[33m$HOME/0rly/resolvers.txt not found!" |
| 136 | + | echo -e "would you like to use your system's resolvers?\e[0m" |
| 137 | + | read -r -p " [y/N] " response |
| 138 | + | case "$response" in |
| 139 | + | [yY][eE][sS]|[yY]) |
| 140 | + | ;; |
| 141 | + | *) |
| 142 | + | echo "re-run after you populate resolvers.txt, exiting" |
| 143 | + | exit |
| 144 | + | ;; |
| 145 | + | esac |
| 146 | + | |
| 147 | + | echo "using nameservers:" |
| 148 | + | cat /etc/resolv.conf | grep 'nameserver' | grep '\.' | sed 's/nameserver //g' | tee $HOME/0rly/resolvers.txt |
| 149 | + | fi |
| 150 | + | |
| 151 | + | echo "" |
| 152 | + | |
| 153 | + | start_spinner "running findomain..." |
| 154 | + | |
| 155 | + | findomain -q -i --resolvers $HOME/0rly/resolvers.txt --target "$1" -u $RESULTS/findomain.txt>/dev/null; |
| 156 | + | awk -F ',' '{print $NF}' $RESULTS/findomain.txt | sort -u > $RESULTS/findomain.unique.ips.txt; |
| 157 | + | |
| 158 | + | stop_spinner $? |
| 159 | + | |
| 160 | + | echo "" |
| 161 | + | |
| 162 | + | start_spinner "running whois and deteecting cloudflare IPs..." |
| 163 | + | |
| 164 | + | while read line; do |
| 165 | + | whois "$line" > $RESULTS/$line.whois.txt |
| 166 | + | if ! cat $RESULTS/$line.whois.txt | grep -i -q cloudflare; then |
| 167 | + | echo "cloudflare ip found: $line" |
| 168 | + | # echo -e "\e[2m$line (cloudflare)\e[0m"; |
| 169 | + | echo "$line" >> $RESULTS/cloudflare.ips.txt; |
| 170 | + | else |
| 171 | + | echo "$line" >> $RESULTS/noncloudflare.ips.txt; |
| 172 | + | echo -n "$line ("; cat $RESULTS/$line.whois.txt | grep -i -m1 org-name; echo -n ")"; |
| 173 | + | fi |
| 174 | + | done < $RESULTS/findomain.unique.ips.txt |
| 175 | + | |
| 176 | + | echo -n "would you like to execute rustscan on all non-cloudflare IPs and generate HTML reports?" |
| 177 | + | read -r -p " [y/N] " response |
| 178 | + | case "$response" in |
| 179 | + | [yY][eE][sS]|[yY]) |
| 180 | + | ;; |
| 181 | + | *) |
| 182 | + | echo "Well then, I suppose we're done!" |
| 183 | + | echo "Here's what we've got:" |
| 184 | + | ls $RESULTS; |
| 185 | + | exit |
| 186 | + | ;; |
| 187 | + | esac |
| 188 | + | |
| 189 | + | mkdir -p $RESULTS/XML |
| 190 | + | mkdir -p $RESULTS/HTML |
| 191 | + | |
| 192 | + | set +e |
| 193 | + | |
| 194 | + | while read line; do |
| 195 | + | start_spinner "Scanning $line..." |
| 196 | + | rmap $line >/dev/null |
| 197 | + | stop_spinner $? |
| 198 | + | done < $RESULTS/noncloudflare.ips.txt |
| 199 | + | |
| 200 | + | |