Skip to content

Commit 55db536

Browse files
committed
Add testing suite.
1 parent 0895bae commit 55db536

5 files changed

Lines changed: 1245 additions & 3 deletions

File tree

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Test files contain solutions - keep local only
2-
tests/
3-
41
# macOS
52
.DS_Store
63

tests/CHALLENGE_REFERENCE.md

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
# CTF Challenge Testing Reference
2+
3+
> **⚠️ SPOILER WARNING**: This file contains all flags and solutions. For maintainers and automated testing only.
4+
5+
This document provides context for testing the Linux CTF challenges across AWS, GCP, and Azure.
6+
7+
## Overview
8+
9+
The CTF contains 18 challenges (plus 1 example) that test Linux command line skills. Each challenge has:
10+
- A specific flag in format `CTF{some_text_here}`
11+
- A setup mechanism in `ctf_setup.sh`
12+
- A solution command to retrieve the flag
13+
- SHA256 hash validation via the `verify` command
14+
15+
## Challenge Reference
16+
17+
### Challenge 0: Example
18+
- **Flag**: `CTF{example}`
19+
- **Test**: `verify 0 CTF{example}`
20+
21+
### Challenge 1: Hidden File Discovery
22+
- **Flag**: `CTF{finding_hidden_treasures}`
23+
- **Location**: `/home/ctf_user/ctf_challenges/.hidden_flag`
24+
- **Solution**: `cat /home/ctf_user/ctf_challenges/.hidden_flag`
25+
- **Verify Setup**: `test -f /home/ctf_user/ctf_challenges/.hidden_flag`
26+
27+
### Challenge 2: Basic File Search
28+
- **Flag**: `CTF{search_and_discover}`
29+
- **Location**: `/home/ctf_user/documents/projects/backup/secret_notes.txt`
30+
- **Solution**: `cat /home/ctf_user/documents/projects/backup/secret_notes.txt`
31+
- **Verify Setup**: `test -f /home/ctf_user/documents/projects/backup/secret_notes.txt`
32+
33+
### Challenge 3: Log Analysis
34+
- **Flag**: `CTF{size_matters_in_linux}`
35+
- **Location**: `/var/log/large_log_file.log` (500MB file, flag at end)
36+
- **Solution**: `tail -1 /var/log/large_log_file.log`
37+
- **Verify Setup**: `test -f /var/log/large_log_file.log && test $(stat -c%s /var/log/large_log_file.log) -gt 100000000`
38+
39+
### Challenge 4: User Investigation
40+
- **Flag**: `CTF{user_enumeration_expert}`
41+
- **Location**: `/home/flag_user/.profile`
42+
- **User**: `flag_user` (UID 1002)
43+
- **Solution**: `cat /home/flag_user/.profile`
44+
- **Verify Setup**: `id flag_user && test -f /home/flag_user/.profile`
45+
46+
### Challenge 5: Permission Analysis
47+
- **Flag**: `CTF{permission_sleuth}`
48+
- **Location**: `/opt/systems/config/system.conf` (chmod 777)
49+
- **Solution**: `cat /opt/systems/config/system.conf`
50+
- **Verify Setup**: `test -f /opt/systems/config/system.conf && test $(stat -c%a /opt/systems/config/system.conf) = "777"`
51+
52+
### Challenge 6: Service Discovery
53+
- **Flag**: `CTF{network_detective}`
54+
- **Service**: `ctf-secret-service.service` on port 8080
55+
- **Solution**: `curl -s localhost:8080`
56+
- **Verify Setup**: `systemctl is-active ctf-secret-service.service && ss -tulpn | grep -q :8080`
57+
58+
### Challenge 7: Encoding Challenge
59+
- **Flag**: `CTF{decoding_master}`
60+
- **Location**: `/home/ctf_user/ctf_challenges/encoded_flag.txt` (double base64)
61+
- **Solution**: `cat /home/ctf_user/ctf_challenges/encoded_flag.txt | base64 -d | base64 -d`
62+
- **Verify Setup**: `test -f /home/ctf_user/ctf_challenges/encoded_flag.txt`
63+
64+
### Challenge 8: SSH Secrets
65+
- **Flag**: `CTF{ssh_security_master}`
66+
- **Location**: `/home/ctf_user/.ssh/secrets/backup/.authorized_keys`
67+
- **Solution**: `cat /home/ctf_user/.ssh/secrets/backup/.authorized_keys`
68+
- **Verify Setup**: `test -f /home/ctf_user/.ssh/secrets/backup/.authorized_keys`
69+
70+
### Challenge 9: DNS Troubleshooting
71+
- **Flag**: `CTF{dns_name}`
72+
- **Location**: `/etc/resolv.conf` (appended to nameserver line)
73+
- **Solution**: `grep -o 'CTF{[^}]*}' /etc/resolv.conf`
74+
- **Verify Setup**: `grep -q 'CTF{' /etc/resolv.conf`
75+
76+
### Challenge 10: Remote Upload Detection
77+
- **Flag**: `CTF{network_copy}`
78+
- **Service**: `ctf-monitor-directory.service` using inotifywait
79+
- **Trigger**: Create any file in `/home/ctf_user/ctf_challenges`
80+
- **Solution**: `touch /home/ctf_user/ctf_challenges/testfile && cat /tmp/.ctf_upload_triggered`
81+
- **Verify Setup**: `systemctl is-active ctf-monitor-directory.service`
82+
83+
### Challenge 11: Web Configuration
84+
- **Flag**: `CTF{web_config}`
85+
- **Location**: `/var/www/html/index.html`
86+
- **Service**: nginx on port 8083
87+
- **Solution**: `curl -s localhost:8083`
88+
- **Verify Setup**: `systemctl is-active nginx && ss -tulpn | grep -q :8083`
89+
90+
### Challenge 12: Network Traffic Analysis
91+
- **Flag**: `CTF{net_chat}`
92+
- **Service**: `ctf-ping-message.service` sending hex-encoded ping pattern
93+
- **Hex Pattern**: `4354467b6e65745f636861747d`
94+
- **Solution**: `echo "4354467b6e65745f636861747d" | xxd -r -p`
95+
- **Verify Setup**: `systemctl is-active ctf-ping-message.service`
96+
97+
### Challenge 13: Cron Job Hunter
98+
- **Flag**: `CTF{cron_task_master}`
99+
- **Location**: `/etc/cron.d/ctf_secret_task`
100+
- **Solution**: `grep -o 'CTF{[^}]*}' /etc/cron.d/ctf_secret_task`
101+
- **Verify Setup**: `test -f /etc/cron.d/ctf_secret_task`
102+
103+
### Challenge 14: Process Environment
104+
- **Flag**: `CTF{env_variable_hunter}`
105+
- **Service**: `ctf-secret-process.service`
106+
- **Environment Variable**: `CTF_SECRET_FLAG`
107+
- **Solution**: `cat /proc/$(pgrep -f ctf_secret_process)/environ | tr '\0' '\n' | grep -o 'CTF{[^}]*}'`
108+
- **Verify Setup**: `systemctl is-active ctf-secret-process.service && pgrep -f ctf_secret_process`
109+
110+
### Challenge 15: Archive Archaeologist
111+
- **Flag**: `CTF{archive_explorer}`
112+
- **Location**: `/home/ctf_user/ctf_challenges/mystery_archive.tar.gz` (triple nested)
113+
- **Structure**: `mystery_archive.tar.gz``middle.tar.gz``inner.tar.gz``flag.txt`
114+
- **Solution**: Extract all layers and read `flag.txt`
115+
- **Verify Setup**: `test -f /home/ctf_user/ctf_challenges/mystery_archive.tar.gz`
116+
117+
### Challenge 16: Symbolic Sleuth
118+
- **Flag**: `CTF{link_follower}`
119+
- **Location**: Chain starting at `/home/ctf_user/ctf_challenges/follow_me`
120+
- **Solution**: `cat $(readlink -f /home/ctf_user/ctf_challenges/follow_me)`
121+
- **Verify Setup**: `test -L /home/ctf_user/ctf_challenges/follow_me`
122+
123+
### Challenge 17: History Mystery
124+
- **Flag**: `CTF{history_detective}`
125+
- **Location**: `/home/old_admin/.bash_history`
126+
- **Solution**: `grep -o 'CTF{[^}]*}' /home/old_admin/.bash_history`
127+
- **Verify Setup**: `test -f /home/old_admin/.bash_history`
128+
129+
### Challenge 18: Disk Detective
130+
- **Flag**: `CTF{disk_detective}`
131+
- **Location**: Hidden file `.flag` inside `/opt/ctf_disk.img` (ext4 filesystem image)
132+
- **Solution**: `sudo mount -o loop /opt/ctf_disk.img /mnt/ctf_disk && cat /mnt/ctf_disk/.flag`
133+
- **Verify Setup**: `test -f /opt/ctf_disk.img`
134+
135+
## Services (Must Survive Reboot)
136+
137+
| Service Name | Challenge | Port | Purpose |
138+
|-------------|-----------|------|---------|
139+
| `ctf-secret-service.service` | 6 | 8080 | HTTP server returning flag |
140+
| `ctf-monitor-directory.service` | 10 | N/A | inotifywait file monitor |
141+
| `ctf-ping-message.service` | 12 | N/A | Ping with hex-encoded pattern |
142+
| `ctf-secret-process.service` | 14 | N/A | Process with env variable |
143+
| `nginx` | 11 | 8083 | Web server with flag |
144+
145+
## Verify Command Subcommands
146+
147+
| Command | Expected Behavior |
148+
|---------|------------------|
149+
| `verify 0 CTF{example}` | Returns "✓ Example flag verified!" |
150+
| `verify progress` | Shows "Flags Found: X/18" |
151+
| `verify list` | Shows all 19 challenges with checkmarks |
152+
| `verify hint 1` | Shows hint for challenge 1 |
153+
| `verify time` | Shows elapsed time or "Timer not started" |
154+
| `verify export <name>` | Shows certificate if 18/18, else error message |
155+
156+
## Cloud Provider Firewall Ports
157+
158+
All providers must allow inbound traffic on:
159+
- Port 22 (SSH)
160+
- Port 80 (HTTP - for user testing)
161+
- Port 8080 (Challenge 6 - hidden service)
162+
- Port 8083 (Challenge 11 - nginx)
163+
164+
## Testing Scripts
165+
166+
### `tests/test_ctf_challenges.sh`
167+
Runs on the VM to validate all challenges. Usage:
168+
```bash
169+
./test_ctf_challenges.sh [--with-reboot]
170+
```
171+
172+
**Flags:**
173+
- `--with-reboot`: After initial tests, creates a marker file and exits with code 100 to signal the orchestration script to reboot the VM. After reboot, re-run the script to verify services restarted and progress persisted.
174+
175+
### `tests/deploy_and_test.sh`
176+
Orchestration script to deploy and test. Usage:
177+
```bash
178+
./deploy_and_test.sh <aws|azure|gcp|all> [--with-reboot]
179+
```
180+
181+
**Prerequisites:**
182+
- `terraform` (>= 1.0)
183+
- `sshpass` (macOS: `brew install hudochenkov/sshpass/sshpass`)
184+
- Provider CLI authenticated:
185+
- AWS: `aws` CLI configured
186+
- Azure: `az` CLI logged in
187+
- GCP: `gcloud` CLI authenticated
188+
189+
**What it does:**
190+
1. Checks prerequisites
191+
2. Runs `terraform apply` in provider directory
192+
3. Waits for VM setup to complete
193+
4. SCPs test script to VM
194+
5. Runs tests via SSH with password auth
195+
6. If `--with-reboot`: stops/starts VM via provider CLI, reconnects, re-runs verification
196+
7. Runs `terraform destroy` on completion
197+
198+
## Expected Test Results
199+
200+
A successful test run should show:
201+
- All 19 verify subcommand tests passing
202+
- All 18 challenge setup verifications passing
203+
- All 18 challenge solution commands returning correct flags
204+
- All 18 flag submissions accepted by verify
205+
- (If --with-reboot) All 5 services active after reboot
206+
- (If --with-reboot) Progress file persisted
207+
208+
## Troubleshooting
209+
210+
### Setup not completing
211+
- Check `/var/log/setup_complete` exists
212+
- Review cloud-init logs: `/var/log/cloud-init-output.log`
213+
214+
### Service not running
215+
- Check status: `systemctl status <service-name>`
216+
- Check logs: `journalctl -u <service-name>`
217+
218+
### Port not accessible externally
219+
- Verify firewall rules in Terraform allow the port
220+
- Check security group/NSG in cloud console
221+
222+
### Verifying Resources Are Destroyed
223+
224+
After tests complete, verify all cloud resources were properly destroyed:
225+
226+
**AWS:**
227+
```bash
228+
aws ec2 describe-instances --filters "Name=tag:Name,Values=CTF*" "Name=instance-state-name,Values=running,pending,stopping,stopped" --query 'Reservations[*].Instances[*].[InstanceId,State.Name]' --output table
229+
aws ec2 describe-vpcs --filters "Name=tag:Name,Values=CTF*" --query 'Vpcs[*].VpcId' --output table
230+
```
231+
232+
**Azure:**
233+
```bash
234+
az group list --query "[?starts_with(name, 'ctf')].name" --output table
235+
```
236+
237+
**GCP:**
238+
```bash
239+
gcloud compute instances list --filter="name~'ctf'" --format="table(name,zone,status)"
240+
```
241+
242+
If any resources remain, run `terraform destroy -auto-approve` in the appropriate provider directory.

0 commit comments

Comments
 (0)