Zh3r0 CTF writeup

Zh3r0 CTFという初級〜中級者向け?のCTFに参加した記録です。高校生が主催されてたみたいです。SUGOI。

9問解け、 スコアは1615ptでした。

Misc

Welcome to Phase 1

textareaの文字を入力。

答え:zh3r0{is_this_a_real_flag?}

Welcome to Phase 2

Zh3r0 CTFのDiscordサーバの#shellでコマンドを打っていきます。

f:id:nafuka11:20200619123856p:plain

答え:zh3r0{Hav3_FuN}

Web

Web-Warmup

bg.cssにflagがコメントアウトされています。

/*css is easy, I think. Don't you?zh3r0{y3s_th1s_1s_w4rmup}*/

答え:zh3r0{y3s_th1s_1s_w4rmup}

Tokens

問題文で与えられているTokenはDiscordのUserToken。

DiscordChatExporterを使い、Userのメッセージからflagを得ます。

DiscordChatExporterを使ってguildsを見ると、DMしか送られていないことが分かります。

$ docker run --rm tyrrrz/discordchatexporter:stable guilds -t NzIyMzM1MTQ5NDA0MTkyODIw.XunLaw.xASADEeu9iXsYf1wqTFOil_jgfo
@me | Direct Messages

exportdmで出力したファイルにflagがあります。

$ cat ./Direct\ Messages\ -\ Private\ -\ Mr.4N0NYM4U5\ \[722336834264498177\].html | grep zh3r0
        <span class="chatlog__author-name" title="zh3r0{1et_7he_F0rce_8e_With_YoU}#5799" data-user-id="722335149404192820" >zh3r0{1et_7he_F0rce_8e_With_YoU}</span>
                    <div class="markdown"><span class="pre pre--inline">flag : zh3r0{1et_7he_F0rce_8e_With_YoU}</span></div>
                    <div class="markdown"><span class="pre pre--inline">flag : zh3r0{1et_7he_F0rce_8e_With_YoU}</span></div>

答え:zh3r0{1et_7he_F0rce_8e_With_YoU}

Reversing

snakes everywhere

py_dis1はPythonバイトコードを逆アセンブルした結果のファイルのようです。snake.txtはpy_dis1を実行して生成されるファイル(本来はciphertext.txtとして保存されるファイル)です。

py_dis1の中に変数flagがあり、snake.txtから逆算してflagを求める問題です。

py_dis1を 公式ドキュメント を見つつ、python -m dis py_dis1.pyで都度確認しつつ、コードに復元しました。逆ポーランド記法っぽく読めます(自動で復元できるツールがあったら教えてください)。

復元したコードからsnake.txtを読み込んでreverseするコードを書いてflagを求めました。

答え:zh3r0{Python_disass3mbly_is v3ry_E4sy}

Subset of subset of hacking machines challenges

Flag 5

ポート22番が空いています。

PORT    STATE    SERVICE
22/tcp open     ssh

curlしてflagを入手。

$ curl hackit.zh3r0.ml:22
z3hr0{shouldve_added_some_filter_here}

答え:z3hr0{shouldve_added_some_filter_here}

Flag 2

nmapでポートスキャンをすると、324番が空いていることが分かります。

$ nmap -p301-400 hackit.zh3r0.ml
Starting Nmap 7.80 ( https://nmap.org ) at 2020-06-17 02:10 JST
Nmap scan report for hackit.zh3r0.ml (139.59.3.42)
Host is up (0.14s latency).
Not shown: 98 closed ports
PORT    STATE    SERVICE
324/tcp open     rpki-rtr-tls
329/tcp filtered unknown

ncしてみます。

$ nc hackit.zh3r0.ml 324
220 (vsFTPd 3.0.3)

Name (hostusername):

220 (vsFTPd 3.0.3)ググるFTPサーバであることが分かります。ftpコマンドでアクセス。パッシブモードでないと一部コマンドが使えないため、-pで指定しました。

$ ftp -p hackit.zh3r0.ml 324
Connected to hackit.zh3r0.ml.
220 (vsFTPd 3.0.3)
Name (hackit.zh3r0.ml:vagrant): admin
530 This FTP server is anonymous only.
Login failed.

ユーザ名はanonymousしか受け付けていない様子。「anonymous FTP」でググった感じ、ユーザ名anonymousだとパスワードは何でもいいようでした。

anonymousでログイン。

220 (vsFTPd 3.0.3)
Name (hackit.zh3r0.ml:vagrant): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

ls -a コマンドでディレクトリを見て、cd ...でどんどんディレクトリを移っていきます。

test.txtと.stayhiddenはダミー。

ftp> ls -a
227 Entering Passive Mode (139,59,3,42,138,97).
150 Here comes the directory listing.
drwxr-xr-x    3 ftp      ftp          4096 Jun 15 15:05 .
drwxr-xr-x    3 ftp      ftp          4096 Jun 15 15:05 ..
drwxr-xr-x    3 ftp      ftp          4096 Jun 15 15:05 ...
-rw-r--r--    1 ftp      ftp            22 Jun 15 15:05 test.txt
226 Directory send OK.

ftp> cd ...
250 Directory successfully changed.

ftp> ls -a
227 Entering Passive Mode (139,59,3,42,174,119).
150 Here comes the directory listing.
drwxr-xr-x    3 ftp      ftp          4096 Jun 15 15:05 .
drwxr-xr-x    3 ftp      ftp          4096 Jun 15 15:05 ..
drwxr-xr-x    2 ftp      ftp          4096 Jun 15 15:05 ...
-rw-r--r--    1 ftp      ftp            46 Jun 15 15:05 .stayhidden
-rw-r--r--    1 ftp      ftp            22 Jun 15 15:05 test.txt
226 Directory send OK.

ftp> cd ...
250 Directory successfully changed.

ftp> ls -a
227 Entering Passive Mode (139,59,3,42,171,225).
150 Here comes the directory listing.
drwxr-xr-x    2 ftp      ftp          4096 Jun 15 15:05 .
drwxr-xr-x    3 ftp      ftp          4096 Jun 15 15:05 ..
-rw-r--r--    1 ftp      ftp            34 Jun 15 15:05 .flag
-rw-r--r--    1 ftp      ftp            22 Jun 15 15:05 test.txt
226 Directory send OK.

get .flag でローカルに.flagを転送します。ファイルを開くとflagがあります。

$ cat .flag
Flag 2: zh3r0{You_know_your_shit}

答え:zh3r0{You_know_your_shit}

Flag 1

4994番ポートが空いています。

PORT     STATE SERVICE
4994/tcp open  unknown

ncでアクセス。

$ nc hackit.zh3r0.ml 4994

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                     ||Employee Entry||

----------------------------------------------------------
                     Sherlock Holmes Inc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here's a free flag for you, just for finding this door! Flag 1: zh3r0{pr05_d0_full_sc4n5}
Heyo, Watcha looking at? Employee ID yoo! :

答え:zh3r0{pr05_d0_full_sc4n5}

Flag 4

Flag1の入力でEmployee IDを入力します。

Employee IDはFlag2にあったファイル、.stayhomeの中にあります。

$ cat .stayhidden
Employee ID: 6890d90d349e3757013b02e495b1a87f

IDを入力します。

Heyo, Watcha looking at? Employee ID yoo! :
6890d90d349e3757013b02e495b1a87f
Hey I know you! You work here!
Books are a uniquely portable magic. - Stephen King

Flag 4: zh3r0{y0ur_s4l4ry_wa5_cr3dit3d}

答え:zh3r0{y0ur_s4l4ry_wa5_cr3dit3d}