From aef17d9fcd0428f8fa884729569f6c6b2104f0e5 Mon Sep 17 00:00:00 2001 From: Fryyyyy Date: Fri, 20 Nov 2026 16:41:26 +1100 Subject: [PATCH 1/3] Only consider images published by Canonical's AWS account Add their official owner-id to the filter --- libcloudforensics/providers/aws/forensics.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libcloudforensics/providers/aws/forensics.py b/libcloudforensics/providers/aws/forensics.py index aafe851f..eed92741 100644 --- a/libcloudforensics/providers/aws/forensics.py +++ b/libcloudforensics/providers/aws/forensics.py @@ -271,7 +271,12 @@ def StartAnalysisVm( # pylint: disable=too-many-arguments,too-many-positional-a # in the region requested. if not ami: logger.info('No AMI provided, fetching one for Ubuntu 22.04') - qfilter = [{'Name': 'name', 'Values': [UBUNTU_2204_FILTER]}] + # Restrict to Canonical's official AWS account so an attacker cannot + # publish a public AMI with a matching Name and have it selected here. + qfilter = [ + {'Name': 'name', 'Values': [UBUNTU_2204_FILTER]}, + {'Name': 'owner-id', 'Values': ['099720109477']} + ] ami_list = aws_account.ec2.ListImages(qfilter) # We should only get 1 AMI image back, if we get multiple we # have no way of knowing which one to use. From 3cd35b76006192cf3d6c6cfab5352eff735c2913 Mon Sep 17 00:00:00 2001 From: Fryyyyy Date: Fri, 20 Nov 2026 16:47:35 +1100 Subject: [PATCH 2/3] Fix line too long --- libcloudforensics/providers/gcp/internal/compute.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libcloudforensics/providers/gcp/internal/compute.py b/libcloudforensics/providers/gcp/internal/compute.py index 94272f1f..92306969 100644 --- a/libcloudforensics/providers/gcp/internal/compute.py +++ b/libcloudforensics/providers/gcp/internal/compute.py @@ -739,6 +739,7 @@ def GetDiskTypes(self, disk_type: str, # Safe to unpack, response is not paged. return common.ExecuteRequest(disk_types_client, 'get', params)[0] + # pylint: disable=line-too-long def GetImageFamily(self, image_family: str, project: Optional[str] = None) -> Dict[str, Any]: """Get image family API object in specified project. @@ -749,16 +750,18 @@ def GetImageFamily(self, image_family: str, Returns: The selected image family API resource: - https://cloud.google.com/compute/docs/reference/rest/v1/images/getFromFamily # pylint: disable=line-too-long + https://cloud.google.com/compute/docs/reference/rest/v1/images/getFromFamily Raises: HttpError if getting image object for the given image family name fails. """ + # pylint: enable=line-too-long images_client = self.GceApi().images() # pylint: disable=no-member params = {'project': project, 'family': image_family} # Safe to unpack, response is not paged. return common.ExecuteRequest(images_client, 'getFromFamily', params)[0] + # pylint: disable=line-too-long def GetNetwork(self, network_name: str) -> Dict[str, Any]: """Get selected network API object in specified project. @@ -767,11 +770,12 @@ def GetNetwork(self, network_name: str) -> Dict[str, Any]: Returns: The selected network API resource: - https://cloud.google.com/compute/docs/reference/rest/v1/networks # pylint: disable=line-too-long + https://cloud.google.com/compute/docs/reference/rest/v1/networks Raises: HttpError if getting network object for the given machine-type name fails. """ + # pylint: enable=line-too-long networks_client = self.GceApi().networks() # pylint: disable=no-member params = { 'project': self.project_id, @@ -2328,13 +2332,15 @@ def __init__( super().__init__( project_id=project_id, zone='', name=name, region=region, **kwargs) + # pylint: disable=line-too-long def GetOperation(self) -> Dict[str, Any]: """Get API operation object for the regional disk. Returns: An API operation object for a Google Regional Compute Engine disk. - https://cloud.google.com/compute/docs/reference/rest/v1/regionDisks/get#response-body # pylint: disable=line-too-long + https://cloud.google.com/compute/docs/reference/rest/v1/regionDisks/get#response-body """ + # pylint: enable=line-too-long gce_disk_client = self.GceApi().regionDisks() # pylint: disable=no-member param = { 'project': self.project_id, 'region': self.region, 'disk': self.name From b8901cfd69db65ce418eefac43bb419093f826a8 Mon Sep 17 00:00:00 2001 From: Fryyyyy Date: Fri, 20 Nov 2026 16:57:54 +1100 Subject: [PATCH 3/3] Add comment with official IDs --- libcloudforensics/providers/aws/forensics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/libcloudforensics/providers/aws/forensics.py b/libcloudforensics/providers/aws/forensics.py index eed92741..60107daf 100644 --- a/libcloudforensics/providers/aws/forensics.py +++ b/libcloudforensics/providers/aws/forensics.py @@ -273,6 +273,7 @@ def StartAnalysisVm( # pylint: disable=too-many-arguments,too-many-positional-a logger.info('No AMI provided, fetching one for Ubuntu 22.04') # Restrict to Canonical's official AWS account so an attacker cannot # publish a public AMI with a matching Name and have it selected here. + # https://ubuntu.com/aws/docs/aws-how-to/instances/find-ubuntu-images/ qfilter = [ {'Name': 'name', 'Values': [UBUNTU_2204_FILTER]}, {'Name': 'owner-id', 'Values': ['099720109477']}