Skip to content

Instantly share code, notes, and snippets.

@paralax
Last active October 17, 2019 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paralax/c1d3a961c8c057e4864ac450e1905631 to your computer and use it in GitHub Desktop.
Save paralax/c1d3a961c8c057e4864ac450e1905631 to your computer and use it in GitHub Desktop.
Censys from Powershell
# 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