-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoke-VulDBApi.ps1
62 lines (48 loc) · 1.32 KB
/
Invoke-VulDBApi.ps1
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
<#
Invoke-VulDBAPI - PowerShell VulDB API Demo
License: GPL-3.0
Required Dependencies: None
Optional Dependencies: None
#>
# Define parameters for API script
[CmdletBinding()]
Param (
[ValidateSet(0,1)]
[Int]
$Details,
[Int]
$Recent,
[Int]
$Id
)
# Add your personal API key here
$PersonalApiKey = ''
# Set HTTP Header
$UserAgent = 'VulDB API Advanced PowerShell Demo Agent'
$Headers = @{'User-Agent' = $UserAgent;'X-VulDB-ApiKey' = $PersonalApiKey}
# URL VulDB endpoint
$Uri = 'https://vuldb.com/?api'
Function Main() {
# Choose the API call based on the passed parameters
# Default call is the last 5 recent entries
If ($Recent -ne 0) {
$Body = @{'recent' = $Recent}
} ElseIf ( $Id -ne 0) {
$Body = @{'id' = $Id}
} Else {
$Body = @{'recent' = 5}
}
If ($Recent -ne 0) {
$Body['details'] = $Details
}
# Get API response
$Response = Invoke-WebRequest -Headers $Headers -Method Post -Uri $Uri -Body $Body
# Display result if evertything went OK
If ($Response.StatusCode -eq 200) {
# Parse HTTP body as JSON
$ResponseJson = ConvertFrom-Json($Response.Content)
# Output
$ResponseJson.result
}
}
Main