-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathinjector.sh
executable file
·350 lines (295 loc) · 9.98 KB
/
injector.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
#!/bin/bash
#Injector a.k.a tr4c1l0rds
#Author: alexos
#Special Contribuitors: userx nekone alacerda
# ____________________________________________________________________________
# /______|________________________________________/__|________________________
# $$$$$$/_________________________________________$$_|________________________
# __$$_|__/_______\_____/__|_/______\__/_______|/_$$___|___/______\__/______\_
# __$$_|__$$$$$$$__|____$$/_/$$$$$$__|/$$$$$$$/_$$$$$$/___/$$$$$$__|/$$$$$$__|
# __$$_|__$$_|__$$_|____/__|$$____$$_|$$_|________$$_|____$$_|__$$_|$$_|__$$/_
# __$$_|__$$_|__$$_|____$$_|$$$$$$$$/_$$_\________$$_|/__|$$_\__$$_|$$_|______
# /_$$___|$$_|__$$_|____$$_|$$_______|$$_______|__$$__$$/_$$____$$/_$$_|______
# $$$$$$/_$$/___$$/_____$$_|_$$$$$$$/__$$$$$$$/____$$$$/___$$$$$$/__$$/_______
# ________________/__\__$$_|__________________________________________________
# ________________$$____$$/___________________________________________________
# _________________$$$$$$/____________________________________________________
build_environment() {
#-----------------------------
# Terminal colors #
#-----------------------------
BLUE="\e[00;34m"
GREEN="\e[00;32m"
BOLD_YELLOW="\e[01;33m"
CYAN="\e[0;31m"
END="\e[00m"
#-----------------------------
# Variables #
#-----------------------------
VOLUME="$HOME/.sqlmap/:/root/.sqlmap"
INST="$HOME/.instances"
THREAD=$(lscpu | grep CPU\(s\) | sed "s/ //g" |grep -v "-" |awk -F ":" '{print $2}')
CID=""
DATA=$2
USERAGENT="--random-agent"
LEVEL="5"
RISK="3"
FILE=""
DATABASE=""
TABLE=""
CONTNAME=""
POST=""
TCONT=$(docker ps -q | wc -l)
TEXIT=$(docker ps -q -f "status=exited" | wc -l)
}
stop_containers() {
if [ $STOPCONT == "all" ]; then
for cont in $(docker ps -aq); do
docker stop $cont | xargs docker rm 2>/dev/null
rm $INST 2>/dev/null
done
else
docker stop $STOPCONT | xargs docker rm 2>/dev/null
echo -e "$GREEN $STOPCONT removed"
fi
exit 0
}
list_containers() {
docker ps -a
echo -e "$GREEN $TCONT instances running$END"
exit 0
}
list_exited() {
docker ps -a -f status=exited
echo -e "$GREEN $TEXIT instances exited$END"
exit 0
}
log_containers() {
if [ $LOGCONT = " " ]; then
echo -e "$BOLD_YELLOW[-] Provide the injector container's name [!!]$END"
exit 0
else
docker logs --details -f $LOGCONT
fi
exit
}
stats_containers() {
docker stats --format "table {{.Name}} \t{{.CPUPerc}}\t{{.MemUsage}}\t{{.NetIO}}\t {{.BlockIO }} "
}
priv_kill () {
docker stop proxy$CID 1>/dev/null
}
attack() {
if [ -z $CONTNAME ]; then
if [ ! -f $INST ]; then
echo -n 1 > $INST
else
expr $(cat $INST) + 1 > $INST
fi
CID=$(cat $INST)
CONTNAME="injector$CID"
fi
echo -e "$GREEN==> Pwning $BOLD_YELLOW$TARGET$END"
# Privoxy container
docker run -d --rm --name proxy$CID alexoscorelabs/privoxy >> /dev/null
sleep 10
privoxy_ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' proxy$CID)
if [ -z $DATABASE ]; then
params="--dbs"
else
if [ -z $TABLE ]; then
params="--tables -D $DATABASE"
else
if [ -z $DUMP ]; then
params="-T $TABLE -D $DATABASE --columns"
else
params="-T $TABLE -D $DATABASE --dump"
fi
fi
fi
if [ ! -z $POST ]; then
if [ -e $POST ]; then
params="--method POST -r $POST"
else
params=$params" --method POST --data $POST"
fi
fi
# Sqlmap container
docker run -d -it -v $VOLUME --name $CONTNAME alexoscorelabs/sqlmap -u $TARGET --proxy "http://$privoxy_ip:8118" $USERAGENT $params --batch --level "5" --risk "3" >> /dev/null
# sudo chown -R $USER:$USER /tmp/sqlmap
# At this point docker watches the container. When it terminates, docker triggers priv_kill function in order to
# remove privoxy container that was pairing with this sqlmap instance
docker wait $CONTNAME 1>/dev/null && priv_kill &
CONTNAME=""
}
read_file () {
for NEW_TARGET in $(cat $FILE); do
TARGET=$NEW_TARGET
attack
done
exit 0
}
update() {
if [ $TCONT != "0" ]; then
echo "$BOLD You have $TCONT instances running now... Please wait that attacks finish or stop the instances!"
exit 0
else
read -p "$BOLD Can update the injector now?[y/n]" input
if [ $input == "y" ] || [ $input == "Y" ]; then
echo -e "$GREEN[+] Removing existent images...$END"
docker rmi alexoscorelabs/sqlmap 2>/dev/null
docker rmi alexoscorelabs/privoxy 2>/dev/null
echo -e "$GREEN[+] Done...$END"
echo -e "$GREEN[+] Updating privoxy image..$END"
cd privoxy
sudo docker build -t alexoscorelabs/privoxy --build-arg CACHEBUST=$(date +%s) . 2>/dev/null
sudo docker run -d --name proxy alexoscorelabs/privoxy 2>/dev/null
echo -e "$GREEN[+] Done...$END"
echo -e "$GREEN[+] Testing network...$END"
curl -x 172.17.0.2:8118 http://ifconfig.es
sudo docker rm -f proxy
echo -e "$GREEN[+] Updating sqlmap image...$END"
cd ../sqlmap
sudo docker build -t alexoscorelabs/sqlmap . 2>/dev/null
echo -e "$GREEN[+] Done...$END"
exit 0
else
echo -e "Ok! Exiting"
exit 0
fi
fi
}
# Main starts here
check_service () {
echo -e "$GREEN[~] Checking if docker service is up...$END"
sudo systemctl status docker.service > /dev/null
if [ $? == "3" ]; then
echo -e "$BOLD_YELLOW[+] Starting docker...$END"
sudo systemctl start docker.service
else
echo -e "$GREEN[+]Service is running...Hack the Planet...$END"
fi
}
usage() {
echo -e "Usage: $0 [-u <url>] [<OPTIONS>]\n" \
"Usage: $0 [OPTIONS]\n" \
"OPTIONS:\n" \
"\t-l | $GREEN--list$END$GREEN\tList all existent containers$END\n" \
"\t-e | $GREEN--exited$END$GREEN\tList all exited containers$END\n" \
"\t-u | $GREEN--url$END$GREEN\tSet target url to be tested (e.g. injector -u www.example.com)$END\n" \
"\t-f | $GREEN--file$END$GREEN\tSet a file containing a list of targets (e.g. injector -f targets.txt)$END\n" \
"\t-d | $GREEN--database$END$GREEN\tSet the target database (e.g. injector -d <database> $END\n" \
"\t-t | $GREEN--table$END$GREEN\tSet the target table (e.g. injector -d <database> -t <table>)$END\n" \
"\t-r | $GREEN--post$END$GREEN\tSet the POST request parameters (e.g -r param1¶m2 or -r POST file request)$END\n" \
"\t-s | $GREEN--stop$END$GREEN\tStop the specified container (e.g. injector -s <container_name>) or use -s all to stop all containers$END\n" \
"\t-o | $GREEN--logs$END$GREEN\tShow the container log$END\n" \
"\t-p | $GREEN--dump$END$GREEN\tDump the data$END\n" \
"\t-a | $GREEN--stats$END$GREEN\tDisplay the container's statistics$END\n" \
"\t-i | $GREEN--update$END$GREEN\tUpdate Injector$END\n" \
"\t-h | $GREEN--help$END$GREEN\tPrint this help$END\n"
exit 0
}
# Here is where the program actually starts
handle_args() {
ARGS=`getopt -o leui::s:o:f:d:t:r:pha --long list,exited,url,update:,stop:,logs:,file:,database:,table:,post:,dump,stats,help -n 'injector' -- "$@"`
if [ $? != 0 ]; then
exit 1
fi
while true; do
case "$1" in
-u | --url )
TARGET=$2
shift
shift
if [ -z $1 ]; then
break
fi
;;
-d | --database )
DATABASE=$2
shift
shift
if [ -z $1 ]; then
break
fi
;;
-t | --table )
TABLE=$2
shift
shift
if [ -z $1 ]; then
break
fi
;;
-n | --name )
CONTNAME=$2
shift
shift
if [ -z $1 ]; then
break
fi
;;
-r | --post )
POST=$2
shift
shift
if [ -z $1 ]; then
break
fi
;;
-p | --dump )
DUMP="True"
shift
if [ -z $1 ]; then
break
fi
;;
-s | --stop )
echo -e "Stopping :$BOLD_YELLOW $2 $END"
STOPCONT=$2
stop_containers
break
;;
-l | --list )
list_containers
shift
break
;;
-i | --update )
update
shift
break
;;
-e | --exited )
list_exited
break
;;
-o | --logs )
LOGCONT=$2
log_containers
break
;;
-a | --stats )
stats_containers
break
;;
-f | --file )
FILE=$2
read_file
shift
shift
;;
-h | --help )
usage
;;
* )
usage
;;
esac
done
}
# clear
build_environment
handle_args "$@"
check_service
attack