ペンギン技術 blog

CTFのWriteupなどを記載していこうと思います

ksnCTF Writeup No.19 ZIP de kure

普通にZIPファイルの解凍を試してみるとヒントが表示される
$ unzip flag.zip
Archive: flag.zip
Hint:
- It is known that the encryption system of ZIP is weak against known-plaintext attacks.
- We employ ZIP format not for compression but for encryption.
[flag.zip] flag.html password:

 

暗号化ZIP内にわかっているファイルがある場合、攻撃ができるとのこと

以前似た問題を見たことがあるが、その時は解けなかった記憶が


zipinfoでファイル情報を見てみる
$ zipinfo -v flag.zip
Archive: flag.zip
The zipfile comment is 161 bytes long and contains the following text:
======================== zipfile comment begins ==========================
Hint:
- It is known that the encryption system of ZIP is weak against known-plaintext attacks.
- We employ ZIP format not for compression but for encryption.
========================= zipfile comment ends ===========================

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

Zip archive file size: 256719 (000000000003EACFh)
Actual end-cent-dir record offset: 256536 (000000000003EA18h)
Expected end-cent-dir record offset: 256536 (000000000003EA18h)
(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 2 entries.
The central directory is 122 (000000000000007Ah) bytes long,
and its (expected) offset in bytes from the beginning of the zipfile
is 256414 (000000000003E99Eh).


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

flag.html

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: 1.0
compression method: none (stored)
file security status: encrypted
extended local header: yes
file last modified on (DOS date/time): 2012 Jun 3 18:14:00
32-bit CRC value (hex): d66cb67b
compressed size: 316 bytes
uncompressed size: 304 bytes
length of filename: 9 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 (20 hex): arc

There is no file comment.

Central directory entry #2:
---------------------------

There are an extra 16 bytes preceding this file.

Standard-lock-key.jpg

offset of local header from start of archive: 371
(0000000000000173h) 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: 1.0
compression method: none (stored)
file security status: encrypted
extended local header: yes
file last modified on (DOS date/time): 2012 Jun 3 18:10:58
32-bit CRC value (hex): af308dc8
compressed size: 255976 bytes
uncompressed size: 255964 bytes
length of filename: 21 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 (20 hex): arc

There is no file comment.


フラグファイルと画像ファイルがあるらしい

 

ファイル名で検索するとStandard-lock-key.jpgは以下のもののようだ

画像ファイルはネット上にあるものなので、pkcrackにて既知平文攻撃で解析できる

 

最初は気づかなかったが、下の方にファイルの履歴があり、複数の画像がある
https://ja.wikipedia.org/wiki/%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB:Standard-lock-key.jpg

f:id:sPENGIN:20210723230415p:plain

 

サイズが250KBぐらいの画像なので、使うのはこちら
https://upload.wikimedia.org/wikipedia/commons/archive/a/a2/20180806082918%21Standard-lock-key.jpg

 

pkcrackコマンドはaptではインストールできず

$ sudo apt install pkcrack
E: パッケージ pkcrack が見つかりません

 

ダウンロード
$ wget https://www.unix-ag.uni-kl.de/~conrad/krypto/pkcrack/pkcrack-1.2.2.tar.gz

 

解凍
$ tar zxvf pkcrack-1.2.2.tar.gz

$ cd pkcrack-1.2.2/src

 

コンパイル
$ make

実行ファイルができあがる

(kali?kali)-[~/Downloads/pkcrack-1.2.2/src]
$ ls -ltr
-rwxr-xr-x 1 kali kali 53888 7月 23 20:59 pkcrack


-C 暗号化されたzipファイル(解析対象)
-c 暗号化されたzipファイル中の平文がわかるファイル名(zip内のファイル名を指定)
-p 平文ファイルのファイル名(今回は画像ファイル。暗号化前の実物が必要)
-d 解析完了後に出力されるファイルのファイル名(なんでもいい)

(kali?kali)-[~/Downloads/pkcrack-1.2.2/src]
$ ./pkcrack -C ../../flag.zip -c Standard-lock-key.jpg -p ../../Standard-lock-key.jpg -d ../../output.zip
Files read. Starting stage 1 on Fri Jul 23 21:17:55 2021
(略)
Stage 2 completed. Starting zipdecrypt on Fri Jul 23 21:18:10 2021
Decrypting flag.html (250d8b78ce908fe210d7c091)... OK!
Decrypting Standard-lock-key.jpg (037d8119e2c2884a4a665d91)... OK!
Finished on Fri Jul 23 21:18:10 2021

解析完了


$ unzip output.zip

パスワードなしで解凍できたので、フラグを確認

$ cat flag.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FLAG</title>
<style>div{text-align:center;margin:2em;font-size:xx-large;}</style>
</head>
<body>
<div><img src="Standard-lock-key.jpg" width="360" height="160"></div>
<div>FLAG_P(略)</div>
</body>
</html>