ZIP 파일 암호 푸는 방법(with John the Ripper, Hashcat)

이 글에서는 John the Ripper 와 Hashcat 을 이용하여 암호화된 ZIP 파일을 크래킹하는 방법에 대해 설명한다.
Windows
John the Ripper 다운로드
John the Ripper 의 공식 사이트에서 Windows OS 용 실행 파일을 다운로드한다.

Hash 정보 추출
설치에 성공하면 John the Ripper 의 실행 파일 중 하나인 zip2john.exe
를 실행할 수 있다. 테스트에 사용할 암호화된 zip 파일은 내부에 vmx2john.py
라는 파일을 가지며, test
를 비밀번호로 사용하여 압축되었다.

아래 명령어를 실행하면 zip.hash
에 실행 결과가 저장된다.
.\zip2john.exe {암호화된 zip 파일} > zip.hash
zip.hash
파일의 내용은 다음과 같은 형식이다. 하지만 이 결과물에서 필요한 내용만 추출해야 한다. 최초로 만나는 :
문자를 기준으로 뒤에 있는 데이터 $pkzip2$1*1*2*0*3a4...후략...
만 우리에게 필요하다. :
앞 데이터를 지워 필요한 데이터만 남기고 파일을 저장한다.
아래 내용은 ZIP 파일의 포맷, 내용에 따라 변할 수 있다.
test.zip/vmx2john.py:$pkzip2$1*1*2*0*3a4*889*81c1f7c*0*29*8*3a4*081c*10ec*a93b8
... 중략 ...
d5750fc99b881120b8c914b2e8286e4050e7c34d1071787a8cc7c0a9c576f0db158259685aa812b5666838c5a20*$/pkzip2$:vmx2john.py:test.zip::.\test.zip
수정된 zip.hash
는 다음과 같다.
$pkzip2$1*1*2*0*3a4*889*81c1f7c*0*29*8*3a4*081c*10ec*a93b8
... 중략 ...
d5750fc99b881120b8c914b2e8286e4050e7c34d1071787a8cc7c0a9c576f0db158259685aa812b5666838c5a20*$/pkzip2$:vmx2john.py:test.zip::.\test.zip
Hashcat 으로 암호 크래킹
이제 Hashcat 을 이용하여 앞서 생성한 hash 값을 크래킹해야 한다. 우선 Hashcat 공식 사이트에서 Windows 용 hashcat 프로그램을 다운로드한다.

다운로드한 파일 내에는 hashcat.exe
라는 실행 파일이 있다. hashcat
에 대한 좀 더 상세한 내용은 Hashcat 사용법 글을 읽어보길 바란다.

hashcat
을 실행하기에 앞서 zip.hash
파일의 내용을 통해 어떤 mode 로 크래킹을 할지 정해야 한다. 앞선 예제에서 zip.hash
파일이 $pkzip2
문자열로 시작한 것으로 보아 PKZIP 포맷의 ZIP 파일이며, 단일 파일을 압축하고 있었으므로, 아래 표에 따르면 17200 모드를 사용하면 될 것이다. 이와 같은 방법으로 크래킹할 대상에 따라 적절한 모드를 선택해야 한다.
hashcat mode | ZIP format |
---|---|
11600 | 7-Zip |
17220 | PKZIP (Compressed Multi-File) |
17200 | PKZIP (Compressed) |
17225 | PKZIP (Mixed Multi-File) |
17230 | PKZIP (Mixed Multi-File Checksum-Only) |
17210 | PKZIP (Uncompressed) |
20500 | PKZIP Master Key |
20510 | PKZIP Master Key (6 byte optimization) |
23001 | SecureZIP AES-128 |
23002 | SecureZIP AES-192 |
23003 | SecureZIP AES-256 |
13600 | WinZip |
아래와 같은 명령어를 실행하면 앞서 생성한 zip.hash
파일의 hash 값을 wordlist.txt
를 이용하여 사전 공격으로 크래킹할 수 있다. wordlist.txt
는 사전 공격(dictionary attact) 에 사용할 암호들을 모아놓은 파일이다. 적절한 wordlist 파일이 없다면 Seclists
의 rockyou.txt
파일을 사용해보자.
.\hashcat.exe -a 0 -m 17200 .\zip.hash .\wordlist.txt
명령어 실행 결과, 예제 파일의 암호 "test" 를 크래킹하는데 성공했다.
... 전략 ...
$pkzip2$1*1*2*0*3a4*889*81c1f7c*0*29*8*3a4*081c*10ec*a93b8bdd
... 중략 ...
b158259685aa812b5666838c5a20*$/pkzip2$:test <---- ZIP 파일의 암호 test 가 크래킹되어 출력됨.
Session..........: hashcat
Status...........: Cracked
Hash.Mode........: 17220 (PKZIP (Compressed Multi-File))
Hash.Target......: $pkzip2$1*1*2*0*3a4*889*81c1f7c*0*29*8*3a4*081c*10e...kzip2$
Time.Started.....: Mon Sep 09 00:57:21 2024 (0 secs)
Time.Estimated...: Mon Sep 09 00:57:21 2024 (0 secs)
Kernel.Feature...: Pure Kernel
Guess.Base.......: File (C:\Users\Moonding\Downloads\john-1.9.0-jumbo-1-win64\john-1.9.0-jumbo-1-win64\run\wordlist.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........: 800 H/s (3.40ms) @ Accel:1024 Loops:1 Thr:32 Vec:1
Recovered........: 1/1 (100.00%) Digests (total), 1/1 (100.00%) Digests (new)
Progress.........: 5/5 (100.00%)
Rejected.........: 0/5 (0.00%)
Restore.Point....: 0/5 (0.00%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidate.Engine.: Device Generator
Candidates.#1....: test -> 11234
Hardware.Mon.#1..: Temp: 51c Fan: 0% Util: 66% Core: 734MHz Mem: 810MHz Bus:16
Linux
Linux 도 Windows 와 동일한 방식으로 진행된다.
John the Ripper 설치
apt
명령어로 John the Ripper 를 설치한다.
$ sudo apt update
$ sudo apt install john
ZIP 파일에서 해시 값 추출
zip2john
으로 hash 값을 생성한다.
$ zip2john ./test.zip > zip.hash
Password Cracking
hashcat 으로 암호를 크래킹한다.
$ hashcat -m 17200 -a 0 ./zip.hash ./wordlist.txt
실행 결과의 일부는 다음과 같다.
Approaching final keyspace - workload adjusted.
$pkzip$1*1*2*0*3a4*889*81c1f7c*0*29*8*3a4*081c*a93b8bddca603298fad7877e0349f595bd0d
... 중략 ...
8c5a20*$/pkzip$:test <---- ZIP 파일의 암호 test 가 크래킹되어 출력됨.
Session..........: hashcat
Status...........: Cracked
Hash.Mode........: 17200 (PKZIP (Compressed))
Hash.Target......: $pkzip$1*1*2*0*3a4*889*81c1f7c*0*29*8*3a4*081c*a93b...pkzip$
Time.Started.....: Sun Sep 8 11:27:11 2024 (0 secs)
Time.Estimated...: Sun Sep 8 11:27:11 2024 (0 secs)
Kernel.Feature...: Pure Kernel
Guess.Base.......: File (/home/kali/Desktop/wordlist.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........: 3151 H/s (0.10ms) @ Accel:512 Loops:1 Thr:1 Vec:8
Recovered........: 1/1 (100.00%) Digests (total), 1/1 (100.00%) Digests (new)
Progress.........: 5/5 (100.00%)
Rejected.........: 0/5 (0.00%)
Restore.Point....: 0/5 (0.00%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidate.Engine.: Device Generator
Candidates.#1....: test -> 11234
Hardware.Mon.#1..: Util: 25%