쉽다고..!?



파일을 받으면 다음과 같이 확장자를 알 수 없는 파일이 하나 생기게 됩니다.



HxD로 확인해보면 앞에 시작부분이 PK인걸 보아하니 ZIP파일임을 눈치챌 수 있고 해당 파일에 확장자를 추가해줍니다.



확장자를 추가하고 열어보니 암호가 걸려있고 암호에 대한 힌트는 조금도 존재하지 않습니다....


여기서 진짜 막막했습니다 ㅜ



이 문제는 알집 Header에 관한 문제였습니다.


아래와 같이 zip파일은 다양한 파일을 하나로 모아주는 역할을 합니다.


파일마다 각각의 "Local header"가 존재하고 마지막에는 "Central directory"에 파일의 정보를 다시 작성합니다.


[출처: 위키피디아]



zip파일의 헤더 항목 중에 "General purpose bit flag"라는 항목이 있습니다. (2byte)


아래와 같은 정보를 담고 있는 값입니다. 그중 첫번째 bit는 암호 유무를 판단하는 bit 값입니다.


이 값이 설정되어 있으면 해당 zip파일은 암호화 되어 있다고 판단하게 됩니다.


        Bit 0: If set, indicates that the file is encrypted.


        (For Method 6 - Imploding)

        Bit 1: If the compression method used was type 6,

               Imploding, then this bit, if set, indicates

               an 8K sliding dictionary was used.  If clear,

               then a 4K sliding dictionary was used.


        Bit 2: If the compression method used was type 6,

               Imploding, then this bit, if set, indicates

               3 Shannon-Fano trees were used to encode the

               sliding dictionary output.  If clear, then 2

               Shannon-Fano trees were used.


        (For Methods 8 and 9 - Deflating)

        Bit 2  Bit 1

          0      0    Normal (-en) compression option was used.

          0      1    Maximum (-exx/-ex) compression option was used.

          1      0    Fast (-ef) compression option was used.

          1      1    Super Fast (-es) compression option was used.


        (For Method 14 - LZMA)

        Bit 1: If the compression method used was type 14,

               LZMA, then this bit, if set, indicates

               an end-of-stream (EOS) marker is used to

               mark the end of the compressed data stream.

               If clear, then an EOS marker is not present

               and the compressed data size must be known

               to extract.


        Note:  Bits 1 and 2 are undefined if the compression

               method is any other.


        Bit 3: If this bit is set, the fields crc-32, compressed 

               size and uncompressed size are set to zero in the 

               local header.  The correct values are put in the 

               data descriptor immediately following the compressed

               data.  (Note: PKZIP version 2.04g for DOS only 

               recognizes this bit for method 8 compression, newer 

               versions of PKZIP recognize this bit for any 

               compression method.)


        Bit 4: Reserved for use with method 8, for enhanced

               deflating. 


        Bit 5: If this bit is set, this indicates that the file is 

               compressed patched data.  (Note: Requires PKZIP 

               version 2.70 or greater)


        Bit 6: Strong encryption.  If this bit is set, you MUST

               set the version needed to extract value to at least

               50 and you MUST also set bit 0.  If AES encryption

               is used, the version needed to extract value MUST 

               be at least 51. See the section describing the Strong

               Encryption Specification for details.  Refer to the 

               section in this document entitled "Incorporating PKWARE 

               Proprietary Technology into Your Product" for more 

               information.


        Bit 7: Currently unused.


        Bit 8: Currently unused.


        Bit 9: Currently unused.


        Bit 10: Currently unused.


        Bit 11: Language encoding flag (EFS).  If this bit is set,

                the filename and comment fields for this file

                MUST be encoded using UTF-8. (see APPENDIX D)


        Bit 12: Reserved by PKWARE for enhanced compression.


        Bit 13: Set when encrypting the Central Directory to indicate 

                selected data values in the Local Header are masked to

                hide their actual values.  See the section describing 

                the Strong Encryption Specification for details.  Refer

                to the section in this document entitled "Incorporating 

                PKWARE Proprietary Technology into Your Product" for 

                more information.


        Bit 14: Reserved by PKWARE.


        Bit 15: Reserved by PKWARE. 


다음과 같이 "Local" 과 "Central directory"의 "General purpose bit flag"의 위치가 살짝 다르다는 것을 알아야 합니다.


Local Header

 Central directory file header

4Byte: Local file header signature

2Byte: Version needed to extract

2Byte: General purpose bit flag

4Byte: Local file header signature

2Byte: Version made by

2Byte: Version needed to extract

2Byte: General purpose bit flag



이것을 알고 문제로 가보면 아래와 같이 "09 08"로 되어있는 부분을 확인 할 수 있습니다.


리틀엔디안 방식을 쓰기때문에 bit값을 확인할때는 08 09 → 1000 1001 로 아셔야 합니다.


첫번째 bit가 1로 되어있어 해당 파일이 암호화 됬다고 나타나고 있습니다. 이 값을 0으로 바꾸려면


"08 08" 로 수정하시면 됩니다. 모든 "General purpose bit flag" 값을 수정해 주시면 해당 파일이 깔끔하게 열리게 됩니다.



두개의 txt파일은 "Dummy"라는 무수한 글자로 채워져 있었고, 실제 zip파일에 txt가 필요했던 겁니다.


해당 인증값으로 인증해도 안되는데 base64로 인코딩 되어있는 거 같아 decode하고 인증하면 성공하게 됩니다.



[참고]

Zip (file format): https://en.wikipedia.org/wiki/Zip_(file_format)

Zip 압축파일 헤더 구조: http://downrg.com/403

Zip파일 헤더 구조: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT



[여담]

이 문제는 암호 자체가 없던 파일입니다.

직접 다른 암호화된 zip파일을 만들고 해당 bit값만 조작해보면 압축파일이 손상되어 있다고 나오니 주의하시기 바랍니다.

'WarGame > SuNiNaTaS' 카테고리의 다른 글

SuNiNaTaS_31 [FORENSIC]  (0) 2018.09.13
SuNiNaTaS_17 [MISC]  (0) 2018.09.12
SuNiNaTaS_13 [MISC]  (0) 2018.09.11
SuNiNaTaS_11 [BINARY]  (0) 2018.09.09
SuNiNaTaS_10 [BINARY]  (0) 2018.09.08

+ Recent posts