Last active
October 17, 2019 18:56
-
-
Save paralax/c1d3a961c8c057e4864ac450e1905631 to your computer and use it in GitHub Desktop.
Censys from Powershell
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
# env vars for your Censys API creds | |
$apiid = $env:CENSYS_API_ID | |
$apisecret = $env:CENSYS_API_SECRET | |
$pair = "$apiid" + ":" + "$apisecret" | |
# Base64 encode them for auth | |
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) | |
$basicAuthValue = "Basic $encodedCreds" | |
# set up our headers | |
$Headers = @{ | |
Authorization = $basicAuthValue | |
"Content-Type" = "application/json" | |
} | |
# search, in this case IPv4 | |
(Invoke-WebRequest -UseBasicParsing https://censys.io/api/v1/search/ipv4 -Method POST -Headers $Headers -Body '{"query": "80.http.get.headers.server: nginx"}').Content | |
(Invoke-RestMethod -UseBasicParsing https://censys.io/api/v1/search/ipv4 -Method POST -Headers $Headers -Body '{"query": "80.http.get.headers.server: nginx"}').results | |
# view, again IPv4 | |
(Invoke-WebRequest -UseBasicParsing https://censys.io/api/v1/view/ipv4/8.8.8.8 -Headers $Headers).Content | |
Invoke-RestMethod -UseBasicParsing https://censys.io/api/v1/view/ipv4/1.1.1.1 -Headers $Headers | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment