← all posts

Dec 4, 2026 · technical · 8 min read

Eighteen Linux puzzles and the Terraform module behind them

The Learn to Cloud Linux CTF is 18 CLI challenges wrapped in a small AWS module. The flags were the easy part; the reusable lessons were the provisioning, the detective work, and the teardown.

ai 100 · human 0topics:cloudsecuritylearningtags:linuxterraformawssecurityctf

I ran the Learn to Cloud Linux CTF twice.

The first run took eight minutes. I drove the VM over SSM, read the setup source, and grepped for the flags. The second took fifty-one minutes. I solved the challenges by hand, read the output, made typos, and corrected them. Both runs produced the same certificate. Only one taught me anything.

That gap is the post.

The flags are a scoring mechanism. The transferable part is the loop: provision → access → investigate → fix → verify → clean up. The lab is a rehearsal of that loop, wrapped in a small Terraform module that is itself worth reading.

What the lab is

The lab is a fork of learntocloud/linux-ctfs. You deploy it with Terraform on AWS, Azure, or GCP, SSH in, and solve 18 challenges plus an example. A verify CLI submits a flag, reports progress, offers hints, and returns a completion token. There are deliberately no public solutions; the certificate is honor-system.

The AWS path is a t3.micro Ubuntu 24.04 VM. A session costs roughly a cent, and terraform destroy removes the whole thing. The lab is meant to be ephemeral.

The important part is not the flag count. It is the habit of observing before assuming, reading the config, verifying the fix, and cleaning up. Those habits transfer directly to cloud and DevOps work.

The environment

One Ubuntu 24.04 VM, a public IP, and a security group opening 22, 80, and 8080. An IAM instance profile lets SSM run the setup and readiness checks without inbound SSH.

The box has a ctf_user with sudo and a handful of other accounts for the identity challenges: vault, flag_user, old_admin, deploy, and intern. Services and artifacts are scattered across the filesystem: nginx, nc, cron, a directory watcher, an ICMP sender, a process with a secret in its environment, and a disk image.

Internet
  │
  ▼
IGW ── 0.0.0.0/0
  │
VPC 10.0.0.0/16
  └── subnet 10.0.1.0/24
        └── EC2 t3.micro (Ubuntu 24.04)
              ├── SG: 22, 80, 8080
              ├── IAM role: SSM managed instance
              └── user_data → release setup → readiness

The open ports and the public password are lab choices, not production ones. Production would use SSM Session Manager, a scoped security group, no public IP, and key or SSO authentication. The lab is intentionally a little exposed so you can practice finding the seams.

The Terraform walkthrough

The module is small enough to read in one sitting, and that is the point. It is a desired-state model: plan, apply, destroy. The state file is the module's memory of what exists.

The resource graph is the architecture:

  • VPC → internet gateway → subnet → route table → security group
  • IAM role and instance profile for SSM
  • EC2 instance with user_data
  • A readiness check
  • An output for the connection details

The data sources are the useful part for cloud practice: the latest Ubuntu AMI by owner, and availability zones filtered by what the instance type can actually launch in.

There is a preflight check that the local AWS CLI can run ssm send-command before creating anything billable. That is a small habit with a big payoff: fail before you spend.

user_data downloads the release asset, verifies its SHA-256, and runs ctf_setup.sh. The module then waits for /var/lib/linux-ctfs/setup.done over SSM before it reports the instance as ready. A null_resource polls the marker; the output depends on it. That is how the module avoids a race between "the instance is running" and "the challenges exist."

Lifecycle is explicit: aws_ec2_instance_state handles stop and start, and terraform destroy removes all 13 resources. The lab is designed to disappear.

There is also a local setup mode for contributors that uses an SSH provisioner. It is a good example of when not to use provisioners: they are fine for a local lab, and a bad fit for a repeatable cloud deployment.

What would I try next with the module?

  • Restrict the security group to your IP.
  • Add a tag variable and thread it through every resource.
  • Move state to S3 with encryption, versioning, and a DynamoDB lock table.
  • Run terraform graph and compare the picture to the mental model.
  • Read the plan before every apply and predict the diff.

The module is a firewall diagram you can read. That is the real Terraform lesson.

The challenges, grouped by skill

I am not going to enumerate every flag. The lab asks players not to publish solutions, and the flags are not the point. Here is the shape of the work, with one command and one real-world analogue per group.

1. Discovery and file system

  • ls -la for dotfiles. .env, .ssh, and .git-credentials are the real targets in a lot of incidents.
  • find by name, type, permission, size, and modification time: find ~ -type f -iname '*secret*', find /opt -type f -perm -0002 -ls.
  • Archives: run file before tar. List before you extract. Zip Slip is a path-traversal bug, not a file-format bug.
  • Symlinks: readlink -f, namei -l, and the TOCTOU problem behind O_NOFOLLOW.
  • Shell history: .bash_history, HISTCONTROL, decoys, and history -c as a signal that someone cleaned up.
  • Disk images: a raw ext4 image, file, dumpe2fs, debugfs, and the volume label as metadata.

Real-world analogue: incident triage, secret hunting, backup handling, and forensic artifacts. The command is simple; knowing which artifact answers the question is the skill.

2. Identity and permissions

  • /etc/passwd fields, GECOS, getent versus cat, and service accounts that should not have shells.
  • Mode versus ownership: a world-writable config is a finding; a 000 file you own is not protection.
  • SSH keys: ssh-keygen, authorized_keys, ownership and mode requirements, and key-only accounts.
  • Process environment: /proc/<pid>/environ, NUL separation, and environment-variable leaks.

Real-world analogue: account audits, privilege escalation, CI deploy keys, and Kubernetes secret injection. The same questions show up in cloud IAM: who is this identity, what can it reach, and where is the secret stored?

3. Services and network

  • ss -ltnp for listeners, curl versus nc, and what a shadow service looks like.
  • nginx: wrong listen port, wrong root, nginx -t, reload versus restart, and the difference between 404, 502, and 403.
  • DNS: /etc/resolv.conf, search domains, getent versus dig, and /etc/hosts persistence.
  • ICMP: tcpdump -i lo -A -n icmp, payloads, and why ICMP is a covert channel.
  • Remote upload: scp, inotifywait, wall, and the CI artifact pattern behind it.
  • Cron: /etc/cron.d, syntax, logs as evidence, and persistence.

Real-world analogue: site-down triage, exposed admin ports, DNS troubleshooting, and PCAP analysis. The lab is a small version of the questions you ask when a service is "up" but not reachable.

The networking thread

The lab connects directly to the networking chapter:

  • DNS resolution order: nsswitch.conf → /etc/hosts → DNS. That is why getent and dig can disagree.
  • Search domains: a bare name expands to a zone. It surprises people in production and in the lab.
  • Ports and services: ss, curl, nc. "Listening" is not the same as "reachable"; the security group is the other half.
  • TCP and SSH: the three-way handshake, host-key verification, password versus keyboard-interactive, and key auth.
  • ICMP: echo request and reply, payloads, and why it is a covert channel.
  • HTTP: status codes, reverse proxies, health checks, and TLS termination.
  • Subnets, routes, security groups: the Terraform module is a firewall diagram you can read.

Mistakes and corrections

The honest part:

  • ech instead of echo. The shell tells you immediately; I still did it twice.
  • echo base64 -d file prints the words base64 -d file; it does not pipe the file. I needed base64 -d file.
  • verify 27 instead of verify 17. The tool rejected the challenge number, which is a good reminder to read the error before retrying.
  • ss -ltnp | grep nginx returned nothing. -p hides other users' processes, and the port was 8083. I needed sudo and a wider search.
  • The first run's eight minutes came from reading the setup source and grepping, not from solving. The second run is the one that taught me the tools.

What I would do differently

  1. Solve by hand first. Use SSM and grep only to unblock, not to race the clock.
  2. Read the Terraform before applying. Predict the resource graph, then compare it to terraform graph.
  3. Keep a command log per challenge. It becomes the cheat sheet, and it shows where the time actually went.
  4. Destroy the lab the same day. Ephemeral environments should stay ephemeral.
  5. Check the process user before trusting ss -p. The flag hides other users' sockets; sudo and a wider search often answer the question.
  6. Read the error. The verify typo and the nginx 404 were both cases where the tool knew more than I did.

Closing

The certificate is honor-system. The skills are the deliverable.

The reusable habits are simple: observe before assuming, read the config, verify the fix, clean up. They show up again in the Terraform and Kubernetes work: a plan is a hypothesis, a rollout is a verification, and a destroy is part of the lifecycle.

If you are following the same path, the CLI reps are worth it. I had already worked through OverTheWire Bandit 0–33 before this lab; the CTF was the next rep. TryHackMe is a good structured follow-up, and the Learn to Cloud cloud/DevOps path takes the same loop into AWS, Terraform, and Kubernetes.

The flags are the easy part. The loop is the point.

Appendix: command map

TaskCommand
List hidden filesls -la
Find by name/typefind ~ -type f -iname '*secret*'
Find world-writablefind /opt -type f -perm -0002 -ls
Search contentsgrep -n, grep -c, grep -Rhao
Decode base64base64 -d
List listenersss -ltnp
HTTP probecurl -sS -m 5 http://127.0.0.1:8080/
Raw TCP probenc -vz host port
DNSgetent hosts, dig, resolvectl status
Capture ICMPtcpdump -i lo -A -n icmp
SSH keyssh-keygen -t ed25519, ssh -i key user@host
Transferscp file user@host:~/dir/
Archivesfile, tar -tzf, tar -xzf/-xjf/-xJf
Symlinksreadlink -f, namei -l
Process envtr '\0' '\n' < /proc/<pid>/environ
Disk imagefile, dumpe2fs -h, debugfs -R 'ls -l /'
Teardownterraform destroy