-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
208 lines (186 loc) · 7.53 KB
/
action.yml
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
name: 'Dastardly SARIF Scan Action'
description: 'Runs a Dastardly scan against a target site, with SARIF support'
author: 'chtzvt'
inputs:
target-url:
description: 'The full url (including scheme) of the site to scan'
required: true
output-filename:
description: 'The filename used for the scan report. This filepath relates to the dastardly container, and will exist in the github workspace (/github/workspace)'
required: false
default: dastardly-report.xml
enable-junit-report:
description: 'Whether to enable the junit report. This will be uploaded as an artifact'
required: false
default: false
enable-sarif-report:
description: 'Whether to enable the sarif report. This will be uploaded as a code scanning result'
required: false
default: true
upload-raw-report:
description: 'Whether to upload the raw Dastardly JUnit report as an artifact'
required: false
default: false
runs:
using: "composite"
steps:
- uses: actions/checkout@v2
- name: Run Dastardly Action Step
continue-on-error: true
uses: PortSwigger/dastardly-github-action@main
with:
target-url: ${{ inputs.target-url }}
output-filename: ${{ inputs.output-filename }}
- uses: actions/upload-artifact@v3
if: ${{ inputs.upload-raw-report == 'true' }}
with:
name: report
path: dastardly-report.xml
- name: Publish JUnit Report
if: ${{ inputs.enable-junit-report == 'true' }}
uses: mikepenz/action-junit-report@v3
with:
require_tests: true
report_paths: '**/dastardly-report.xml'
- name: Set up Python
uses: actions/setup-python@v4
if: ${{ inputs.enable-sarif-report == 'true' }}
with:
python-version: '3.10'
- name: Convert Dastardly JUnit Report to SARIF
if: ${{ inputs.enable-sarif-report == 'true' }}
shell: python
run: |
import xml.etree.ElementTree as ET
from urllib.parse import urlparse, urlunparse
import hashlib
import json
import re
# Parse XML tree
tree = ET.parse('dastardly-report.xml')
root = tree.getroot()
# Initialize SARIF schema
sarif = {
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": []
}
# Convert Dastardly severity to SARIF problem severity
def sarif_problem_severity(s):
return {
"High": "error",
"Medium": "warning",
"Low": "note",
"Information": "none"
}.get(s, "none")
# Convert Dastardly severity to SARIF security severity
def sarif_security_severity(s):
return {
"High": "7.0",
"Medium": "4.0",
"Low": "1.0",
"Information": "0.0"
}.get(s, "1.0")
# Define a run
run = {
"tool": {
"driver": {
"name": "Dastardly",
"version": "1.0",
"informationUri": "https://portswigger.net/burp/dastardly",
"rules": []
}
},
"originalUriBaseIds": {
"target": {
"uri": "PLACEHOLDER",
"description": {
"text": "The base URI for all Dastardly scan artifacts."
}
}
},
"results": []
}
rule_index = 0
# Iterate over Dastardly results (testsuites)
for suite in root.findall('testsuite'):
# If this is the first testsuite, set the uri
if run['originalUriBaseIds']['target']['uri'] == "PLACEHOLDER":
parsed_url = urlparse(suite.attrib['name'])
stripped_url = urlunparse((parsed_url.scheme, parsed_url.netloc, '', '', parsed_url.query, ''))
run['originalUriBaseIds']['target']['uri'] = stripped_url + "/"
# Skip current testsuite if there are no failures
if int(suite.attrib['failures']) == 0:
continue
# Iterate through testcases
for case in suite.findall('testcase'):
failure = case.find('failure')
if failure is None:
continue
severity = case.attrib.get('type', '')
# Create a unique ID for the rule
rule_id = hashlib.md5(bytes(suite.attrib['name'] + failure.attrib['message'], 'utf-8')).hexdigest()
# Define a rule
rule = {
"id": rule_id,
"shortDescription": {
"text": failure.attrib['message']
},
"help": {
"text": failure.attrib['message'],
"markdown": "# " + failure.attrib['message']
},
"properties": {
"impact": [failure.attrib['message']],
"problem.severity": sarif_problem_severity(severity),
"resolution": [failure.attrib['message']],
"security-severity": sarif_security_severity(severity)
}
}
# Get the severity of the failure
severity_failure = failure.attrib.get('type', '')
stripped_text = failure.text.strip()
# Update the properties of the rule
rule['help']['text'] = stripped_text
rule['help']['markdown'] = stripped_text
rule['properties']['impact'] = [stripped_text]
rule['properties']['resolution'] = [stripped_text]
rule['properties']['problem.severity'] = sarif_problem_severity(severity_failure)
rule['properties']['security-severity'] = sarif_security_severity(severity_failure)
# Add the rule to the run
run['tool']['driver']['rules'].append(rule)
parsed_url = urlparse(suite.attrib['name'])
# Define a result
result = {
"ruleId": rule_id,
"ruleIndex": rule_index,
"level": sarif_problem_severity(severity_failure),
"message": {
"text": failure.attrib['message']
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": urlunparse(("", "", parsed_url.path.lstrip('/'), parsed_url.params, parsed_url.query, parsed_url.fragment)),
"uriBaseId": "target"
}
}
}
],
"hostedViewerUri": suite.attrib['name']
}
run['results'].append(result)
rule_index += 1
sarif['runs'].append(run)
with open('output.sarif', 'w') as f:
json.dump(sarif, f, indent=4)
- name: Upload SARIF as Code Scanning Results
if: ${{ inputs.enable-sarif-report == 'true' }}
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: output.sarif
category: "dastardly-scan"
branding:
icon: 'activity'
color: 'blue'