Project: KICS (Provisioning / Security & Compliance)
File: ee464fc2-54a6-4e22-b10a-c6dcd2474d0c.md

title: Security Group Egress With All Protocols hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: ee464fc2-54a6-4e22-b10a-c6dcd2474d0c Query name: Security Group Egress With All Protocols Platform: CloudFormation Severity: <span style="color:#ff7213">Medium</span> Category: Networking and Firewall URL: AWS Security Group Egress should not specify all protocols to prevent allow traffic on all ports<br> ```yaml title="Positive test num. 1 - yaml file" hl_lines="21 14" Resources: InstanceSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Allow http to client host VpcId: Ref: myVPC SecurityGroupIngress: IpProtocol: -1 FromPort: 80 ToPort: 80 CidrIp: 0.0.0.0/0 SecurityGroupEgress: IpProtocol: -1 FromPort: 80 ToPort: 80 CidrIp: 0.0.0.0/0 OutboundRule: Type: AWS::EC2::SecurityGroupEgress Properties: IpProtocol: -1 FromPort: 0 ToPort: 65535 DestinationSecurityGroupId: Fn::GetAtt: TargetSG GroupId GroupId: Fn::GetAtt: SourceSG GroupId InboundRule: Type: AWS::EC2::SecurityGroupIngress Properties: IpProtocol: -1 FromPort: 0 ToPort: 65535 SourceSecurityGroupId: Fn::GetAtt: SourceSG GroupId GroupId: Fn::GetAtt: TargetSG GroupId ``` ```json title="Positive test num. 2 - json file" hl_lines="43 21" { "Resources": { "InstanceSecurityGroup": { "Type": "AWS::EC2::SecurityGroup", "Properties": { "GroupDescription": "Allow http to client host", "VpcId": { "Ref": "myVPC" }, "SecurityGroupIngress": [ { "CidrIp": "0.0.0.0/0", "IpProtocol": -1, "FromPort": 80, "ToPort": 80 } ], "SecurityGroupEgress": [ { "CidrIp": "0.0.0.0/0", "IpProtocol": -1, "FromPort": 80, "ToPort": 80 } ] } }, "OutboundRule": { "Type": "AWS::EC2::SecurityGroupEgress", "Properties": { "DestinationSecurityGroupId": { "Fn::GetAtt": [ "TargetSG", "GroupId" ] }, "GroupId": { "Fn::GetAtt": [ "SourceSG", "GroupId" ] }, "IpProtocol": -1, "FromPort": 0, "ToPort": 65535 } }, "InboundRule": { "Properties": { "GroupId": { "Fn::GetAtt": [ "TargetSG", "GroupId" ] }, "IpProtocol": -1, "FromPort": 0, "ToPort": 65535, "SourceSecurityGroupId": { "Fn::GetAtt": [ "SourceSG", "GroupId" ] } }, "Type": "AWS::EC2::SecurityGroupIngress" } } } ``` ```yaml title="Negative test num. 1 - yaml file" Resources: InstanceSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Allow http to client host VpcId: Ref: myVPC SecurityGroupIngress: IpProtocol: tcp FromPort: 80 ToPort: 80 CidrIp: 0.0.0.0/0 SecurityGroupEgress: IpProtocol: tcp FromPort: 80 ToPort: 80 CidrIp: 0.0.0.0/0 OutboundRule: Type: AWS::EC2::SecurityGroupEgress Properties: IpProtocol: tcp FromPort: 0 ToPort: 65535 DestinationSecurityGroupId: Fn::GetAtt: TargetSG GroupId GroupId: Fn::GetAtt: SourceSG GroupId InboundRule: Type: AWS::EC2::SecurityGroupIngress Properties: IpProtocol: tcp FromPort: 0 ToPort: 65535 SourceSecurityGroupId: Fn::GetAtt: SourceSG GroupId GroupId: Fn::GetAtt: TargetSG GroupId ``` ```json title="Negative test num. 2 - json file" { "Resources": { "InstanceSecurityGroup": { "Type": "AWS::EC2::SecurityGroup", "Properties": { "GroupDescription": "Allow http to client host", "VpcId": { "Ref": "myVPC" }, "SecurityGroupIngress": [ { "IpProtocol": "tcp", "FromPort": 80, "ToPort": 80, "CidrIp": "0.0.0.0/0" } ], "SecurityGroupEgress": [ { "IpProtocol": "tcp", "FromPort": 80, "ToPort": 80, "CidrIp": "0.0.0.0/0" } ] } }, "OutboundRule": { "Type": "AWS::EC2::SecurityGroupEgress", "Properties": { "IpProtocol": "tcp", "FromPort": 0, "ToPort": 65535, "DestinationSecurityGroupId": { "Fn::GetAtt": [ "TargetSG", "GroupId" ] }, "GroupId": { "Fn::GetAtt": [ "SourceSG", "GroupId" ] } } }, "InboundRule": { "Type": "AWS::EC2::SecurityGroupIngress", "Properties": { "SourceSecurityGroupId": { "Fn::GetAtt": [ "SourceSG", "GroupId" ] }, "GroupId": { "Fn::GetAtt": [ "TargetSG", "GroupId" ] }, "IpProtocol": "tcp", "FromPort": 0, "ToPort": 65535 } } } } ```