-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.vb
More file actions
363 lines (288 loc) · 14 KB
/
Copy pathProgram.vb
File metadata and controls
363 lines (288 loc) · 14 KB
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
Imports System
Module Program
Private apiID As String
Private apiKey As String
Private secLabs_token$
Private slClient As SL_Client
Private studentS As List(Of slStudent)
Private VC As VC_Client
Private uFolder$
Sub Main(args As String())
uFolder$ = Environment.GetEnvironmentVariable("UserProfile")
Dim actionWord$ = ""
' GoTo forceContinue
If args.Count.ToString < 1 Or argExist("help", args) Then
Call giveHelp()
End
Else
actionWord$ = args(0)
Console.WriteLine("ACTION: " + actionWord)
End If
forceContinue:
apiKey = ""
apiID = ""
secLabs_token = ""
apiID = argValue("--apiID", args)
apiKey = argValue("--apiKey", args)
secLabs_token = argValue("--slToken", args)
If Len(apiID) = 0 Or Len(apiKey) = 0 Then
Call getCredsFromFile()
' If Len(apiID) Then Console.WriteLine("Pulled apiID from UserProfile: " + apiID)
End If
Select Case actionWord
Case "get_seclabs_summary"
If Len(secLabs_token) = 0 Then
Console.WriteLine("ERROR: Use --slToken to provide the Security Labs API Token")
End
End If
Call getSecLabsSummary(secLabs_token)
Case "get_app_profiles"
If Len(apiKey) = 0 Or Len(apiID) = 0 Then
Console.WriteLine("ERROR: Must provide --apiID and --apiKEY parameters")
End
End If
VC = New VC_Client
Call VC.getAppProfiles(apiID, apiKey)
Call showAppProfiles()
Case "get_dast"
If Len(apiKey) = 0 Or Len(apiID) = 0 Then
Console.WriteLine("ERROR: Must provide --apiID and --apiKEY parameters")
End
End If
VC = New VC_Client
Call showDASTanalysis()
Case "new_dast"
If Len(apiKey) = 0 Or Len(apiID) = 0 Then
Console.WriteLine("ERROR: Must provide --apiID and --apiKEY parameters")
End
End If
VC = New VC_Client
Dim appUUID$ = argValue("--linkapp_UUID", args)
If Len(argValue("--linkapp_NAME", args)) Then
Call VC.getAppProfiles(apiID, apiKey)
For Each P In VC.appProfiles
If LCase(P.name) = LCase(argValue("--linkapp_NAME", args)) Then
appUUID = P.uuid
' Console.WriteLine(appUUID + "=" + P.uuid)
End If
Next
End If
Call VC.newDAST(argValue("--dast_name", args), argValue("--dast_url", args), apiID, apiKey, appUUID)
Case "link_dast"
If Len(apiKey) = 0 Or Len(apiID) = 0 Then
Console.WriteLine("ERROR: Must provide --apiID and --apiKEY parameters")
End
End If
VC = New VC_Client
Dim appUUID$ = argValue("--linkapp_UUID", args)
If Len(argValue("--linkapp_NAME", args)) Then
Call VC.getAppProfiles(apiID, apiKey)
For Each P In VC.appProfiles
If LCase(P.name) = LCase(argValue("--linkapp_NAME", args)) Then
appUUID = P.uuid
' Console.WriteLine(appUUID + "=" + P.uuid)
End If
Next
End If
Call linkDAST(appUUID, argValue("--dast_name", args))
End Select
End
End Sub
Private Sub linkDAST(appUUID$, dastName$)
Dim dastAnalyses As List(Of dastAnalysis) = New List(Of dastAnalysis)
dastAnalyses = VC.getDynamicAnalyses(apiID, apiKey, dastName)
Dim dNDX As Integer = 0
Dim appNDX As Integer = 0
For Each D In dastAnalyses
If LCase(dastName) = LCase(D.name) Then appNDX = dNDX
dNDX += 1
Next
If appNDX = 0 Then
Console.WriteLine("ERROR: No DAST named " + dastName + " found")
Exit Sub
End If
Dim scanID$ = dastAnalyses(appNDX).scansOfOccurrence(0).scan_id
Console.WriteLine("Linking APP " + appUUID + " to SCAN ID:" + scanID)
Call VC.linkDAST(apiID, apiKey, appUUID, scanID)
End Sub
Private Sub showDASTanalysis()
Dim dastAnalyses As List(Of dastAnalysis) = New List(Of dastAnalysis)
dastAnalyses = VC.getDynamicAnalyses(apiID, apiKey)
Console.WriteLine("NAME" + spaces(36) + "ANALYSIS_OCC_ID" + spaces(20) + "SCAN_ID" + spaces(30) + "END_TIME" + spaces(20) + "LINKED_APP" + spaces(18) + "FLAWS" + spaces(5) + "TARGET_URL" + spaces(18) + "STATUS")
Console.WriteLine("----" + spaces(36) + "---------------" + spaces(20) + "-------" + spaces(30) + "--------" + spaces(20) + "----------" + spaces(18) + "-----" + spaces(5) + "----------" + spaces(18) + "------")
Dim rowNum As Integer = 1
Dim a$ = ""
Dim b$ = ""
Dim c$ = ""
Dim targetURL$ = ""
For Each D In dastAnalyses
With D
a$ = "" : b$ = "" : c$ = ""
a$ = .name + spaces(40 - Len(.name)) ' + .analysis_id + spaces(35 - Len(.analysis_id))
' a$ = .name + spaces(40 - Len(.name)) + .number_of_scans.ToString + spaces(Len(10 - .number_of_scans.ToString)) + .analysis_id + spaces(35 - Len(.analysis_id))
rowNum = 1
For Each dA In .occurrenceS
b$ = dA.analysis_occurrence_id + spaces(35 - Len(dA.analysis_occurrence_id))
' b$ = dA.analysis_occurrence_id + spaces(35 - Len(dA.analysis_occurrence_id)) + dA.actual_end_date + spaces(25 - Len(dA.actual_end_date))
For Each sD In .scansOfOccurrence
If dA.analysis_occurrence_id = sD.analysis_occurrence_id Then
targetURL$ = Mid(Replace(Replace(sD.target_url, "http://", ""), "https://", ""), 1, 25)
c$ = sD.scan_id + spaces(37 - Len(sD.scan_id)) + sD.end_date + spaces(28 - Len(sD.end_date)) + sD.linked_platform_app_name + spaces(30 - Len(sD.linked_platform_app_name)) + sD.total_flaw_count.ToString + spaces(8 - Len(sD.total_flaw_count.ToString)) + targetURL + spaces(28 - Len(targetURL)) + sD.analysis_occurrence_status
' c$ = sD.scan_id + spaces(40 - Len(sD.scan_id)) + sD.result_import_status + spaces(20 - Len(sD.result_import_status)) + sD.target_url + spaces(20 - Len(sD.target_url)) + sD.linked_platform_app_name
End If
If rowNum = 1 Then
Console.WriteLine(a + b + c)
Else
Console.WriteLine(spaces(Len(a)) + b + c)
End If
Next
rowNum += 1
Next
End With
Next
End Sub
Private Sub showAppProfiles()
Dim a$ = ""
Dim b$ = ""
Dim c$ = ""
For Each App In VC.appProfiles
With App
b = "[" + .id.ToString + "]"
b += spaces(10 - Len(b)) : a = b
a += .name + spaces(40 - Len(.name))
b = .uuid
b += spaces(40 - Len(b)) : a += b
c = .linked_scan_target_url
If Len(c) = 0 Then c = "NO DAST" Else c = "DAST:" + c
a += c
End With
Console.WriteLine(a)
Next
End Sub
Public Sub getSecLabsSummary(apiToken$)
slClient = New SL_Client(secLabs_token)
slClient.loadProgressAllUsers()
Console.WriteLine("# of Lessons: " + slClient.moduleNames.Count.ToString)
For Each L In slClient.moduleNames
Dim a$ = L + spaces(50 - Len(L))
Dim S As stats
S = lessonStats(L)
Dim b$ = ""
b += "[" + S.numStudents.ToString + "/" + slClient.studentList.Count.ToString + "] " : a += b
b = "[Min/Avg/Max Mins]:" + S.minTime.ToString + "/" + S.avgTime.ToString + "/" + S.maxTime.ToString
b += spaces(35 - Len(b)) : a += b
b = "[Before/After/Avg Improve]:" + S.avgBefore.ToString + "/" + S.avgAfter.ToString + "/" + S.avgImprove.ToString
b += spaces(45 - Len(b)) : a += b
b = "[Students/Revisits]:" + S.numStudentsRevisit.ToString + "/" + S.numRevisitsTL.ToString
b += spaces(25 - Len(b))
a += b
a += "FAST: " + S.quickestStudent + " SLOW: " + S.slowestStudent
Console.WriteLine(a)
Next
End Sub
Private Function lessonStats(moduleName$) As stats
lessonStats = New stats
Dim tlTime As Decimal
Dim tlImprove As Decimal
Dim numImproveRatings As Integer
With lessonStats
For Each U In slClient.studentList
Dim S As studentLessonStats
S = gatherStudentLessonStats(U.id, moduleName)
If S.numVisits > 0 Then
If S.numVisits > 1 Then
.numStudentsRevisit += 1
.numRevisitsTL += S.numVisits - 1
End If
.numStudents += 1
tlTime += S.tlTime
.totalPoints += S.points
If S.startRating > 0 And S.endRating > 0 Then
tlImprove += S.endRating - S.startRating
numImproveRatings += 1
.avgBefore += S.startRating
.avgAfter += S.endRating
End If
If S.tlTime > .maxTime Then
.maxTime = S.tlTime
.slowestStudent = U.name + " (" + .maxTime.ToString + ")"
End If
If S.tlTime > 0 Then
If .minTime = 0 Then
.minTime = S.tlTime
.quickestStudent = U.name + " (" + .minTime.ToString + ")"
End If
If S.tlTime < .minTime Then
.minTime = S.tlTime
.quickestStudent = U.name + " (" + .minTime.ToString + ")"
End If
End If
End If
Next
' final calcs
.avgBefore = Math.Round(.avgBefore / numImproveRatings, 2)
.avgAfter = Math.Round(.avgAfter / numImproveRatings, 2)
.avgImprove = Math.Round(tlImprove / numImproveRatings, 2)
.avgTime = Math.Round(tlTime / .numStudents, 2)
End With
End Function
Private Function gatherStudentLessonStats(userID$, lessonName$) As studentLessonStats
gatherStudentLessonStats = New studentLessonStats
For Each S In slClient.studentList
If S.id <> userID Then GoTo skipStudent
For Each L In S.lessons
If L.module <> lessonName Then GoTo skipLesson
With gatherStudentLessonStats
.numVisits += 1
If L.startRating > 0 Then .startRating = L.startRating
If L.endRating > 0 Then .endRating = L.endRating
.tlTime += L.minutes
.points += L.points
End With
skipLesson:
Next
skipStudent:
Next
End Function
Private Sub giveHelp()
Console.WriteLine("USAGE: VCCLI action --param1 param1_value --param2 param2_value" + vbCrLf)
Console.WriteLine("ACTIONS:")
Console.WriteLine("--------")
Console.WriteLine(fLine("help", "Produces this list of actions and parameters"))
Console.WriteLine(fLine("get_seclabs_summary", "Returns a summary of Security Labs student & lesson activity"))
Console.WriteLine(fLine("get_dast", "Returns a summary of DAST analyses and scans"))
Console.WriteLine(fLine("get_app_profiles", "Returns a summary of Application Profiles"))
Console.WriteLine(fLine("new_dast", "Creates and starts a DAST scan [req:dast_name & dast_url,optional: linkapp_UUID/NAME]"))
Console.WriteLine(fLine("link_dast", "Links a DAST scan to an Application Profile [req dast_name & linkapp_UUID/NAME"))
Console.WriteLine(vbCrLf + "PARAMETERS:")
Console.WriteLine("-----------")
Console.WriteLine(fLine("--apiID", "The Veracode API ID (if not inside " + uFolder))
Console.WriteLine(fLine("--apiKEY", "The Veracode API KEY (if not inside " + uFolder))
Console.WriteLine(fLine("--slToken", "The Security Labs API KEY"))
Console.WriteLine(fLine("--dast_name", "Name of the DAST scan"))
Console.WriteLine(fLine("--dast_url", "URL used for a DAST scan"))
Console.WriteLine(fLine("--linkapp_UUID", "Used to link a DAST scan to a Profile using APP UUID"))
Console.WriteLine(fLine("--linkapp_Name", "Used to link a DAST scan to a Profile using APP NAME"))
End Sub
Private Function fLine(arg1$, arg2$, Optional ByVal numSpaces As Integer = 25) As String
Return arg1 + spaces(numSpaces - Len(arg1)) + arg2
End Function
Private Sub getCredsFromFile()
Dim fName$ = uFolder + "\.veracode\credentials"
If Dir(fName) = "" Then Exit Sub
Dim a$ = ""
Dim FF As Integer
FF = FreeFile()
FileOpen(FF, fName, OpenMode.Input)
Do Until EOF(FF) = True
a$ = LineInput(FF)
If InStr(a, "veracode_api_key_id") Then
apiID = Trim(Mid(a, InStr(a, "=") + 1))
End If
If InStr(a, "veracode_api_key_secret") Then
apiKey = Trim(Mid(a, InStr(a, "=") + 1))
End If
Loop
FileClose(FF)
End Sub
End Module