-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvulnlab.tf
280 lines (232 loc) · 6.18 KB
/
vulnlab.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
provider "aws" {
access_key = "ADD YOUR KEY HERE"
secret_key = "ADD YOUR KEY HERE"
region = "us-east-1"
}
data "template_file" "install_script" {
template = "${file("vulnlab.sh")}"
}
data "http" "myip" {
url = "http://ipv4.icanhazip.com"
}
resource "aws_key_pair" "vulnlab" {
key_name = "vulnlab"
public_key = file("~/.ssh/vulnlab.pub")
}
resource "aws_vpc" "vuln_vpc" {
cidr_block = "10.0.0.0/16" # Replace with your desired VPC CIDR block
tags = {
Name = "vuln-vpc"
}
}
resource "aws_subnet" "vuln_subnet" {
vpc_id = aws_vpc.vuln_vpc.id
cidr_block = "10.0.0.0/24" # Replace with your desired subnet CIDR block
availability_zone = "us-east-1a" # Replace with your desired availability zone
tags = {
Name = "vuln-subnet"
}
}
resource "aws_security_group" "vulnlab_sg" {
name_prefix = "vulnlab_sg"
description = "Security group for the vulnlab instance"
vpc_id = aws_vpc.vuln_vpc.id # Associate the security group with the VPC
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 25
to_port = 25
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 81
to_port = 81
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 82
to_port = 82
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 84
to_port = 84
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 85
to_port = 85
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 111
to_port = 111
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 137
to_port = 137
protocol = "udp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 138
to_port = 138
protocol = "udp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 139
to_port = 139
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 161
to_port = 161
protocol = "udp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 199
to_port = 199
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 389
to_port = 389
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 445
to_port = 445
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 636
to_port = 636
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 2049
to_port = 2049
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 4444
to_port = 4444
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 4567
to_port = 4567
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 4568
to_port = 4568
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 6200
to_port = 6200
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 6306
to_port = 6306
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 8080
to_port = 8080
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = 9306
to_port = 9306
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
ingress {
from_port = -1 # ICMP type -1 represents all ICMP traffic
to_port = -1
protocol = "icmp"
cidr_blocks = ["${chomp(data.http.myip.response_body)}/32"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "vulnlab_sg"
}
}
resource "aws_instance" "vulndocker" {
ami = "ami-007855ac798b5175e" # Specify the AMI ID for your desired Ubuntu version.
instance_type = "t2.medium" # Specify the instance type.
key_name = "vulnlab" # Specify the name of the key pair you want to use to connect to the instance.
vpc_security_group_ids = [aws_security_group.vulnlab_sg.id]
subnet_id = aws_subnet.vuln_subnet.id # Specify the subnet ID
associate_public_ip_address = true # Assign a public IP address to the instance
# Configure the user data to install vulnlab on the instance
user_data = "${data.template_file.install_script.rendered}"
tags = {
Name = "vulndocker"
}
}
resource "aws_internet_gateway" "vuln_igw" {
vpc_id = aws_vpc.vuln_vpc.id
tags = {
Name = "vuln-igw"
}
}
resource "aws_route_table" "vuln_route_table" {
vpc_id = aws_vpc.vuln_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.vuln_igw.id
}
tags = {
Name = "vuln-route-table"
}
}
resource "aws_route_table_association" "vuln_route_association" {
subnet_id = aws_subnet.vuln_subnet.id
route_table_id = aws_route_table.vuln_route_table.id
}