Get-ShodanExploitSearch.psm1

<#PSScriptInfo
 
.VERSION 1.1
 
.GUID 1fc06be4-fb73-4203-ab1c-7387b2562f88
 
.AUTHOR simeononsecurity.ch
 
.COMPANYNAME SimeonOnSecurity
 
.COPYRIGHT 2020 SimeonOnSecurity. All rights reserved.
 
.TAGS Shodan PowerShell Modules ShodanPS cmdlet
 
.PROJECTURI https://github.com/simeononsecurity/Shodan_PS
 
.DESCRIPTION "Search across a variety of data sources for exploits and use facets to get summary information. Ex: Get-ShodanExploitSearch -Query [string] -Facet [string] -API [string]"
 
.RELEASENOTES
Init
 
#>

function Get-ShodanExploitSearch {
    param(
        [Parameter(Mandatory = $false, Position = 0)]
        [string]$api,
        [Parameter(Mandatory = $true, Position = 1)]
        [string]$query,
        [Parameter(Mandatory = $false, Position = 2)]
        [string]$facet
    )
    $apistring = "?key=$api"
    $querystring = "&query=$query"
    If (!$facet) {
        Write-Output "You chose no facet"
        $facetstring = ""
    }
    Else {
        $facetstring = "&facet=$facet"
    }
    If (!$api) {
        Write-Output "Please set the 'api' variable to your shodan API key."
    }
    Else {
        If (!$query) {
            Write-Output "Please specify your query with -Query [string]"
        }
        Else {
            (Invoke-WebRequest "https://exploits.shodan.io/api/search$apistring$querystring$facetstring").content | ConvertFrom-Json
        }
    }
}