CSAW CTF 2017 Writeup
毎年9月中旬恒例のCSAW CTFが今年も開催されてたので、********で出場していた。
社会人になって休日の時間が貴重すぎるので、ガッツリ休日の時間をCTFに全振り…とはせずに、今回は結果にはあまり拘らずやれるところだけ。
Writeup
今回はRecon 1問、Forensicsの2問だけ解けた。
- Super Difficult Recon (Recon 1)
- Missed Registration (Forensics 150)
- Best Router (Forensics 200)
他には、Crypto 1問に挑戦したが解けなかった。
- Another Xor (Crypto 100)
Super Difficult Recon (Recon 1)
lol jk no recon this year :P flag is flag{f00led_uuuuuuu}
激ヤバイRecon来るのかと思ったら、今年はReconなかった。やったぜ。
flag{f00led_uuuuuuu}
Missed Registration (Forensics 150)
It's registration day! These forms just seem longer and longer...
https://ctf.csaw.io/files/bd2d3bcfdf09f06728d81d1a0cc0e4ff/cap.pcap
pcapファイルなForensics問題なので、解くしかないでしょう。
まず、Wiresharkで開いて中を覗いてみる。 192.168.0.0/24のホスト間で8080/tcpのHTTPの通信が大量にあり、これは怪しい。
HTTP Responseはすべて同じものなので、WiresharkのDisplay Filterにtcp.port == 8080 and http.request
を入力して、怪しい通信のHTTP Requestだけを見てみる。
Packet全体のLengthが1033bytesなのに、HTTPのContent-Lengthが615bytesしかない。
WiresharkのPacketDetails画面で、HTML Form URL Encoded
でエンコードされているデータもあるけど、
Packet Bytes画面で後ろの方を見てみると、&x=
というPacket Detailsでエンコードされていないデータが。*1
最初に&x=
が出てくるデータの先頭を見てみると、42 4d
となっているので、BMPぽい。
他のパケットに含まれているこのデータ部をつなげて、1binaryファイルとして出力すれば、BMPの画像になるのでは?と思った。
手作業でデータをつなげるのはしんどいので、Pythonのpcapを扱うライブラリであるdpktを使ってスクリプトを書いた。
ちなみに、cap_filtered.pcap
は上記Display Filterを使って余計なパケットを取り除いたpcapファイルである。
# ! /usr/bin/env python # ! -*- coding:utf-8 -*- import dpkt f = dpkt.pcap.Reader(open('cap_filtered.pcap', 'rb')) result = [] for t,buf in f: eth = dpkt.ethernet.Ethernet(buf) ip = eth.data tcp = ip.data if tcp.dport == 8080 and len(tcp.data) > 0: result.append(dpkt.http.Request(tcp.data)) data = '' for r in result: data += r.data[3:].decode('hex') f2 = open('flag.bmp', 'wb') f2.write(data)
それで出力されたファイルがこれ。
ここまで30分くらいで来たのに、画像の解像度が悪すぎて文字がつぶれてて文字が読めない…
何だこのFlagの文字を解読させる勝負のクソ問は、と思って数時間放置してたら、新しい問題ファイルが降ってきた。
UPDATE 10:44 Eastern: New pcap that should be a bit easier to work with.
最初の問題ファイルはpcapngだったけど、pcapファイルになってる。そして、余計なパケットがなくなっていた。 このファイルをスクリプトにかけてみると、今度はちゃんとFlag文字が読める鮮明な画像が出力された。
FLAG{HElp_Th3_BANANASCRIPt-guy_15_thr0wing_m0nkeys@me}
ちなみに、この問題は、大会中に問題ファイルが2回、Flagが1回変わったが、上記スクリプトですべて解ける。
UPDATE 2:58 Eastern: We're regenerating due to flag leaks, submissions disabled until then. Please be patient.
Update 3:31 Eastern: Updated pcap with new flag after leak. Please re-run your solutions on the file!
誰かがFlagをおもらししちゃったのか…
Best Router (Forensics 200)
http://forensics.chal.csaw.io:3287
NOTE: This will expand to ~16GB!
19:00 Eastern: updated. Old flags have been removed.
https://ctf.csaw.io/files/e003b7cd6d0406d93467f3c7290d4ef7/best_router.tar.gz
best_router.tar.gz を展開すると16GBのファイル。 とりあえず、Ubuntu 16.04でのfileコマンドをしてみる。
taka@ubuntu:~/ctf/csawctf2017$ file best_router.img best_router.img: DOS/MBR boot sector; partition 1 : ID=0xc, start-CHS (0x0,130,3), end-CHS (0x5,214,7), startsector 8192, 85622 sectors; partition 2 : ID=0x83, start-CHS (0x5,220,24), end-CHS (0x3ff,254,63), startsector 94208, 30453760 sectors
ディスクイメージぽいので、Ubuntuでmountして中身を見てみる。
taka@ubuntu:~/ctf/csawctf2017$ fdisk -l -u best_router.img Disk best_router.img: 14.6 GiB, 15640559616 bytes, 30547968 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x7f39f284 Device Boot Start End Sectors Size Id Type best_router.img1 8192 93813 85622 41.8M c W95 FAT32 (LBA) best_router.img2 94208 30547967 30453760 14.5G 83 Linux taka@ubuntu:~/ctf/csawctf2017$ sudo mkdir /mnt/point1 taka@ubuntu:~/ctf/csawctf2017$ sudo mount -o loop,offset=$((94208*512)) ~/ctf/csawctf2017/best_router.img /mnt/point1 taka@ubuntu:~/ctf/csawctf2017$ ls /mnt/point1/ bin dev home lost+found mnt proc run srv tmp var boot etc lib media opt root sbin sys usr
ユーザのhomeディレクトリを見てみると、/root
にinstall.shが置いてあった。
sudo apt-get update sudo apt-get install apache2 -y sudo a2enmod cgid sudo cp 000-default.conf /etc/apache2/sites-available/000-default.conf sudo service apache2 restart sudo rm -rf /var/www/* sudo mv www/* /var/www chmod 755 /var/www/*.pl
これを実行していたとすると、/var/www/
にコンテンツが置かれてるはずなので、ここを見てみる。
taka@ubuntu:/mnt/point1$ ls -al var/www total 24 drwxr-xr-x 2 root root 4096 Sep 10 13:51 . drwxr-xr-x 12 root root 4096 Sep 10 13:20 .. -rw-r--r-- 1 root root 0 Sep 10 13:43 flag.txt -rwxr-xr-x 1 root root 472 Sep 10 13:51 index.pl -rwxr-xr-x 1 root root 1238 Sep 10 13:50 login.pl -rw-r--r-- 1 taka taka 23 Sep 10 13:49 password.txt -rw-r--r-- 1 taka taka 5 Sep 10 13:49 username.txt
login.plを読むと、usename.txtとpassword.txtの内容を読み込んで、認証してるぽい。
username.txtにはadmin
、password.txtにはiforgotaboutthemathtest
と書かれていたので、これをhttp://forensics.chal.csaw.io:3287
のログイン画面で入力するとログインができ、その先のページにFlagがあった。
flag{but_I_f0rgot_my_my_math_test_and_pants}
Best Routerという問題名だけど、安いRouterにありそうな実装だなとちょっと思った。
Another Xor (Crypto 100)
Another Xor
Hey, hey can you find my secret.
https://ctf.csaw.io/files/ef303796b276cd0bdf4f7c61b2606df5/cipher.py
https://ctf.csaw.io/files/02a457c28ec0b04e5f7118e54ac8e138/encrypted
暗号化に使うPythonのスクリプトファイルと暗号化されたデータファイルが配布されている状態からスタート。
暗号化の処理は難しいものではないのですぐにわかったけど、解読は手が出せなかった。
KEYの長さがわからないので、たぶんそこから求めないといけないのだろう。。
感想
Forensicsのポイントが難易度の割に少し高すぎかなと思った。 特にForensics 200は特にトリッキーなこともやってなくて、個人的にはForensics 150の方が難しく感じた。
あと、毎度のことですが、Forensics以外にも解けるジャンル増やしたいなぁ…