potatoqualitee / tentools

💙 tenable.sc / nessus / acas powershell module
BSD 3-Clause "New" or "Revised" License
38 stars 7 forks source link

Save-TNReportResult.ps1 saves files with .zip extension but are not zip files #103

Open chrisbensch opened 2 years ago

chrisbensch commented 2 years ago

I use this command to download report results and save locally: Start-TNReport -ReportId 123 -wait | Get-TNReportResult | Save-TNReportResult -Path C:\Temp\reports

The report format is PDF yet the file on disk ends with .zip. It is actually a PDF with a bad name. Here is the line where this happens: Line 47 $filename = Join-Path -Path $Path -ChildPath "$($file.Name.Split([IO.Path]::GetInvalidFileNameChars()) -join '')-$($file.Id)-reportresults.zip"

This happens with all report types, PDF and CSV, that I've generated. I couldn't find an option to save the files directly without change the name or adding zip to them. Am I doing something wrong with my command?

potatoqualitee commented 2 years ago

heyy thanks for using tentools 😊 interesting! no, that is not a command ive used or tested often so the error is likely on my side. im not actively working on this project at the moment but would do a new release if you would like to create a pull request.

chrisbensch commented 2 years ago

If I can figure out the fix I will definitely submit!

chrisbensch commented 2 years ago

Digging through the public functions and looking at Get-TNReportResult.ps1 I see the path requesting the 'type' which is a piece I need to properly name the files. However, it's not making it through to the end result. In the try block the Invoke-TNRequest data is piped to ConvertFrom-TNRestResponse. If I modify Get-TNReportResult.ps1 and remove this last pipe, I now get 'type' returned on the object. It seems to me it's in the ConvertFrom-TNRestResponse.ps1 file, this is where I'll focus for now.

chrisbensch commented 2 years ago

Invoking the requests manually shows that Get-TNReportResult.ps1 does in fact return the necessary information, but ConvertFrom-TNRestResponse.ps1 somehow is removing the 'type'. I do see where it appears to handle the type information, but haven't figured out yet why it's not making it through.

potatoqualitee commented 2 years ago

Sometimes, the best results are in the .results section of the initial return, so you'll have to go one above that, perhaps by making two distinct calls. If ConvertFrom-TNRestResponse doesn't have a -Raw parameter, you could force it to return the whole thing (I haven't looked). Oh! Or maybe you can get it using HEAD like here: https://github.com/potatoqualitee/disarepotools/blob/main/public/Get-DisaFile.ps1#L230

chrisbensch commented 2 years ago

Ok, I think I've fixed it.."it works on my system"! I modified two files, ConvertFrom-TNRestResponse.ps1 and Save-TNReportResult.ps1. This allows the Type to be passed through correctly and save based on that file type. I'll have to wait until I'm home to submit the pull request.

potatoqualitee commented 2 years ago

awesome! thank you so much, looking forward to it