-
Notifications
You must be signed in to change notification settings - Fork 0
/
Veracode_XML_to_Excel.py
97 lines (86 loc) · 3.66 KB
/
Veracode_XML_to_Excel.py
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
import xml.etree.ElementTree as ET
import xlsxwriter
import pyfiglet
from pyfiglet import fonts
import sys
import argparse
from termcolor import colored
from colorama import init
init()
G = '\033[32m'
O = '\033[33m'
Y = '\033[93m'
BOLD = '\033[1m'
END = '\033[0m'
def banner():
print (colored(pyfiglet.figlet_format("Veracode XML Report to Excel Converter", font="standard"), "red"))
print (G+BOLD+"By Rishabh Sharma [Follow: https://lazyhacker.medium.com]\n"+END)
def parsingxmldata(inxml):
mytree = ET.parse(inxml)
myroot = mytree.getroot()
workbook = xlsxwriter.Workbook('Veracodeout.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'severity')
worksheet.write('B1', 'Vulnerability Name')
worksheet.write('C1', 'issueid')
worksheet.write('D1', 'Description')
worksheet.write('E1', 'Remidiation')
worksheet.write('F1', 'Sourcepath_Line')
worksheet.write('G1', 'Mitigation_Status')
row = 1
col = 0
for severity in myroot.findall("{https://www.veracode.com/schema/reports/export/1.0}severity/{https://www.veracode.com/schema/reports/export/1.0}category/{https://www.veracode.com/schema/reports/export/1.0}cwe/{https://www.veracode.com/schema/reports/export/1.0}staticflaws/"):
dic = (severity.attrib)
for i in dic:
if (i == "severity"):
severity1 = (dic[i])
if (severity1 == "5"):
severity1 = "Critical"
if (severity1 == "4"):
severity1 = "High"
if (severity1 == "3"):
severity1 = "Medium"
if (severity1 == "2" or severity1 == "1"):
severity1 = "Low"
if (severity1 == "0"):
severity1 = "Informational"
if (i == "categoryname"):
cate1 = (dic[i])
cate1 = cate1.replace(",","")
if (i == "issueid"):
issueid1 = (dic[i])
if (i == "description"):
desc = str(dic[i])
description =(desc.split('\r\n\r\n', 1)[0])
description = description.replace(",","")
recommendation = (desc.split('\r\n\r\n', 1)[1])
recommendation = recommendation.replace('\r', '').replace('\n', '')
recommendation = recommendation.replace(",","")
if (i=="sourcefile"):
sfile = (dic[i])
if (i=="line"):
sline = (dic[i])
if (i == "mitigation_status"):
mitistatus = (dic[i])
if (i=="sourcefilepath"):
spath = (dic[i])
sfilesline = str(sfile+":"+sline)
print (severity1+","+cate1+","+issueid1+","+description+","+recommendation+","+sfilesline+","+mitistatus)
worksheet.write(row, col, severity1)
worksheet.write(row, col + 1, cate1)
worksheet.write(row, col + 2, issueid1)
worksheet.write(row, col + 3, description)
worksheet.write(row, col + 4, recommendation)
worksheet.write(row, col + 5, sfilesline)
worksheet.write(row, col + 6, mitistatus)
row += 1
workbook.close()
def main():
banner()
parser = argparse.ArgumentParser(description='Convert Veracode XML report to CSV')
parser.add_argument('infile', help='XML report you want to parse')
args = parser.parse_args()
inxml = args.infile
parsingxmldata(inxml)
if __name__ =='__main__':
main()