Trend Micro CTF 2017 - Raimund Genes Cup - Online Qualifier [Analysis-Offensive 100]

exploit

forっぽい問題だったのでいきなりexploitから。

とりあえずbinwalkをしてみます。

$ ~/c/t/Analysis_offensive100> binwalk Forensic_Encyption

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
13390         0x344E          Zip archive data, at least v2.0 to extract, compressed size: 16181, uncompressed size: 20874, name: file_1
29607         0x73A7          Zip archive data, at least v2.0 to extract, compressed size: 378, uncompressed size: 418, name: file_2
30177         0x75E1          End of Zip archive

zipファイルがふたつ含まれているようです。

さっそく解凍してみるとjpegファイルであるfile_1とzipファイルであるfile_2が出てきました。

$ ~/c/t/Analysis_offensive100> unar Forensic_Encyption 
Forensic_Encyption: Self-extracting Zip
"Forensic_Encyption" already exists.
(r)ename to "Forensic_Encyption-1", (R)ename all, (o)verwrite, (O)verwrite all, (s)kip, (S)kip all, (q)uit? q
$ ~/c/t/Analysis_offensive100> ls
Forensic_Encyption  files1.enc  files1.zip
$ ~/c/t/Analysis_offensive100> unar Forensic_Encyption 
Forensic_Encyption: Self-extracting Zip
"Forensic_Encyption" already exists.
(r)ename to "Forensic_Encyption-1", (R)ename all, (o)verwrite, (O)verwrite all, (s)kip, (S)kip all, (q)uit? R
  file_1  (20874 B)... OK.
  file_2  (418 B)... OK.
Successfully extracted to "Forensic_Encyption-1".
$ ~/c/t/Analysis_offensive100> file Forensic_Encyption-1/*
Forensic_Encyption-1/file_1: JPEG image data, JFIF standard 1.01, resolution (DPI), density 72x72, segment length 16, Exif Standard: [TIFF image data, big-endian, direntries=6, description=MM, xresolution=86, yresolution=94, resolutionunit=2, software=MM], baseline, precision 8, 641x417, frames 3
Forensic_Encyption-1/file_2: Zip archive data, at least v2.0 to extract

file_2はパスワードがかかってるようなので後回しにして、file_1をexiftoolにかけてみます。

$ ~/c/t/Analysis_offensive100> exiftool file_1
ExifTool Version Number         : 10.10
File Name                       : file_1
Directory                       : .
File Size                       : 20 kB
File Modification Date/Time     : 2017:05:01 12:40:54+09:00
File Access Date/Time           : 2017:06:24 16:44:45+09:00
File Inode Change Date/Time     : 2017:06:24 16:44:28+09:00
File Permissions                : rw-rw-r--
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Big-endian (Motorola, MM)
Image Description               : 
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Software                        : 
Exif Version                    : 0210
Components Configuration        : Y, Cb, Cr, -
User Comment                    : VHVyaW5nX01hY2hpbmVfYXV0b21hdG9u
Exif Image Width                : 753
Exif Image Height               : 417
Compression                     : JPEG (old-style)
Thumbnail Offset                : 332
Thumbnail Length                : 2273
JFIF Version                    : 1.01
Image Width                     : 641
Image Height                    : 417
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 641x417
Megapixels                      : 0.267
Thumbnail Image                 : (Binary data 2273 bytes, use -b option to extract)

怪しいユーザーコメントがあります。これをbase64でデコードすると

$ ~/c/t/Analysis_offensive100> echo 'VHVyaW5nX01hY2hpbmVfYXV0b21hdG9u' | base64 -d
Turing_Machine_automaton⏎       

と出てきます。この文字列を使ってfile_2をunzipしようとしましたが出来ませんでした。

$ ~/c/t/Analysis_offensive100> unzip Forensic_Encyption-1/file_2
Archive:  Forensic_Encyption-1/file_2
   skipping: key.txt                 unsupported compression method 99

調べてみると7zコマンドで解凍できるようでした。今度は解凍できました。

解凍すると今度はkey.txtが出てきました。

$ ~/c/t/Analysis_offensive100> cat key.txt
src 192.168.30.211 dst 192.168.30.251
        proto esp spi 0xc300fae7 reqid 1 mode transport
        replay-window 32
        auth hmac(sha1) 0x2f279b853294aad4547d5773e5108de7717f5284
        enc cbc(aes) 0x9d1d2cfa9fa8be81f3e735090c7bd272
        sel src 192.168.30.211/32 dst 192.168.30.251/32
src 192.168.30.251 dst 192.168.30.211
        proto esp spi 0xce66f4fa reqid 1 mode transport
        replay-window 32
        auth hmac(sha1) 0x3bf9c1a31f707731a762ea45a85e21a2192797a3
        enc cbc(aes) 0x886f7e33d21c79ea5bac61e3e17c0422
        sel src 192.168.30.251/32 dst 192.168.30.211/32

これを使うとパケットの暗号を復号できるようですが、肝心のパケットが含まれたpcapファイルが見つかりません。

そこで始めに与えられたファイルにstringsをかけるとfile_3がfile_1,file_2とは別に含まれているようです。

試しにzipinfoをすると確かにfile_3がありました。

$ ~/c/t/Analysis_offensive100> zipinfo -v Forensic_Encyption 
Archive:  Forensic_Encyption
There is no zipfile comment.

End-of-central-directory record:
-------------------------------

  Zip archive file size:                     30199 (00000000000075F7h)
  Actual end-cent-dir record offset:         30177 (00000000000075E1h)
  Expected end-cent-dir record offset:       30177 (00000000000075E1h)
  (based on the length of the central directory and its expected offset)

  This zipfile constitutes the sole disk of a single-part archive; its
  central directory contains 3 entries.
  The central directory is 156 (000000000000009Ch) bytes long,
  and its (expected) offset in bytes from the beginning of the zipfile
  is 30021 (0000000000007545h).


Central directory entry #1:
---------------------------

  file_3

  offset of local header from start of archive:   0
                                                  (0000000000000000h) bytes
  file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
  version of encoding software:                   2.0
  minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
  minimum software version required to extract:   2.0
  compression method:                             deflated
  compression sub-type (deflation):               normal
  file security status:                           not encrypted
  extended local header:                          no
  file last modified on (DOS date/time):          2017 May 15 16:39:40
  32-bit CRC value (hex):                         c21779bc
  compressed size:                                13354 bytes
  uncompressed size:                              31112 bytes
  length of filename:                             6 characters
  length of extra field:                          0 bytes
  length of file comment:                         0 characters
  disk number on which file begins:               disk 1
  apparent file type:                             binary
  non-MSDOS external file attributes:             000000 hex
  MS-DOS file attributes (00 hex):                none
...

ファイルの先頭がおかしいようなので先頭の二文字をPKに変えると今度は解凍するとfile_3が出てくるようになりました。

file_3は予想通りpcapファイルだったのでこれをwiresharkに突っ込み、以下のブログの通りにESPの復号をします。

saitoh.hatenablog.jp

すると以下のhtmlファイルが手に入るのであとは Enigma M4 - Simulator by dp を使いフラグを手に入れます。

<HTML>

<BODY>

M4 Navy

Reflector:C Thin, beta, I, IV, II (T M J F), Plugboard: L-X/A-C/B-Y



TMCTF{APZTQQHYCKDLQZRG}



APZTQQHYCKDLQZRG is encrypted.



</BODY>

</HTML>

フラグ TMCTF{RISINGSUNANDMOON}

rising sun and moon