Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions modules/aws_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,24 @@ def show(self) -> None:
for instance in instances:
if instance["State"]["Name"] == "running":
instances_running = True
# Find the Name tag
instance_name = None
for tag in instance["Tags"]:
if tag["Key"] == "Name":
instance_name = tag["Value"]
break

if instance_name is None:
instance_name = "Unknown"

response.append(
[
instance["Tags"][0]["Value"],
instance_name,
instance["State"]["Name"],
instance["NetworkInterfaces"][0]["Association"]["PublicIp"],
instance["InstanceId"],
]
)
instance_name = instance["Tags"][0]["Value"]
if instance_name.startswith("ar-splunk"):
splunk_ip = instance["NetworkInterfaces"][0]["Association"][
"PublicIp"
Expand Down Expand Up @@ -443,8 +452,18 @@ def show(self) -> None:
+ self.config["general"]["attack_range_password"]
)
else:
# Find the Name tag for non-running instances
instance_name = None
for tag in instance["Tags"]:
if tag["Key"] == "Name":
instance_name = tag["Value"]
break

if instance_name is None:
instance_name = "Unknown"

response.append(
[instance["Tags"][0]["Value"], instance["State"]["Name"]]
[instance_name, instance["State"]["Name"]]
)

print()
Expand Down
20 changes: 16 additions & 4 deletions modules/aws_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ def get_all_instances(key_name, ar_name, region):
for instance in reservation['Instances']:
if instance['State']['Name']!='terminated':
if len(instance['Tags']) > 0:
tag_value = instance['Tags'][0]['Value']
if tag_value.startswith('ar-'):
# Find the Name tag
tag_value = None
for tag in instance['Tags']:
if tag['Key'] == 'Name':
tag_value = tag['Value']
break

if tag_value and tag_value.startswith('ar-'):
if (key_name in tag_value) and (ar_name in tag_value):
instances.append(instance)

Expand All @@ -38,8 +44,14 @@ def get_all_instances(key_name, ar_name, region):
def get_instance_by_name(ec2_name, key_name, ar_name, region):
instances = get_all_instances(key_name, ar_name, region)
for instance in instances:
str = instance['Tags'][0]['Value']
if str == ec2_name:
# Find the Name tag
instance_name = None
for tag in instance['Tags']:
if tag['Key'] == 'Name':
instance_name = tag['Value']
break

if instance_name == ec2_name:
return instance

def get_instances_by_ids(instance_ids, ec2_name, key_name, ar_name, region):
Expand Down
1 change: 1 addition & 0 deletions terraform/aws/modules/caldera-server/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ resource "aws_instance" "caldera_server" {
volume_type = "gp2"
volume_size = "60"
delete_on_termination = "true"
encrypted = "true"
}

tags = {
Expand Down
7 changes: 7 additions & 0 deletions terraform/aws/modules/kali-server/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ resource "aws_instance" "kali_machine" {
Name = "ar-kali-${var.general.key_name}-${var.general.attack_range_name}"
}

root_block_device {
volume_type = "gp2"
volume_size = "20"
delete_on_termination = "true"
encrypted = "true"
}

provisioner "remote-exec" {
inline = ["echo booted"]

Expand Down
1 change: 1 addition & 0 deletions terraform/aws/modules/linux-server/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ resource "aws_instance" "linux_server" {
volume_type = "gp2"
volume_size = "60"
delete_on_termination = "true"
encrypted = "true"
}

tags = {
Expand Down
1 change: 1 addition & 0 deletions terraform/aws/modules/nginx-server/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ resource "aws_instance" "nginx_server" {
volume_type = "gp2"
volume_size = "20"
delete_on_termination = "true"
encrypted = "true"
}

tags = {
Expand Down
1 change: 1 addition & 0 deletions terraform/aws/modules/phantom-server/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ resource "aws_instance" "phantom-server" {
volume_type = "gp2"
volume_size = "30"
delete_on_termination = "true"
encrypted = "true"
}
tags = {
Name = "ar-phantom-${var.general.key_name}-${var.general.attack_range_name}"
Expand Down
7 changes: 7 additions & 0 deletions terraform/aws/modules/snort-server/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ resource "aws_instance" "snort_sensor" {
Name = "ar-snort-${var.general.key_name}-${var.general.attack_range_name}"
}

root_block_device {
volume_type = "gp2"
volume_size = "20"
delete_on_termination = "true"
encrypted = "true"
}

provisioner "remote-exec" {
inline = ["echo booted"]

Expand Down
1 change: 1 addition & 0 deletions terraform/aws/modules/splunk-server/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ resource "aws_instance" "splunk-server" {
volume_type = "gp2"
volume_size = "120"
delete_on_termination = "true"
encrypted = "true"
}

tags = {
Expand Down
1 change: 1 addition & 0 deletions terraform/aws/modules/windows/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ EOF
root_block_device {
delete_on_termination = true
volume_size = 50
encrypted = "true"
}

provisioner "remote-exec" {
Expand Down
7 changes: 7 additions & 0 deletions terraform/aws/modules/zeek-server/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ resource "aws_instance" "zeek_sensor" {
Name = "ar-zeek-${var.general.key_name}-${var.general.attack_range_name}"
}

root_block_device {
volume_type = "gp2"
volume_size = "20"
delete_on_termination = "true"
encrypted = "true"
}

provisioner "remote-exec" {
inline = ["echo booted"]

Expand Down