<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sam Wedgwood on Medium]]></title>
        <description><![CDATA[Stories by Sam Wedgwood on Medium]]></description>
        <link>https://medium.com/@swedgwood?source=rss-2bc65658f90f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_NfDH61ylIjjdNnSwDKMuA.png</url>
            <title>Stories by Sam Wedgwood on Medium</title>
            <link>https://medium.com/@swedgwood?source=rss-2bc65658f90f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 00:18:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@swedgwood/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Hack The Box — Access Write-up]]></title>
            <link>https://medium.com/ctf-writeups/hack-the-box-access-write-up-33ab4cb7d9b3?source=rss-2bc65658f90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/33ab4cb7d9b3</guid>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[sam-wedgwood]]></category>
            <category><![CDATA[writeup]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Sam Wedgwood]]></dc:creator>
            <pubDate>Sat, 23 Mar 2019 18:43:18 GMT</pubDate>
            <atom:updated>2019-03-23T18:43:18.814Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oFmpsqqscrhajvI6vgPbKQ.png" /></figure><h3>Hack The Box — Access Write-up</h3><p><em>This is my write-up for the ‘Access’ box found on </em><a href="https://hackthebox.eu/"><em>Hack The Box</em></a><em>.</em></p><p><em>In short: Anonymous FTP login, password-protected zip-file with a database storing the password, contents of zip-file were an email with password for telnet, use of </em><em>runas /savecred to escalate.</em></p><h3>Part 1: User</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*dapPYYjccyxHNyu8qaKA-Q.png" /><figcaption><a href="https://explainshell.com/explain?cmd=nmap+-sVC+-oN+nmap.txt+10.10.10.98">nmap -sVC -oN nmap.txt 10.10.10.98</a></figcaption></figure><p>The initial nmap scan shows us that there’s three services: FTP (with anonymous login allowed), Telnet and HTTP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*1lyPJoVCdZ_1eqpUhFvy2w.png" /></figure><p>We can take a look at the FTP server by logging in anonymously;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*jAl_XbgF9yen8JjrKHcVNw.png" /></figure><p>In the Backups folder there’s a file called ‘backup.mdb’, so let’s download that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*wQpFkW1Vf-g9-lK51YekeA.png" /></figure><p>In the Engineer folder there’s a file called ‘Access Control.zip’, so let’s get that one also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*FklLSwZJvTKgqKMJpBpC4g.png" /></figure><p>We’ve got everything we can from there, let’s try extracting that zip file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*-dUa8CzWSsSYE47NOtiO0Q.png" /></figure><p>It requires a password, we can probably assume the password is located within the ‘backup.mdb’ file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*pwE-QdGXYlbCtk3qfUnrKA.png" /></figure><p>It’s a Microsoft Access Database file. As I run Linux natively, I had to find a tool for the job; Unfortunately, I couldn’t get any working so I ended up just searching through the raw data in Bless Hex Editor, searching for keywords:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tmrpCrzKPv87e04ImFuXJA.png" /></figure><p>When searching for admin, we find a suspicious string ‘access4u@security’ which looks password-like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*Z4Ac3wfS4j4UhzYGkoIfrQ.png" /></figure><p>And it works! We’re left with a new file called ‘Access Control.pst’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*Xfmtuv1hWkAhiCFpTgAk_Q.png" /></figure><p>More Microsoft file-types!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*49kLHK00W6f0lLJ3osa6WA.png" /></figure><p>Unfortunately, running cat or strings doesn’t yield much, maybe we can convert it to a more global file-type?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*7gQ5sc9Qf6JvxiVkXnwmEg.png" /></figure><p>Luckily someone has made a program for this already! And with that we have our mbox file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*oibUqTHCk8RJtxqB4nvK1g.png" /></figure><p>Running strings on the mbox file gives us some login details, let’s try those details on the telnet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*KLcisjU77toLbetpLJQwag.png" /></figure><p>And we have user!</p><h3>Part 2: Root</h3><p>Now that we have user, we need to find our privilege escalation. So let’s have a poke around! For some reason this shell doesn’t let you backspace, which is annoying.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*2uAG8F7R61UobyNOH5064A.png" /></figure><p>After having a poke through this (ignoring user-made files, which you can tell from the timestamp) I couldn’t find much interesting other than .yawcam which appeared to be some application to help take photos? Not quite sure, let’s have a look at other folders we have access to outside of the user folder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*jbHY5iyag00tK0Lg6kMhow.png" /></figure><p>A Public user? Let’s look in there!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*jkF-zm5KZJuKV_QtQhPeyw.png" /></figure><p>Seems rather… empty? Where’s Desktop for example?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*OavFPsPj75NZWzdBc9P2Uw.png" /></figure><p>It’s hidden! Just like how Linux has ls -a , Windows has dir /a , who woulda guessed?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*MxoYTQSbGJiEF7_HQaCk3Q.png" /></figure><p>There’s a shortcut (.lnk) file, lets just type it and see what we get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eMFvJ9MWADzZ3ItS2dW9Tg.png" /></figure><p>A big mess! But a keen eye might spot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*5d1n1wtzWVNv8JHeHWMBtw.png" /></figure><p>runas , /user:ACCESS\Administrator and /savecred . The last one is for lazy people who want their credentials saved when they use runas so they don’t have to type their password every time. If the credentials are still saved, we might be able to leverage this into a full blown shell!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*VTEGarj_QQKd7Ww4ROgR_Q.png" /></figure><p>Uh…? Doesn’t seem like it worked, but it didn’t ask for a password either?</p><p>From what I can tell, the runas command appears to open a process and it does run the command, but just not in our telnet session. So we essentially have blind command execution as System. Since the Root flag will be located in root.txt on the Desktop of the Admin, we can just copy it out; I devised this command:</p><pre>runas /savecred /user:ACCESS\Administrator &quot;cmd.exe /C type C:\Users\Administrator\Desktop\root.txt &gt; C:\Users\security\Searches\out.txt&quot;</pre><p>Essentially I’m just copying the file to the Searches folder, which I do to hide it from other people attempting to escalate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*n5uuyGfjqAA7dgXrH4S2YA.png" /></figure><p>Boom! Rooted!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*UIikbvGexAk_QLVlSl8gTg.png" /></figure><p>And let’s delete that file to stop cheating!</p><p><em>Access was my second box, and all-in-all, I thought it was a pretty well-rounded box. The only annoyance is the pain of that telnet session which I failed to convey in this write-up, not only would it die frequently, I couldn’t backspace! Regardless, I had fun and learnt lots so it was good for me.</em></p><h4>Keep an eye out for my future write-ups!</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33ab4cb7d9b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ctf-writeups/hack-the-box-access-write-up-33ab4cb7d9b3">Hack The Box — Access Write-up</a> was originally published in <a href="https://medium.com/ctf-writeups">CTF Writeups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Context 2018 Christmas Competition]]></title>
            <link>https://medium.com/ctf-writeups/context-2018-christmas-competition-c8fedf922051?source=rss-2bc65658f90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8fedf922051</guid>
            <category><![CDATA[writeup]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[sam-wedgwood]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Sam Wedgwood]]></dc:creator>
            <pubDate>Mon, 07 Jan 2019 15:00:06 GMT</pubDate>
            <atom:updated>2019-01-07T15:05:33.968Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*hnBDoU8ofZkoDVe3.png" /></figure><h3>Context 2018 Christmas Competition — Writeup</h3><blockquote>December is finally here! And what better way to celebrate than with a good old CTF? —<a href="https://www.contextis.com/en/careers/challenges/context-christmas-competition"> contextis.com</a></blockquote><p>Click <a href="https://www.contextis.com/en/careers/challenges/context-christmas-competition">here</a> for the original web page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*ES-nV11Z9IgsuiGU0pxdOw.png" /></figure><p>We’re given a clue, and a cipher to decrypt. The clue is a bit strange, it makes sense to begin with 1+1=2, 2+2=4, 4+4=8, but then you reach 8+8=7?</p><p>The main thing to take note on is the fact the elf calls it ‘A lossy cipher’, implying data is lost upon encryption and that this cipher may just be a glorified hash or checksum.</p><p>And those of you with a keen eye may have noticed that 8+8=16, and that 1+6=7. So our best guess is that because the ciphers are all 1 digit, we could assume that they are the output of this checksum function. Following this line of thought, let’s assume that the inputs of this function are in the range 1 to 26 inclusive (as those can correlate to the letters of the alphabet.).</p><p>After these assumptions we could begin to write a script to find out all the input numbers in the range 1–26 inclusive, that will turn into the values in the cipher.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8dd9491de5c31f0f92ddb0c47db8af7/href">https://medium.com/media/a8dd9491de5c31f0f92ddb0c47db8af7/href</a></iframe><p>This is the script I came up with, let’s step through it and explain what each part is doing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*1M53Uuzj1bJ4Gfpb-_zBLw.png" /></figure><p>Here I have the shebang, an import of the alphabet (to convert numbers to letters) and the cipher as a list of integers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/198/1*zwBVVWCChA9NyfVsZjQeRA.png" /></figure><p>This is the ‘meat’ of the code so to speak, this function works out what numbers from 1–26 such that when you add the digits of the number it results in whatever number you specify, for example: If you pass in 4, it returns [4, 13, 22].</p><p>It works out the first possibility by simply using the number you pass in, since it’s only got one digit so it adds to itself.</p><p>The second possibility is that it starts with a 1, so first we check if the number given is 1 or higher, and if so we add it to 10 and minus 1 (+9), so 4 goes to 13.</p><p>Then we apply the same logic to if it starts with 2, by checking if it is 2 or higher, adding 20 removing 2 (+18), so 4 goes to 22. However this means a value such as 9 can go to 27, but this is out of range (there’s no letter after z!) so we limit the x values by checking if they are less than or equal to 8.</p><p>The last possibility is a special case, as if you plug in 1 (without these two lines) the function returns [1, 10]. However, if you checksum 19, you get 1+9=10, which isn’t 1 digit, so we need to apply the checksum again 1+0=1. This is the only exception to the previous possibilities, as it’s an exception, I just check if it’s equal to 1, and if so add 19 to the list of possibilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*RsP0_F6dZfwUqqaUrDYnvQ.png" /></figure><p>This next part applies the function pos to every number in the cipher, and then converts it to a letter, so we get a list of lists, where each nested list is a list of possible characters that could be in that position.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*u0NSThRcZQZhyIXQr9OwcA.png" /></figure><p>Then we print it out so we can look at it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GioL02p9g1jniBosJTgCnw.png" /></figure><p>Running results in this output, and by reading across you may notice that you can form ‘merrychristmasyoufilthyanimal’ by selecting the right letters from each group of letters.</p><p>And that’s it, the answer!</p><h4>MERRYCHRISTMASYOUFILTHYANIMAL</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8fedf922051" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ctf-writeups/context-2018-christmas-competition-c8fedf922051">Context 2018 Christmas Competition</a> was originally published in <a href="https://medium.com/ctf-writeups">CTF Writeups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack The Box — Jerry Write-up]]></title>
            <link>https://medium.com/ctf-writeups/hack-the-box-jerry-write-up-6f045601315f?source=rss-2bc65658f90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f045601315f</guid>
            <category><![CDATA[writeup]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[sam-wedgwood]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Sam Wedgwood]]></dc:creator>
            <pubDate>Sat, 17 Nov 2018 16:49:00 GMT</pubDate>
            <atom:updated>2018-11-17T16:49:00.498Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u5geW2CkzLfUj3TlqvmN1A.png" /></figure><h3>Hack The Box — Jerry Write-up</h3><p><em>This is my write-up for the ‘Jerry’ box found on </em><a href="https://www.hackthebox.eu/"><em>Hack The Box</em></a><em>.</em></p><p><em>In short: Default credentials and authenticated RCE using metasploit module, Apache was running as root so no privilege escalation required.</em></p><h3>Part 1: User</h3><p>The information we start with is that it’s IP is 10.10.10.95, and it runs Windows. Of course, this is hardly enough information! So we use nmap to see what this machine has to offer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*qddW5evThv4QR1uIfYC0XQ.png" /><figcaption>nmap -sV 10.10.10.95</figcaption></figure><p>We see that it’s running Apache Tomcat on port 8080, so our first instinct would be to visit the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Olb5uXwNM92oCBygfkpQOg.png" /><figcaption>Apache Tomcat/7.0.88</figcaption></figure><p>Manager App sounds interesting!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lCfwB6aVsQ_W_cJHb2By7A.png" /><figcaption>Authentication Required :(</figcaption></figure><p>Looks like we need login information, or we could just try ‘admin’ and ‘admin’?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_QUdfV9LTdD2yx9emGZ9vw.png" /><figcaption>403 Access Denied</figcaption></figure><p>Well, something happened.</p><p>If we have a read of this, we can see it’s showing us how to set up an account that can access the Manager App, with the username ‘tomcat’ and the password ‘s3cret’. So we tried ‘admin’ and ‘admin’, it didn’t work, but we are presented with new login credentials now, so let’s try them!</p><p>However we’re already logged in, so I quickly close Firefox and open it again, this will wipe the cookies as we’re in Private Browsing mode, thus logging us out. We then log back in with the new credentials and…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EMBW32Y1rr70rGY4WHsopQ.png" /><figcaption>Tomcat Web Application Manager</figcaption></figure><p>This looks promising! Let’s have a gander at what we can do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ajMx8pYJ-_PWiU8gLVvXxg.png" /><figcaption>Interesting names…</figcaption></figure><p>Some of these names don’t look standard, indicating that this may be our way to getting user access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rEKHJmy7itBA_833FyPEgg.png" /><figcaption>File upload? I smell an exploit…</figcaption></figure><p>Scrolling further down, we see the reason for the strangely named apps. There’s an option to upload a WAR file, which is basically a JAR file for web apps. This sounds like our vulnerability to me, so we go to our best friend Google.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*widJ3wepDp1HKwwTXBQGJw.png" /><figcaption>Looking for some RCE</figcaption></figure><p>After chucking some random words together, we come across an exploit that makes use of authenticated upload, so the next step is to load up msfconsole</p><p><em>Side note: The module I’m using is multi/http/tomcat_mgr_upload which uses a POST to /manager/html/upload to get the payload on the server, there is another similar module called multi/http/tomcat_mgr_deploy which uses a PUT to upload the payload, from testing the deploy payload has given limited success, so I’d suggest using the upload payload.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qTGGjYVRGkK9QcMzeVGXOA.png" /><figcaption>We’re gonna need a full-screen terminal this time!</figcaption></figure><p>We set our exploit by typing in use multi/http/tomcat_mgr_upload .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*baGMIwt-NfcU5dJ_LQp0sA.png" /></figure><p>We then configure our exploit with the login credentials, the host, the payload, and the target. Once that is all set up all we need to do type is exploit , fingers-crossed!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*QD-dpSIa949wnaEtgpy6SA.png" /></figure><p>Ta-da!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*D4mlji2I80uQpift-Ad8mA.png" /></figure><p>I drop into a shell, and… what? I guess we’re already System, that was easy!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*ZyFkJzALAwvVTg9N5rCPDA.png" /><figcaption>2 flags for the price of 1!</figcaption></figure><p>After we navigate to the Administrator’s desktop, we find a directory named flags, which contains a text file called 2 for the price of 1.txt , which contains both of the flags we need to submit.</p><h3>Part 2: Root</h3><p>Well, we already have System, and the root flag, so this section is pretty useless.</p><p><em>Jerry was my first own on HTB, mainly because it was rated as ‘Piece of cake’ by a large majority of those who owned it. And, whilst it’s pretty easy (Especially because you get System as soon as you get a shell!), we all start somewhere.</em></p><h4>Keep an eye out for my future write-ups!</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f045601315f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ctf-writeups/hack-the-box-jerry-write-up-6f045601315f">Hack The Box — Jerry Write-up</a> was originally published in <a href="https://medium.com/ctf-writeups">CTF Writeups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSAW’18 RTC Quals — Clicker 2.0 Write-ups]]></title>
            <link>https://medium.com/ctf-writeups/csaw18-rtc-quals-clicker-2-0-write-ups-618a6a52c056?source=rss-2bc65658f90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/618a6a52c056</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[csaw18-rtc-quals]]></category>
            <category><![CDATA[sam-wedgwood]]></category>
            <category><![CDATA[writeup]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Sam Wedgwood]]></dc:creator>
            <pubDate>Thu, 18 Oct 2018 20:05:14 GMT</pubDate>
            <atom:updated>2018-10-18T20:05:14.817Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*PCfGf4hT4F7c6Lb4b21cig.png" /></figure><h3>CSAW’18 RTC Quals — Clicker 2.0 Write-ups</h3><p><em>Write-ups for the challenges Adrift, Negativity and OpenObjectivity from the CSAW’18 RTC Qualifiers.</em></p><p><em>Whilst not being eligible for the finals, me and my CTF team decided to do the CSAW’18 RTC Qualifiers anyway, for the practice, learning, and fun!</em></p><p><em>This set of challenges got really interesting toward the end as it had me and my team members playing with the key logic behind common Python functions and libraries in order to exploit the services.</em></p><h3>Flag 0: Recon</h3><p>No, this isn’t a flag, but it’s important to know what we’re dealing with before trying to exploit it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zWoaH0xIHhcMO8ou8jEyaw.png" /><figcaption><a href="http://web.chal.csaw.io:10106/">http://web.chal.csaw.io:10106/</a></figcaption></figure><p>If we visit the website, we’re greeted with what seems to be some documentation on a REST API. If we look at the name ‘Clicker 2.0’ and the endpoints under the clicker namespace it all hints at being a <a href="https://en.wikipedia.org/wiki/Incremental_game">clicker game,</a> (such as the famous <a href="http://orteil.dashnet.org/cookieclicker/">Cookie Clicker</a>) but with the twist that it’s all done through a REST API. There’s also a zip file supplied which contains the source code for the site; You’ll notice it says that it runs on Python3, this information is important later on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zv_c3PMZ5xjjO-H0h4Q7Jg.png" /><figcaption><a href="http://web.chal.csaw.io:10106/">http://web.chal.csaw.io:10106/</a></figcaption></figure><p>If we click on the individual endpoints it details how it should be used, as well as a handy ‘Try it out’ button. Let’s try making ourselves a user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vwLCTxtHaZq7P7mQHMQKjQ.png" /></figure><p>Woah, that’s a lot of information; Let’s focus on what’s important here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3QFeDxguyWmZDzi3cn66w.png" /></figure><p>Here I edited their example to ‘sammy’ and the unquestionably secure password of ‘samsamsam’, and hit the big ‘Execute’ button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSQ9VqE1QKB9RvW1U4n0KA.png" /></figure><p>And then here we’ve got our response, stating that our user was successfully created, and it gives us our token. Something to note with this token is that it begins with ey , which tells us it’s encoded JSON.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*se2LMarJGu9yRc1mEeg1rQ.png" /><figcaption><a href="https://gchq.github.io/CyberChef/#recipe=From_Base64(&#39;A-Za-z0-9%2B/%3D&#39;,true)&amp;input=ZXlKMGVYQWlPaUpLVjFRaUxDSmhiR2NpT2lKSVV6STFOaUo5LmV5SmxlSEFpT2pFMU16ZzJOalUxTlRRc0ltbGhkQ0k2TVRVek9EVTNPVEUwT1N3aWMzVmlJam96TWpVc0ltRmtiV2x1SWpwbVlXeHpaWDAuSWtPbWk5RkFRaVVQQUxlY0hiTW9nUmZtVkV0OUVORDZVaEN3YzNuM3pwTQ">https://gchq.github.io/CyberChef</a></figcaption></figure><p>If we decode it, we get some JSON and some seemingly-random data; That data is not random, this is in fact a JWT (JSON Web Token). <a href="https://gchq.github.io/CyberChef">CyberChef</a> has support for decoding JWT to JSON, and vice-versa.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Ym4VrGAsnMZh62jKu4Dpw.png" /><figcaption><a href="https://gchq.github.io/CyberChef/#recipe=JWT_Decode()&amp;input=ZXlKMGVYQWlPaUpLVjFRaUxDSmhiR2NpT2lKSVV6STFOaUo5LmV5SmxlSEFpT2pFMU16ZzJOalUxTlRRc0ltbGhkQ0k2TVRVek9EVTNPVEUwT1N3aWMzVmlJam96TWpVc0ltRmtiV2x1SWpwbVlXeHpaWDAuSWtPbWk5RkFRaVVQQUxlY0hiTW9nUmZtVkV0OUVORDZVaEN3YzNuM3pwTQ">https://gchq.github.io/CyberChef</a></figcaption></figure><p>Now we some nice JSON. Of course we can’t modify this token unless we get the secret key as that seemingly-random data is actually a signature, so we would need the secret key to re-sign it.</p><p>Anyways, back to Clicker 2.0. Let’s try using our new token to play this game. The web interface isn’t going to cut it for us, let’s program our own wrapper for the Clicker 2.0 REST API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*rO4LQWHwKHWniNcKoYn6lQ.png" /></figure><p>At first we can begin with a simple little wrapper to let us query the endpoints easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*IjMl1yR61-qIreSZdrFsew.png" /></figure><p>It’s working so far, let’s add some more specific functions to make this a bit easier.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b7b763aa9149d87e9d93105560cca21/href">https://medium.com/media/1b7b763aa9149d87e9d93105560cca21/href</a></iframe><p>Now we can play the game!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*ThgMqCTw8HaSPIVBbUqL9g.png" /></figure><p>So we have enough money to buy the cheapest clicker called ‘base’, it costed all 5 of our hard-earned money!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*SmIMGZpnWLWM1FLLevWF8g.png" /></figure><p>Now we’ve clicked it, we’ve managed to get +1 money!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*tUjFE537-nrCl0J9gPTNbw.png" /></figure><p>If we spam it though, we’re told we’ll get banned? There must be a rate-limit of some sort.</p><p>Of course we could keep this going on for hours and get lots of money… But, time is flags!</p><h3>Flag 1: Adrift</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*7m-AK-GpoaznOrx3kvvDvQ.png" /></figure><p>Now that we’re in flag territory, let’s have a look at the supplied source code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/167/1*fX_Bw2nXaxjuOSLqvkJByg.png" /></figure><p>Extracting the zipped file gives us the complete source code for the clicker site; Of course not fully up to date when it comes to the database file there, but good enough for us. The challenge description doesn’t tell us too much about how to solve the challenge, so let’s just search for the word ‘flag’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*0Kuz1TzF7r-Qtpnyq2i37A.png" /><figcaption><a href="https://explainshell.com/explain?cmd=grep+-rni+%27flag%27">grep -rni ‘flag’</a></figcaption></figure><p>If we do a quick search for the word flag through all the files, we see that there is reference to three different flags in clicker/__init__.py , so let’s take a look at the first one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*AOMowhi8hf0OcqXaVHPraw.png" /><figcaption>clicker/__init__.py</figcaption></figure><p>The first flag appears want a request with a header called bring_back_random_click which has to equal the return of the function random_string and if it’s not, it will return a 404 error. Before we take a look at random_string we must have a look at the route that this is located in, as it’s not @app.route but rather @default.route which implies that this may be a <a href="http://flask.pocoo.org/docs/1.0/blueprints/">Flask Blueprint</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*hTjLWdy1UZOa7q_EmAIZsw.png" /><figcaption>clicker/__init__.py</figcaption></figure><p>It appears that this isn’t a Blueprint, but rather a Namespace, which is offered by the python module <a href="https://flask-restplus.readthedocs.io/en/stable/">flask_restplus</a> but we don’t need to worry about that part, as if we scroll further down in the code…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*_u-oj0oxZHt3HPMm31_HiQ.png" /><figcaption>clicker/__init__.py</figcaption></figure><p>We can see that default is added to the namespace /default so the path we must GET to get the flag is /default/ .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*vhUJ3CmLDY5hb4yJwwG9aA.png" /></figure><p>If we take a look at the random_string function we see that defines random_str with nothing, picks a index from the lowercase alphabet ( string.ascii_lowercase ) and then appends the letter at that index to random_str 10 times, then it returns random_str .</p><p>As there are only 26 characters in the lowercase alphabet, we can just keep trying the same string over and over until we eventually get it right.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d3bf78a0b243c01a1654c9c16768f7e/href">https://medium.com/media/7d3bf78a0b243c01a1654c9c16768f7e/href</a></iframe><p>Here we write a script which will keep trying the trying the string “aaaaaaaaaa” until the the request doesn’t return 404, which would mean we got the guess correct, and then print the response text, which should be the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*z7_ferAKVXb8eXG4yAPtfw.png" /></figure><p>After a second or two when running it, we are sent the flag and can claim our 100 points</p><h4>flag{wh@t_Ar3_lAt3_b1nDiNg_cl0sUreS}</h4><h3>Flag 2: Negativity</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*3nv2-ldy8FMMt_x76T1qVw.png" /></figure><p>Negativity gives us the same URL and file as Adrift, as they are all part of the same series, with only 18 solves, it must be pretty challenging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*0Kuz1TzF7r-Qtpnyq2i37A.png" /><figcaption><a href="https://explainshell.com/explain?cmd=grep+-rni+%27flag%27">grep -rni ‘flag’</a></figcaption></figure><p>Going back to our grep command, we can see that clicker/__init__.py also contains some reference to the second flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*lCsr0gMuYblp2Q8XGO-X3g.png" /><figcaption>clicker/__init__.py</figcaption></figure><p>We find that at the route /default/money we have a function that requires a user token; then appears to grab some user object and checks if that user’s money is greater than or equal to 0, if so, return error 404, if not, return the flag.</p><p>So the clear goal here is to create a user account and get it to have negative money, but where do we start?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gZBX_DsMityOTyFFTEsRZg.png" /><figcaption><a href="https://explainshell.com/explain?cmd=grep+-rni+%27user.money%27">grep -rni ‘user.money’</a></figcaption></figure><p>In the end, the only thing that can change our money is the service itself, so we can use grep to search for all references to user.money . Let’s check them in order. Line 54 is part of the second flag function, so we can ignore that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*lDOEoX3HS5Zajw9uA1oiHA.png" /><figcaption>clicker/__init__.py</figcaption></figure><p>Lines 76, 77 and 79 all appear to be part of some admin command to give a user money.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*oMjWOKM1-qb0I6ORP0pOpA.png" /></figure><p>Lines 36 and 53 of clicker/service/user_click.py immediately stick out to me, as they both make use of the round function. Why would they need to round these values? Let’s inspect the code further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*6-ptmYwwNebx8vx5hArnKA.png" /><figcaption>clicker/service/user_click.py</figcaption></figure><p>These lines are part of the function purchase_clicker , although this function is pretty big so let’s focus on the part of the function with these lines using user.money .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*Ozb9W6jb4Amk3CZuNShM4g.png" /><figcaption>clicker/service/user_click.py</figcaption></figure><p>So the first thing to take note of is that round() is used here, in Python3 (I said it would be important) this function has a seemingly strange behaviour.</p><blockquote>if two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2). (<a href="https://docs.python.org/3.5/library/functions.html#round">https://docs.python.org/3.5/library/functions.html#round</a>)</blockquote><p>Essentially, if we’re rounding a number which ends in .5, it will round to the nearest <em>even </em>integer.</p><p>Using the knowledge of this behaviour, there must be a way to get the if statement to pass, but with round(price) larger than user.money so that we can get negative money, and then get the flag.</p><p>Let’s think of a number for price, and an integer for user.money that causes this. We would want price to be bigger than user.money when rounded, But when subtracted before rounded from user.money to be 0 or greater. The lowest value user.money-price can be and still round to 0 is -0.5, so let’s have that as a constraint for our numbers: Whatever user.money is, price is 0.5 more than it. Now we want a pair of number following this constraint such that price is rounded to a larger number than user.money, as round rounds to the nearest even number, user.money to be an odd value and price to be that same odd value plus 0.5 then price should theoretically round up to be 1 higher than user.money . Let’s test this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*XFTjVFmvKrhXaaZ3uoqtgw.png" /></figure><p>I picked the odd number 3 arbitrarily, let’s see what the round(money-price) is equal to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*bivjj18aEWZ7Qa-e2zZZjw.png" /></figure><p>This is 0, meaning the first if would pass, allowing all the stuff that handles buying the clicker to be executed. Lets see what money-round(price) comes out to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*A4bBa7gJNuinEEo-Rr775g.png" /></figure><p>It results in a negative! We have found our exploit!</p><p>The next step is to figure out how to get these numbers into those variables, as a recap: Money needs to be odd, and price needs to be money plus 0.5.</p><p>As money need only be an odd integer, and the base clicker can give us 1 money per click, this can be easily set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*OAQajLVR3RkTMtdQ1SnBuA.png" /><figcaption>clicker/service/user_click.py</figcaption></figure><p>Price is calculated from the clicker price multiplied by this scale, which is raised to the power of the quantity of clickers, essentially scaling the price of the clicker depending on how many you already own.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*emPKcM1jszzjRWo23OJG9Q.png" /></figure><p>During recon we discovered this scale value to be constant of 1.15 for all clickers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*xuLJ3yQhFOCG5zhDRmFt6Q.png" /></figure><p>If we look through all the clickers, there’s a clicker called momo where the price is 10, and 10 * 1.15 is 11.5, which is an odd number plus 0.5!</p><p>So we need to click base until we get 10, buy momo, then click until we get 11, and buy momo to get negative money. As our old account already has a lot of money on it, let’s create a new one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*Mvbphk_2msfAUisYH8K_HA.png" /><figcaption><a href="http://web.chal.csaw.io:10106/">http://web.chal.csaw.io:10106/</a></figcaption></figure><p>Let’s call it ‘B1g F3ll4’, after my team name ‘B1g F3ll4s’ with the ever-so-secure password ‘samsamsam’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rN5lrRGQJI3QCROFv8ujdA.png" /><figcaption><a href="http://web.chal.csaw.io:10106/">http://web.chal.csaw.io:10106/</a></figcaption></figure><p>Let’s copy our new key into our wrapper that we wrote from the recon and run it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*fyDzt1CxstxNHzYxD6IAHQ.png" /></figure><p>Let’s buy the base clicker, and click 10 times (we sleep to avoid the rate-limit ban).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*M_4kw3Gpr3po4eZFdMT06Q.png" /></figure><p>Now we’ve bought momo, we need to click 11 times and buy momo again!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*1njun_NvbjHN619X7ngnBw.png" /></figure><p>Success! Negative money! Now we just need to HTTP GET /default/money</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*peS9Vl436z25iTyZKzhJDg.png" /></figure><p>And that is our flag!</p><h4>flag{d1d_u_eXp3r1ence_gr0wTh}</h4><h3>Flag 3: OpenObjectivity</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*ax0EtbpkVY6DdGFJdY-QIQ.png" /></figure><p>OpenObjectivity gives us the same URL and file as Adrift and Negativity, as they are all part of the same series, with only 11 solves and 500 points up to grabs it must be quite a tough challenge; We have two challenges in the clicker series under our belt, how hard could another one be?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*g5yk6E53TdBjHOq13bR5Jw.png" /><figcaption>clicker/__init__.py</figcaption></figure><p>Looking at the part for the third flag, we see it’s located at /default/record and requires the logged in user to have a record of over 5000000000 (which is 5×10⁹ or more commonly known as 5 billion) otherwise it will just report 404.</p><p>First question, what is user.record ? Let’s grep it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*05rbelGZavD8qj-jrN9gMA.png" /><figcaption><a href="https://explainshell.com/explain?cmd=grep+-rni+%22user.record%22">grep -rni “user.record”</a></figcaption></figure><p>Other than the occurrence we already know of, it takes us back to the user_click.py file we used in the second flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*R1jKXEFNf-7XrciaUhtVMg.png" /><figcaption>clicker/services/user_click.py</figcaption></figure><p>This time under the function use_clicker which is implied to run when we click a clicker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*R9OcyEAl4YWuev5jE4rrEw.png" /><figcaption>clicker/services/user_click.py</figcaption></figure><p>This may look a little confusing to begin with, but if we dissect it it will become more understandable. First it sets the variables curr_time to the current time, and works out the difference between this time, and whatever user.record_time is and stores it in time_diff , it then checks if this difference is bigger than 5 seconds and if so it will set user.record to 0 and the user.record_time to the current time, if not it will add the amount of money from that click to the user.record .</p><p>This is essentially recording how much money you make for 5 seconds, and then resets it. So we need to get 5 billion money in 5 seconds.</p><p>First let’s check if this is possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*V1dilIhaDOlFUWL0BqfOTQ.png" /></figure><p>The most valuable clicker is captiosus, which is 10000000 (which is 10⁷ or 10 million). As the maximum quantity is 10, that means the highest amount we can get in 1 click is 10 * 1000000 = 100000000 (which is 10⁸ or 100 million). Which means we need to click in 5000000000÷100000000 = 50 times (with the best clicker) in 5 seconds. Back in the recon we discovered a rate-limit where if you spam too quickly it will threaten you with a ban.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*tUjFE537-nrCl0J9gPTNbw.png" /></figure><p>So let’s find out what this rate-limit actually is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*1GITQrNC2AZz60JBlMXsHA.png" /></figure><p>We can try a couple search terms until we find one that works, and here we see two uses of the string rate_limit .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*kwX5yJFEXIbMSiH-_hoVJw.png" /><figcaption>clicker/controller/clicker.py</figcaption></figure><p>The first imports rate_limit and the second in the same file uses that import on the click route, or what manages when we click.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*01L7Z9DObTDedLwERX5eFQ.png" /><figcaption>clicker/util/decorator.py</figcaption></figure><p>Decorators in python are a bit confusing, lets focus on the part that matters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*EL0orvhnX1Tw_CAqTBu-bA.png" /><figcaption>clicker/util/decorator.py</figcaption></figure><p>So this seems to check if the time since you’ve last clicked is smaller than the interval which is the reciprocal of reqs_per_sec . This means that you can click reqs_per_sec times per second, as implied by the name which could be read as ‘requests per second’.</p><p>This means that we can only click twice per second, so we can only click 10 times in 5 seconds, meaning we the maximum record we can get is 100000000×10=1000000000 (10⁹ or 1 billion) which is only a fifth of our goal, 5 billion. This likely means that playing the game normally is not our ticket to victory.</p><p>One thing to take note of is that the user.record has to be stored somewhere between requests, which is where the database file comes into play.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*Hh-xuqanDGcKcLutcziyNg.png" /></figure><p>Yup, there’s a database file in there. Let’s have a poke around.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*0lubqvqiNwF33p-LMuppdg.png" /><figcaption><a href="https://explainshell.com/explain?cmd=file+main.db">file main.db</a></figcaption></figure><p>Seems to be a SQLite3 database, which is common for small-scale python projects like this. Luckily there is a program which lets us see what is inside:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*U8dODfkHdYSPSY2hAZz79A.png" /></figure><p>Let’s see what tables and columns in those tables are available to us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*dJeRXAR3Aj6l7k3kebc-SA.png" /></figure><p>We can see that the table user has a column called record , lets have a peek at the contents of that table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FFKiEkt4xBJ_-wtOymDeEw.png" /></figure><p>Well, that’s a bit of a mess, let’s only pick out username and record:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*QL1Am5JtGHaVdFd7VBsyjg.png" /></figure><p>We can see that this one outlier has 7400000000 (7.4×10⁹ or 7.4 billion!) as their record! Meaning that our route is probably to find a way to log in as a user that already has a record over 5 billion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*MFKUThCoeoNAUlwRRUya6A.png" /></figure><p>Having a look at the auth table, we can see that password hashes are stored, so let’s find the password hash of our record-breaking user!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*dPYzzPu_DKcpiNjx1LdPnQ.png" /></figure><p>Ah, that’s quite a good hashing algorithm which slightly discourages my hash-breaking side. Let’s try something else.</p><p>Do you remember earlier, when we found out that the key used for authorisation was in fact a JSON Web Token? Let’s have a play with this information.</p><p>The only thing stopping us from creating our own JSON Web Tokens is the lack of a SECRET_KEY to sign the token, maybe there is a vulnerability that can get us this secret?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*cTDC-sCImObScRakghQG1w.png" /><figcaption>clicker/service/clicker.py</figcaption></figure><p>Whilst skimming over the code, we might notice the user of getattr here in clicker/service/clicker.py . getattr is short for Get Attribute, which essentially does what is says on the tin, it takes in an object, and takes in a name, and will try to get the value from an attribute named as specified in the object. The vulnerability is that the person passes in sys.modules[__name__] which essentially refers to the current script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*2bpBZUYfOejQ2s9UHir_iQ.png" /><figcaption>clicker/service/clicker.py</figcaption></figure><p>The programmer intended for the only accessible things to be these clicker classes, which would return the information about the clicker (as they all inherit base).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*iu5B82WYnOtYFFUKpfWJQg.png" /><figcaption>clicker/service/clicker.py</figcaption></figure><p>However, we can access all variables within this script, which includes the imported Config here at the top of the script; Let’s try this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*daEXo7geGxtNy_2gIflX8A.png" /></figure><p>We’ll have to find where this function is called, and if it passes unsanitised input into it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*Z_6oQ7EUNNsRNs1IzdSv0w.png" /><figcaption>clicker/controller/clicker.py</figcaption></figure><p>The first occurrence seems to be what we want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*SwHJfKujH0_XDiiBh2rSgA.png" /><figcaption><a href="http://web.chal.csaw.io:10106/">http://web.chal.csaw.io:10106/</a></figcaption></figure><p>If we remember from the original website, this is the endpoint to get a clicker by name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jasoe6_Ki8aLcUNCIoJvFg.png" /></figure><p>Sadly, it didn’t quite work. Let’s go back to the script to see what went wrong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*70P7mmuO3hWUQ_-f7NFUKA.png" /><figcaption>clicker/service/clicker.py</figcaption></figure><p>The focus is on the last line, it tries to call the output of getattr and get the __dict__ of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*MUybqety4_sG-worq1VIVQ.png" /><figcaption>clicker/controller/clicker.py</figcaption></figure><p>You may have noticed get_clicker_field here, and you wouldn’t be alone, so let’s take a look at that one, which just so happens to be right below the definition of get_clicker .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*I3mhPFOb1SvJUITqqh-CfQ.png" /><figcaption>clicker/service/clicker.py</figcaption></figure><p>This one also uses getattr but it uses it twice, so we could potentially use it to extract a specific variable from config, so let’s take a look at what is in config.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*RzKvCp8DwWiHZKrbzanzWQ.png" /><figcaption>clicker/service/clicker.py</figcaption></figure><p>It’s imported from a directory up, from config.py .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*qzRGA-fD6jkPV3KZ1wQsVA.png" /><figcaption>clicker/config.py</figcaption></figure><p>We need not look far, the secret key is right there! Let’s try specifying a field of SECRET_KEY when querying /clicker/Config this time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*2SZpgTf5eP3O5ZnZqXMG1Q.png" /></figure><p>Looks like we found ourselves the SECRET_KEY!</p><h4>dId_you_r3aLly_think_I_w0u1dnt_s3t_a_key</h4><p>Let’s decode one of our older tokens using CyberChef:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v48Sjn7rHpluKS_aUhomLQ.png" /><figcaption><a href="https://gchq.github.io/CyberChef/#recipe=JWT_Decode()&amp;input=ZXlKMGVYQWlPaUpLVjFRaUxDSmhiR2NpT2lKSVV6STFOaUo5LmV5SmxlSEFpT2pFMU16azVOekExT0RNc0ltbGhkQ0k2TVRVek9UZzROREUzT0N3aWMzVmlJam96TXpVc0ltRmtiV2x1SWpwbVlXeHpaWDAuVnhWUXFDUFBodmxSNGZyVlNfQUt3YW9zMWVCc3hhbmloSE84R1lXN3F2aw">https://gchq.github.io/CyberChef</a></figcaption></figure><p>This is the decoded token. As specified in the <a href="https://tools.ietf.org/html/rfc7519#section-4.1">standard</a> the exp is Expiration Time, the iat is the Issued At Time, and the sub is the Subject. Judging that the Subject is a number, I’m assuming that this is the user ID.</p><p>Let’s write a script to keep trying different IDs until we find one which has a record higher than 5 billion.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e01e12355c39a94c426aa8ba64fe7b4/href">https://medium.com/media/7e01e12355c39a94c426aa8ba64fe7b4/href</a></iframe><p>Luckily there’s a library just for our case, I set the expiry to be really big so the token won’t expire. I then iterate over the numbers 0 to 4999, and try them all as ids.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*mIAsXy5Isy_DNwvGaHSscg.png" /></figure><p>And with that, the 500 points can be claimed!</p><h4>flag{p3rson@l_1den7ity_is_A_m3Me}</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=618a6a52c056" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ctf-writeups/csaw18-rtc-quals-clicker-2-0-write-ups-618a6a52c056">CSAW’18 RTC Quals — Clicker 2.0 Write-ups</a> was originally published in <a href="https://medium.com/ctf-writeups">CTF Writeups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSAW’18 RTC Quals — Magic 2 Write-up]]></title>
            <link>https://medium.com/ctf-writeups/csaw18-rtc-quals-magic-2-write-up-a393b7256ecf?source=rss-2bc65658f90f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a393b7256ecf</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[sam-wedgwood]]></category>
            <category><![CDATA[writeup]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[csaw18-rtc-quals]]></category>
            <dc:creator><![CDATA[Sam Wedgwood]]></dc:creator>
            <pubDate>Tue, 02 Oct 2018 21:48:16 GMT</pubDate>
            <atom:updated>2018-10-03T14:31:25.416Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*PCfGf4hT4F7c6Lb4b21cig.png" /></figure><p><em>Write-up for the challenge Magic 2 from the CSAW’18 RTC Qualifiers.</em></p><p><em>Whilst not being eligible for the finals, me and my CTF team decided to do the CSAW’18 RTC Qualifiers anyway, for the practice, learning, and fun!</em></p><p><em>Magic 2 was brain teaser for me, and even though it isn’t much to do with InfoSec, or Red Teaming, I still had a lot of fun with it!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*sILg8RbQGglSBAggDsNO1g.png" /><figcaption>74 solves? Must be easy, right?</figcaption></figure><p>Magic 2 is a sequel to Magic 1. Magic 1 is a 9×9 matrix where only some cells are filled in, the goal was to fill in the rest of the gaps in the matrix, so that the matrix will become a 9×9 magic square.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IwoG1dE2yqsTR1g9aFmxbg.png" /></figure><blockquote>a <strong>magic square</strong> is a <strong><em>n×n</em></strong><em> </em>square grid (where <em>n</em> is the number of cells on each side) filled with distinct positive integers in the range <strong><em>1, 2, . . . , n² </em></strong>[…] the sum of integers in each row, column and diagonal is equal. The sum is called the <em>magic constant</em> or <em>magic sum</em> of the magic square. — <a href="https://en.wikipedia.org/wiki/Magic_square">Wikipedia</a></blockquote><p>Magic 2 was fairly similar to Magic 1, except the magic square was 10×10, adding a whole new layer of difficulty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ws47Ldo0aDA9XhYRQ8d9IQ.png" /></figure><p>We accomplished Magic 1 by happening upon the exact magic square whilst googling for how to solve them, however the same tactic did not work for Magic 2. So whilst my other team members reverse engineered binaries and hacked web pages, I took to solving Magic 2.</p><p>After googling (Or in my case, <a href="https://duckduckgo.com/"><em>DuckDuckGo-ing</em></a>) around for ages looking at different tutorials, they made solving a 10×10 magic square seem extremely difficult and time-consuming, I wasn’t prepared to read up on how other people solve it, so I came up with my own method.</p><p><em>Side note: In hindsight, my method is probably also difficult and time-consuming, plus since the number of solves was around 40 I still think there was an easier way, but hey, this is my method not theirs.</em></p><p>Whilst I spent a lot of time digging, it didn’t come completely dry, I found out a pattern which, whilst probably not inherent to all 10×10 magic squares, seemed to apply to Magic 2. Can you spot it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*TNSkeDLCtACQ0mKnpRTBJw.png" /><figcaption><a href="https://www.grogono.com/magic/10x10.php">https://www.grogono.com/magic/10x10.php</a></figcaption></figure><p>Can’t spot it? How about now?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*-jAacx-NYrzOsD42nIIuWA.png" /></figure><p>If I split the 10×10 grid into a 5×5 grid, where each cell contains 4 numbers, those 4 numbers are consecutive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/139/1*-0vTSMz03C8QmZxrxoURFA.png" /></figure><p>If we take a look at the top left group of numbers we can see that sums of the each row are equal, and the sum of each column are two apart from one another. We can make a notation for this, where one vertical line means 2 more than the other column in the smaller group of 4 numbers, and one horizontal means 2 more than the other row. There are also situations where the difference between the two rows or two columns is equal to 4, so I use a double line to 4 more than the other row/column.</p><p>Applying this notation to the magic square above gives us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*alCf5zWMA7LB6rTi040BPA.png" /></figure><p>It may look a bit messy and confusing to begin with, but if you single out the vertical lines in each pair of columns, there are the same amount of lines in both columns, same pattern applies to the rows.</p><p>Then, applying this pattern to the starting state of Magic 2’s grid:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*LyBXckaA2WeWtQlSwM-9xw.png" /><figcaption>The lack of horizontal lines isn’t a mistake, it’s just coincidence.</figcaption></figure><p>Now we have to fill the rest of the boxes with other combinations of 4 consecutive numbers in specific ways such that the lines all cancel out, right? Not only that, no. Since we can only use each number from 1–100 only <em>once</em>, as a rule. So not only do we need to place 4 consecutive numbers in each of these smaller squares, we also need to make sure those 4 consecutive numbers are the correct numbers such that the rows and columns add up to the magic constant, which for a 10×10 magic square is 505. We’re going to start with what sets of 4 consecutive numbers we need to place in the smaller squares, so that we make sure the lines cancel out and give the same value when ultimately added up.</p><p>As this is a 10×10 magic square, the numbers we have to choose from are from 1–10², or 1–100. This divides evenly into 25 sets of 4 consecutive integers (As 25×4=100), which are the multiples of 4, and the 3 integers below it (e.g. {1, 2, 3, 4}, {21, 22, 23, 24} and {69, 70, 71, 72}). By thinking of the 10×10 magic square as instead a 5×5 square can simplify the problem down and make it easier to manage, but to do that we must simplify these sets of 4 consecutive numbers down into 1 number, the easiest way to do that is take the 4th number and divide it by 4, leaving us with 1–25 to represent each set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vJonZT1EV3YDvPKAz11sXQ.png" /></figure><p>And so using that, we can simplify it into a 5×5 magic square, and because the numbers are the same relative to one another, as long as we can solve this square, we can get one step closer to solving the 10×10.</p><p><em>Side note: I can fill in the corner numbers as, even though they aren’t completed, they still follow the same rule of sets we discovered earlier. For example the top left one has 65 and 66, which are part of the {65, 66, 67, 68} set, so if we divide the 4th element by 4, we get 17.</em></p><p>When looking up how to solve a 5×5 magic square, I came across <a href="https://www.youtube.com/watch?v=g8E52iLhuJ4">this video,</a> which just so happens to be the exact same magic square we have, but flipped. This means our completed 5×5 is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*Hpv0GttOJge3fuvpj4RJUw.png" /></figure><p>I added numbers showing the sums of the rows and columns, showing that this is a solved 5×5 magic square, with a magic constant of 65. We can turn this back into the sets of numbers by multiplying the number by 4, and getting the three integers before it, so 5 becomes {17, 18, 19, 20}.</p><p>Now that we know the sets of numbers we need to use in the main 10×10 magic square, we need to know the arrangement of them within their smaller 2×2 squares. To do this we must construct a diagram that builds upon the original line diagram of the 10×10 to know what order to put them in, but to do that we need a way of converting the arrangement of the numbers into the lines, and vice-versa.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*6Ymv3flxsyEWMS9YdQv5ng.png" /></figure><p>Armed with this table, we have everything we need to starting filling in Magic 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*XvKr0Q_k-hTXG2BxdS0g9A.png" /></figure><p>If we take a look at our line diagram from earlier, we can start filling in lines. We should start with the corners, as they already have two numbers filled in.</p><p>Looking at the top left one, which already has 65 in the top left, and 66 in the bottom right, we know the set it came from is {65, 66, 67, 68}, so we must refer to our table of lines to see what has 1 in the top left, and 2 in the bottom right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/166/1*-iw6UFN6GUqMsJvhP-Pj4Q.png" /></figure><p>We can use this one, so we can draw a horizontal line on the picture</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*YQBrfDf19tVW81NHMgisUQ.png" /></figure><p>We can then apply the same method to the three other corners.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*BWNQ-iLc4Yx_OKWJqx9WcQ.png" /></figure><p>After this, we have to fill in the rest of the spaces, such that in each pair of columns or rows (as split by the black lines) the number of blue lines in each row/column of the pair is equal so that they cancel each other out, using the table of lines we made earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*6Vw96IPWNXOVGzk14K-8Lg.png" /></figure><p>With all the squares filled in with lines, we can now fill it in with numbers using the lines table. We can start anywhere, so let’s go with top left first.</p><p>We know that it is already filled with two numbers 65 and 66, so the full set of numbers is {65, 66, 67, 68}, and referring to our table from above we can fill in the fields as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/150/1*VHsreoZZg2q9UggaQLj2ZQ.png" /></figure><p>After these 4, we can move onto the 4 afterwards, which is completely blank, so we must refer to our 5×5 solved magic square.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*Hpv0GttOJge3fuvpj4RJUw.png" /></figure><p>In the next position is 24, so to get the set of numbers we multiply it by 4 to get 96, so the set is {93, 94, 95, 96}, and then we can refer to our line table and the type of line we chose for this next slot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*bH-gFFpfByGyslDVogtg0g.png" /></figure><p>By repeating this same process for all the unfilled squares, we should result in a solved 10×10 magic square, and our flag!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBjKpcASw-joYxHtApJBOg.png" /></figure><p>We now have the flag, and can claim our 150 points!</p><h4><strong>flag{y3r_a_wiz3rd_h4rry}</strong></h4><p><em>Foot note: This is quite a complex method and it’s one of my first few write-ups, if you have any suggestions or misunderstandings feel free to contact me! I’m assuming the reason this is only 150 points and has many solves is probably due to a 10×10 solver online if you dig deep enough, I don’t know, but I had fun with my method so that’s enough points for me.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a393b7256ecf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ctf-writeups/csaw18-rtc-quals-magic-2-write-up-a393b7256ecf">CSAW’18 RTC Quals — Magic 2 Write-up</a> was originally published in <a href="https://medium.com/ctf-writeups">CTF Writeups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>