]> git.somenet.org - pub/jan/ctf-seminar.git/blob - writeups/ifkata/hxp36c3.md
Add hxp36c3 writeup and fix seccon formatting
[pub/jan/ctf-seminar.git] / writeups / ifkata / hxp36c3.md
1 # hxp 36C3
2 ## Overview
3 I found the CTF really interesting, but also frustrating.
4 I decided to focus only on includer, as it seemed intriguing and complex enough to do so.
5 Tackling the challenge was again a team effort, but unfotunately we couldn't solve it.
6
7
8 ## Attempted challenges
9 ### includer-web
10 #### Overview
11 The challenge consisted of a simple page which said "Hello, your sandbox is <insert_random_bytes_here>".
12 There was no JavaScript, no styling, no input.
13
14 #### Research
15 The first thing I did was to look into the provided files. Thus, I found the following information:
16 * the thing runs in a debian buster docker container, behind an nginx web server.
17 * a filename can be POSTed and the file will be evaluated if it does not start with `<?`
18 * file uploads are disabled in www.conf
19 * the `readflag` binary will be run with effective gid `1337`
20 * the sandbox is included as a `TMPDIR` in the server environment. This means that temporary files uploaded to the site will be stored there.
21
22 #### Exploiting
23 When exploiting, I started with the basic stuff. First, I built the docker image, started the container and checked for anything useful.
24
25 I then read the documentation of PHP `include_once` to see exactly what we could include. My hopes were that we could
26 trigger a remote file inclusion, as file upload was disabled and we cannot upload files from anywhere in the page (at first glance).
27 That is why I researched if we could include files from URLs. Normally,
28 `include_once` allows that but unfortunatelly, the setting `allow_url_include` is `false`
29 by default and it had not been changed so that was not possible.
30
31
32 Then, Hetti pointed us to `CVE-2019-11043`, which allows us to exploit remote code execution:
33 https://github.com/neex/phuip-fpizdam
34 https://github.com/theMiddleBlue/CVE-2019-11043/blob/master/exploit.py
35
36 I tried running a couple of prepared exploits against the service, but they didn't work.
37 At first, I thought that there was something wrong with the exploits themselves and started checking and debugging theMiddleBlue's exploit.
38 This attempt didn't result in anything useful.
39 Later on, after some digging in the container itself, I found out that `CVE-2019-11043` cannot be used because:
40 * nginx had the required configuration fixes applied
41 * the PHP version was the patched one
42
43 Additionally, after some time the creator of the challenge told us that the CVE was indeed not the intended exploit.
44
45
46 After the disappointment that the CVE was, I decided to see exactly what we could read.
47 First, I tried posting a filename and this discovered that we can read files.
48 Later on, I discovered that we are restricted to reading files from `/var/www/html`, meaning that calling `/readflag` was not possible.
49
50 Finally, in acts of desperation I researched for PHP 7.3.11 and nginx 1.14.2 vulnerabilities, but I couldn't find anything useful.
51
52 #### Takeaways
53 The solution of includer can be found [here](https://balsn.tw/ctf_writeup/20191228-hxp36c3ctf/#includer).
54 Unfortunately, we could not figure that ourselves as we were kind of concentrated on exploiting the CVE from above.
55
56 As a takeaway from this challenge, I would list:
57 * not focusing too much on a single exploit
58 * reading not only the documentation of the languages, that the services are written in, but also the source code of the language itself=
59
60 ### file-magician-web
61 #### Overview
62 I started this challenge in an attempt to distract myself from `includer` as I had wasted a lot of time there and was burning out.
63 In the end, I left this one in order to continue working on the other challenge.
64
65 #### Research
66 The site had a basic file upload function and again runs in a docker container.
67
68 The script places the flag in a file with a predictable and random part of the name.
69
70 It also creates a sqlite database for every session and it saves data about the uploaded files there.
71
72 I also checked whether or not it would be a problem to do path traversal and found out that it would not be a problem,
73 seeing that the script was not limited to the web root only as it was the case with `includer`.
74
75 I left the challenge after the research phase as it did not interest me so much and I wanted to work on `includer`.