こんとろーるしーこんとろーるぶい

週末にカチャカチャッターン!したことを貼り付けていくブログ

Byte Bandits CTF 2019 Writeup - Online Previewer 1, 2

Online Previewer 1

Question

We just learnt about a proxy service run by NSB. The network is known to have a secret service running.
Can you find that secret?
http://op1.ctf.euristica.in

f:id:graneed:20190413235923p:plain

Solution

URLを入力すると、URL先からコンテンツを取得してくれるサービス。
こういうときは、大抵、LFIかSSRFで攻める問題である。

HTMLソースを見る。

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css" type="text/css" media="all">
   <title>Online Previewer</title>
</head>
<body>
    <div class="columns hero is-fullheight is-vcentered is-centered">
        <div class="column is-half">
            <div class="title">Preview any url</div>
            
            
            
            <form method="post" action="/view">
                <div class="field">
                    <input type="text" name="url" class="input"  placeholder="https://google.com">
                </div>
                <div class="field">
                    <input type="submit" class="button is-primary">
                    <!--some secret stuff is there at http://127.0.0.1:1337/-->
                </div>
            </form>
        </div>
    </div>    
</body>
</html>

コメントより、http://127.0.0.1:1337/にフラグがありそうだ。

以下のパターンを試すがCan't do that mate.と表示されNG。

127.0.0.1に名前解決するドメインを用意して試すことにする。
自分で用意するのが面倒だったので、以下の記事を参照してloopback.jpを利用させていただく。

qiita.com

http://loopback.jp:1337/を入力する。
f:id:graneed:20190414001015p:plain

すると、フラグをゲットできた。
flag{ev1l_dn$_2750927}

Online Previewer 2

Question

So, the secret in the previous service was not that valuable.
But no worries, we just found another proxy service.
They say that it is the next version of the previous one and is way more secure.

But I know you like challenges!

http://op2.ctf.euristica.in

f:id:graneed:20190413235923p:plain

Solution

HTMLソースを見る。

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css" type="text/css" media="all">
   <title>Online Previewer</title>
</head>
<body>
    <div class="columns hero is-fullheight is-vcentered is-centered">
        <div class="column is-half">
            <div class="title">Preview any url</div>
            
            
            
            <form method="post" action="/view">
                <div class="field">
                    <input type="text" name="url" class="input"  placeholder="https://google.com">
                </div>
                <div class="field">
                    <input type="submit" class="button is-primary">
                    <!--some secret stuff is there at http://127.0.0.1:1337/-->
                </div>
            </form>
        </div>
    </div>    
</body>
</html>

HTMLソースはOnline Previewer 1と同じ。

しかし、http://loopback.jp:1337/は通らない。
チェック機能が強化されているのだろう。

似たような問題を見たことがある。

Security Fest 2018 - Pongdom | JBZ CTF Team

サーバー内の処理で、IPアドレスをチェックするためにDNS問い合わせしてから、再度、コンテンツを取得するためにDNS問い合わせしていると仮定する。 1つのドメインに、127.0.0.1と任意のIPアドレスの2つを割り当てることで、IPアドレスのチェック時には任意のIPアドレスで名前解決、コンテンツを取得時に127.0.0.1で名前解決されれば、チェック機能をバイパスできる。

ドメインを用意する。
f:id:graneed:20190414002552p:plain

http://XXX.XXX.mydns.jp:1337/を何回か入力するとフラグをゲットできた。

flag{dNs_c@nT_b3_Tru$ted_258097}