1 # <u>CTFZone 2019 Quals</u>
7 **category**: forensics, rev
11 You have one PDF file. Now calculate the flag. It's in decimal, by the way.
17 We receive a .pdf file. Opening it we find a strange function definition f(x) = 109394007*x + 13
18 In itself, this is not very helpful!
20 I tried looking for clues in the file details, then taking it apart with LibreOffice draw, but nothing unusual was revealed.
22 Analysing the file with the unix tool `strings` did not reveal any hidden information, but it revealed the underlying file structure.
24 After getting into the details of how .pdf files are built up (see TD) , I took a closer look with `less`:
59 There is only one section with 26 objects. First I thought that some of these are somehow hidden, I tried copying parts into a new file, but it did not work, later it turned out because of the offsets. As I looked into the exact specifications, it turned out that the offsets for the original file were not correct in the first place and that the file contained a mysterious second comment, apart from the standard pdf-header defining the version and file type.
61 I tried interpreting the comment in many ways, looked at the hex and binary values, but could not determine the purpose of it. I was stuck here, until I've stumbled upon a writeup, which stated that the file command should've identified the file as a DOS/MBR boot sector. Which is surprising as I have received:
65 document.pdf: PDF document, version 1.4
68 every time when I tried identifying the data type.
70 With this new information, the only thing standing in my way was being able to execute the instructions to get x.
72 Interpreting the code as x86 assembly:
102 This code returns 99399, substituting it into the original equation:
104 109394007*99399 + 13 = 10873654901806, so the flag is: ctfzone{10873654901806}
106 ### Technical details
108 Structure of PDF files:
110 ![pdf.png](ctf_zone\pdf.png)
112 [https://d3i71xaburhd42.cloudfront.net/b4f47fb71221a0676e2e892af7b98acad2c3c5cd/2-Figure1-1.png]
117 - Always go a level deeper!
123 **category**: forensics
127 This should be an easy one, just remember to rock. (Sorry, the flag on disk begins with CTFZone, please change it to all lowercase, when you submit).
133 We get a 20GB raw disk image. The unix tool `file` tells us:
137 joshua.img: DOS/MBR boot sector
140 that it is the image of an MBR disk.
142 I tried to mount the mentioned image, but it does not go as easy as one would think.
144 We have to find the starting sector with the `fdisk` tool:
147 $ fdisk -l joshua.img
148 Disk joshua.img: 20 GiB, 21474836480 bytes, 41943040 sectors
149 Units: sectors of 1 * 512 = 512 bytes
150 Sector size (logical/physical): 512 bytes / 512 bytes
151 I/O size (minimum/optimal): 512 bytes / 512 bytes
153 Disk identifier: 0x70b3f931
155 Device Boot Start End Sectors Size Id Type
156 joshua.img1 * 2048 7999487 7997440 3.8G 82 Linux swap / Solaris
157 joshua.img2 8001534 39835647 31834114 15.2G 5 Extended
158 joshua.img3 39835648 41932799 2097152 1G 83 Linux
159 joshua.img5 8001536 39835647 31834112 15.2G 83 Linux
161 Partition table entries are not in disk order.
164 Based on these results we can calculate the offset:
167 mount -o ro,loop,offset=$((512 * 8001536)) joshua.img5 /mnt/joshua
170 After mounting the largest partition, we immediately head over to /etc/passwd, to find some more information about who this drive could belong to. (It needed reading around online how to approach such challenges.) We find an interesting entry:
173 joshua:x:1000:1000:joshua:/home/joshua:/bin/bash
176 there seems to be a user called "joshua", let's check out his home directory!
178 We find an interesting file .bash_history:
182 sudo cryptsetup close cryptovolume
186 cat /var/log/auth.log
191 sudo apt install keepass2
193 sudo luksformat /dev/sda3
194 sudo cryptsetup close /dev/mapper/
207 We can make some interesting observations:
209 - joshua has sudo access
210 - he used the zsh shell and he deleted its history
211 - he set up an encrypted volume (probably joshua.img3)
212 - he used the keepass2 password safe
214 In the Documents folder we find a KeepItSafe.kdbx keepass2 file. But we do not have a key for opening it!
217 $ mount -o ro,loop,offset=$((512 * 39835648)) joshua.img3 /mnt/joshua_crypt
218 mount: /mnt/joshua_crypt: failed to setup loop device for joshua.img3.
221 I could not mount the encrypted partition, probably the encryption prevents us from loading it.
223 We also find an interesting file in the home directory ".recently-used":
228 <URI>file:///home/joshua/Documents/KeepItSafe.key</URI><Mime-Type>application/x-iwork-keynote-sffkey</Mime-Type><Timestamp>1570444296</Timestamp><Groups/>
231 <URI>file:///home/joshua/Documents/KeepItSafe.kdbx</URI><Mime-Type>application/x-keepass2</Mime-Type><Timestamp>1570444267</Timestamp><Groups/>
234 <URI>file:///home/joshua/Documents/KeepItSage.kdbx</URI><Mime-Type>application/x-keepass2</Mime-Type><Timestamp>1570444179</Timestamp><Groups/>
239 He seems to have created an other keepass2 file, maybe deleted it later? But what is even more interesting: He created a key file to the safe, it has to be somewhere around!
241 We find the key in the trash `/local/share/Trash`! This seems to easy!
243 Unfortunately, it really is, keepass2 reports that the composite key is invalid! Maybe a password is also needed.
245 I tried brute-forcing /etc/shadow with hashcat to maybe get a relevant password, but it took too long, maybe with a strong graphics card it would go faster!
249 ### Technical details
251 Linux file structure:
255 > The password file is human-readable file that contains information about users on the system including their encrypted passwords. Some systems don’t have encrypted passwords in this file if [/etc/shadow](https://kerneltalks.com/user-management/understanding-etc-shadow-file/) file is generated.
257 [https://kerneltalks.com/user-management/understanding-etc-passwd-file/]
260 joshua:x:1000:1000:joshua:/home/joshua:/bin/bash
263 In our case the second "x" meant that the password is in an encrypted format in the /etc/shadow file.
269 > The /etc/shadow file stores actual password in encrypted format.
271 [https://www.2daygeek.com/understanding-linux-etc-shadow-file-format/]
274 joshua:$6$6PWRmE20$BAkQBhvRUnnyuGBgIrikxBp8YkOOUO7REg285NqJbFNt7E.19xNTfa2wdT0.NiFxdcw2nMLmT3/hgw1doIB2x/:18176:0:99999:7:::
277 In our case the prefix $6$6 means that the password is hashed with 6 rounds of SHA-512 and
278 PWRmE20$BAkQBhvRUnnyuGBgIrikxBp8YkOOUO7REg285NqJbFNt7E.19xNTfa2wdT0.NiFxdcw2nMLmT3/hgw1doIB2x/ is the hashed password of the user "joshua".
284 - Mounting .img files
285 - Approaching a forensic challenge