Prisma Public Cloud Query - Exclude AWS security group that is not associated with any resources

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements

Prisma Public Cloud Query - Exclude AWS security group that is not associated with any resources

L0 Member

Hi,

 

Some policies are producing alerts against SGs that are not associated with any resources.

Can you please advise how to customize the query and exclude those SGs? 

 

For example, policy "AWS Security Groups allow internet traffic from internet to MYSQL port (3306)"  is defined as follows:

config where cloud.type = 'aws' AND api.name='aws-ec2-describe-security-groups' AND json.rule = (((ipPermissions[?(@.toPort > 3306 && @.fromPort < 3306)].ipRanges[*] contains 0.0.0.0/0) or (ipPermissions[?(@.toPort == 3306 || @.fromPort == 3306)].ipRanges[*] contains 0.0.0.0/0)) or ((ipPermissions[?(@.toPort > 3306 && @.fromPort < 3306)].ipv6Ranges[*].cidrIpv6 contains ::/0) or (ipPermissions[?(@.toPort == 3306 || @.fromPort == 3306)].ipv6Ranges[*].cidrIpv6 contains ::/0)))

 

 

Thank you

1 accepted solution

Accepted Solutions

L4 Transporter

There isn't a way to exclude SGs attached to any kind of resources, but you can at least put in a few more restrictions.  For example, the below query will return all security groups that are open to the public on port 22 that are on a VPC which contains an IGW with an EC2 instance attached.

 

config where api.name = 'aws-ec2-describe-security-groups' as X; config where api.name = 'aws-ec2-describe-internet-gateways' as Y; config where api.name = 'aws-ec2-describe-instances' as Z; filter '$.Z.securityGroups[*].groupId contains $.X.groupId and $.Y.attachments[*].vpcId contains $.X.vpcId and ($.X.ipPermissions[?(@.toPort==22||@.fromPort==22)].ipv6Ranges[*].cidrIpv6 contains ::/0 or $.X.ipPermissions[?(@.toPort==22||@.fromPort==22)].ipRanges[*] contains 0.0.0.0/0 or $.X.ipPermissions[?(@.toPort>22&&@.fromPort<22)].ipv6Ranges[*].cidrIpv6 contains ::/0 or $.X.ipPermissions[?(@.toPort>22&&@.fromPort<22)].ipRanges[*] contains 0.0.0.0/0)'; show X;

 

Hope this helps.

View solution in original post

1 REPLY 1

L4 Transporter

There isn't a way to exclude SGs attached to any kind of resources, but you can at least put in a few more restrictions.  For example, the below query will return all security groups that are open to the public on port 22 that are on a VPC which contains an IGW with an EC2 instance attached.

 

config where api.name = 'aws-ec2-describe-security-groups' as X; config where api.name = 'aws-ec2-describe-internet-gateways' as Y; config where api.name = 'aws-ec2-describe-instances' as Z; filter '$.Z.securityGroups[*].groupId contains $.X.groupId and $.Y.attachments[*].vpcId contains $.X.vpcId and ($.X.ipPermissions[?(@.toPort==22||@.fromPort==22)].ipv6Ranges[*].cidrIpv6 contains ::/0 or $.X.ipPermissions[?(@.toPort==22||@.fromPort==22)].ipRanges[*] contains 0.0.0.0/0 or $.X.ipPermissions[?(@.toPort>22&&@.fromPort<22)].ipv6Ranges[*].cidrIpv6 contains ::/0 or $.X.ipPermissions[?(@.toPort>22&&@.fromPort<22)].ipRanges[*] contains 0.0.0.0/0)'; show X;

 

Hope this helps.

  • 1 accepted solution
  • 5118 Views
  • 1 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!