-
Notifications
You must be signed in to change notification settings - Fork 1
/
ct-abuse
executable file
·83 lines (58 loc) · 1.63 KB
/
ct-abuse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
# bash-scripts/ct-abuse
# ct-abuse
# Enumerate HTTPS enabled subdomains via Certificate Transparency
set -euo pipefail
# -e exit if any command returns non-zero status code
# -u prevent using undefined variables
# -o pipefail force pipelines to fail on first non-zero status code
IFS=$'\n\t'
# Set Internal Field Separator to newlines and tabs
# This makes bash consider newlines and tabs as separating words
# See: http://redsymbol.net/articles/unofficial-bash-strict-mode/
### Define Colours ###
tput sgr0;
# reset colors
readonly RESET=$(tput sgr0)
readonly BOLD=$(tput bold)
readonly RED=$(tput setaf 1)
readonly ORANGE=$(tput setaf 3)
readonly GREEN=$(tput setaf 64)
### END Colours ###
### Define output messages ###
FATAL="${RED}FATAL${RESET}"
INFO="${ORANGE}INFO${RESET}"
### END output messages ###
function usage {
echo "Usage: ./ct-abuse.sh {target_domain}"
}
function check_curl () {
if ! [ -x "$(command -v curl)" ]; then
echo "[${FATAL}] curl not installed"
echo "[${INFO}] Linux: apt install curl"
exit 1
fi
}
function get_subdomains () {
local subdomains=()
# shellcheck disable=SC2207
mapfile -t subdomains < <(curl --silent "https://crt.sh/?q=%25.${1}&output=json" \
| grep -Eo '"name_value":(\d*?,|.*?[^\\]",)' \
| awk -F '"' '{print $4}' \
| sort -u)
# grep regex from: https://stackoverflow.com/a/6852427
for result in "${subdomains[@]}"; do
echo "${result}"
done
}
function main {
local target_domain=${1:-""}
if [[ $# -eq 0 ]] ; then
# If no args then print help
usage
exit 1
fi
check_curl
get_subdomains "${target_domain}"
}
main "$@"