-
Notifications
You must be signed in to change notification settings - Fork 64
/
domains.sh
352 lines (317 loc) · 9.64 KB
/
domains.sh
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
#!/bin/bash
#
# script for subdomain enumeration using 4 of the best tools and some online services:
# * findomain: https://github.com/Edu4rdSHL/findomain
# * SubFinder: https://github.com/projectdiscovery/subfinder
# * Amass: https://github.com/OWASP/Amass
# * AssetFinder: https://github.com/tomnomnom/assetfinder
#
bold="\e[1m"
Underlined="\e[4m"
red="\e[31m"
green="\e[32m"
blue="\e[34m"
end="\e[0m"
VERSION="2022-03-20"
PRG=${0##*/}
Usage(){
while read -r line; do
printf "%b\n" "$line"
done <<-EOF
\r
\r# ${bold}${blue}Options${end}:
\r -d, --domain - Domain To Enumerate
\r -l, --list - List of domains
\r -u, --use - Tools To Be Used ex(Findomain,Subfinder,...,etc)
\r -e, --exclude - Tools To Be Excluded ex(Findomain,Amass,...,etc)
\r -o, --output - The output file to save the Final Results (Default: <TargetDomain>-DATE-TIME.txt)
\r -s, --silent - The Only output will be the found subdomains - (Results saved: subenum-<DOMAIN>.txt).
\r -k, --keep - To Keep the TMPs files (the results from each tool).
\r -r, --resolve - To Probe For Working HTTP and HTTPS Subdomains, (Output: resolved-<DOMAIN>.txt).
\r -t, --thread - Threads for Httprobe - works with -r/--resolve option (Default: 40)
\r -p, --parallel - To Use Parallel For Faster Results, Doesn't Work With -e/--exclude or -u/--use.
\r -h, --help - Displays this help message and exit.
\r -v, --version - Displays the version and exit.
\r# ${bold}${blue}Available Tools${end}:
\r wayback,crt,bufferover,Findomain,Subfinder,Amass,Assetfinder
\r# ${bold}${blue}Examples${end}:
\r - To use a specific Tool(s):
\r $PRG -d hackerone.com -u Findomain,wayback,Subfinder
\r - To exclude a specific Tool(s):
\r $PRG -d hackerone.com -e Amass,Assetfinder
\r - To use all the Tools:
\r $PRG -d hackerone.com
\r - To run SubEnum.sh against a list of domains:
\r $PRG -l domains.txt
\r - Run with parallel for faster results, (Doesn't work with -e/--exclude or -u/--use).
\r 1- $PRG --domain target.com --parallel
\r 2- $PRG --list domains.txt --parallel
EOF
exit 1
}
spinner(){
processing="${1}"
while true;
do
dots=(
"/"
"-"
"\\"
"|"
)
for dot in ${dots[@]};
do
printf "[${dot}] ${processing} \U1F50E"
printf " \r"
sleep 0.3
done
done
}
wayback() {
[ "$silent" == True ] && curl -sk "http://web.archive.org/cdx/search/cdx?url=*.$domain&output=txt&fl=original&collapse=urlkey&page=" | awk -F/ '{gsub(/:.*/, "", $3); print $3}' | sort -u | anew subenum-$domain.txt || {
[[ ${PARALLEL} == True ]] || { spinner "${bold}WayBackMachine${end}" &
PID="$!"
}
curl -sk "http://web.archive.org/cdx/search/cdx?url=*.$domain&output=txt&fl=original&collapse=urlkey&page=" | awk -F/ '{gsub(/:.*/, "", $3); print $3}' | sort -u > tmp-wayback-$domain
[[ ${PARALLEL} == True ]] || kill ${PID} 2>/dev/null
echo -e "$bold[*] WayBackMachine$end: $(wc -l < tmp-wayback-$domain)"
}
}
crt() {
[ "$silent" == True ] && curl -sk "https://crt.sh/?q=%.$domain&output=json" | tr ',' '\n' | awk -F'"' '/name_value/ {gsub(/\*\./, "", $4); gsub(/\\n/,"\n",$4);print $4}' | anew subenum-$domain.txt || {
[[ ${PARALLEL} == True ]] || { spinner "${bold}crt.sh${end}" &
PID="$!"
}
curl -sk "https://crt.sh/?q=%.$domain&output=json" | tr ',' '\n' | awk -F'"' '/name_value/ {gsub(/\*\./, "", $4); gsub(/\\n/,"\n",$4);print $4}' | sort -u > tmp-crt-$domain
[[ ${PARALLEL} == True ]] || kill ${PID} 2>/dev/null
echo -e "$bold[*] crt.sh$end: $(wc -l < tmp-crt-$domain)"
}
}
bufferover() {
[ "$silent" == True ] && curl -s "https://dns.bufferover.run/dns?q=.$domain" | grep $domain | awk -F, '{gsub("\"", "", $2); print $2}' | anew subenum-$domain.txt || {
[[ ${PARALLEL} == True ]] || { spinner "${bold}BufferOver${end}" &
PID="$!"
}
curl -s "https://dns.bufferover.run/dns?q=.$domain" | grep $domain | awk -F, '{gsub("\"", "", $2); print $2}' | sort -u > tmp-bufferover-$domain
[[ ${PARALLEL} == True ]] || kill ${PID} 2>/dev/null
echo -e "$bold[*] BufferOver$end: $(wc -l < tmp-bufferover-$domain)"
}
}
Findomain() {
[ "$silent" == True ] && findomain -t $domain -q 2>/dev/null | anew subenum-$domain.txt || {
[[ ${PARALLEL} == True ]] || { spinner "${bold}Findomain${end}" &
PID="$!"
}
findomain -t $domain -u tmp-findomain-$domain &>/dev/null
[[ ${PARALLEL} == True ]] || kill ${PID} 2>/dev/null
echo -e "$bold[*] Findomain$end: $(wc -l tmp-findomain-$domain 2>/dev/null | awk '{print $1}')"
}
}
Subfinder() {
[ "$silent" == True ] && subfinder -all -silent -d $domain 2>/dev/null | anew subenum-$domain.txt || {
[[ ${PARALLEL} == True ]] || { spinner "${bold}SubFinder${end}" &
PID="$!"
}
subfinder -all -silent -d $domain 1> tmp-subfinder-$domain 2>/dev/null
[[ ${PARALLEL} == True ]] || kill ${PID} 2>/dev/null
echo -e "$bold[*] SubFinder$end: $(wc -l < tmp-subfinder-$domain)"
}
}
Amass() {
# amass is with "-passive" option to make it faster, but it may cuz less results
[ "$silent" == True ] && amass enum -passive -norecursive -noalts -d $domain 2>/dev/null | anew subenum-$domain.txt || {
[[ ${PARALLEL} == True ]] || { spinner "${bold}Amass${end}" &
PID="$!"
}
amass enum -passive -norecursive -noalts -d $domain 1> tmp-amass-$domain 2>/dev/null
[[ ${PARALLEL} == True ]] || kill ${PID} 2>/dev/null
echo -e "$bold[*] Amass$end: $(wc -l < tmp-amass-$domain)"
}
}
Assetfinder() {
[ "$silent" == True ] && assetfinder --subs-only $domain | anew subenum-$domain.txt || {
[[ ${PARALLEL} == True ]] || { spinner "${bold}AssetFinder${end}" &
PID="$!"
}
assetfinder --subs-only $domain > tmp-assetfinder-$domain
kill ${PID} 2>/dev/null
echo -e "$bold[*] AssetFinder$end: $(wc -l < tmp-assetfinder-$domain)"
}
}
USE() {
for i in $lu; do
$i
done
OUT
}
EXCLUDE() {
for i in ${list[@]}; do
if [[ " ${le[@]} " =~ " ${i} " ]]; then
continue
else
$i
fi
done
OUT
}
OUT(){
[ "$silent" == False ] && {
[ -n "$1" ] && out="$1" || out="$domain-$(date +'%Y-%m-%d').txt"
sort -u tmp-* > $out
echo -e $green"[+] The Final Results:$end $(wc -l $out)"
[ $resolve == True ] && ALIVE "$out" "$domain"
[ $delete == True ] && rm tmp-*
}
}
ALIVE(){
[ "$silent" == False ] && printf "$bold[+] Resolving $end"
printf " \r"
cat $1 | httprobe -c $thread > "resolved-$2.txt"
[ "$silent" == False ] && echo -e $green"[+] Resolved:$end $(wc -l < resolved-$2.txt)"
}
LIST() {
lines=$(wc -l < $hosts)
count=1
while read domain; do
[ "$silent" == False ] && echo -e "\n${Underlined}${bold}${green}[+] Domain ($count/$lines):${end} ${domain}"
[ $prv == "a" ] && {
[[ ${PARALLEL} == True ]] && {
spinner "Reconnaissance" &
PID="$!"
export -f wayback crt bufferover Findomain Subfinder Amass Assetfinder spinner
export domain silent bold end
parallel ::: wayback crt bufferover Findomain Subfinder Amass Assetfinder
kill ${PID}
OUT
} || {
wayback
crt
bufferover
Findomain
Subfinder
Amass
Assetfinder
OUT
}
}
[ $prv == "e" ] && EXCLUDE
[ $prv == "u" ] && USE
let count+=1
done < $hosts
}
Main() {
[ $domain == False ] && [ $hosts == False ] && { echo -e $red"[-] Argument -d/--domain OR -l/--list is Required!"$end; Usage; }
[ $use != False ] && [ $exclude != False ] && { echo -e $Underlined$red"[!] You can use only one Option: -e/--exclude OR -u/--use"$end; Usage; }
[ $domain != False ] && {
[ $use == False ] && [ $exclude == False ] && {
[[ ${PARALLEL} == True ]] && {
spinner "Reconnaissance" &
PID="$!"
export -f wayback crt bufferover Findomain Subfinder Amass Assetfinder spinner
export domain silent bold end
parallel ::: wayback crt bufferover Findomain Subfinder Amass Assetfinder
kill ${PID}
} || {
wayback
crt
bufferover
Findomain
Subfinder
Amass
Assetfinder
}
[ "$out" == False ] && OUT || OUT $out
} || {
[ $use != False ] && USE
[ $exclude != False ] && EXCLUDE
}
}
[ "$hosts" != False ] && {
[ $use != False ] && prv=u
[ $exclude != False ] && prv=e
[ $use == False ] && [ $exclude == False ] && prv=a
LIST
}
}
domain=False
hosts=False
use=False
exclude=False
silent=False
delete=True
out=False
resolve=False
thread=40
PARALLEL=False
list=(
wayback
crt
bufferover
Findomain
Subfinder
Amass
Assetfinder
)
while [ -n "$1" ]; do
case $1 in
-d|--domain)
domain=$2
shift ;;
-l|--list)
hosts=$2
shift ;;
-u|--use)
use=$2
lu=${use//,/ }
for i in $lu; do
if [[ ! " ${list[@]} " =~ " ${i} " ]]; then
echo -e $red$Underlined"[-] Unknown Function: $i"$end
Usage
fi
done
shift ;;
-e|--exclude)
exclude=$2
le=${exclude//,/ }
for i in $le; do
if [[ ! " ${list[@]} " =~ " ${i} " ]]; then
echo -e $red$Underlined"[-] Unknown Function: $i"$end
Usage
fi
done
shift ;;
-o|--output)
out=$2
shift ;;
-s|--silent)
silent=True ;;
-k|--keep)
delete=False ;;
-r|--resolve)
resolve=True ;;
-t|--thread)
thread=$2
shift ;;
-h|--help)
Usage;;
-p|--parallel)
PARALLEL=True ;;
-v|--version)
echo "Version: $VERSION"
exit 0 ;;
*)
echo "[-] Unknown Option: $1"
Usage ;;
esac
shift
done
[ "$silent" == False ] && echo -e $blue$bold"""
____ _ _____
/ ___| _ _| |__ | ____|_ __ _ _ _ __ ___
\___ \| | | | '_ \| _| | '_ \| | | | '_ \` _ \\
___) | |_| | |_) | |___| | | | |_| | | | | | |
|____/ \__,_|_.__/|_____|_| |_|\__,_|_| |_| |_|
Subdomains Enumeration Tool
By: bing0o @hack1lab
"""$end
Main