Created
September 14, 2017 10:57
-
-
Save cactaceae21/5d85b9b0588d69a20d318eefb252ada8 to your computer and use it in GitHub Desktop.
Security Center AddAssets #powershell #sccv #tenable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Ignore self signed certificates | |
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} ; | |
#variables | |
$hostname = "https://hostname/rest" | |
#prompt for credentials | |
$LoginCreds = Get-Credential | |
$username = $LoginCreds.UserName | |
$password = $LoginCreds.GetNetworkCredential().Password | |
#hardcode creds - not recommended | |
#$username = "username" | |
#$password = "password" | |
# Build credentials object | |
$LoginData = (ConvertTo-Json -compress @{username=$username; password=$password}) | |
#list of assets - more info for fields at https://support.tenable.com/support-center/cerberus-support-center/includes/widgets/sc_api/Asset.html | |
#it should be possible to add different kinds of assets as long as the fields are filled out correctly | |
$ASSET_LIST=@( | |
@{type="static"; name="ASSET1"; tags="TAG"; description="Description 1" ; definedIPs="10.0.0.0/24" }, | |
@{type="static"; name="ASSET2"; tags="TAG"; description="Description 2" ; definedIPs="10.0.1.0/24" } | |
@{type="static"; name="ASSET3"; tags="TAG"; description="Description 3" ; definedIPs="10.0.2.0/24" }, | |
@{type="static"; name="ASSET4"; tags="TAG"; description="Description 4" ; definedIPs="10.0.3.0/24" }, | |
@{type="static"; name="ASSET5"; tags="TAG"; description="Description 5" ; definedIPs="10.0.4.0/24" }) | |
# Login to SC5 | |
$ret = Invoke-WebRequest -URI $hostname/token -Method POST -Body $LoginData -UseBasicParsing -SessionVariable sv | |
# extract the token | |
$loginToken = (convertfrom-json $ret.Content).response.token | |
# get IP list of asset 70 - reading asset data | |
#$ret = Invoke-WebRequest -URI hostname/asset/70 -UseBasicParsing -Headers @{"X-SecurityCenter"="$loginToken"} -Websession $sv | |
# Extract data from response | |
#$objdata = (convertfrom-json ($ret.Content)).response.content | |
#Write-Host $objdata | |
#Loop through asset list and add each asset | |
foreach ($NewAsset in $ASSET_LIST) { | |
$NewAsset = (ConvertTo-Json -Compress $NewAsset) | |
$ret = Invoke-WebRequest -URI $hostname/asset -Method Post -body $NewAsset -UseBasicParsing -Headers @{"X-SecurityCenter"="$loginToken"} -Websession $sv | |
} | |
#destroy the token | |
$ret = Invoke-WebRequest -URI $hostname/token -method Delete -UseBasicParsing -Headers @{"X-SecurityCenter"="$loginToken"} -Websession $sv | |
#cleanup creds | |
Remove-Variable username | |
Remove-Variable password | |
Remove-Variable LoginData |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you - you're a life saver!