mauvehed's dotfiles for personal and work environments
at main 244 lines 9.5 kB view raw
1#!/bin/bash 2 3#### Colors Output 4 5RESET="\033[0m" # Normal Colour 6RED="\033[0;31m" # Error / Issues 7GREEN="\033[0;32m" # Successful 8BOLD="\033[01;01m" # Highlight 9WHITE="\033[1;37m" # BOLD 10YELLOW="\033[1;33m" # Warning 11 12#### Other Colors / Status Code 13 14LYELLOW="\033[0;93m" 15LGRAY="\033[0;37m" # Light Gray 16LRED="\033[1;31m" # Light Red 17LGREEN="\033[1;32m" # Light GREEN 18LBLUE="\033[1;34m" # Light Blue 19LPURPLE="\033[1;35m" # Light Purple 20LCYAN="\033[1;36m" # Light Cyan 21SORANGE="\033[0;33m" # Standar Orange 22SBLUE="\033[0;34m" # Standar Blue 23SPURPLE="\033[0;35m" # Standar Purple 24SCYAN="\033[0;36m" # Standar Cyan 25DGRAY="\033[1;30m" # Dark Gray 26 27# Information Notification 28showINF=$(printf "[${GREEN}INF${RESET}]") 29showLINF=$(printf "[${LGREEN}INF${RESET}]") 30showERR=$(printf "[${RED}ERR${RESET}]") 31showWRN=$(printf "[${YELLOW}WRN${RESET}]") 32showLWRN=$(printf "[${LYELLOW}WRN${RESET}]") 33 34## Configuration (you can modify it) 35OUTPUT_PATH="$(pwd)/crt-result" 36TEMP_PATH="/tmp" 37FILE_DATE=$(date +"%d-%m-%Y") 38SILENT_MODE="false" 39 40## Cool Banner Tho 41showBanner(){ 42 printf " 43 __ ${LBLUE} __ ${RESET} 44 __________/ /_ ${LBLUE}_____/ /_ ${RESET} 45 / ___/ ___/ __/ ${LBLUE}/ ___/ __ \\ ${RESET} 46/ /__/ / / /__ ${LBLUE}(__ ) / / / ${RESET} 47\___/_/ \__${LYELLOW}(_)${LBLUE}____/_/ /_/${RESET} v1.0.0 48 49KeepWannabe - 0x0.si\n\n" 50} 51 52## Showing Help 53getHelp(){ 54 showBanner 55 printf "Usage: bash crt.sh [options]\n\n" 56 printf "Options:\n -h, --help Showing Helps\n" 57 printf " -d DOMAIN, --domain=DOMAIN Search by using Domain Name (${RED}*${RESET}\n" 58 printf " -org ORG-NAME, --organiz.. Search by using Organization Name (${RED}*${RESET}\n\n" 59} 60 61## Showing Help if there's no args 62[[ "${#}" == 0 ]] && { 63 getHelp && exit 1 64} 65 66## Timestamp 67getCurrentTime(){ 68 69 printf "[${SCYAN}%s${RESET}]\n" "$(date +"%T")" 70 71} 72 73# COMMAND LINE SWITCHES 74while [[ "${#}" -gt 0 ]]; do 75 args="${1}" 76 case "$(echo ${args})" in 77 # Target 78 # Help 79 "-h" | "--help") 80 getHelp 81 exit 1 82 ;; 83 "-d" | "--domain") 84 DOM_TARGET="${2}" 85 shift 86 shift 87 ;; 88 "--domain="*) 89 DOM_TARGET="${1#*=}" 90 shift 1 91 ;; 92 "-org" | "--organization") 93 ORG_TARGET="${2}" 94 shift 95 shift 96 ;; 97 "--organization="*) 98 ORG_TARGET="${1#*=}" 99 shift 1 100 ;; 101 "-s" | "--silent") 102 SILENT_MODE="true" 103 shift 104 ;; 105 "-"*) 106 showBanner 107 printf "$(getCurrentTime) ${showERR} Invalid option: ${RED}${1}${RESET}" && shift && exit 1 108 ;; 109 *) 110 showBanner 111 printf "$(getCurrentTime) ${showERR} Invalid: Unknown option ${RED}${1}${RESET}" && shift && exit 112 exit 113 ;; 114 esac 115done 116 117if [ -n "${DOM_TARGET}" ] && [ -n "${ORG_TARGET}" ]; then 118 getHelp 119 printf "$(getCurrentTime) ${showERR} Please use either '${WHITE}-d,--domain${RESET}' or '${WHITE}-org,--organization${RESET}'. not both at the same time.\n" 120 exit 1 121fi 122 123if [ -z "${DOM_TARGET}" ] && [ -z "${ORG_TARGET}" ]; then 124 getHelp 125 printf "$(getCurrentTime) ${showERR} Please specify a target for either '${WHITE}-d,--domain${RESET}' or '${WHITE}-org,--organization${RESET}' option.\n" 126 exit 1 127fi 128 129createOutputDir(){ 130 131 if [ "${SILENT_MODE}" == "false" ]; then 132 ## Checking Directory 133 if [ ! -d "${OUTPUT_PATH}" ]; then 134 printf "$(getCurrentTime) ${showINF} Creating directory at \"${WHITE}${OUTPUT_PATH}\"${RESET}\n" 135 mkdir "${OUTPUT_PATH}" 136 fi 137 else 138 ## Checking Directory 139 if [ ! -d "${OUTPUT_PATH}" ]; then 140 mkdir "${OUTPUT_PATH}" 141 fi 142 fi 143 144} 145 146getByDomain(){ 147 148 if [ "${SILENT_MODE}" = "true" ]; then 149 ## Create Output Dir 150 createOutputDir 151 ## Create 5 Random String for temp file name 152 randString=$(openssl rand -base64 7 | tr -dc 'a-zA-Z0-9') 153 ## Send GET Request to https://crt.sh 154 reqByDomain=$(curl -skL "https://crt.sh?q=${DOM_TARGET}&output=json" -o "${TEMP_PATH}/${randString}-${DOM_TARGET}-temp.txt") 155 ## Parsing Result and Save to ${OUTPUT_PATH} (see config on top) 156 $(cat "${TEMP_PATH}/${randString}-${DOM_TARGET}-temp.txt" | jq -r ".[].common_name,.[].name_value"| cut -d '"' -f2 | sed 's/\\n/\n/g' | sed 's/\*.//g'| sed -r 's/([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})//g' | sort | uniq >> "${OUTPUT_PATH}/result-${DOM_TARGET}.txt") 157 ## Delete temp file 158 rm "${TEMP_PATH}/${randString}-${DOM_TARGET}-temp.txt" 159 ## Showing Result 160 printf "$(cat "${OUTPUT_PATH}/result-${DOM_TARGET}.txt" | uniq)\n" 161 else 162 showBanner 163 printf "[*] starting @ $(date +"%T /%Y-%m-%d/")\n" 164 ## Create Output Dir 165 createOutputDir 166 printf "$(getCurrentTime) ${showINF} Searching subdomain of ${DOM_TARGET}\n" 167 168 ## Create 5 Random String for temp file name 169 randString=$(openssl rand -base64 7 | tr -dc 'a-zA-Z0-9') 170 ## Send GET Request to https://crt.sh 171 reqByDomain=$(curl -skL "https://crt.sh?q=${DOM_TARGET}&output=json" -o "${TEMP_PATH}/${randString}-${DOM_TARGET}-temp.txt") 172 ## Parsing Result and Save to ${OUTPUT_PATH} (see config on top) 173 $(cat "${TEMP_PATH}/${randString}-${DOM_TARGET}-temp.txt" | jq -r ".[].common_name,.[].name_value"| cut -d '"' -f2 | sed 's/\\n/\n/g' | sed 's/\*.//g'| sed -r 's/([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})//g' | sort | uniq >> "${OUTPUT_PATH}/result-${DOM_TARGET}.txt") 174 175 printf "$(getCurrentTime) ${showINF} Success collecting ${LGREEN}$(cat "${OUTPUT_PATH}/result-${DOM_TARGET}.txt" | wc -l) subdomain${RESET} from ${DOM_TARGET}\n" 176 ## Showing Result 177 printf "%s\n" "---" 178 printf "$(cat "${OUTPUT_PATH}/result-${DOM_TARGET}.txt" | uniq)\n" 179 printf "%s\n" "---" 180 printf "$(getCurrentTime) ${showINF} Result saved to '${LGREEN}${OUTPUT_PATH}/result-${DOM_TARGET}.txt${RESET}'\n" 181 printf "$(getCurrentTime) ${showINF} Deleting temp file '${WHITE}${TEMP_PATH}/${randString}-${DOM_TARGET}-temp.txt'${RESET}\n" 182 183 ## Delete temp file 184 rm "${TEMP_PATH}/${randString}-${DOM_TARGET}-temp.txt" 185 186 printf "\n[*] ending @ $(date +"%T /%Y-%m-%d/")\n" 187 fi 188 189} 190 191getByOrganization(){ 192 193 if [ "${SILENT_MODE}" = "true" ]; then 194 ## Create Output Dir 195 createOutputDir 196 ## Replacing `space` to `dash` for file name 197 dashedORG_TARGET=$(echo ${ORG_TARGET} | sed 's/ /-/g') 198 ## Create 5 Random String for temp file name 199 randString=$(openssl rand -base64 7 | tr -dc 'a-zA-Z0-9') 200 ## Send GET Request to https://crt.sh 201 reqByOrganization=$(curl -skL "https://crt.sh?q=${ORG_TARGET}&output=json" -o "${TEMP_PATH}/${randString}-${dashedORG_TARGET}-temp.txt") 202 ## Parsing Result and Save to ${OUTPUT_PATH} (see config on top) 203 $(cat "${TEMP_PATH}/${randString}-${dashedORG_TARGET}-temp.txt" | jq ".[].common_name" | cut -d '"' -f2 | sed 's/\\n/\n/g' | sed 's/\*.//g' | sed -r 's/([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})//g' | sort | uniq >> "${OUTPUT_PATH}/result-${dashedORG_TARGET}.txt") 204 ## Delete temp file 205 rm "${TEMP_PATH}/${randString}-${dashedORG_TARGET}-temp.txt" 206 ## Showing File 207 printf "$(cat "${OUTPUT_PATH}/result-${dashedORG_TARGET}.txt" | uniq)\n" 208 else 209 showBanner 210 printf "[*] starting @ $(date +"%T /%Y-%m-%d/")\n" 211 ## Create Output Dir 212 createOutputDir 213 printf "$(getCurrentTime) ${showINF} Searching subdomain of ${ORG_TARGET}\n" 214 215 ## Replacing `space` to `dash` for file name 216 dashedORG_TARGET=$(echo ${ORG_TARGET} | sed 's/ /-/g') 217 ## Create 5 Random String for temp file name 218 randString=$(openssl rand -base64 7 | tr -dc 'a-zA-Z0-9') 219 ## Send GET Request to https://crt.sh 220 reqByOrganization=$(curl -skL "https://crt.sh?q=${ORG_TARGET}&output=json" -o "${TEMP_PATH}/${randString}-${dashedORG_TARGET}-temp.txt") 221 ## Parsing Result and Save to ${OUTPUT_PATH} (see config on top) 222 $(cat "${TEMP_PATH}/${randString}-${dashedORG_TARGET}-temp.txt" | jq ".[].common_name" | cut -d '"' -f2 | sed 's/\\n/\n/g' | sed 's/\*.//g' | sed -r 's/([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})//g' | sort | uniq >> "${OUTPUT_PATH}/result-${dashedORG_TARGET}.txt") 223 224 printf "$(getCurrentTime) ${showINF} Success collecting ${LGREEN}$(cat "${OUTPUT_PATH}/result-${dashedORG_TARGET}.txt" | wc -l) subdomain${RESET} from ${ORG_TARGET}\n" 225 ## Showing Result 226 printf "%s\n" "---" 227 printf "$(cat "${OUTPUT_PATH}/result-${dashedORG_TARGET}.txt" | uniq)\n" 228 printf "%s\n" "---" 229 printf "$(getCurrentTime) ${showINF} Result saved to '${LGREEN}${OUTPUT_PATH}/result-${dashedORG_TARGET}.txt${RESET}'\n" 230 printf "$(getCurrentTime) ${showINF} Deleting temp file '${WHITE}${TEMP_PATH}/${randString}-${dashedORG_TARGET}-temp.txt'${RESET}\n" 231 232 ## Delete temp file 233 rm "${TEMP_PATH}/${randString}-${dashedORG_TARGET}-temp.txt" 234 235 printf "\n[*] ending @ $(date +"%T /%Y-%m-%d/")\n" 236 fi 237 238} 239 240if [ -n "${DOM_TARGET}" ]; then 241 getByDomain 242elif [ -n "${ORG_TARGET}" ]; then 243 getByOrganization 244fi