mirror of
https://github.com/NetSPI/PowerHuntShares.git
synced 2025-06-28 21:58:42 +02:00
Add files via upload
This commit is contained in:
53
Scripts/ConfigParsers/parser-context.xml.ps1
Normal file
53
Scripts/ConfigParsers/parser-context.xml.ps1
Normal file
@ -0,0 +1,53 @@
|
||||
# Author: Scott Sutherland, NetSPI (@_nullbind / nullbind)
|
||||
|
||||
# Function to extract credentials from a given context.xml file
|
||||
function Get-CredentialsFromContextXml {
|
||||
param (
|
||||
[string]$contextXmlPath
|
||||
)
|
||||
|
||||
# Check if the file exists
|
||||
if (-Not (Test-Path $contextXmlPath)) {
|
||||
Write-Host "File not found: $contextXmlPath"
|
||||
return
|
||||
}
|
||||
|
||||
# Load the XML file
|
||||
[xml]$xml = Get-Content $contextXmlPath
|
||||
|
||||
# Extract username and password from the Resource element
|
||||
$username = $xml.Context.Resource | Where-Object { $_.name -eq 'jdbc/MyDB' } | Select-Object -ExpandProperty username
|
||||
$password = $xml.Context.Resource | Where-Object { $_.name -eq 'jdbc/MyDB' } | Select-Object -ExpandProperty password
|
||||
|
||||
# Create a PowerShell object to hold the extracted information
|
||||
$credentials = [PSCustomObject]@{
|
||||
Username = $username
|
||||
Password = $password
|
||||
}
|
||||
|
||||
# Return the credentials object
|
||||
return $credentials
|
||||
}
|
||||
|
||||
# Example usage of the function
|
||||
$exampleFilePath = "c:\temp\configs\context.xml"
|
||||
$credentials = Get-CredentialsFromContextXml -contextXmlPath $exampleFilePath
|
||||
|
||||
# Display the credentials
|
||||
$credentials
|
||||
|
||||
<# context.xml
|
||||
<Context>
|
||||
<Resource name="jdbc/MyDB"
|
||||
auth="Container"
|
||||
type="javax.sql.DataSource"
|
||||
maxTotal="100"
|
||||
maxIdle="30"
|
||||
maxWaitMillis="10000"
|
||||
username="dbuser"
|
||||
password="dbpassword"
|
||||
driverClassName="com.mysql.jdbc.Driver"
|
||||
url="jdbc:mysql://localhost:3306/mydb"/>
|
||||
</Context>
|
||||
|
||||
#>
|
Reference in New Issue
Block a user