Skip to content

Commit

Permalink
security groups now auto-delete themselves? ignore those errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacopo committed Aug 12, 2021
1 parent 4f4ea1a commit 4aa2d71
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ctfoood/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,15 @@ def delete_ooo_vm(vm:VM, raise_exceptions=False) -> Tuple[int,str]:

if vm.security_group_id:
all_output += "[*] Deleting the EC2 Security Group\n"
sg = ec2.SecurityGroup(vm.security_group_id)
sg.delete()
try:
sg = ec2.SecurityGroup(vm.security_group_id)
sg.delete()
except ec2.meta.client.exceptions.ClientError as error: # ec2 doesn't have other exception types?
assert error.operation_name == "DeleteSecurityGroup"
if error.response['Error']['Code'] == 'InvalidGroup.NotFound':
all_output += "[-] The security group was auto-deleted? Ignoring.\n"
else:
raise # Ignore anyway?
vm.security_group_id = ""
vm.save()

Expand Down

0 comments on commit 4aa2d71

Please sign in to comment.