Find Java Based Azure App Services
A quick Azure PowerShell command to locate any Java based Azure App Services and Functions so you can check if they are vulnerable to the CVE-2021-44228 Apache Log4j2 vulnerability. Get-AzWebApp | ForEach-Object{ Get-AzWebApp -ResourceGroupName $_.ResourceGroup -Name $_.Name | Select-Object -Property Name, @{l='JavaVersion';e={$_.SiteConfig.JavaVersion}}, ResourceGroup, Id } | Format-Table
Quick and Easy Password Generator
This is a quick and easy password/random character generator. It returns random numbers between 33 and 126 and converts the number to the corresponding ASCII character. $password = [string]::Empty 1..32 | ForEach-Object { $password += [char]$(33..126 | Get-Random) }
Apply CVE-2020-1350 Workaround to Remote Computer
A patch has been released for the security vulnerability CVE-2020-1350, which has a 10 out of 10 on the CVSS scale and affects all Windows DNS servers from 2003 to 2019. However, since not everyone can patch systems right away, Microsoft has provided a workaround. The workaround restricts the size of DNS response packets, which only requires a restart of...
Run PSExec From PowerShell
PowerShell remoting help in a lot of areas, but there are times when you need to use PSExec. For those instances, I’ve created a function that you can use to run a command on a remote machine using PSExec. Function ExecutePsExec($computer, $command){ $ping = Test-Connection $computer -Count 1 -Quiet if($ping){ $StdOutput = (Join-path $env:temp "$($computer).txt") Start-Process -FilePath $psexec -ArgumentList "-s...
Expand Shortened URLs
# Create Web Request Object $request = [System.Net.WebRequest]::Create($url) # Make it think we are using Edge on Windows 10. Required for some shorteners. $request.UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246' # Get the expanded URL $request.GetResponse().ResponseUri.AbsoluteUri
Elevate Script to Run As Administrator
# Request elevation with administration rights If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { $arguments = "& '" + $myinvocation.mycommand.definition + "'" Start-Process powershell -Verb runAs -ArgumentList $arguments Break } else { # Code to run elevated here }
Run Multiple Commands on Remote Machine
# Create a persistent connection to remote machine $Session = New-PSSession -ComputerName $Computer -Credential $Credential # Runs on remote machine Invoke-Command -Session $Session -ScriptBlock {Stop-Service -Name Bits} # Run on local machine Get-Service # Runs on remote machine again Invoke-Command -Session $Session -ScriptBlock {Start-Service -Name Bits}
Run Command on Remote Machine with Credentials
$Credential = Get-Credential Invoke-Command -ComputerName $Computer -ScriptBlock {Stop-Service -Name Bits} -Credential $Credential
Run Command on Remote Machine
$Credential = Get-Credential Invoke-Command -ComputerName $Computer -ScriptBlock {Stop-Service -Name Bits}