Skip to content

Commit c2290a9

Browse files
authored
Add sample web task that uses gcsfuse (google#43)
* Add sample web task that uses gcsfuse * unpublish task * downscale to 3 * unpublish * Add sample web task that uses gcsfuse * unpublish task * downscale to 3 * unpublish * small refactor * Move mount directory definitions * set permissions in dockerfile * Update launch-apache * Update chal.conf
1 parent ebdadf7 commit c2290a9

File tree

7 files changed

+67
-5
lines changed

7 files changed

+67
-5
lines changed

infrastructure/kctf-samples/apache-php/challenge/Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ RUN ln -s /config/apache2-nsjail-php.conf /etc/apache2/conf-enabled/nsjail-php.c
2222
RUN rm -rf /var/www
2323
RUN ln -s /chroot/var/www /var/www
2424

25+
RUN rm -rf /chroot/var/lib/php/sessions
26+
RUN chroot /chroot rm -rf /var/lib/php/sessions
27+
RUN chroot /chroot mkdir -p /mnt/disks/sessions /mnt/disks/uploads
28+
RUN chroot /chroot ln -s /mnt/disks/sessions /var/lib/php/sessions
29+
2530
COPY files/html/ /chroot/var/www/html/
2631
COPY files/cgi-bin/ /usr/lib/cgi-bin/
2732
COPY files/root/ /root/
2833

29-
RUN chmod 0755 /chroot/var/www/html /usr/lib/cgi-bin/nsjail-php-cgi /root/launch-apache
34+
RUN chmod 0755 /chroot/var/www/html /usr/lib/cgi-bin/
35+
RUN chmod 0755 /chroot/var/www/html/*.php /usr/lib/cgi-bin/nsjail-php-cgi /root/launch-apache
3036

3137
CMD /root/launch-apache

infrastructure/kctf-samples/apache-php/challenge/config/apache2-nsjail-php.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ServerName kctf-nsjail-php
22
Listen 1337
3+
User user
34

45
<Directory "/var/www/html">
56
Options +ExecCGI

infrastructure/kctf-samples/apache-php/challenge/config/nsjail-php.cfg

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mode: ONCE
55
chroot_dir: "/chroot"
66
log_level: ERROR
77
uidmap {inside_id: "1000"}
8-
gidmap {inside_id: "1000"}
98
mount_proc: true
109
keep_env: true
1110
rlimit_as_type: HARD
@@ -28,6 +27,18 @@ mount: [
2827
dst: "/tmp"
2928
fstype: "tmpfs"
3029
rw: true
30+
},
31+
{
32+
src: "/mnt/disks/sessions"
33+
dst: "/mnt/disks/sessions"
34+
is_bind: true
35+
rw: true
36+
},
37+
{
38+
src: "/mnt/disks/uploads"
39+
dst: "/mnt/disks/uploads"
40+
is_bind: true
41+
rw: true
3142
}
3243
]
3344

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#!/bin/bash
2-
/usr/bin/nsjail --config /config/nsjail-php.cfg -- /usr/lib/cgi-bin/php $@
2+
3+
/usr/bin/nsjail --config /config/nsjail-php.cfg -v -- /usr/lib/cgi-bin/php $@
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
session_start();
3+
4+
if (isset($_REQUEST['foo'])) {
5+
$_SESSION['foo'] = $_REQUEST['foo'];
6+
}
7+
echo $_SESSION['foo'];
8+
?>
9+
<hr/>
10+
<pre>
11+
<?php
12+
if (isset($_FILES['file'])) {
13+
print_r($_FILES['file']);
14+
$filename = uniqid('file_', true);
15+
echo $filename;
16+
move_uploaded_file($_FILES['file']['tmp_name'], '/mnt/disks/uploads/'. $filename);
17+
}
18+
?>
19+
</pre>
20+
<hr/>
21+
<form method=post enctype=multipart/form-data>
22+
<input name=foo>
23+
<input name=file type=file>
24+
<input type=submit>
25+
</form>

infrastructure/kctf-samples/apache-php/k8s/deployment/autoscaling.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ apiVersion: "autoscaling/v1"
22
kind: "HorizontalPodAutoscaler"
33
metadata:
44
name: "chal"
5-
#spec:
6-
# maxReplicas: 3
5+
spec:
6+
minReplicas: 2
7+
maxReplicas: 2

infrastructure/kctf-samples/apache-php/k8s/deployment/containers.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,20 @@ apiVersion: "apps/v1"
22
kind: "Deployment"
33
metadata:
44
name: "chal"
5+
spec:
6+
template:
7+
spec:
8+
containers:
9+
- name: challenge
10+
volumeMounts:
11+
- name: sessions
12+
mountPath: /mnt/disks/sessions
13+
- name: uploads
14+
mountPath: /mnt/disks/uploads
15+
volumes:
16+
- name: sessions
17+
hostPath:
18+
path: /mnt/disks/gcs/apache-php/sessions
19+
- name: uploads
20+
hostPath:
21+
path: /mnt/disks/gcs/apache-php/uploads

0 commit comments

Comments
 (0)