Created
March 31, 2021 18:10
-
-
Save jasonadsit/80280002d74fc0a666fe98bd4213588b to your computer and use it in GitHub Desktop.
Get-OregonCensysData.ps1
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
$ApiId = '<API ID>' | |
$Secret = '<API SECRET>' | |
$AsciiBytes = [System.Text.Encoding]::ASCII.GetBytes("$ApiId`:$Secret") | |
$Base64String = [convert]::ToBase64String($AsciiBytes) | |
$Authorization = "Basic $Base64String" | |
$Header = @{Authorization = $Authorization} | |
$Query = 'autonomous_system.asn: 1798 OR 443.https.tls.certificate.parsed.names: (oregon.gov OR state.or.us)' | |
$Body = @" | |
{ | |
"query":"$Query", | |
"fields":["ip","443.https.tls.certificate.parsed.names","protocols","autonomous_system.asn","autonomous_system.name"], | |
"flatten":true | |
} | |
"@ | |
$Uri = 'https://censys.io/api/v1/search/ipv4' | |
$Params = @{ | |
Uri = $Uri | |
Method = 'Post' | |
Headers = $Header | |
Body = $Body | |
UseBasicParsing = $true | |
} | |
$Pages = [int](Invoke-RestMethod @Params).metadata.pages | |
1..$Pages | ForEach-Object { | |
$Body = @" | |
{ | |
"query":"$Query", | |
"page":$_, | |
"fields":["ip","443.https.tls.certificate.parsed.names","protocols","autonomous_system.asn","autonomous_system.name"], | |
"flatten":true | |
} | |
"@ | |
$Params = @{ | |
Uri = $Uri | |
Method = 'Post' | |
Headers = $Header | |
Body = $Body | |
UseBasicParsing = $true | |
} | |
Invoke-RestMethod @Params | Select-Object -ExpandProperty results | |
} | Select-Object -Property 'ip', | |
@{n='names';e={$_.'443.https.tls.certificate.parsed.names'}}, | |
'protocols', | |
@{n='asn';e={$_.'autonomous_system.asn'}}, | |
@{n='description';e={$_.'autonomous_system.name'}}, | |
'notes' | | |
Tee-Object -Variable TheResults | ForEach-Object { | |
$_.names = $_.names -join "`n" | |
$_.protocols = $_.protocols -join "`n" | |
$_ | |
} | Export-Csv "$HOME\Downloads\oregon.csv" -NoTypeInformation | |
$TheResults |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment