-
Notifications
You must be signed in to change notification settings - Fork 0
/
CVEHerald.ds
235 lines (235 loc) · 12.8 KB
/
CVEHerald.ds
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
// CVEHerald Zoho Deluge script.
// ------------------------------
// For sending out CVE email notifications to the relevant parties upon the creation of a Zoho Desk ticket generated by the Wazuh open-source XDR & SIEM vulnerability detector.
// You first need to create a Workflow rule to be triggered upon the creation of a ticket with the necessary parameters related to the vulnerability detector's logs.
// After which you will set the Workflow rule to execute this script.
// If tickets are submitted into your Zoho Desk via email then you will also need my `zohodesk-addDescFromEmail` script in order to make this work.
// This script also automatically closes the ticket (would not work with Blueprint mode enabled) and adds a comment to the ticket saying that an email notification has been sent.
// This would require you to setup an API connection with the necessary scope permissions required to close and add comments to tickets in your Zoho Desk.
// Or alternatively, you could disable this feature entirely by commenting out the relevant lines in this script.
//
void CVEHerald(int TktID)
{
OrgID = #########;// Your unique Zoho tenant ID here.
//
//TktID = ;// For testing purposes.
//
// Data retriever
getDesc = "";
// Method A
getRawTktDesc = zoho.desk.getRecordById(OrgID,"tickets",TktID).getJSON("description");
getDesc = getRawTktDesc.replaceAll("<(.|\n)*?>","").replaceAll(" "," ").ltrim().rtrim();
// Method B (redundant)
/*
getThds = zoho.desk.getRelatedRecords(OrgID,"threads","tickets",TktID,0,1);
ThdID = getThds.getJSON("data").getJSON("id");
getRawTktThd = zoho.desk.getRelatedRecordById(OrgID,"threads",ThdID,"tickets",TktID).getJSON("content");
*/
//Method checker
/*
if(getRawTktDesc.isBlank() == true)
{
getDesc = getRawTktThd.replaceAll("<(.|\n)*?>","").replaceAll(" "," ").ltrim().rtrim();
}
else if(getRawTktThd.isBlank() == true)
{
getDesc = getRawTktDesc.replaceAll("<(.|\n)*?>","").replaceAll(" "," ").ltrim().rtrim();
}
else
{
info "ERROR: SooL. ";
}
*/
//---
//SIEM/Log bug checker
if(getDesc.getOccurenceCount("vulnerability-detector") == 1 && getDesc.getOccurenceCount("END OF NOTIFICATION") == 1)
{
//---Text Parser
//---
//CVSS version checker & Anomalous ticket checker
cntV2 = getDesc.getOccurenceCount("vulnerability.cvss.cvss2");
cntV3 = getDesc.getOccurenceCount("vulnerability.cvss.cvss3");
if(cntV2 == 0 && cntV3 != 0 || cntV3 == 0 && cntV2 != 0)
{
cvssVerCheck = getDesc.getSuffix("vulnerability.cvss.cvss");
cvssVer = cvssVerCheck.subString(0,cvssVerCheck.indexOf("."));
cvss2Auth = "";
if(cvssVer == "3")
{
cvss2Auth = "n/a";
}
else if(cvssVer == "2")
{
rawCVSS2Auth = getDesc.getSuffix("vulnerability.cvss.cvss2.vector.authentication:");
cvss2Auth = rawCVSS2Auth.subString(1,rawCVSS2Auth.indexOf("vulnerability.cvss.cvss2.vector.confidentiality_impact:"));
}
}
else
{
info "ERROR: SIEM/Log bug x9001. ";
}
//---
rawHost = getDesc.getSuffix("Received From: (");
hostName = rawHost.subString(0,rawHost.indexOf(")"));
rawDeviceOS = getDesc.getSuffix("vulnerability.package.name:");
deviceOS = rawDeviceOS.subString(1,rawDeviceOS.indexOf("vulnerability.package.version:"));
rawOSVer = getDesc.getSuffix("vulnerability.package.version:");
osVer = rawOSVer.subString(1,rawOSVer.indexOf("vulnerability.package.architecture:"));
rawOSArch = getDesc.getSuffix("vulnerability.package.architecture:");
rawOSArchCheck = rawOSArch.subString(0,rawOSArch.indexOf("vulnerability.package.condition:"));
//Arch data checker
//osArch = "n/a";
if(length(rawOSArchCheck) <= 1)
{
osArch = "n/a";
}
else
{
osArch = rawOSArch.subString(1,rawOSArch.indexOf("vulnerability.package.condition:"));
}
//---
rawKBPatch = getDesc.getSuffix("vulnerability.package.condition:");
kbPatch = rawKBPatch.subString(1,rawKBPatch.indexOf("vulnerability.cvss.cvss" + cvssVer + ".vector.attack_vector:"));
rawAtkVect = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".vector.attack_vector:");
atkVect = rawAtkVect.subString(1,rawAtkVect.indexOf("vulnerability.cvss.cvss" + cvssVer + ".vector.access_complexity:"));
//Extra steps for CVSS v2
if(cvssVer = "2")
{
rawAtkComplex = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".vector.access_complexity:");
atkComplex = rawAtkComplex.subString(1,rawAtkComplex.indexOf("vulnerability.cvss.cvss2.vector.authentication:"));
}
else
{
rawAtkComplex = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".vector.access_complexity:");
atkComplex = rawAtkComplex.subString(1,rawAtkComplex.indexOf("vulnerability.cvss.cvss" + cvssVer + ".vector.privileges_required:"));
}
//---
if(cvssVer = "2")
{
reqPrivs = "n/a";
usrInt = "n/a";
atkScope = "n/a";
}
else
{
rawReqPrivs = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".vector.privileges_required:");
reqPrivs = rawReqPrivs.subString(1,rawReqPrivs.indexOf("vulnerability.cvss.cvss" + cvssVer + ".vector.user_interaction:"));
rawUsrInt = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".vector.user_interaction:");
usrInt = rawUsrInt.subString(1,rawUsrInt.indexOf("vulnerability.cvss.cvss" + cvssVer + ".vector.scope:"));
rawAtkScope = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".vector.scope:");
atkScope = rawAtkScope.subString(1,rawAtkScope.indexOf("vulnerability.cvss.cvss" + cvssVer + ".vector.confidentiality_impact:"));
}
//---
rawConfImpact = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".vector.confidentiality_impact:");
confImpact = rawConfImpact.subString(1,rawConfImpact.indexOf("vulnerability.cvss.cvss" + cvssVer + ".vector.integrity_impact:"));
rawIntegImpact = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".vector.integrity_impact:");
integImpact = rawIntegImpact.subString(1,rawIntegImpact.indexOf("vulnerability.cvss.cvss" + cvssVer + ".vector.availability:"));
rawAvailImpact = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".vector.availability:");
availImpact = rawAvailImpact.subString(1,rawAvailImpact.indexOf("vulnerability.cvss.cvss" + cvssVer + ".base_score:"));
rawBasScore = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".base_score:");
basScore = rawBasScore.subString(1,rawBasScore.indexOf("vulnerability.cvss.cvss" + cvssVer + ".exploitability_score:"));
rawExpScore = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".exploitability_score:");
expScore = rawExpScore.subString(1,rawExpScore.indexOf("vulnerability.cvss.cvss" + cvssVer + ".impact_score:"));
rawImpScore = getDesc.getSuffix("vulnerability.cvss.cvss" + cvssVer + ".impact_score:");
impScore = rawImpScore.subString(1,rawImpScore.indexOf("vulnerability.cve:"));
rawCveCode = getDesc.getSuffix("vulnerability.cve:");
cveCode = rawCveCode.subString(1,rawCveCode.indexOf("vulnerability.title:"));
rawCveTitle = getDesc.getSuffix("vulnerability.title:");
cveTitle = rawCveTitle.subString(1,rawCveTitle.indexOf("vulnerability.rationale"));
rawCveRat = getDesc.getSuffix("vulnerability.rationale:");
cveRat = rawCveRat.subString(1,rawCveRat.indexOf("vulnerability.severity:"));
rawCveSev = getDesc.getSuffix("vulnerability.severity:");
cveSev = rawCveSev.subString(1,rawCveSev.indexOf("vulnerability.published:"));
rawCveDate = getDesc.getSuffix("vulnerability.published:");
cveDate = rawCveDate.subString(1,rawCveDate.indexOf("vulnerability.updated:"));
rawCveUpd = getDesc.getSuffix("vulnerability.updated:");
cveUpd = rawCveUpd.subString(1,rawCveUpd.indexOf("vulnerability.cwe_reference:"));
//Reference URLs
cveRefA = "https://cve.mitre.org/cgi-bin/cvename.cgi?name=" + cveCode;
cveRefB = "https://nvd.nist.gov/vuln/detail/" + cveCode;
cveRefC = "https://msrc.microsoft.com/update-guide/vulnerability/" + cveCode;
cveRefD = "https://www.cve.org/CVERecord?id=" + cveCode;
//GitHub URL preparation
cveYear = cveCode.getSuffix("CVE-").subString(0,cveCode.indexOf("-") + 1);
cveNum = cveCode.getSuffix("CVE-" + cveYear + "-").ltrim().rtrim();
if(cveNum.startsWith("0") == true && length(cveNum) == 4)
{
matchedEntry = "0xxx";
}
else if(length(cveNum) = 5)
{
matchedEntry = cveNum.left(2).concat("xxx");
}
else if(length(cveNum) = 4 && cveNum.startsWith("0") == false)
{
matchedEntry = cveNum.left(1).concat("xxx");
}
else
{
matchedEntry = "xxxxx";
}
cveRefE = "https://www.github.com/CVEProject/cvelistV5/tree/main/cves/" + cveYear + "/" + matchedEntry + "/" + cveCode + ".json";
//---
rawCweRef = getDesc.getSuffix("vulnerability.cwe_reference:");
cweRef = rawCweRef.subString(1,rawCweRef.indexOf("vulnerability.status:"));
rawCveStat = getDesc.getSuffix("vulnerability.status:");
cveStat = rawCveStat.subString(1,rawCveStat.indexOf("vulnerability.type:"));
rawCveTyp = getDesc.getSuffix("vulnerability.type:");
cveTyp = rawCveTyp.subString(1,rawCveTyp.indexOf("vulnerability.references:"));
rawCveAuth = getDesc.getSuffix("vulnerability.assigner:");
//cveAuth = rawCveAuth.replaceAll("[ ]+","",false).remove("--ENDOFNOTIFICATION");//Alt method
cveAuthProp = rawCveAuth.trim().remove("--END OF NOTIFICATION");
tktLink = "https://desk.zoho.com/agent/YOUR_TENANT_NAME_HERE/YOUR_DEPT_NAME_HERE/tickets/details/" + TktID + "/conversation";
//---Notification structure
alertSubj = proper(cveSev) + " severity alert from Santa Claus: " + cveCode + " on " + hostName;
alertSubjProp = alertSubj.replaceAll("\r","");
msgPtA = "<mark><strong>" + alertSubjProp + "</strong></mark><hr><table><tr><td><b>Host</b></td><td>" + hostName + "</td></tr><tr><td><b>Pkg</b></td><td>" + deviceOS + "</td></tr><tr><td><b>Ver</b></td><td>" + osVer + "</td></tr><tr><td><b>Arch</b></td><td>" + osArch + "</td></tr><tr><td><b>Cond</b></td><td>" + kbPatch + "</td></tr>";
msgPtB = "<tr><td><b>Vec</b></td><td>" + atkVect + "</td></tr><tr><td><b>Cx</b></td><td>" + atkComplex + "</td></tr><tr><td><b>Auth</b></td><td>" + cvss2Auth + "</td></tr><tr><td><b>Priv</b></td><td>" + reqPrivs + "</td></tr><tr><td><b>UI</b></td><td>" + usrInt + "</td></tr><tr><td><b>Scop</b></td><td>" + atkScope + "</td></tr></table><br>";
msgPtC = "<table><tr><th>CIA</th><th>Impact</th></tr><tr><td><b>C</b></td><td>" + confImpact + "</td></tr><tr><td><b>I</b></td><td>" + integImpact + "</td></tr><tr><td><b>A</b></td><td>" + availImpact + "</td></tr></table><br>";
msgPtD = "<table><tr><th>CVSS v" + cvssVer + "</th><th>Scores</th></tr><tr><td><b>Bs</b></td><td>" + basScore + "</td></tr><tr><td><b>Ex</b></td><td>" + expScore + "</td></tr><tr><td><b>Im</b></td><td>" + impScore + "</td></tr></table><br>";
msgPtE = "<table><tr><td><b>ID</b></td><td>" + cveCode + "</td></tr><tr><td><b>Ttl</b></td><td>" + cveTitle + "</td></tr><tr><td><b>Rtl</b></td><td>" + cveRat + "</td></tr><tr><td><b>Sev</b></td><td>" + cveSev + "</td></tr><tr><td><b>Pub</b></td><td>" + cveDate + "</td></tr><tr><td><b>Upd</b></td><td>" + cveUpd + "</td></tr>";
msgPtF = "<tr><td><b>CWE</b></td><td><a href=\"https://cwe.mitre.org/cgi-bin/jumpmenu.cgi?id=" + cweRef + "\">" + cweRef + "</a></td></tr><tr><td><b>Ref</b></td><td><a href=\"" + cveRefA + "\">MITRE</a> | <a href=\"" + cveRefD + "\">CVE</a> | <a href=\"" + cveRefB + "\">NIST</a> | <a href=\"" + cveRefC + "\">MS</a> | <a href=\"" + cveRefE + "\">GH</a></td></tr><tr><td><b>Stat</b></td><td>" + cveStat + "</td></tr><tr><td><b>Typ</b></td><td>" + cveTyp + "</td></tr><tr><td><b>CNA</b></td><td>" + cveAuthProp + "</table><hr><a href=\"" + tktLink + "\">View Ticket</a>";
//Send email task (non-API)
sendmail
[
from :zoho.adminuserid
bcc :"[email protected]"
subject :alertSubjProp.replaceAll("\n","")
message :msgPtA + msgPtB + msgPtC + msgPtD + msgPtE + msgPtF
]
//Add comment (API - authentication/workflow connection required)
apiCallUrlA = "https://desk.zoho.com/supportapi/zd/YOUR_TENANT_NAME_HERE/api/v1/tickets/" + TktID + "/comments";
msgPayload = "Email notification sent to: [email protected],[email protected]<br><br>" + msgPtA + msgPtB + msgPtC + msgPtD + msgPtE + msgPtF;
comment = Map();
comment.put("content",msgPayload);
comment.put("isPublic","false");
callApiA = invokeurl
[
url :apiCallUrlA
type :POST
parameters:comment + ""
connection:"YOUR_CONNECTION_NAME_HERE"
];
info callApiA;
//Close ticket (API - authentication/workflow connection required)
apiCallUrlB = "https://desk.zoho.com/supportapi/zd/YOUR_TENANT_NAME_HERE/api/v1/closeTickets";
headerData = Map();
headerData.put("Content-Type","application/json");
clsTktPayload = "{\"ids\":[" + TktID + "]}";
callApiB = invokeurl
[
url :apiCallUrlB
type :POST
parameters:clsTktPayload
headers:headerData
connection:"YOUR_CONNECTION_NAME_HERE"
];
info callApiB;
}
else if(getDesc.getOccurenceCount("vulnerability-detector") != 1 || getDesc.getOccurenceCount("END OF NOTIFICATION") != 1)
{
info "ERROR: SIEM/Log bug. ";
}
}