-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkali-gce.pkr.hcl
172 lines (146 loc) · 4.35 KB
/
kali-gce.pkr.hcl
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
packer {
required_plugins {
googlecompute = {
source = "github.com/hashicorp/googlecompute"
version = "~> 1"
}
}
}
variable "project_id" {
type = string
default = ""
description = "Project ID, e.g. gcp-asigbahgcp-nprd-47930"
}
variable "zone" {
type = string
default = ""
description = "Zone, e.g. us-east1-b."
}
variable "service_account_email" {
type = string
default = ""
description = "Service account to use while building."
}
variable "source_image_family" {
type = string
default = "kali-linux-cloud-gce-amd64"
description = "Parent image family, e.g. kali-linux-cloud-gce-amd64"
}
variable "provision_script" {
type = string
default = "setup.sh"
description = "Provisioning script"
}
locals {
ssh_public_key = file("${path.root}/secrets/id_ed25519.pub")
user_data = {
users = [
{
name = "root"
lock_passwd = true
ssh_authorized_keys = [
local.ssh_public_key,
]
},
]
}
}
source "googlecompute" "kali-linux-cloud-cml-amd64" {
project_id = var.project_id
# Pristine image from base GCE image family
source_image_family = var.source_image_family
# For tweaks to existing image we've already built
#source_image_family = "kali-linux-cloud-cml-amd64"
image_family = "kali-linux-cloud-cml-amd64"
image_name = "kali-linux-{{timestamp}}-cloud-cml-amd64"
zone = var.zone
machine_type = "n2-highcpu-8"
disk_size = 48
disk_type = "pd-ssd"
image_storage_locations = [
"us-east1",
]
ssh_username = "root"
ssh_private_key_file = "secrets/id_ed25519"
service_account_email = var.service_account_email
scopes = [
"https://www.googleapis.com/auth/cloud-platform",
]
metadata = {
user-data = format("#cloud-config\n%s", yamlencode(local.user_data))
}
}
build {
sources = ["sources.googlecompute.kali-linux-cloud-cml-amd64"]
provisioner "shell" {
inline = [
"mkdir -vp /provision/websploit",
"mkdir -vp /provision/becoming-a-hacker"
]
}
# These are files copied here, rather than in the cloud-init because we don't
# want to do any YAML encoding/processing on them.
provisioner "file" {
source = "/workspace/setup.sh"
destination = "/provision/setup.sh"
}
provisioner "file" {
source = "/workspace/tweaks.sh"
destination = "/provision/tweaks.sh"
}
provisioner "file" {
source = "/workspace/websploit.sh"
destination = "/provision/websploit/websploit.sh"
}
provisioner "file" {
source = "/workspace/websploit-docker-compose.yml"
destination = "/provision/websploit/docker-compose.yml"
}
provisioner "file" {
source = "/workspace/becoming-a-hacker.sh"
destination = "/provision/becoming-a-hacker/becoming-a-hacker.sh"
}
# Let cloud-init finish before running the
# main provisioning script. If cloud-init fails,
# output the log and stop the build.
provisioner "shell" {
inline = [ <<-EOF
echo "waiting for cloud-init setup to finish..."
cloud-init status --wait || true
cloud_init_state="$(cloud-init status | awk '/status:/ { print $2 }')"
if [ "$cloud_init_state" = "done" ]; then
echo "cloud-init setup has successfully finished"
else
echo "cloud-init setup is in unknown state: $cloud_init_state"
cloud-init status --long
cat /var/log/cloud-init-output.log
echo "stopping build..."
exit 1
fi
echo "Starting main provisioning script..."
chmod u+x /provision/${var.provision_script}
/provision/${var.provision_script}
EOF
]
env = {
APT_OPTS = "-o Dpkg::Options::=--force-confmiss -o Dpkg::Options::=--force-confnew -o DPkg::Progress-Fancy=0 -o APT::Color=0"
DEBIAN_FRONTEND = "noninteractive"
}
}
# Clean up all cloud-init data and shutdown cleanly.
provisioner "shell" {
inline = [
"cloud-init clean -c all -l --machine-id",
"rm -rf /var/lib/cloud",
"sync",
"sync",
]
}
post-processor "manifest" {
output = "/workspace/manifest.json"
strip_path = true
#custom_data = {
# foo = "bar"
#}
}
}