# Author: Scott Sutherland, NetSPI (@_nullbind / nullbind) # Function to check if a string is a valid base64-encoded string function IsBase64String { param ([string]$string) if ($string -match '^[a-zA-Z0-9\+/]*={0,2}$' -and ($string.Length % 4 -eq 0)) { return $true } return $false } # Function to process the SiteManager.xml file and extract server information function Get-SiteManagerServerInfo { param ( [string]$xmlFilePath ) # Check if the file exists if (-not (Test-Path $xmlFilePath)) { Write-Error "File not found: $xmlFilePath" return } # Load the XML file $xml = [xml](Get-Content $xmlFilePath) # Iterate through each server entry and extract relevant information $xml.FileZilla3.Servers.Server | ForEach-Object { $decodedPassword = "Invalid or not present" # Access the Pass element's inner text, ensuring it's properly treated as a string [string]$base64Pass = $_.Pass.InnerText # Check if the password is a valid base64 string before decoding if ($base64Pass) { try { # Trim any extra whitespace from the base64 string $cleanPass = $base64Pass.Trim() $decodedPassword = [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($cleanPass)) } catch { $decodedPassword = "Error decoding password: $_" } } # Output the server details [pscustomobject]@{ Server = $_.Host Port = $_.Port Username = $_.User Password = $decodedPassword } } } # Example usage $xmlFilePath = "c:\temp\configs\SiteManager.xml" Get-SiteManagerServerInfo -xmlFilePath $xmlFilePath <# SiteManager.xml ftp.example.com 21 0 0 username SGVsbG9QYXNzd29yZA== 1 0 MODE_DEFAULT 0 Auto 0 My FTP Site Sample FTP site for demonstration 0 0 sftp.example.com 22 1 1 sftpuser SGVsbG9QYXNzd29yZA== 1 0 MODE_DEFAULT 1 Auto 0 My SFTP Site Sample SFTP site 0 0 #>