Created
September 3, 2019 14:15
-
-
Save thebeebs/14163a865788eb0ded1dedb12b8f9877 to your computer and use it in GitHub Desktop.
PowerShell Lambda Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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