//native
/**
* List Vulnerability Findings
* List vulnerability findings (CVEs detected on cloud resources), with optional filters by severity, status, CVE, exploit and fix availability.
*/
export async function main(
auth: RT.Wiz,
vendor_severity:
| ("NONE" | "LOW" | "MEDIUM" | "HIGH" | "CRITICAL")[]
| undefined,
status: ("UNRESOLVED" | "RESOLVED" | "PASSED" | "IGNORED")[] | undefined,
cve: string | undefined,
has_exploit: boolean | undefined,
has_fix: boolean | undefined,
first: number | undefined,
after: string | undefined
) {
const tokenResponse = await fetch(
auth.auth_url || "https://auth.app.wiz.io/oauth/token",
{
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: new URLSearchParams({
grant_type: "client_credentials",
audience: auth.audience || "wiz-api",
client_id: auth.client_id,
client_secret: auth.client_secret,
}),
}
)
if (!tokenResponse.ok) {
throw new Error(`${tokenResponse.status} ${await tokenResponse.text()}`)
}
const { access_token } = (await tokenResponse.json()) as {
access_token: string
}
const filterBy: { [key: string]: any } = {}
if (vendor_severity && vendor_severity.length > 0)
filterBy.vendorSeverity = vendor_severity
if (status && status.length > 0) filterBy.status = status
if (cve !== undefined && cve !== "") filterBy.vulnerabilityExternalId = [cve]
if (has_exploit !== undefined) filterBy.hasExploit = has_exploit
if (has_fix !== undefined) filterBy.hasFix = has_fix
const query = `
query ListVulnerabilityFindings($first: Int, $after: String, $filterBy: VulnerabilityFindingFilters) {
vulnerabilityFindings(first: $first, after: $after, filterBy: $filterBy) {
totalCount
pageInfo { hasNextPage endCursor }
nodes {
id
name
detailedName
severity: vendorSeverity
CVSSSeverity
score
exploitabilityScore
impactScore
hasExploit
hasCisaKevExploit
status
vulnerabilityExternalId
version
fixedVersion
detectionMethod
firstDetectedAt
lastDetectedAt
resolvedAt
resolutionReason
remediation
link
portalUrl
vulnerableAsset {
... on VulnerableAssetBase {
id
type
name
cloudPlatform
subscriptionId
tags
}
... on VulnerableAssetVirtualMachine {
id
type
name
cloudPlatform
subscriptionId
tags
operatingSystem
}
... on VulnerableAssetServerless {
id
type
name
cloudPlatform
subscriptionId
tags
}
... on VulnerableAssetContainerImage {
id
type
name
cloudPlatform
subscriptionId
tags
}
... on VulnerableAssetContainer {
id
type
name
cloudPlatform
subscriptionId
tags
}
}
}
}
}`
const response = await fetch(auth.api_endpoint, {
method: "POST",
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query,
variables: { first: first ?? 50, after: after || null, filterBy },
}),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const result = (await response.json()) as { data?: any; errors?: any }
if (result.errors) {
throw new Error(JSON.stringify(result.errors))
}
return result.data.vulnerabilityFindings
}
Submitted by hugo989 5 days ago