Skip to content

Commit 4ac6262

Browse files
committed
fix: Prevent AMI name confusion attack
1 parent ccf418e commit 4ac6262

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

chapter04/virtualmachine.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Right click on the *.ps1 file and select Run with PowerShell
99
$ErrorActionPreference = "Stop"
1010

11-
$AMIID=aws ec2 describe-images --filters "Name=name,Values=amzn2-ami-hvm-2.0.202*-x86_64-gp2" --query "Images[0].ImageId" --output text
11+
$AMIID=aws ec2 describe-images --owner amazon --filters "Name=name,Values=amzn2-ami-hvm-2.0.202*-x86_64-gp2" --query "Images[0].ImageId" --output text
1212
$VPCID=aws ec2 describe-vpcs --filter "Name=isDefault, Values=true" --query "Vpcs[0].VpcId" --output text
1313
$SUBNETID=aws ec2 describe-subnets --filters "Name=vpc-id, Values=$VPCID" --query "Subnets[0].SubnetId" --output text
1414
$INSTANCEID=aws ec2 run-instances --image-id $AMIID --instance-type t3.micro --subnet-id $SUBNETID --iam-instance-profile "Name=ec2-ssm-core" --query "Instances[0].InstanceId" --output text

chapter04/virtualmachine.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash -e
22
# You need to install the AWS Command Line Interface from http://aws.amazon.com/cli/
3-
AMIID="$(aws ec2 describe-images --filters "Name=name,Values=amzn2-ami-hvm-2.0.202*-x86_64-gp2" --query "Images[0].ImageId" --output text)"
3+
AMIID="$(aws ec2 describe-images --owner amazon --filters "Name=name,Values=amzn2-ami-hvm-2.0.202*-x86_64-gp2" --query "Images[0].ImageId" --output text)"
44
VPCID="$(aws ec2 describe-vpcs --filter "Name=isDefault, Values=true" --query "Vpcs[0].VpcId" --output text)"
55
SUBNETID="$(aws ec2 describe-subnets --filters "Name=vpc-id, Values=$VPCID" --query "Subnets[0].SubnetId" --output text)"
66
INSTANCEID="$(aws ec2 run-instances --image-id "$AMIID" --instance-type t3.micro --subnet-id "$SUBNETID" --iam-instance-profile "Name=ec2-ssm-core" --query "Instances[0].InstanceId" --output text)"

0 commit comments

Comments
 (0)