-
Notifications
You must be signed in to change notification settings - Fork 112
/
recon.sh
executable file
·354 lines (309 loc) · 12.2 KB
/
recon.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
353
354
#!/bin/bash
: '
@name ReconPi recon.sh
@author Martijn B <Twitter: @x1m_martijn>
@link https://github.com/x1mdev/ReconPi
'
: 'Set the main variables'
YELLOW="\033[1;33m"
GREEN="\033[0;32m"
RESET="\033[0m"
domain="$1"
RESULTDIR="$HOME/assets/$domain"
WORDLIST="$RESULTDIR/wordlists"
SCREENSHOTS="$RESULTDIR/screenshots"
SUBS="$RESULTDIR/subdomains"
DIRSCAN="$RESULTDIR/directories"
HTML="$RESULTDIR/html"
GFSCAN="$RESULTDIR/gfscan"
IPS="$RESULTDIR/ips"
PORTSCAN="$RESULTDIR/portscan"
ARCHIVE="$RESULTDIR/archive"
VERSION="2.2"
NUCLEISCAN="$RESULTDIR/nucleiscan"
: 'Display the logo'
displayLogo() {
echo -e "
__________ __________.__
\______ \ ____ ____ ____ ____\______ \__|
| _// __ \_/ ___\/ _ \ / \| ___/ |
| | \ ___/\ \__( <_> ) | \ | | |
|____|_ /\___ >\___ >____/|___| /____| |__|
\/ \/ \/ \/
v$VERSION - $YELLOW@x1m_martijn$RESET"
}
: 'Display help text when no arguments are given'
checkArguments() {
if [[ -z $domain ]]; then
echo -e "[$GREEN+$RESET] Usage: recon <domain.tld>"
exit 1
fi
}
checkDirectories() {
echo -e "[$GREEN+$RESET] Creating directories and grabbing wordlists for $GREEN$domain$RESET.."
mkdir -p "$RESULTDIR"
mkdir -p "$SUBS" "$SCREENSHOTS" "$DIRSCAN" "$HTML" "$WORDLIST" "$IPS" "$PORTSCAN" "$ARCHIVE" "$NUCLEISCAN" "$GFSCAN"
}
startFunction() {
tool=$1
echo -e "[$GREEN+$RESET] Starting $tool"
}
: 'Gather resolvers'
gatherResolvers() {
startFunction "Get fresh working resolvers"
wget https://raw.githubusercontent.com/janmasarik/resolvers/master/resolvers.txt -O "$IPS"/resolvers.txt
}
: 'subdomain gathering'
gatherSubdomains() {
startFunction "sublert"
echo -e "[$GREEN+$RESET] Checking for existing sublert output, otherwise add it."
if [ ! -e "$SUBS"/sublert.txt ]; then
cd "$HOME"/tools/sublert || return
yes | python3 sublert.py -u "$domain"
cp "$HOME"/tools/sublert/output/"$domain".txt "$SUBS"/sublert.txt
cd "$HOME" || return
else
cp "$HOME"/tools/sublert/output/"$domain".txt "$SUBS"/sublert.txt
fi
echo -e "[$GREEN+$RESET] Done, next."
startFunction "subfinder"
"$HOME"/go/bin/subfinder -d "$domain" -all -config "$HOME"/ReconPi/configs/config.yaml -o "$SUBS"/subfinder.txt
echo -e "[$GREEN+$RESET] Done, next."
startFunction "assetfinder"
"$HOME"/go/bin/assetfinder --subs-only "$domain" >"$SUBS"/assetfinder.txt
echo -e "[$GREEN+$RESET] Done, next."
startFunction "amass"
"$HOME"/go/bin/amass enum -passive -d "$domain" -config "$HOME"/ReconPi/configs/config.ini -o "$SUBS"/amassp.txt
echo -e "[$GREEN+$RESET] Done, next."
startFunction "findomain"
findomain -t "$domain" -u "$SUBS"/findomain_subdomains.txt
echo -e "[$GREEN+$RESET] Done, next."
startFunction "chaos"
chaos -d "$domain" -key $CHAOS_KEY -o "$SUBS"/chaos_data.txt
echo -e "[$GREEN+$RESET] Done, next."
startFunction "github-subdomains"
github-subdomains -t $github_subdomains_token -d "$domain" | sort -u >> "$SUBS"/github_subdomains.txt
echo -e "[$GREEN+$RESET] Done, next."
startFunction rapiddns
crobat -s "$domain" | sort -u | tee "$SUBS"/rapiddns_subdomains.txt
echo -e "[$GREEN+$RESET] Done, next."
echo -e "[$GREEN+$RESET] Combining and sorting results.."
cat "$SUBS"/*.txt | sort -u >"$SUBS"/subdomains
echo -e "[$GREEN+$RESET] Resolving subdomains.."
cat "$SUBS"/subdomains | sort -u | shuffledns -silent -d "$domain" -r "$IPS"/resolvers.txt > "$SUBS"/alive_subdomains
echo -e "[$GREEN+$RESET] Getting alive hosts.."
cat "$SUBS"/alive_subdomains | "$HOME"/go/bin/httprobe -prefer-https | tee "$SUBS"/hosts
echo -e "[$GREEN+$RESET] Done."
}
: 'subdomain takeover check'
checkTakeovers() {
startFunction "subjack"
"$HOME"/go/bin/subjack -w "$SUBS"/hosts -a -ssl -t 50 -v -c "$HOME"/go/src/github.com/haccer/subjack/fingerprints.json -o "$SUBS"/all-takeover-checks.txt -ssl
grep -v "Not Vulnerable" <"$SUBS"/all-takeover-checks.txt >"$SUBS"/takeovers
rm "$SUBS"/all-takeover-checks.txt
vulnto=$(cat "$SUBS"/takeovers)
if [[ $vulnto == *i* ]]; then
echo -e "[$GREEN+$RESET] Possible subdomain takeovers:"
for line in "$SUBS"/takeovers; do
echo -e "[$GREEN+$RESET] --> $vulnto "
done
else
echo -e "[$GREEN+$RESET] No takeovers found."
fi
startFunction "nuclei to check takeover"
cat "$SUBS"/hosts | nuclei -t subdomain-takeover/ -c 50 -o "$SUBS"/nuclei-takeover-checks.txt
vulnto=$(cat "$SUBS"/nuclei-takeover-checks.txt)
if [[ $vulnto != "" ]]; then
echo -e "[$GREEN+$RESET] Possible subdomain takeovers:"
for line in "$SUBS"/nuclei-takeover-checks.txt; do
echo -e "[$GREEN+$RESET] --> $vulnto "
done
else
echo -e "[$GREEN+$RESET] No takeovers found."
fi
}
: 'Get all CNAME'
getCNAME() {
startFunction "dnsprobe to get CNAMEs"
cat "$SUBS"/subdomains | dnsprobe -r CNAME -o "$SUBS"/subdomains_cname.txt
}
: 'Gather IPs with dnsprobe'
gatherIPs() {
startFunction "dnsprobe"
cat "$SUBS"/subdomains | dnsprobe -silent -f ip | sort -u | tee "$IPS"/"$domain"-ips.txt
python3 $HOME/ReconPi/scripts/clean_ips.py "$IPS"/"$domain"-ips.txt "$IPS"/"$domain"-origin-ips.txt
echo -e "[$GREEN+$RESET] Done."
}
: 'Portscan on found IP addresses'
portScan() {
startFunction "Port Scan"
cat "$SUBS"/alive_subdomains | naabu -p - -silent -no-probe -exclude-cdn -nmap -config "$HOME"/ReconPi/configs/naabu.conf
mv reconpi-nmap* "$PORTSCAN"
echo -e "[$GREEN+$RESET] Port Scan finished"
}
: 'Use eyewitness to gather screenshots'
gatherScreenshots() {
startFunction "Screenshot Gathering"
# Bug in aquatone, once it gets fixed, will enable aquatone on x86 also.
arch=`uname -m`
if [[ "$arch" == "x86_64" ]]; then
python3 $HOME/tools/EyeWitness/Python/EyeWitness.py -f "$SUBS"/hosts --no-prompt -d "$SCREENSHOTS"
else
"$HOME"/go/bin/aquatone -http-timeout 10000 -out "$SCREENSHOTS" <"$SUBS"/hosts
fi
echo -e "[$GREEN+$RESET] Screenshot Gathering finished"
}
fetchArchive() {
startFunction "fetchArchive"
cat "$SUBS"/hosts | sed 's/https\?:\/\///' | gau > "$ARCHIVE"/getallurls.txt
cat "$ARCHIVE"/getallurls.txt | sort -u | unfurl --unique keys > "$ARCHIVE"/paramlist.txt
cat "$ARCHIVE"/getallurls.txt | sort -u | grep -P "\w+\.js(\?|$)" | httpx -silent -status-code -mc 200 | awk '{print $1}' | sort -u > "$ARCHIVE"/jsurls.txt
cat "$ARCHIVE"/getallurls.txt | sort -u | grep -P "\w+\.php(\?|$) | httpx -silent -status-code -mc 200 | awk '{print $1}' | sort -u " > "$ARCHIVE"/phpurls.txt
cat "$ARCHIVE"/getallurls.txt | sort -u | grep -P "\w+\.aspx(\?|$) | httpx -silent -status-code -mc 200 | awk '{print $1}' | sort -u " > "$ARCHIVE"/aspxurls.txt
cat "$ARCHIVE"/getallurls.txt | sort -u | grep -P "\w+\.jsp(\?|$) | httpx -silent -status-code -mc 200 | awk '{print $1}' | sort -u " > "$ARCHIVE"/jspurls.txt
echo -e "[$GREEN+$RESET] fetchArchive finished"
}
fetchEndpoints() {
startFunction "fetchEndpoints"
for js in `cat "$ARCHIVE"/jsurls.txt`;
do
python3 "$HOME"/tools/LinkFinder/linkfinder.py -i $js -o cli | anew "$ARCHIVE"/endpoints.txt;
done
echo -e "[$GREEN+$RESET] fetchEndpoints finished"
}
: 'Gather information with meg'
startMeg() {
startFunction "meg"
cd "$SUBS" || return
meg -d 1000 -v /
mv out meg
cd "$HOME" || return
}
: 'Use gf to find secrets in responses'
startGfScan() {
startFunction "Checking for secrets using gf"
cd "$SUBS"/meg || return
for i in `gf -list`; do [[ ${i} =~ "_secrets"* ]] && gf ${i} >> "$GFSCAN"/"${i}".txt; done
cd "$HOME" || return
}
: 'directory brute-force'
startBruteForce() {
startFunction "directory brute-force"
# maybe run with interlace? Might remove
cat "$SUBS"/hosts | parallel -j 5 --bar --shuf gobuster dir -u {} -t 50 -w wordlist.txt -l -e -r -k -q -o "$DIRSCAN"/"$sub".txt
"$HOME"/go/bin/gobuster dir -u "$line" -w "$WORDLIST"/wordlist.txt -e -q -k -n -o "$DIRSCAN"/out.txt
}
: 'Check for Vulnerabilities'
runNuclei() {
startFunction "Nuclei Basic-detections"
nuclei -l "$SUBS"/hosts -t generic-detections/ -c 50 -H "x-bug-bounty: $hackerhandle" -o "$NUCLEISCAN"/generic-detections.txt
startFunction "Nuclei CVEs Detection"
nuclei -l "$SUBS"/hosts -t cves/ -c 50 -H "x-bug-bounty: $hackerhandle" -o "$NUCLEISCAN"/cve.txt
startFunction "Nuclei default-creds Check"
nuclei -l "$SUBS"/hosts -t default-credentials/ -c 50 -H "x-bug-bounty: $hackerhandle" -o "$NUCLEISCAN"/default-creds.txt
startFunction "Nuclei dns check"
nuclei -l "$SUBS"/hosts -t dns/ -c 50 -H "x-bug-bounty: $hackerhandle" -o "$NUCLEISCAN"/dns.txt
startFunction "Nuclei files check"
nuclei -l "$SUBS"/hosts -t files/ -c 50 -H "x-bug-bounty: $hackerhandle" -o "$NUCLEISCAN"/files.txt
startFunction "Nuclei Panels Check"
nuclei -l "$SUBS"/hosts -t panels/ -c 50 -H "x-bug-bounty: $hackerhandle" -o "$NUCLEISCAN"/panels.txt
startFunction "Nuclei Security-misconfiguration Check"
nuclei -l "$SUBS"/hosts -t security-misconfiguration/ -c 50 -H "x-bug-bounty: $hackerhandle" -o "$NUCLEISCAN"/security-misconfiguration.txt
startFunction "Nuclei Technologies Check"
nuclei -l "$SUBS"/hosts -t technologies/ -c 50 -H "x-bug-bounty: $hackerhandle" -o "$NUCLEISCAN"/technologies.txt
startFunction "Nuclei Tokens Check"
nuclei -l "$SUBS"/hosts -t tokens/ -c 50 -H "x-bug-bounty: $hackerhandle" -o "$NUCLEISCAN"/tokens.txt
startFunction "Nuclei Vulnerabilties Check"
nuclei -l "$SUBS"/hosts -t vulnerabilities/ -c 50 -H "x-bug-bounty: $hackerhandle" -o "$NUCLEISCAN"/vulnerabilties.txt
echo -e "[$GREEN+$RESET] Nuclei Scan finished"
}
: 'Setup screenshot results on the target IP address'
makePage() {
startFunction "HTML webpage"
cd /var/www/html/ || return
sudo chmod -R 755 .
sudo cp -r "$SCREENSHOTS" /var/www/html/$domain
sudo chmod a+r -R /var/www/html/$domain/*
cd "$HOME" || return
echo -e "[$GREEN+$RESET] Scan finished, start doing some manual work ;)"
echo -e "[$GREEN+$RESET] The screenshot results page, nuclei results directory and the meg results directory are great points!"
echo -e "[$GREEN+$RESET] screenshot results page: http://$(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n 1)/$domain/screenshots/report.html"
}
notifySlack() {
startFunction "Trigger Slack Notification"
source "$HOME"/ReconPi/configs/tokens.txt
export SLACK_WEBHOOK_URL="$SLACK_WEBHOOK_URL"
echo -e "ReconPi $domain scan completed!" | slackcat
totalsum=$(cat $SUBS/hosts | wc -l)
echo -e "$totalsum live subdomain hosts discovered" | slackcat
posibbletko="$(cat $SUBS/takeovers | wc -l)"
if [ -s "$SUBS/takeovers" ]
then
echo -e "Found $posibbletko possible subdomain takeovers." | slackcat
else
echo "No subdomain takeovers found." | slackcat
fi
if [ -f "$NUCLEISCAN/cve.txt" ]; then
echo "CVE's discovered:" | slackcat
cat "$NUCLEISCAN/cve.txt" | slackcat
else
echo -e "No CVE's discovered." | slackcat
fi
if [ -f "$NUCLEISCAN/files.txt" ]; then
echo "files discovered:" | slackcat
cat "$NUCLEISCAN/files.txt" | slackcat
else
echo -e "No files discovered." | slackcat
fi
echo -e "[$GREEN+$RESET] Done."
}
notifyDiscord() {
startFunction "Trigger Discord Notification"
intfiles=$(cat $NUCLEISCAN/*.txt | wc -l)
source "$HOME"/ReconPi/configs/tokens.txt
export DISCORD_WEBHOOK_URL="$DISCORD_WEBHOOK_URL"
totalsum=$(cat $SUBS/hosts | wc -l)
message="**$domain scan completed!\n $totalsum live hosts discovered.**\n"
if [ -s "$SUBS/takeovers" ]
then
posibbletko="$(cat $SUBS/takeovers | wc -l)"
message+="**Found $posibbletko possible subdomain takeovers.**\n"
else
message+="**No subdomain takovers found.**\n"
fi
cd $NUCLEISCAN
for file in *.txt
do
if [ -s "$file" ]
then
fileName=$(basename ${file%%.*})
fileNameUpper="$(tr '[:lower:]' '[:upper:]' <<< ${fileName:0:1})${fileName:1}"
nucleiData="$(jq -Rs . <$file | cut -c 2- | rev | cut -c 2- | rev)"
message+="**$fileNameUpper discovered:**\n "$nucleiData"\n"
fi
done
python3 $HOME/ReconPi/scripts/webhook_Discord.py <<< $(echo "$message")
echo -e "[$GREEN+$RESET] Done."
}
: 'Execute the main functions'
source "$HOME"/ReconPi/configs/tokens.txt || return
export SLACK_WEBHOOK_URL="$SLACK_WEBHOOK_URL"
displayLogo
checkArguments
checkDirectories
gatherResolvers
gatherSubdomains
checkTakeovers
getCNAME
gatherIPs
gatherScreenshots
startMeg
#fetchArchive
#fetchEndpoints
startGfScan
runNuclei
portScan
#makePage
notifySlack
notifyDiscord
# Uncomment the functions