Celerium.vPenTest
About The Project
The Celerium.vPenTest PowerShell wrapper offers a way to read data from the vPenTest REST API (v3). vPenTest is an automated penetration testing platform from Vonahi Security (a Kaseya company). This module serves to abstract away the details of interacting with vPenTest’s API endpoints in such a way that is consistent with PowerShell nomenclature. This gives system administrators and PowerShell developers a convenient and familiar way of using vPenTest’s API to create documentation scripts, automation, and integrations.
- :book: Celerium.vPenTest project documentation can be found on Github Pages
- :book: vPenTest’s REST API documentation
A function is generated for every endpoint in the vPenTest OpenAPI spec (vPenTest-v3.json) and every endpoint is tracked in the endpoints.csv file.
:information_source: The vPenTest API v3 is currently read-only, so every endpoint function is a Get- function.
In order to maintain PowerShell best practices, only approved verbs are used and PowerShell’s verb-noun nomenclature is respected. Each noun is prefixed with vPenTest in an attempt to prevent naming problems.
- GET ->
Get- - POST ->
New- - PUT\PATCH ->
Set- - DELETE ->
Remove-
For example, one might access the /assessments/{assessment_id}/findings endpoint by running the following PowerShell command with the appropriate parameters:
Get-vPenTestFindings -AssessmentId '24b38497-01cd-4539-a7d5-4f4b0ced2228'
- Function names are built from the endpoint path, such as
/assessmentsisGet-vPenTestAssessments - An endpoint & its single item endpoint (
/assessments&/assessments/{id}) with the same method are one function that uses the parameter setsList&ById.Get-vPenTestAssessmentslists assessments &Get-vPenTestAssessments -AssessmentId 123gets one assessment - Parameter names are the PascalCase version of the names used by the API, such as
company_idis-CompanyId&per_pageis-PerPage - The first path parameter accepts the
idof objects from other functions by property name,Get-vPenTestAssessments -PerPage 5 | Get-vPenTestFindings -AllResultsorGet-vPenTestAssessments -PerPage 5 | Get-vPenTestAssessmentPhase - Endpoints that support the
pageparameter also have an-AllResultsswitch that requests every page for you - By default only the
dataof a response is returned, use-Rawto also get the pagination values (total_count,total_pages…) Save-vPenTestReportFileis a helper function that downloads the PDF & ZIP files of a report
Write functions
The API does not have any write endpoints today. If vPenTest adds them, the functions are generated with the same naming rules and protections:
- Every write function supports
-WhatIf, which shows what would be sent without sending anything - Every write function has a
ConfirmImpactofHigh, so PowerShell asks for confirmation before the request is sent unless-Confirm:$falseis used - A write request is never retried automatically
- The unit tests, the live tests, & the examples never send a write request
Install
This module can be installed directly from the PowerShell Gallery with the following command:
Install-Module -Name Celerium.vPenTest
- :information_source: This module supports Windows PowerShell 5.1 and PowerShell 7+ on Windows, Linux, & macOS. Every change is tested on all of them by the CI workflow.
- :information_source: If you are running an older version of PowerShell, or if PowerShellGet is unavailable, you can manually download the main branch and place the latest version of Celerium.vPenTest from the build folder into the (default)
C:\Program Files\WindowsPowerShell\Modulesfolder.
Celerium.vPenTest project documentation can be found on Github Pages
- A full list of functions can be retrieved by running
Get-Command -Module Celerium.vPenTest. - Help info and a list of parameters can be found by running
Get-Help <command name>, such as:
Get-Help Get-vPenTestAssessments
Get-Help Get-vPenTestAssessments -Full
- Use wildcards to find the function for an endpoint:
Get-Command -Module Celerium.vPenTest -Name Get-vPenTest*Assessment*
Initial Setup
After installing this module, you will need to configure your API key that is used to talk with the vPenTest API.
- Generate an API key in vPenTest
- Click your profile name (My Account) > My Settings > API Key > Generate API Key
- The key has the same access as the user that generated it, treat it like a password
- Run
Add-vPenTestAPIKey- It will prompt you to enter your API key as a secure string, or use
Add-vPenTestAPIKey -ApiKey 'key'
- It will prompt you to enter your API key as a secure string, or use
- [optional] Run
Add-vPenTestBaseURI- By default the module uses
https://app.vpentest.io/api/v3 - Only run this if your account is in another region, such as
Add-vPenTestBaseURI -BaseURI 'https://emea.app.vpentest.io/api/v3'. Onlyhttpsis supported
- By default the module uses
- [optional] Run
Test-vPenTestAPIKey- Makes a single GET request to the
/companiesendpoint to validate the base uri & API key
- Makes a single GET request to the
- [optional] Run
Export-vPenTestModuleSettings- This will create a config file at
%UserProfile%\Celerium.vPenTestthat holds the base uri & API key information. - Next time you run
Import-Module -Name Celerium.vPenTest, this configuration file will automatically be loaded. - :warning: Exporting module settings encrypts your API key in a format that can only be unencrypted by the user principal that encrypted the secret. It makes use of .NET DPAPI, which for Windows uses reversible encrypted tied to your user principal. This means that you cannot copy your configuration file to another computer or user account and expect it to work.
- :warning: However in Linux\Unix operating systems the secret keys are more obfuscated than encrypted so it is recommend to use environment variables or a more secure & cross-platform storage method.
- This will create a config file at
Environment variables (recommended for CI\CD, Linux, & macOS) are loaded when the module is imported and take precedence over the configuration file:
$env:VPENTEST_API_KEY = 'your-api-key'
$env:VPENTEST_BASE_URI = 'https://app.vpentest.io/api/v3' # optional
Import-Module -Name Celerium.vPenTest
The mixed case names of version 1.0.0 (vPenTest_API_KEY & vPenTest_BASE_URI) still work, but the uppercase names are recommended because environment variables are case sensitive on Linux & macOS.
Usage
Calling an API endpoint is as simple as running its Get-vPenTest* function. The API returns 25 items per page by default and a maximum of 100, use -AllResults to get every item.
# Find a company
$Company = Get-vPenTestCompanies -AllResults | Where-Object short_name -eq 'Contoso'
# Get the assessments of the company, latest first
$Assessments = Get-vPenTestAssessments -CompanyId $Company.id -AllResults | Sort-Object created_at -Descending
# Get the progress & the findings of an assessment
Get-vPenTestAssessmentPhase -AssessmentId $Assessments[0].id
Get-vPenTestFindings -AssessmentId $Assessments[0].id -AllResults
# Get a single item by id & get the full response including the pagination values
Get-vPenTestCompanies -CompanyId $Company.id
Get-vPenTestCompanies -PerPage 5 -Raw
# Download the executive summary & technical report of a report
Get-vPenTestReports -CompanyId $Company.id -AllResults | Save-vPenTestReportFile -Type ExecutiveSummary, TechnicalReport -Path C:\Reports
- The full list of endpoints & their functions is tracked in the endpoints.csv file and on Github Pages.
- Example scripts can be found in the examples folder of this repository. They only use read-only requests.
- :information_source: PowerShell 7 converts the date strings of a response to
[datetime]objects while Windows PowerShell 5.1 leaves them as strings.
Supported functions
The module has 16 endpoints in the spec that are covered by 9 public functions, plus a report download helper. The following table shows all of them:
| Category | EndpointUri | Method | Function |
|---|---|---|---|
| Activities | /assessments/{assessment_id}/activities | GET | Get-vPenTestActivities |
| Activities | /assessments/{assessment_id}/activities/{id} | GET | Get-vPenTestActivities (ById) |
| AssessmentPhase | /assessments/{assessment_id}/assessment_phase | GET | Get-vPenTestAssessmentPhase |
| Agents | /agents | GET | Get-vPenTestAgents |
| Agents | /agents/{id} | GET | Get-vPenTestAgents (ById) |
| Assessments | /assessments | GET | Get-vPenTestAssessments |
| Assessments | /assessments/{id} | GET | Get-vPenTestAssessments (ById) |
| Assessments | /assessments/{assessment_id}/evidence_details | GET | Get-vPenTestEvidenceDetails |
| Companies | /companies | GET | Get-vPenTestCompanies |
| Companies | /companies/{id} | GET | Get-vPenTestCompanies (ById) |
| Findings | /assessments/{assessment_id}/findings | GET | Get-vPenTestFindings |
| Findings | /assessments/{assessment_id}/findings/{id} | GET | Get-vPenTestFindings (ById) |
| Reports | /reports | GET | Get-vPenTestReports |
| Reports | /reports/{id} | GET | Get-vPenTestReports (ById) |
| Schedules | /schedules | GET | Get-vPenTestSchedules |
| Schedules | /schedules/{id} | GET | Get-vPenTestSchedules (ById) |
| Reports | (report file urls) | GET | Save-vPenTestReportFile |
Development
The module is built from the files in this repository with the scripts in the build folder. The same steps are run by the GitHub Actions workflows in .github/workflows.
| Folder | Description |
|---|---|
| Celerium.vPenTest | The module source: the manifest & the Private & Public functions |
| build | The helper scripts below & the compiled module (build/Celerium.vPenTest/<version>) |
| docs | The GitHub pages documentation, generated by the build scripts, the endpoints.csv tracking file, & the OpenAPI spec (vPenTest-v3.json) |
| examples | Example scripts that use the module |
| tests | The Pester tests |
| .github | The GitHub Actions workflows, issue templates, & contributing guides |
| Script | Description |
|---|---|
| Install-Prerequisites.ps1 | Installs the latest ModuleBuilder, Pester, Microsoft.PowerShell.PlatyPS, & PSScriptAnalyzer |
| New-PublicFunctions.ps1 | (PowerShell 7+) Regenerates every public function, the manifest entries, & docs/endpoints.csv from the spec |
| Compare-vPenTestSpec.ps1 | Compares the newest docs/vPenTest-<version>.json with the published OpenAPI spec, -UpdateLocal replaces the local copy (the old file is archived) |
| Get-vPenTestSpec.ps1 | Downloads the published OpenAPI spec to docs as {product}-{version}.json, such as vPenTest-v3.json |
| Invoke-ModuleBuild.ps1 | Builds the module into build/Celerium.vPenTest/<version> (manifest, a single .psm1, & the OpenAPI spec) |
| Invoke-PesterTests.ps1 | Runs the Pester tests against the source or built module |
| Invoke-HelpContent.ps1 | Regenerates the GitHub pages documentation in docs |
| Publish-CeleriumModule.ps1 | Publishes the built module to the PowerShell Gallery |
./build/Install-Prerequisites.ps1
./build/New-PublicFunctions.ps1
./build/Invoke-PesterTests.ps1 -Version 1.1.0 -BuildTarget notBuilt
./build/Invoke-ModuleBuild.ps1 -Version 1.1.0
./build/Invoke-PesterTests.ps1 -Version 1.1.0 -BuildTarget built
./build/Invoke-HelpContent.ps1
To support a newer version of the API, run ./build/Compare-vPenTestSpec.ps1 to see what changed in the published OpenAPI spec, ./build/Get-vPenTestSpec.ps1 to download it to docs/vPenTest-<version>.json (an existing file with the same name is archived first), and then ./build/New-PublicFunctions.ps1.
GitHub Actions (Azure Pipelines is no longer used)
| Workflow | Description |
|---|---|
| ci.yml | Tests the source & the built module on Windows PowerShell 5.1, & PowerShell 7+ on Windows, Linux, & macOS |
| powershell.yml | Runs PSScriptAnalyzer & uploads the results to GitHub code scanning |
| docs.yml | Regenerates the GitHub pages documentation in docs |
| release.yml | Builds, tests, & publishes the module to the PowerShell Gallery when a v1.0.0 style tag is pushed |
| api-spec.yml | Compares the committed OpenAPI spec with the published spec every week |
Live tests make about 15 real, read-only GET requests (at least 500 ms apart). They only check the shape of the responses (counts & types) because findings & reports contain sensitive data, and they never download a report file. They are excluded unless the following environment variables are set and the Live tag is included:
$env:VPENTEST_API_KEY = 'your-api-key'
$env:VPENTEST_BASE_URI = 'https://app.vpentest.io/api/v3' # optional
./build/Invoke-PesterTests.ps1 -Version 1.1.0 -BuildTarget built -IncludeTag Live -ExcludeTag Online
Contributing
Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag “enhancement”. Don’t forget to give the project a star! Thanks again!
See the CONTRIBUTING guide for more information about contributing.
License
Distributed under the MIT license. See LICENSE for more information.