forked from zerobyte-id-bak/Bashter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashter.bash
264 lines (247 loc) · 8.27 KB
/
bashter.bash
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
#!/bin/bash
HOME_DIR="$(cd "$(dirname "$0")" ; pwd -P)"
BASHTER_VERSION="4.1"
RELEASED_DATE="1 May 2019"
function UrlSelector() {
WEBSITE="${1}"
URL="${2}"
SOURCECODE="${3}"
URL_SELECTOR_MODE="${4}"
if [[ ${URL_SELECTOR_MODE} == "y" ]] || [[ ${URL_SELECTOR_MODE} == "Y" ]]
then
BASESITE=$(echo "${WEBSITE}" | sed 's|/| |g' | awk '{print $2}' | awk -F '.' '{print $(NF - 1)"."$NF}')
else
BASESITE=$(echo "${WEBSITE}" | sed 's|/| |g' | awk '{print $2}')
fi
if [[ ! -z $(echo "${URL}" | grep ^"javascript:\|mailto:\|tel:\|data:") ]]
then
echo -ne ""
elif [[ ! -z $(echo "${URL}" | grep -i "[.]pdf\|[.]doc\|docx\|[.]png\|[.]gif\|[.]jpg\|[.]jpeg\|[.]ico\|[.]svg\|[.]css\|[.]js\|[.]woff") ]]
then
echo -ne ""
elif [[ ! -z $(echo "${URL}" | grep ^'//') ]]
then
if [[ $(echo "${WEBSITE}" | grep ^'https://') ]] && [[ $(echo "${URL}" | grep ^"//[a-zA-Z0-9.]*.${BASESITE}") ]]
then
echo "[GET] https:${URL}"
fi
elif [[ ! -z $(echo "${URL}" | grep ^"/") ]]
then
WEBSITE=$(echo "${WEBSITE}" | sed 's|://|P12O70COL|g' | sed 's|/| |g' | awk '{print $1}' | sed 's|P12O70COL|://|g')
FULLURL=$(echo "${WEBSITE}/${URL}" | sed 's|://|P12O70COL|g' | sed 's,/*/,/,g' | sed 's|P12O70COL|://|g')
echo "[GET] ${FULLURL}"
elif [[ ! -z $(echo "${URL}" | grep ^'?') ]]
then
WEBSITE=$(echo "${WEBSITE}" | sed 's|://|P12O70COL|g' | sed 's|/| |g' | awk '{print $1}' | sed 's|P12O70COL|://|g')
FULLURL=$(echo "${WEBSITE}/${URL}" | sed 's|://|P12O70COL|g' | sed 's,/*/,/,g' | sed 's|P12O70COL|://|g')
echo "[GET] ${FULLURL}"
elif [[ ! -z $(echo "${URL}" | grep ^"\(http\|https\)://[a-zA-Z0-9.]*.${BASESITE}") ]]
then
echo "[GET] ${URL}"
elif [[ ! -z $(echo "${URL}" | grep ^'#') ]]
then
echo -ne ""
elif [[ ! -z $(echo "${URL}" | grep ^"[a-zA-Z0-9-]*://" | grep -v ^'http') ]]
then
echo -ne ""
else
echo -ne ""
fi
}
function UrlCrawler() {
SOURCECODE="${1}"
cat ${SOURCECODE} | grep -o 'href=['"'"'"][^"'"'"']*['"'"'"]' | sed -e 's/^href=["'"'"']//' -e 's/["'"'"']$//'
cat ${SOURCECODE} | grep -o 'src=['"'"'"][^"'"'"']*['"'"'"]' | sed -e 's/^src=["'"'"']//' -e 's/["'"'"']$//'
}
function CheckForm() {
URL="${1}"
SOURCECODE="${2}"
PROC_ID="${3}"
HOME_DIR="$(cd "$(dirname "$0")" ; pwd -P)"
TEMPDIR="${HOME_DIR}/bashter-tempdata"
CHECKEDFORMFILE="${TEMPDIR}/CHECKED-FORM.BASHTER-${PROC_ID}.TMP"
IFS=$'\n'
for FORM in $(cat ${SOURCECODE} | grep -Po '<form\K.*?(?=>)' | sed 's/^/<form/g' | sed 's/$/>/g')
do
FORMPOST=$(echo $FORM | grep -o 'method=['"'"'"][^"'"'"']*['"'"'"]' | grep -i post)
if [[ ! -z $(cat ${CHECKEDFORMFILE} 2> /dev/null | grep ''$FORM'') ]]
then
echo -ne ""
elif [[ -z ${FORMPOST} ]]
then
echo "$(date +"[%H:%M:%S]") INFO: Form GET on \"${URL}\""
echo "$(date +"[%H:%M:%S]") FORM [GET]: \"${URL}\"" >> ${HOME_DIR}/scan-logs/${PROC_ID}-info.log
for FORM_TEST in $(find ${HOME_DIR}/modules/form | grep bash$)
do
if [[ ! -z ${FORM_TEST} ]]
then
bash ${FORM_TEST} ${URL} ${SOURCECODE}
fi
done
else
echo "$(date +"[%H:%M:%S]") INFO: Form POST on \"${URL}\""
echo "$(date +"[%H:%M:%S]") FORM [POST]: \"${URL}\"" >> ${HOME_DIR}/scan-logs/${PROC_ID}-info.log
for FORM_TEST in $(find ${HOME_DIR}/modules/form | grep bash$)
do
if [[ ! -z ${FORM_TEST} ]]
then
bash ${FORM_TEST} ${URL} ${SOURCECODE}
fi
done
fi
echo ${FORM} >> ${CHECKEDFORMFILE}
done
}
if [[ -z ${HOME_DIR} ]]
then
echo "ERROR: Can't define HOME_DIR"
exit
elif [[ ! -d ${HOME_DIR} ]]
then
echo "ERROR: ${HOME_DIR} not found"
exit
fi
cat ${HOME_DIR}/BANNER.file
echo ""
echo " ##### Version ${BASHTER_VERSION} released on ${RELEASED_DATE} #####"
echo " [ $(hostname)@HOME_DIR : ${HOME_DIR} ]"
echo ""
echo " Please enter the URL you want to scan..."
echo " Example: https://website.com/[optional-path]/"
echo -ne " >>> "
read WEBSITE
echo ""
echo " Crawling site based on main domain or domain which you scan only"
echo " If you want to scan *.domain.com you can enter: [Y/y]"
echo " But If you want to scan sub.domain.com only (let it empty)"
echo -ne " >>> "
read URL_SELECTOR_MODE
echo ""
if [[ -z ${WEBSITE} ]]
then
echo "ERROR: Website can't empty!"
exit
elif [[ -z $(echo "${WEBSITE}" | grep ^"\(http\|https\)://") ]]
then
echo "ERROR: ${WEBSITE} must using [HTTP/HTTPS]"
exit
fi
TEMPDIR="${HOME_DIR}/bashter-tempdata"
if [[ ! -d ${TEMPDIR} ]]
then
mkdir ${TEMPDIR}
fi
if [[ ! -d ${TEMPDIR} ]]
then
echo "ERROR: Can't make directory \"${TEMPDIR}\" on \"$(pwd)\""
exit
fi
PROC_ID="$(echo "${WEBSITE}" | sed 's|/| |g' | awk '{print $2}')"
CURRENT_TEMPFILE="${TEMPDIR}/"$(echo "SOURCECODE.BASHTER-PROC_$(date +%Y%m%d%H%M%S)${RANDOM}.TMP")
URL_LIST="${TEMPDIR}/URL-LISTS.BASHTER-${PROC_ID}.TMP"
SCANNED_URL="${TEMPDIR}/SCANNED-URL.BASHTER-${PROC_ID}.TMP"
curl -vskL --connect-timeout 5 --max-time 5 -A "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0" "${WEBSITE}" &> ${CURRENT_TEMPFILE}
if [[ ! -z $(cat ${CURRENT_TEMPFILE} | grep ^'* Could not resolve host:') ]]
then
echo "ERROR: Could not resolve host: ${WEBSITE}"
exit
fi
echo "$(date +"[%H:%M:%S]")(Scan) ${WEBSITE}..."
LOGNAME=$(echo "${WEBSITE}" | sed 's|/| |g' | awk '{print $2}')
echo "$(date +"[%H:%M:%S]") URL [Scanned]: \"${WEBSITE}\"" >> ${HOME_DIR}/scan-logs/${LOGNAME}-info.log
CheckForm "${WEBSITE}" "${CURRENT_TEMPFILE}" "${PROC_ID}"
for HEADER_ANALYZE in $(find ${HOME_DIR}/modules/header | grep bash$)
do
if [[ ! -z ${HEADER_ANALYZE} ]]
then
bash ${HEADER_ANALYZE} "${WEBSITE}" "${CURRENT_TEMPFILE}" "${PROC_ID}"
fi
done
for URL_ANALYZE in $(find ${HOME_DIR}/modules/url | grep bash$)
do
if [[ ! -z ${URL_ANALYZE} ]]
then
bash ${URL_ANALYZE} "${WEBSITE}" "${CURRENT_TEMPFILE}" "${PROC_ID}"
fi
done
echo -ne "" > ${URL_LIST}
for URL in $(UrlCrawler ${CURRENT_TEMPFILE})
do
URLTEMP=$(UrlSelector ${WEBSITE} ${URL} ${CURRENT_TEMPFILE} ${URL_SELECTOR_MODE} | awk '{print $2}')
if [[ ! -z ${URLTEMP} ]]
then
if [[ -z $(cat ${URL_LIST} | grep "${URLTEMP}"$) ]]
then
UrlSelector ${WEBSITE} ${URL} ${CURRENT_TEMPFILE} ${URL_SELECTOR_MODE} >> ${URL_LIST}
fi
fi
done
cat ${URL_LIST} | sort -nr | uniq > ${URL_LIST}.XTMP
cat ${URL_LIST}.XTMP > ${URL_LIST}
rm ${URL_LIST}.XTMP
rm ${CURRENT_TEMPFILE}
echo "${WEBSITE}" > ${SCANNED_URL}
########## INFINITE LOOP CRAWLING ##########
CMPCHECKPOINT=0
while true
do
for WEBSITE in $(cat ${URL_LIST} | awk '{print $2}')
do
if [[ -z $(cat ${SCANNED_URL} | grep "${WEBSITE}"$) ]]
then
echo "$(date +"[%H:%M:%S]")(Scan) ${WEBSITE}..."
LOGNAME=$(echo "${WEBSITE}" | sed 's|/| |g' | awk '{print $2}')
echo "$(date +"[%H:%M:%S]") URL [Scanned]: \"${WEBSITE}\"" >> ${HOME_DIR}/scan-logs/${LOGNAME}-info.log
CURRENT_TEMPFILE="${TEMPDIR}/"$(echo "SOURCECODE.BASHTER-PROC_$(date +%Y%m%d%H%M%S)${RANDOM}.TMP")
curl -vskL --connect-timeout 5 --max-time 5 -A "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0" "${WEBSITE}" &> ${CURRENT_TEMPFILE}
CheckForm "${WEBSITE}" "${CURRENT_TEMPFILE}" "${PROC_ID}"
for HEADER_ANALYZE in $(find ${HOME_DIR}/modules/header | grep bash$)
do
if [[ ! -z ${HEADER_ANALYZE} ]]
then
bash ${HEADER_ANALYZE} "${WEBSITE}" "${CURRENT_TEMPFILE}" "${PROC_ID}"
fi
done
for URL_ANALYZE in $(find ${HOME_DIR}/modules/url | grep bash$)
do
if [[ ! -z ${URL_ANALYZE} ]]
then
bash ${URL_ANALYZE} "${WEBSITE}" "${CURRENT_TEMPFILE}" "${PROC_ID}"
fi
done
for URL in $(UrlCrawler ${CURRENT_TEMPFILE})
do
URLTEMP=$(UrlSelector ${WEBSITE} ${URL} ${CURRENT_TEMPFILE} ${URL_SELECTOR_MODE} | awk '{print $2}')
if [[ ! -z ${URLTEMP} ]]
then
if [[ -z $(cat ${URL_LIST} | grep "${URLTEMP}"$) ]]
then
UrlSelector ${WEBSITE} ${URL} ${CURRENT_TEMPFILE} ${URL_SELECTOR_MODE} >> ${URL_LIST}
fi
fi
done
cat ${URL_LIST} | sort -nr | uniq > ${URL_LIST}.XTMP
cat ${URL_LIST}.XTMP > ${URL_LIST}
rm ${URL_LIST}.XTMP
echo "${WEBSITE}" >> ${SCANNED_URL}
rm ${CURRENT_TEMPFILE}
if [[ $(cat ${URL_LIST} | wc -l) -eq $(cat ${URL_LIST} | sort -nr | uniq | wc -l) ]]
then
echo -ne ""
else
cat ${URL_LIST} | sort -nr | uniq > ${URL_LIST}.XTMP
cat ${URL_LIST}.XTMP > ${URL_LIST}
rm ${URL_LIST}.XTMP
break
fi
fi
done
CMPCOMPARISON=$(cat ${SCANNED_URL} | wc -l)
if [[ ${CMPCHECKPOINT} -eq ${CMPCOMPARISON} ]];
then
break
else
CMPCHECKPOINT=${CMPCOMPARISON}
fi
done
rm ${SCANNED_URL}