Skip to content

Commit 3d0770e

Browse files
committed
Capital One SSRF Terraform Demo file was added to compare the breach with checkov and terrasecure
1 parent 902c6ff commit 3d0770e

1 file changed

Lines changed: 296 additions & 0 deletions

File tree

examples/vulnerable/main.tf

Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
#############################
2+
# Variables
3+
#############################
4+
variable "region" {
5+
default = "eu-west-1"
6+
}
7+
8+
variable "environment" {
9+
default = "demo"
10+
}
11+
12+
variable "profile" {
13+
default = "shayrm"
14+
}
15+
16+
variable "ubuntu-ami" {
17+
default = "ami-0fd8802f94ed1c969"
18+
}
19+
20+
variable "instance_type" {
21+
default = "t2.micro"
22+
}
23+
24+
variable "instance_profile" {
25+
default = "c-demo-role"
26+
}
27+
28+
variable "instance_policy" {
29+
default = "c-demo-policy"
30+
31+
}
32+
33+
variable "base_name" {
34+
default = "c-one-ssrf"
35+
}
36+
37+
variable "bucket_name" {
38+
default = "c-one-demo"
39+
}
40+
41+
variable "key_pair" {
42+
default = "shay-key"
43+
}
44+
45+
#############################
46+
# Locals
47+
#############################
48+
locals {
49+
base_name = "${var.environment}-${var.base_name}"
50+
tags = {
51+
"Name" = local.base_name
52+
"Environment" = var.environment
53+
}
54+
cloudinit_config = <<EOF
55+
#cloud-config
56+
package_update: true
57+
packages:
58+
- jq
59+
- apt-transport-https
60+
- ca-certificates
61+
- curl
62+
- gnupg-agent
63+
- software-properties-common
64+
- git
65+
- python3
66+
- python3-pip
67+
runcmd:
68+
# Install SSRF NodeJS
69+
- cd /opt
70+
- sudo git clone https://github.com/sethsec/Nodejs-SSRF-App.git
71+
- cd Nodejs-SSRF-App/
72+
- sudo ./install.sh
73+
- sudo nodejs ssrf-demo-app.js
74+
EOF
75+
}
76+
77+
#############################
78+
# Providers
79+
#############################
80+
terraform {
81+
required_providers {
82+
aws = {
83+
source = "hashicorp/aws"
84+
version = "~> 4.16"
85+
}
86+
}
87+
88+
required_version = ">= 1.2.0"
89+
90+
}
91+
92+
provider "aws" {
93+
region = var.region
94+
# profile = "${var.profile}"
95+
}
96+
97+
#############################
98+
# VPCs
99+
#############################
100+
resource "aws_vpc" "vpc" {
101+
cidr_block = "172.33.0.0/16"
102+
instance_tenancy = "default"
103+
enable_dns_support = true
104+
enable_dns_hostnames = true
105+
tags = local.tags
106+
}
107+
108+
data "aws_availability_zones" "available" {
109+
state = "available"
110+
}
111+
112+
resource "aws_eip" "eip" {
113+
instance = aws_instance.web-server.id
114+
vpc = true
115+
116+
tags = local.tags
117+
}
118+
119+
#############################
120+
# Internet Gateways
121+
#############################
122+
resource "aws_internet_gateway" "igw" {
123+
vpc_id = aws_vpc.vpc.id
124+
tags = local.tags
125+
}
126+
127+
resource "aws_route" "igw" {
128+
route_table_id = aws_vpc.vpc.default_route_table_id
129+
destination_cidr_block = "0.0.0.0/0"
130+
gateway_id = aws_internet_gateway.igw.id
131+
}
132+
133+
#############################
134+
# Subnets
135+
#############################
136+
resource "aws_subnet" "subnet1" {
137+
vpc_id = aws_vpc.vpc.id
138+
availability_zone = data.aws_availability_zones.available.names[0]
139+
cidr_block = cidrsubnet(aws_vpc.vpc.cidr_block, 8, 0)
140+
141+
tags = merge(local.tags, { "Name" = "${local.tags.Name}-subnet1" })
142+
}
143+
144+
#############################
145+
# Security Groups
146+
#############################
147+
resource "aws_security_group" "sg1" {
148+
name = "sg1"
149+
description = "sg1"
150+
vpc_id = aws_vpc.vpc.id
151+
152+
egress {
153+
from_port = 0
154+
to_port = 0
155+
protocol = "-1"
156+
cidr_blocks = ["0.0.0.0/0"]
157+
}
158+
159+
tags = merge(local.tags, { "Name" = "${local.tags.Name}-sg1" })
160+
}
161+
162+
resource "aws_security_group_rule" "web" {
163+
for_each = toset(["80", "443"])
164+
type = "ingress"
165+
from_port = each.key
166+
to_port = each.key
167+
protocol = "tcp"
168+
cidr_blocks = ["0.0.0.0/0"]
169+
security_group_id = aws_security_group.sg1.id
170+
}
171+
172+
resource "aws_security_group_rule" "ssh" {
173+
type = "ingress"
174+
from_port = 22
175+
to_port = 22
176+
protocol = "tcp"
177+
cidr_blocks = ["0.0.0.0/0"]
178+
security_group_id = aws_security_group.sg1.id
179+
}
180+
181+
#####################################
182+
# Policy Roles and Instance Policy
183+
#####################################
184+
resource "aws_iam_policy" "demo-policy" {
185+
name = var.instance_policy
186+
path = "/"
187+
description = "c-demo policy"
188+
policy = jsonencode(
189+
{
190+
"Version" : "2012-10-17",
191+
"Statement" : [
192+
{
193+
"Effect" : "Allow",
194+
"Action" : [
195+
"s3:*",
196+
"s3-object-lambda:*"
197+
],
198+
"Resource" : "*"
199+
}
200+
]
201+
})
202+
}
203+
204+
resource "aws_iam_role" "demo-role" {
205+
name = var.instance_profile
206+
assume_role_policy = <<EOF
207+
{
208+
"Version": "2012-10-17",
209+
"Statement": [
210+
{
211+
"Effect": "Allow",
212+
"Principal": {
213+
"Service": "ec2.amazonaws.com"
214+
},
215+
"Action": "sts:AssumeRole"
216+
}
217+
]
218+
}
219+
EOF
220+
221+
tags = local.tags
222+
}
223+
224+
resource "aws_iam_role_policy_attachment" "demo-attach" {
225+
role = aws_iam_role.demo-role.name
226+
policy_arn = aws_iam_policy.demo-policy.arn
227+
}
228+
229+
resource "aws_iam_instance_profile" "demo-profile" {
230+
name = var.instance_profile
231+
role = aws_iam_role.demo-role.name
232+
}
233+
#
234+
##############################
235+
# VMs
236+
#############################
237+
238+
resource "aws_instance" "web-server" {
239+
ami = var.ubuntu-ami
240+
instance_type = var.instance_type
241+
availability_zone = data.aws_availability_zones.available.names[0]
242+
iam_instance_profile = var.instance_profile
243+
subnet_id = aws_subnet.subnet1.id
244+
vpc_security_group_ids = [aws_security_group.sg1.id]
245+
associate_public_ip_address = true
246+
key_name = var.key_pair
247+
user_data = local.cloudinit_config
248+
249+
root_block_device {
250+
volume_type = "gp3"
251+
volume_size = 10
252+
delete_on_termination = true
253+
}
254+
255+
lifecycle {
256+
ignore_changes = [ami]
257+
}
258+
259+
tags = local.tags
260+
}
261+
262+
#############################
263+
# Buckets
264+
#############################
265+
resource "aws_s3_bucket" "c-one-demo" {
266+
bucket = var.bucket_name
267+
force_destroy = true
268+
}
269+
270+
resource "aws_s3_bucket_acl" "acl" {
271+
bucket = aws_s3_bucket.c-one-demo.id
272+
acl = "private"
273+
}
274+
275+
# Upload the secret file
276+
resource "aws_s3_object" "object" {
277+
bucket = aws_s3_bucket.c-one-demo.id
278+
key = "top_secret_file"
279+
source = "top_secret_file.csv"
280+
etag = filemd5("top_secret_file.csv")
281+
}
282+
283+
#############################
284+
# Outputs
285+
#############################
286+
output "public_ip" {
287+
value = aws_eip.eip.public_ip
288+
}
289+
290+
output "instance_id" {
291+
value = aws_instance.web-server.id
292+
}
293+
294+
output "bucket_name" {
295+
value = aws_s3_bucket.c-one-demo.id
296+
}

0 commit comments

Comments
 (0)