Skip to content

Instantly share code, notes, and snippets.

@thebeebs
Created September 3, 2019 14:15
Show Gist options
  • Save thebeebs/14163a865788eb0ded1dedb12b8f9877 to your computer and use it in GitHub Desktop.
Save thebeebs/14163a865788eb0ded1dedb12b8f9877 to your computer and use it in GitHub Desktop.
PowerShell Lambda Script
#Requires -Modules @{ModuleName='AWSPowerShell.NetCore';ModuleVersion='3.3.343.0'}
$rulesRemoved = 0
Get-EC2SecurityGroup | ForEach-Object -Process {
$securityGroupId = $_.GroupId
$_.IpPermission | ForEach-Object -Process {
if($_.ToPort -eq 3389) {
Write-Host "Found open RDP port for $securityGroupId"
Revoke-EC2SecurityGroupIngress -GroupId $securityGroupId -IpPermission $_
Write-Host "Removed open RDP port for $securityGroupId"
$rulesRemoved++
}
}
}
Write-Host "Scan complete and removed $rulesRemoved EC2 security group ingress rules"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment