]> git.somenet.org - pub/jan/ctf-seminar.git/blob - writeups/chgue/ctfzone19.md
Update old writeups, add ctfzone writeup.
[pub/jan/ctf-seminar.git] / writeups / chgue / ctfzone19.md
1 # Retrospective
2 This CTF was not really fun. It felt like _a lot_ of guesswork (at least the web challenges that I attempted).
3
4 At first I tried chicken together with @theguy, but the obvious vulnerability did not help us to find anything. Instead we wasted a few hours trying to find a hint in the filesystem. In total I spent about 2 hours.
5
6 On the second day I tried to help with bathhouse. @lavish and @smashing already did most of the interesting stuff (SQLi and PDF writer exploitation). It seemed like the challenge is almost done and one just needs to find the next hint in the filesystem (again...). However, I spent around 5 hours finding nothing of interest until @lavish used `dirbuster` to find the next hint... After we had the correct paths it took about 30 minutes to find the next and final hint.
7
8 # bathhouse (solved)
9 ## Overview
10 Given is a django-based webpage of a bathhouse. One can book a bathhouse by filling out a form. The form consists of a radio button selector, a hours number field, a phone number fild and a username text field.
11
12 ##  Exploit
13 The username field allows for SQL to be injected. @lavish created a script to run a blind SQLi and found a table called `backup` which contains the columns `username` and `password`. The only row contained `main_admin_user` and `njafnGAJNSGAkn123`. These credentials can be used to login at `http://web-bathhouse.ctfz.one/set_price/`. This page can be found in the `robots.txt` which contains
14
15     User-Agent: *
16     Disallow:/set_price/
17
18 When logged in one sees the last request submitted through the booking form including all the given information. Additionally, a number input is given where the admin can set the price for the request. On submission of the price a PDF booking confirmation is generated using `wkhtmltopdf 0.12.1`. Instead of a price one can inject HTML which will be rendered in the PDF. Therefore, it is possible to include JavaScript to read local files.
19
20     <script> 
21         x=new XMLHttpRequest;
22         x.onload=function() {
23             document.write(this.responseText)
24         };
25         x.open("GET","file:///etc/passwd");
26         x.send();
27     </script> 
28
29 However, reading directories is not possible. How can one find an interesting file to read? Well after spending hours searchin for the next hint, @lavish found the `http://web-bathhouse.ctfz.one/status/` page by using `dirbuster`.The page has the following contents which hint at interesting directories:
30
31     Status page
32     
33     Web app folder: /opt/project/
34     Submodules: task, calculate
35     
36     Everything works correctly (200)
37
38 The project is implemented in a typical django fashion. The next hint is included in `/opt/project/calculate/views.py`. Apart from the other views, the file includes the following comments
39
40     # def sync(request): # Get sync data by http request. #syncData('http://syncdata/sync.html')
41
42 Curiously enough, using the above script does not work for fetching `http://syncdata/sync.html`. However, an iframe works
43
44     <div><p>Report Heading</p><iframe src=http://syncdata/sync.html height="500" width="500">
45
46 which yields the flag.
47
48 # chicken (unsolved)
49 ## Overview
50 Given is a webpage of a chicken farm. One page shows their hens and for every hen there is a link to its passport, e.g. `web-chicken.ctfz.one/File/Download?filename=My50eHQ=`. 
51
52 Furthermore, there is a contact page which contains an e-mail `admin@chicken.ctf.zone`. However, sending a mail to it does not work according to @theguy.
53
54 Additionally, there is a login form.
55
56 ## Exploit attempt
57 The URL contains the filename in base64 encoding at the end. Any arbitrary path can be read by encoding the path in base64. The website sets the cookie `.AspNetCore.Antiforgery.9TtSrW0hzOs` which confirms that the webpage is created using ASP.NETcore. The directory structure is approximately this:
58
59     /
60         etc
61             passwd
62         ???
63             Passports
64                 1.txt
65                 2.txt
66                 3.txt
67                 4.txt
68                 5.txt
69             wwwroot
70                 css
71                     site.min.css
72                 js
73                     site.min.js
74                 images
75                     hens
76                         1.jpg
77                         2.jpg
78                         3.jpg
79                         4.jpg
80                         5.jpg
81             Views
82                 Auth
83                     Login.cshtml
84                 Home
85                     Hens.cshtml
86                 Shared
87                     _Layout.cshtml
88                     _CookieConsentPartial.cshtml
89                     Error.cshtml
90                 _ViewImports.cshtml
91             appsettings.json
92     
93 e.g. `../../etc/passwd` allows one to read `passwd` (which contains nothing interesting).    
94
95 Interestingly enough, one cannot read `*.cs` source code files. It seems like that certain files or filetypes are filtered and not readable. Therefore, we cannot read the important part of the website's source code.
96
97 After trying to find interesting files for hours we gave up.