-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdast.groovy
125 lines (117 loc) · 3.93 KB
/
dast.groovy
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
def scan_type
def target
pipeline {
agent any
parameters {
choice choices: ["Baseline", "APIS", "Full"],
description: 'Type of scan that is going to perform inside the container',
name: 'SCAN_TYPE'
string defaultValue: "https://example.com",
description: 'Target URL to scan',
name: 'TARGET'
booleanParam defaultValue: true,
description: 'Parameter to know if wanna generate report.',
name: 'GENERATE_REPORT'
}
stages {
stage('Pipeline information') {
steps {
script {
echo "<--Parameter Initialization-->"
echo """
The current parameters are:
Scan Type: ${params.SCAN_TYPE}
Target: ${params.TARGET}
Generate report: ${params.GENERATE_REPORT}
"""
}
}
}
stage('Setting up OWASP ZAP docker container') {
steps {
script {
echo "Pulling up last OWASP ZAP container --> Start"
sh 'docker pull owasp/zap2docker-stable'
echo "Pulling up last VMS container --> End"
echo "Starting container --> Start"
sh """
docker run -dt --name owasp \
owasp/zap2docker-stable \
/bin/bash
"""
}
}
}
stage('Prepare wrk directory') {
when {
environment name : 'GENERATE_REPORT', value: 'true'
}
steps {
script {
sh """
docker exec owasp \
mkdir /zap/wrk
"""
}
}
}
stage('Scanning target on owasp container') {
steps {
script {
scan_type = "${params.SCAN_TYPE}"
echo "----> scan_type: $scan_type"
target = "${params.TARGET}"
if(scan_type == "Baseline"){
sh """
docker exec owasp \
zap-baseline.py \
-t $target \
-x report.xml \
-I
"""
}
else if(scan_type == "APIS"){
sh """
docker exec owasp \
zap-api-scan.py \
-t $target \
-x report.xml \
-I
"""
}
else if(scan_type == "Full"){
sh """
docker exec owasp \
zap-full-scan.py \
-t $target \
-x report.xml \
-I
"""
//-x report-$(date +%d-%b-%Y).xml
}
else{
echo "Something went wrong..."
}
}
}
}
stage('Copy Report to Workspace'){
steps {
script {
sh '''
docker cp owasp:/zap/wrk/report.xml ${WORKSPACE}/owasp-scan-report-report.xml
'''
}
}
}
}
post {
always {
echo "Removing container"
sh '''
docker stop owasp
docker rm owasp
'''
}
}
}