Skip to content

Commit 400f636

Browse files
Added new security commands
1 parent f07961b commit 400f636

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

cloudiscovery/provider/security/data/commands_enabled.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
"method": "ebs_encryption",
1414
"short_description": "Check that Amazon Elastic Block Store (EBS) encryption is enabled by default.",
1515
},
16+
"restricted-ssh": {
17+
"parameters": [
18+
{"name": "restricted_ssh", "default_value": "no", "type": "bool"}
19+
],
20+
"class": "EC2",
21+
"method": "restricted_ssh",
22+
"short_description": "Checks whether SG that are in use disallow unrestricted incoming SSH traffic.",
23+
},
1624
"imdsv2-check": {
1725
"parameters": [{"name": "imdsv2_check", "default_value": "no", "type": "bool"}],
1826
"class": "EC2",
@@ -25,4 +33,12 @@
2533
"method": "pitr_enabled",
2634
"short_description": "Checks that point in time recovery is enabled for Amazon DynamoDB tables.",
2735
},
36+
"cloudtrail-enabled": {
37+
"parameters": [
38+
{"name": "cloudtrail_enabled", "default_value": "no", "type": "bool"}
39+
],
40+
"class": "CLOUDTRAIL",
41+
"method": "cloudtrail_enabled",
42+
"short_description": "Checks whether AWS CloudTrail is enabled in your AWS account.",
43+
},
2844
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from provider.security.command import SecurityOptions
2+
3+
from shared.common import (
4+
Resource,
5+
ResourceDigest,
6+
SecurityValues,
7+
)
8+
9+
10+
class CLOUDTRAIL:
11+
def __init__(self, options: SecurityOptions):
12+
self.options = options
13+
14+
def cloudtrail_enabled(self, cloudtrail_enabled):
15+
16+
client = self.options.client("cloudtrail")
17+
18+
trails = client.list_trails()
19+
20+
resources_found = []
21+
22+
if not trails["Trails"]:
23+
resources_found.append(
24+
Resource(
25+
digest=ResourceDigest(id="cloudtrail", type="cloudtrail_enabled"),
26+
details="CLOUDTRAIL disabled",
27+
name="cloudtrail",
28+
group="cloudtrail_security",
29+
security=SecurityValues(
30+
status="CRITICAL",
31+
parameter="cloudtrail_enabled",
32+
value="False",
33+
),
34+
)
35+
)
36+
37+
return resources_found

cloudiscovery/provider/security/resource/commands/EC2.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,59 @@ def imdsv2_check(self, imdsv2_check):
7070
)
7171

7272
return resources_found
73+
74+
def restricted_ssh(self, restricted_ssh):
75+
76+
client = self.options.client("ec2")
77+
78+
security_groups = client.describe_security_groups()
79+
80+
resources_found = []
81+
82+
# pylint: disable=too-many-nested-blocks
83+
for security_group in security_groups["SecurityGroups"]:
84+
for ip_permission in security_group["IpPermissions"]:
85+
if "FromPort" in ip_permission and "ToPort" in ip_permission:
86+
# Port 22 possible opened using port range
87+
if ip_permission["FromPort"] <= 22 >= ip_permission["ToPort"]:
88+
# IPv4
89+
for cidr in ip_permission["IpRanges"]:
90+
if cidr["CidrIp"] == "0.0.0.0/0":
91+
resources_found.append(
92+
Resource(
93+
digest=ResourceDigest(
94+
id=security_group["GroupId"],
95+
type="restricted_ssh",
96+
),
97+
details="The SSH port of this security group is opened to the world.",
98+
name=security_group["GroupName"],
99+
group="ec2_security",
100+
security=SecurityValues(
101+
status="CRITICAL",
102+
parameter="restricted_ssh",
103+
value="False",
104+
),
105+
)
106+
)
107+
108+
# IPv6
109+
for cidr in ip_permission["Ipv6Ranges"]:
110+
if cidr["CidrIpv6"] == "::/0":
111+
resources_found.append(
112+
Resource(
113+
digest=ResourceDigest(
114+
id=security_group["GroupId"],
115+
type="restricted_ssh",
116+
),
117+
details="The SSH port of this security group is opened to the world.",
118+
name=security_group["GroupName"],
119+
group="ec2_security",
120+
security=SecurityValues(
121+
status="CRITICAL",
122+
parameter="restricted_ssh",
123+
value="False",
124+
),
125+
)
126+
)
127+
128+
return resources_found

0 commit comments

Comments
 (0)