itm4n / PrivescCheck

Privilege Escalation Enumeration Script for Windows
BSD 3-Clause "New" or "Revised" License
2.91k stars 422 forks source link

Convert-To-XML error due to invalid character #24

Closed mpgn closed 3 years ago

mpgn commented 3 years ago

Hello

I have an issue when exporting the file using XML (only xml is buggy)

image

Tested on Windows server 2016 (1607), PSversion 5.1

I can provide more info if needed :)

itm4n commented 3 years ago

Hi!

One would expect that ConvertTo-Xml properly handles and escapes invalid characters, but it does not as it turns out...

PS C:\> [char]0x00  | ConvertTo-Xml
ConvertTo-Xml : '.', hexadecimal value 0x00, is an invalid character.
At line:1 char:15
+ [char]0x00  | ConvertTo-Xml
+               ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [ConvertTo-Xml], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertToXmlCommand

PS C:\> [char]0x01  | ConvertTo-Xml
ConvertTo-Xml : '☺', hexadecimal value 0x01, is an invalid character.
At line:1 char:15
+ [char]0x01  | ConvertTo-Xml
+               ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [ConvertTo-Xml], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertToXmlCommand

PS C:\> [char]0x02  | ConvertTo-Xml
ConvertTo-Xml : '☻', hexadecimal value 0x02, is an invalid character.
At line:1 char:15
+ [char]0x02  | ConvertTo-Xml
+               ~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [ConvertTo-Xml], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertToXmlCommand

PS C:\> [char]0x41  | ConvertTo-Xml

xml                            Objects
---                            -------
version="1.0" encoding="utf-8" Objects

I'll have to add a function for sanitizing the output before exporting to XML.

itm4n commented 3 years ago

Before converting the result to XML, I now strip all the potentially invalid XML characters from the ResultRawString member. I found a very efficient way to do so on StackOverflow. :slightly_smiling_face:

Could you test again in the same conditions and tell me if it's ok?

mpgn commented 3 years ago

Yep, fixed ! I let you the satisfaction of closing the issue :)

mpgn commented 3 years ago

(also thx for the beautiful color, much better ! )

itm4n commented 3 years ago

Thanks for the confirmation! :+1: