Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Nessus plugins
- #This Powershell script queries the Nessus Professional 8 API for plugin informations, format the JSON response and sends it at the #Logstash http input.
- #Installation
- #Ip and port of Nessus and Logstash need to be set ; $nessusIP and $logstashIP
- #API keys of Nessus and Logstash need to be set ; $xApiKey and $logstashAuth
- # Ignore the self-signed certificates
- if (-not("dummy" -as [type])) {
- add-type -TypeDefinition @"
- using System;
- using System.Net;
- using System.Net.Security;
- using System.Security.Cryptography.X509Certificates;
- public static class Dummy {
- public static bool ReturnTrue(object sender,
- X509Certificate certificate,
- X509Chain chain,
- SslPolicyErrors sslPolicyErrors) { return true; }
- public static RemoteCertificateValidationCallback GetDelegate() {
- return new RemoteCertificateValidationCallback(Dummy.ReturnTrue);
- }
- }
- "@
- }
- [System.Net.ServicePointManager]::ServerCertificateValidationCallback = [dummy]::GetDelegate()
- # authentication header
- $xApiKey = '' #<=============NessusAPIKey=============
- $headers = @{
- "X-ApiKeys" = $xApiKey
- "Accept" = "application/json"
- }
- $logstashAuth = '' #<=============LogstashBasicAuth=============
- $headersLog = @{
- "Authorization" = $logstashAuth
- }
- $nessusIP = 'srv675m:8834' #<=============Nessus=============
- $logstashIP = 'srv723l:8080' #<=============Logstash=============
- # get all families
- $uri = "https://"+$nessusIP+"/plugins/families"
- $Result = Invoke-RestMethod -Uri $uri -Method GET -Headers $headers
- $j = 0
- $total = $Result.families.Count
- # for each family
- Foreach ($family in $Result.families){
- $j += 1
- Write-Progress -Activity "Nessus to Logstash" -PercentComplete (($j / $total) * 100)
- # get information on one family
- $uri = "https://"+$nessusIP+"/plugins/families/" + $family.id
- $Result = Invoke-RestMethod -Uri $uri -Method GET -Headers $headers
- # for each plugin of the family
- Foreach ($plugin in $Result.plugins){
- # get information on the plugin
- $uri = "https://"+$nessusIP+"/plugins/plugin/" + $plugin.id
- $Result = Invoke-RestMethod -Uri $uri -Method GET -Headers $headers
- # format dictionary
- $newAttLst = @()
- foreach ($att in $Result.attributes) {
- if($att.attribute_name -ne "plugin_modification_date" -and $att.attribute_name -ne "plugin_publication_date"){
- $newAttLst += @{ $att.attribute_name = $att.attribute_value}
- }
- }
- # we remove the attribute list and add our newly formated one.
- $Result.psobject.properties.remove('attributes')
- $Result | Add-Member -MemberType NoteProperty -Name "attributes" -Value $newAttLst
- # send it to logstash
- $JSON = $Result | ConvertTo-json
- $uri = "https://"+$logstashIP
- $empty = Invoke-WebRequest -uri $uri -Method POST -Body $JSON -UseBasicParsing -Headers $headersLog
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement