Skip to content

Commit 1eb7417

Browse files
better negative testing for "Unknown Port Exposed To Internet" (#7725)
* Improved first 3 negative tests for "Unknown Port Exposed To Internet" query to properly reflect valid scenarios
1 parent b927ebf commit 1eb7417

File tree

3 files changed

+56
-26
lines changed

3 files changed

+56
-26
lines changed

assets/queries/terraform/aws/unknown_port_exposed_to_internet/test/negative1.tf

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
resource "aws_security_group" "negative1-1" {
2-
name = "allow_tls"
3-
description = "Allow TLS inbound traffic"
4-
vpc_id = aws_vpc.main.id
52

63
ingress {
7-
description = "TLS from VPC"
8-
from_port = 443
9-
to_port = 443
4+
description = "Remote desktop open private"
5+
from_port = 2383
6+
to_port = 2383
107
protocol = "tcp"
8+
cidr_blocks = ["192.168.0.0/24", "0.0.0.0/0"]
119
}
1210
}
1311

1412
resource "aws_security_group" "negative1-2" {
1513

1614
ingress {
1715
description = "Remote desktop open private"
18-
from_port = 2383
19-
to_port = 2383
16+
from_port = 20
17+
to_port = 20
2018
protocol = "tcp"
21-
cidr_blocks = ["192.168.0.0/24", "192.162.0.0/24"]
19+
ipv6_cidr_blocks = ["::/0"]
2220
}
2321
}
2422

2523
resource "aws_security_group" "negative1-3" {
2624

2725
ingress {
2826
description = "Remote desktop open private"
29-
from_port = 20
30-
to_port = 20
27+
from_port = 0
28+
to_port = 10000
29+
protocol = "tcp"
30+
cidr_blocks = ["192.168.0.0/24", "192.201.0.0/12"]
31+
}
32+
}
33+
34+
resource "aws_security_group" "negative1-4" {
35+
36+
ingress {
37+
description = "Remote desktop open private"
38+
from_port = 0
39+
to_port = 10000
3140
protocol = "tcp"
3241
ipv6_cidr_blocks = ["2001:db8:abcd:0012::/64"]
3342
}

assets/queries/terraform/aws/unknown_port_exposed_to_internet/test/negative2.tf

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,37 @@ resource "aws_security_group" "negative2" {
66

77
resource "aws_vpc_security_group_ingress_rule" "negative2-1" {
88
security_group_id = aws_security_group.negative3.id
9-
from_port = 443
10-
to_port = 443
9+
from_port = 2383
10+
to_port = 2383
1111
ip_protocol = "tcp"
12-
description = "TLS from VPC"
12+
cidr_ipv4 = "0.0.0.0/0"
13+
description = "Remote desktop open private"
1314
}
1415

16+
1517
resource "aws_vpc_security_group_ingress_rule" "negative2-2" {
1618
security_group_id = aws_security_group.negative3.id
17-
from_port = 2383
18-
to_port = 2383
19+
from_port = 20
20+
to_port = 20
21+
ip_protocol = "tcp"
22+
cidr_ipv6 = "::/0"
23+
description = "Remote desktop open private"
24+
}
25+
26+
resource "aws_vpc_security_group_ingress_rule" "negative2-3" {
27+
security_group_id = aws_security_group.negative3.id
28+
from_port = 0
29+
to_port = 10000
1930
ip_protocol = "tcp"
2031
cidr_ipv4 = "192.168.0.0/24"
2132
description = "Remote desktop open private"
2233
}
2334

2435

25-
resource "aws_vpc_security_group_ingress_rule" "negative2-3" {
36+
resource "aws_vpc_security_group_ingress_rule" "negative2-4" {
2637
security_group_id = aws_security_group.negative3.id
27-
from_port = 20
28-
to_port = 20
38+
from_port = 0
39+
to_port = 10000
2940
ip_protocol = "tcp"
3041
cidr_ipv6 = "2001:db8:abcd:0012::/64"
3142
description = "Remote desktop open private"

assets/queries/terraform/aws/unknown_port_exposed_to_internet/test/negative3.tf

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,35 @@ resource "aws_security_group" "negative3" {
66

77
resource "aws_security_group_rule" "negative3-1" {
88
type = "ingress"
9-
from_port = 443
10-
to_port = 443
9+
from_port = 2383
10+
to_port = 2383
1111
protocol = "tcp"
12+
cidr_blocks = ["192.168.0.0/24", "0.0.0.0/0"]
1213
security_group_id = aws_security_group.negative3.id
1314
}
1415

1516
resource "aws_security_group_rule" "negative3-2" {
1617
type = "ingress"
17-
from_port = 2383
18-
to_port = 2383
18+
from_port = 20
19+
to_port = 20
1920
protocol = "tcp"
20-
cidr_blocks = ["192.168.0.0/24", "192.162.0.0/24"]
21+
ipv6_cidr_blocks = ["::/0"]
2122
security_group_id = aws_security_group.negative3.id
2223
}
2324

2425
resource "aws_security_group_rule" "negative3-3" {
2526
type = "ingress"
26-
from_port = 20
27-
to_port = 20
27+
from_port = 0
28+
to_port = 10000
29+
protocol = "tcp"
30+
cidr_blocks = ["192.168.0.0/24", "192.162.0.0/24"]
31+
security_group_id = aws_security_group.negative3.id
32+
}
33+
34+
resource "aws_security_group_rule" "negative3-4" {
35+
type = "ingress"
36+
from_port = 0
37+
to_port = 10000
2838
protocol = "tcp"
2939
ipv6_cidr_blocks = ["2001:db8:abcd:0012::/64"]
3040
security_group_id = aws_security_group.negative3.id

0 commit comments

Comments
 (0)