0

导出 PDF 和 HTML 格式的报告时,报告是空的,我可以说最好有一个报告属性,但是在运行 API 5 个小时并搜索我能想到的所有方法后,我没有找到任何引用它的东西。

对于那些感兴趣的人,这是我开始优化它之前的起始脚本。

https://github.com/Pwd9000-ML/NessusV7-Report-Export-PowerShell/blob/master/NessusPro_v7_Report_Exporter_Tool.ps1

add-type @" 
    using System.Net; 
    using System.Security.Cryptography.X509Certificates; 
    public class TrustAllCertsPolicy : ICertificatePolicy { 
        public bool CheckValidationResult( 
            ServicePoint srvPoint, X509Certificate certificate, 
            WebRequest request, int certificateProblem) { 
                return true; 
                } 
    } 
"@ 
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
[System.Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$GNR = @{
    OutputDir = "$Env:SystemDrive\Nessus\$(([DateTime]::Now).ToString("yyyy-MM-dd"))"
    StatusUri = [System.Collections.ArrayList]::new()
}

#------------------Input Variables----------------------------------------------------------------- 
$Baseurl = "https://$($env:COMPUTERNAME):8834"
$Username = <Removed>
$Password = <Removed>
$ContentType = "application/json"
$POSTMethod = 'POST' 
$GETMethod = 'GET'

#------------------Stage props to obtain session token (Parameters)-------------------------------- 
$session = @{ 
    Uri         = $Baseurl + "/session" 
    ContentType = $ContentType 
    Method      = $POSTMethod 
    Body        = convertto-json (New-Object PSObject -Property @{username = $Username; password = $Password})
} 

#------------------Commit session props for token header X-cookie---------------------------------- 
$TokenResponse = Invoke-RestMethod @session
if ($TokenResponse) { 
    $Header = @{"X-Cookie" = "token=" + $TokenResponse.token} 
} else {
    Write-nLog -Message "Error occured obtaining session token. Script Terminating... Please ensure Username and Password Correct." -Type Error -TerminatingError
} 

IF (![System.IO.Directory]::Exists($GNR.OutputDir)) {
    New-Item -Path $GNR.OutputDir  -ItemType directory -Force |Out-Null
}

#------------------Output completed scans---------------------------------------------------------- 
$Scans = (Invoke-RestMethod -Uri "$baseurl/scans" -Headers $Header -Method $GETMethod -ContentType "application/json").scans

ForEach ($Format in @("nessus","pdf")) {
    $StatusURI = [System.Collections.ArrayList]::new()
    $StatusArray = [System.Collections.ArrayList]::new()
    ForEach ($Scan in $Scans) {
        Add-Content -Path "$($GNR.OutputDir)\ScanReport.txt" -Value "$($Scan.Name) ($($Scan.status))"
        IF ($Scan.status -eq "Completed") {
            $File = (Invoke-RestMethod -URI "$baseurl/scans/$($Scan.ID)/export" -ContentType $ContentType -Headers $Header -Method $POSTMethod -Body $(convertto-json (New-Object PSObject -Property @{format = "$Format"}))).file
            [Void]$StatusArray.Add(
                [pscustomobject]@{
                    ScanName    = $scan.name
                    StatusUri   = $baseurl + "/scans" + "/" + $Scan.id + "/export/" + "$file" + "/status"
                    DownloadUri = $baseurl + "/scans" + "/" + $Scan.id + "/export/" + "$file" + "/download"
                }
            )
        }
    }
    #------------------Check Status of Export requests------------------------------------------------- 
    While ($StatusArray.StatusUri.count -GT $StatusURI.Count) {
        ForEach ($ScanStatus in $StatusArray.StatusURI) {
            IF ((Invoke-RestMethod -Uri $ScanStatus -ContentType $ContentType -Headers $Header -Method $GETMethod).status -EQ "Ready") {
                if ($StatusURI -notcontains $ScanStatus) {
                    Write-Host "Adding $ScanStatus"
                    [void]$StatusURI.Add($ScanStatus)
                }
            } Else {
                Write-nLog -Type "Info" -Message "Not all scans complete. ($($GNR.StatusURI.Count)/$($StatusArray.StatusUri.count)"
                Start-Sleep -s 5
            }
        }
    }

    #------------------Download the Reports------------------------------------------------------------ 
    $ExportUri = $StatusArray.DownloadUri
    $outputs = $StatusArray.ScanName

    foreach ($i in 0..($ExportUri.Count - 1)) {
        Write-nLog -Type Info -Message "Exporting Report: $($outputs[$i])"
        Invoke-WebRequest -Uri $ExportUri[$i] -ContentType $ContentType -Headers $Header -Method $GETMethod -OutFile "$($GNR.OutputDir)\$($outputs[$i]).$Format"                  
    }
}
#------------------Script END----------------------------------------------------------------------
4

1 回答 1

0

您可以在POST /scans/{id}/export端点上设置几个附加参数。这里遗漏的重要一点是chapters它接受所需内容部分的分号分隔列表。这必须为pdfhtml类型的导出设置,否则您会得到一个空结果。

例如,要获取执行摘要,除了formatof html//等,pdf设置为. 其他可用选项是:csvchaptersvuln_hosts_summary

  • vuln_by_host
  • compliance_exec
  • remediations
  • vuln_by_plugin
  • compliance

希望这也能帮助下一个尝试调试空 Nessus API 导出的人!

有关您的版本的完整 API 文档,请查看https://{YOUR_NESSUS_INSTALL}/api

于 2020-10-16T12:17:18.870 回答