-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpentestlab.sh
591 lines (537 loc) · 17.8 KB
/
pentestlab.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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
#!/bin/bash
ETC_HOSTS=/etc/hosts
#########################
# The command line help #
#########################
display_help() {
echo "Local PentestLab Management Script (Docker based)"
echo
echo "Usage: $0 {list|status|info|start|stop} [projectname]" >&2
echo
echo " This scripts uses docker and hosts alias to make web apps available on localhost"
echo
echo " Ex."
echo " $0 list"
echo " List all available projects"
echo " $0 status"
echo " Show status for all projects"
echo " $0 start bwapp"
echo " Start project and make it available on localhost"
echo " $0 info bwapp"
echo " Show information about bwapp project"
echo
echo " Dockerfiles from:"
echo " DVWA - Ryan Dewhurst (vulnerables/web-dvwa)"
echo " Mutillidae II - Nikolay Golub (citizenstig/nowasp)"
echo " bWapp - Rory McCune (raesene/bwapp)"
echo " Webgoat(s) - OWASP Project"
echo " NodeGoat - Ben McMahon (bjm243/nodegoat)"
echo " Juice Shop - Bjoern Kimminich (bkimminich/juice-shop)"
echo " Vulnerable Wordpress - WPScan Team (l505/vulnerablewordpress)"
echo " Security Ninjas - OpenDNS Security Ninjas AppSec Training"
exit 1
}
############################################
# Check if docker is installed and running #
############################################
if ! [ -x "$(command -v docker)" ]; then
echo
echo "Docker was not found. Please install docker before running this script."
echo "You can try the script: install_docker_kali_x64.sh"
echo "In the same repo at https://github.com/itboxltda/pentestlab"
exit
fi
if sudo service docker status | grep inactive > /dev/null
then
echo "Docker is not running."
echo -n "Do you want to start docker now (y/n)?"
read answer
if echo "$answer" | grep -iq "^y"; then
sudo service docker start
else
echo "Not starting. Script will not be able to run applications."
fi
fi
#########################
# List all pentest apps #
#########################
list() {
echo "Available pentest applications" >&2
echo " bwapp - bWAPP PHP/MySQL based from itsecgames.com"
echo " webgoat7 - WebGoat 7.1 OWASP Flagship Project"
echo " webgoat8 - WebGoat 8.0 OWASP Flagship Project"
echo " nodegoat - NodeGoat OWASP Project"
echo " dvwa - Damn Vulnerable Web Application"
echo " mutillidae - OWASP Mutillidae II"
echo " juiceshop - OWASP Juice Shop"
echo " vulnerablewordpress - WPScan Vulnerable Wordpress"
echo " securityninjas - OpenDNS Security Ninjas"
echo
exit 1
}
#########################
# Info dispatch #
#########################
info () {
case "$1" in
bwapp)
project_info_bwapp
;;
webgoat7)
project_info_webgoat7
;;
webgoat8)
project_info_webgoat8
;;
nodegoat)
project_info_nodegoat
;;
dvwa)
project_info_dvwa
;;
mutillidae)
project_info_mutillidae
;;
juiceshop)
project_info_juiceshop
;;
vulnerablewordpress)
project_info_vulnerablewordpress
;;
securityninjas)
project_info_securityninjas
;;
*)
echo "Unknown project name"
list
;;
esac
}
#########################
# hosts file util #
######################### # Based on https://gist.github.com/irazasyed/a7b0a079e7727a4315b9
function removehost() {
if [ -n "$(grep $1 /etc/hosts)" ]
then
echo "Removing $1 from $ETC_HOSTS";
sudo sed -i".bak" "/$1/d" $ETC_HOSTS
else
echo "$1 was not found in your $ETC_HOSTS";
fi
}
function addhost() { # ex. 127.5.0.1 bwapp
HOSTS_LINE="$1\t$2"
if [ -n "$(grep $2 /etc/hosts)" ]
then
echo "$2 already exists in /etc/hosts"
else
echo "Adding $2 to your $ETC_HOSTS";
sudo -- sh -c -e "echo '$HOSTS_LINE' >> /etc/hosts";
if [ -n "$(grep $2 /etc/hosts)" ]
then
echo -e "$HOSTS_LINE was added succesfully to /etc/hosts";
else
echo "Failed to Add $2, Try again!";
fi
fi
}
#########################
# PROJECT INFO & STARTUP#
#########################
project_info_bwapp ()
{
echo "bWAPP, or a buggy web application, is a free and open source deliberately insecure web application."
echo "It helps security enthusiasts, developers and students to discover and to prevent web vulnerabilities."
echo "bWAPP prepares one to conduct successful penetration testing and ethical hacking projects."
echo
echo "What makes bWAPP so unique? Well, it has over 100 web vulnerabilities!"
echo " It covers all major known web bugs, including all risks from the OWASP Top 10 project."
echo
echo " bWAPP is a PHP application that uses a MySQL database. It can be hosted on Linux/Windows"
echo " with Apache/IIS and MySQL. It can also be installed with WAMP or XAMPP."
echo "Another possibility is to download the bee-box, a custom Linux VM pre-installed with bWAPP."
echo
echo "Download our What is bWAPP? introduction tutorial, including free exercises..."
echo
echo "bWAPP is for web application security-testing and educational purposes only."
echo "Have fun with this free and open source project!"
echo
echo "Cheers, Malik Mesellem"
echo " http://www.itsecgames.com/"
echo
echo "TECH: PHP / MySQL"
echo "FEATURES: DIFFERENT SKILL LEVELS"
}
project_startinfo_bwapp ()
{
echo "Remember to run install.php before using bwapp the first time."
echo "at http://bwapp/install.php"
echo "Default username/password: bee/bug"
echo "bWAPP will then be available at http://bwapp"
}
project_info_webgoat7 ()
{
echo "WebGoat is a deliberately insecure web application maintained by OWASP designed to teach"
echo "web application security lessons. You can install and practice with WebGoat."
echo "their understanding of a security issue by exploiting a real vulnerability in the"
echo "WebGoat applications. For example, in one of the lessons the user must use SQL injection"
echo "to steal fake credit card numbers. The application aims to provide a realistic teaching"
echo " environment, providing users with hints and code to further explain the lesson"
echo
echo "Why the name WebGoat? Developers should not feel bad about not knowing security. Even the best programmers make security errors. What they need is a scapegoat, right? Just blame it on the Goat!"
echo
echo " https://www.owasp.org/index.php/Category:OWASP_WebGoat_Project"
echo
echo "TECH: J2EE JAVA"
echo "FEATURES: LESSONS"
}
project_startinfo_webgoat7 ()
{
echo "WebGoat 7.1 now available at http://webgoat7/WebGoat"
}
project_info_webgoat8 ()
{
echo "WebGoat is a deliberately insecure web application maintained by OWASP designed to teach"
echo "web application security lessons. You can install and practice with WebGoat."
echo "their understanding of a security issue by exploiting a real vulnerability in the"
echo "WebGoat applications. For example, in one of the lessons the user must use SQL injection"
echo "to steal fake credit card numbers. The application aims to provide a realistic teaching"
echo "environment, providing users with hints and code to further explain the lesson"
echo
echo "Why the name WebGoat? Developers should not feel bad about not knowing security. Even the best programmers make security errors. What they need is a scapegoat, right? Just blame it on the Goat!"
echo
echo " https://www.owasp.org/index.php/Category:OWASP_WebGoat_Project"
echo "Project Leader Bruce Mayhew"
echo
echo "TECH: J2EE JAVA"
echo "FEATURES: LESSONS"
}
project_startinfo_webgoat8 ()
{
echo "WebGoat 8.0 now available at http://webgoat8/WebGoat"
}
project_info_nodegoat ()
{
echo "NodeGoat is a deliberately insecure web application maintained by OWASP designed to teach"
echo "web application security lessons. You can install and practice with NodeGoat."
echo "There are other goats such as NodeGoat for Node.js. In each lesson, users must demonstrate"
echo "their understanding of a security issue by exploiting a real vulnerability in the"
echo "NodeGoat applications. For example, in one of the lessons the user must use javascript injections"
echo "to steal fake credit card numbers. The application aims to provide a realistic teaching"
echo "environment, providing users with hints and code to further explain the lesson"
echo
echo "Why the name NodeGoat? Developers should not feel bad about not knowing security. Even the best programmers make security errors. What they need is a scapegoat, right? Just blame it on the Goat!"
echo
echo "https://wiki.owasp.org/index.php/Projects/OWASP_Node_js_Goat_Project"
echo "Project Leader Chetan Karande"
echo
echo "TECH: Node.js NoSQL"
echo "FEATURES: LESSONS"
}
project_startinfo_nodegoat ()
{
echo "NodeGoat 1.3 now available at http://nodegoat.net/login"
echo "Demo Account - u:demo p:demo"
echo "New users can also be added using the sign-up page."
}
project_info_dvwa ()
{
echo "The aim of DVWA is to practice some of the most common web vulnerabilities, with various"
echo "levels of difficulty, with a simple straightforward interface. Please note, there are"
echo "both documented and undocumented vulnerabilities with this software. This is intentional."
echo " You are encouraged to try and discover as many issues as possible."
echo " Ryan Dewhurst"
echo "TECH: PHP / MySQL"
echo "FEATURES: DIFFERENT SKILL LEVELS"
}
project_startinfo_dvwa ()
{
echo "Damn Vulnerable Web Application now available at http://dvwa"
echo "Default username/password: admin/password"
echo "Remember to click on the CREATE DATABASE Button before you start"
}
project_info_mutillidae ()
{
echo "NOWASP (Mutillidae) is a free, open source, deliberately vulnerable web-application"
echo "providing a target for web-security enthusiest. "
echo "OWASP Incubator Project. Leader Jeremy Druin"
echo
echo "TECH: PHP / MySQL"
echo "FEATURES: "
}
project_startinfo_mutillidae ()
{
echo "OWASP Mutillidae II now available at http://mutillidae"
echo "Remember to click on the create database link before you start"
}
project_info_juiceshop ()
{
echo "OWASP Juice Shop is an intentionally insecure web application written entirely in JavaScript"
echo "which encompasses the entire range of OWASP Top Ten and other severe security flaws."
echo " https://github.com/bkimminich/juice-shop"
echo
echo "TECH: Javascript"
echo "FEATURES: "
}
project_startinfo_juiceshop ()
{
echo "OWASP Juice Shop now available at http://juiceshop"
}
project_info_securitysheperd ()
{
echo "The OWASP Security Shepherd project is a web and mobile application security training platform. "
echo "Security Shepherd has been designed to foster and improve security awareness among a varied"
echo "skill-set demographic. The aim of this project is to take AppSec novices or experienced"
echo "engineers and sharpen their penetration testing skillset to security expert status."
echo " https://www.owasp.org/index.php/OWASP_Security_Shepherd"
echo
echo "TECH: "
echo "FEATURES: "
}
project_startinfo_securitysheperd ()
{
echo "OWASP Security Sheperd now available at http://securitysheperd"
}
project_info_vulnerablewordpress ()
{
echo "https://github.com/wpscanteam/VulnerableWordpress"
echo "Vulnerable Wordpress Application"
echo "TECH: PHP / MySQL"
echo "FEATURES: "
}
project_startinfo_vulnerablewordpress ()
{
echo "WPScan Vulnerable Wordpress site now awailable at localhost on http://vulnerablewordpress"
}
project_info_securityninjas ()
{
echo " https://github.com/opendns/Security_Ninjas_AppSec_Training"
echo
echo "TECH: "
echo "FEATURES: Leassons, Tips and Solutions"
}
project_startinfo_securityninjas ()
{
echo "Open DNS Security Ninjas site now available at localhost on http://securityninjas"
}
#########################
# Common start #
#########################
project_start ()
{
fullname=$1 # ex. WebGoat 7.1
projectname=$2 # ex. webgoat7
dockername=$3 # ex. raesene/bwapp
ip=$4 # ex. 127.5.0.1
port=$5 # ex. 80
port2=$6 # optional second port binding
echo "Starting $fullname"
addhost "$ip" "$projectname"
if [ "$(sudo docker ps -aq -f name=$projectname)" ];
then
echo "Running command: docker start $projectname"
sudo docker start $projectname
else
if [ -n "${6+set}" ]; then
echo "Running command: docker run --name $projectname -d -p $ip:80:$port -p $ip:$port2:$port2 $dockername"
sudo docker run --name $projectname -d -p $ip:80:$port -p $ip:$port2:$port2 $dockername
else echo "not set";
echo "Running command: docker run --name $projectname -d -p $ip:80:$port $dockername"
sudo docker run --name $projectname -d -p $ip:80:$port $dockername
fi
fi
echo "DONE!"
echo
echo "Docker mapped to http://$projectname or http://$ip"
echo
}
#########################
# Common stop #
#########################
project_stop ()
{
fullname=$1 # ex. WebGoat 7.1
projectname=$2 # ex. webgoat7
echo "Stopping... $fullname"
echo "Running command: docker stop $projectname"
sudo docker stop $projectname
removehost "$projectname"
}
project_status()
{
if [ "$(sudo docker ps -q -f name=bwapp)" ]; then
echo "bWaPP running at http://bwapp"
else
echo "bWaPP not running"
fi
if [ "$(sudo docker ps -q -f name=webgoat7)" ]; then
echo "WebGoat 7.1 running at http://webgoat7/WebGoat"
else
echo "WebGoat 7.1 not running"
fi
if [ "$(sudo docker ps -q -f name=webgoat8)" ]; then
echo "WebGoat 8.0 running at http://webgoat8/WebGoat"
else
echo "WebGoat 8.0 not running"
fi
if [ "$(sudo docker ps -q -f name=nodegoat)" ]; then
echo "NodeGoat 1.3 running at http://nodegoat.net/login"
else
echo "NodeGoat 1.3 not running"
fi
if [ "$(sudo docker ps -q -f name=dvwa)" ]; then
echo "DVWA running at http://dvwa"
else
echo "DVWA not running"
fi
if [ "$(sudo docker ps -q -f name=mutillidae)" ]; then
echo "Mutillidae II running at http://mutillidae"
else
echo "Mutillidae II not running"
fi
if [ "$(sudo docker ps -q -f name=juiceshop)" ]; then
echo "OWASP Juice Shop running at http://juiceshop"
else
echo "OWASP Juice Shop not running"
fi
if [ "$(sudo docker ps -q -f name=vulnerablewordpress)" ]; then
echo "WPScan Vulnerable Wordpress running at http://vulnerablewordpress"
else
echo "WPScan Vulnerable Wordpress not running"
fi
if [ "$(sudo docker ps -q -f name=securityninjas)" ]; then
echo "OpenDNS Security Ninjas running at http://securityninjas"
else
echo "OpenDNS Security Ninjas not running"
fi
}
project_start_dispatch()
{
case "$1" in
bwapp)
project_start "bWAPP" "bwapp" "raesene/bwapp" "127.5.0.1" "80"
project_startinfo_bwapp
;;
webgoat7)
project_start "WebGoat 7.1" "webgoat7" "webgoat/webgoat-7.1" "127.6.0.1" "8080"
project_startinfo_webgoat7
;;
webgoat8)
project_start "WebGoat 8.0" "webgoat8" "webgoat/webgoat-8.0" "127.7.0.1" "8080"
project_startinfo_webgoat8
;;
nodegoat)
project_start "NodeGoat 1.3" "nodegoat" "bjm243/nodegoat" "127.8.0.1" "4000"
project_startinfo_nodegoat
;;
dvwa)
project_start "Damn Vulnerable Web Appliaction" "dvwa" "vulnerables/web-dvwa" "127.9.0.1" "80"
project_startinfo_dvwa
;;
mutillidae)
project_start "Mutillidae II" "mutillidae" "citizenstig/nowasp" "127.10.0.1" "80"
project_startinfo_mutillidae
;;
juiceshop)
project_start "OWASP Juice Shop" "juiceshop" "bkimminich/juice-shop" "127.11.0.1" "3000"
project_startinfo_juiceshop
;;
securitysheperd)
project_start "OWASP Security Shepard" "securitysheperd" "ismisepaul/securityshepherd" "127.12.0.1" "80"
project_startinfo_securitysheperd
;;
vulnerablewordpress)
project_start "WPScan Vulnerable Wordpress" "vulnerablewordpress" "l505/vulnerablewordpress" "127.13.0.1" "80" "3306"
project_startinfo_vulnerablewordpress
;;
securityninjas)
project_start "Open DNS Security Ninjas" "securityninjas" "opendns/security-ninjas" "127.14.0.1" "80"
project_startinfo_securityninjas
;;
*)
echo "ERROR: Project dispatch doesn't recognize the project name"
;;
esac
}
project_stop_dispatch()
{
case "$1" in
bwapp)
project_stop "bWAPP" "bwapp"
;;
webgoat7)
project_stop "WebGoat 7.1" "webgoat7"
;;
webgoat8)
project_stop "WebGoat 8.0" "webgoat8"
;;
nodegoat)
project_stop "NodeGoat 1.3" "nodegoat"
;;
dvwa)
project_stop "Damn Vulnerable Web Appliaction" "dvwa"
;;
mutillidae)
project_stop "Mutillidae II" "mutillidae"
;;
juiceshop)
project_stop "OWASP Juice Shop" "juiceshop"
;;
securitysheperd)
project_stop "OWASP Security Sheperd" "securitysheperd"
;;
vulnerablewordpress)
project_stop "WPScan Vulnerable Wordpress" "vulnerablewordpress"
;;
securityninjas)
project_stop "Open DNS Security Ninjas" "securityninjas"
;;
*)
echo "ERROR: Project dispatch doesn't recognize the project name"
;;
esac
}
#########################
# Main switch case #
#########################
case "$1" in
start)
if [ -z "$2" ]
then
echo "ERROR: Option start needs project name in lowercase"
echo
list # call list ()
break
fi
project_start_dispatch $2
;;
stop)
if [ -z "$2" ]
then
echo "ERROR: Option stop needs project name in lowercase"
echo
list # call list ()
break
fi
project_stop_dispatch $2
;;
list)
list # call list ()
;;
status)
project_status # call project_status ()
;;
info)
if [ -z "$2" ]
then
echo "ERROR: Option info needs project name in lowercase"
echo
list # call list ()
break
fi
info $2
;;
*)
display_help
;;
esac