# Author: Scott Sutherland, NetSPI (@_nullbind / nullbind) function Parse-DataSourceConfig { param ( [string]$ConfigPath ) # Load the XML config [xml]$configXml = Get-Content -Path $ConfigPath # Define a hashtable to store results $result = @{} # Parse the server and port from the connection URL $connectionUrl = $configXml.server.subsystem.datasources.datasource."connection-url" if ($connectionUrl -match "jdbc:mysql://([^:/]+)(?::(\d+))?") { $result.Server = $matches[1] $result.Port = if ($matches[2]) { $matches[2] } else { "3306" } # Default MySQL port } # Get the username $result.Username = $configXml.server.subsystem.datasources.datasource.security."user-name" # Get the password $result.Password = $configXml.server.subsystem.datasources.datasource.security.password # Get the keystore password from the vault section $keystorePassword = $configXml.server.security.vault."vault-option" | Where-Object { $_.name -eq "KEYSTORE_PASSWORD" } $result.KeystorePassword = $keystorePassword.value # Convert hashtable to PowerShell object $resultObject = [PSCustomObject]$result # Output the result object return $resultObject } # Example usage $parsedConfig = Parse-DataSourceConfig -ConfigPath "c:\temp\configs\standalone.xml" $parsedConfig <# standalone.xml used by jboss jdbc:mysql://localhost:3306/mydatabase mysql ${VAULT::vault::mydbuser} ${VAULT::vault::mydbpassword} 5 20 true true 5000 false com.mysql.jdbc.jdbc2.optional.MysqlXADataSource #>