본문 바로가기

취약점 분석/여러가지 구조 형식

GZIP header format (.gz extention)

반응형

 gzip file format 

참조URL : (http://www.gzip.org/zlib/rfc-gzip.html#file-format)



[GZIP 구조 요약]

+---+---+---+---+---+---+---+---+---+---+

|ID1|ID2|CM |FLG|     MTIME     |XFL|OS | (more-->)

+---+---+---+---+---+---+---+---+---+---+

●(if FLG.FEXTRA set)

+---+---+=================================+

| XLEN  |...XLEN bytes of "extra field"...| (more-->)

+---+---+=================================+

●(if FLG.FNAME set)

+=========================================+

|...original file name, zero-terminated...| (more-->)

+=========================================+

●(if FLG.FCOMMENT set)

+===================================+

|...file comment, zero-terminated...| (more-->)

+===================================+

●(if FLG.FHCRC set)

+---+---+

| CRC16 |

+---+---+

+=======================+

|...compressed blocks...| (more-->)

+=======================+ㅏ,

  0   1   2   3   4   5   6   7

+---+---+---+---+---+---+---+---+

|     CRC32     |     ISIZE     |

+---+---+---+---+---+---+---+---+



[구성 요소 설명]

[ID1] (IDentification 1) = 31 (0x1f, \037) -- MAGIC NUMBER

[ID2] (IDentification 2) = 139 (0x8b, \213) -- MAGIC NUMBER

[CM] (Compression Method) -- 0~7=reserved, 8="deflate" method

[FLG] (FLaGs) -- byte인데 bit 단위로 쪼개져 있음.

bit 0   FTEXT  --- optional, if set, file is probably ASCII text. (elst : binary data)

bit 1   FHCRC -- set되면 압축 데이터 직전에 CRC16이 존재함. -- (gzip 1.2.4까지는 never set)

bit 2   FEXTRA -- set되면 optinal extra fields가 존재한다는 뜻, 

bit 3   FNAME -- set이면 null-terminated되는 원래 파일 이름이 존재. -----must consist of ISO 8859-1 (LATIN-1) characters.

bit 4   FCOMMENT -- zero-terminated file comment가 존재. (주석)  -----must consist of ISO 8859-1 (LATIN-1) characters. ==> 이외의 것을 넣을 시 hwp를 읽는 과정에서 오류가 생기지 않을까?

bit 5   reserved = must be 0

bit 6   reserved = 0

bit 7   reserved = 0


[MTIME] (Modification TIME)

압축될 파일의 가장 최근 수정 시간. 유닉스 포맷(MS-DOS라던지 다른 건 오류 유발)

압축할 데이터가 파일로부터 오는 게 아니라면 압축 시작 시간을 명시.

MTIME=0은 time stamp 이용 불가를 뜻함.


[XFL] (eXtra FLags)

flags들은 특정 압축 메서드에 의해 사용 가능하며, "defalte"(CM=8)에서는 다음과 같이 사용한다.

XFL = 2 - compressor used maximum compression,

          slowest algorithm (가장 느린 알고리즘)

XFL = 4 - compressor used fastest algorithm (가장 빠른 알고리즘)

==> 2 or 4 중에 선택


[OS] (Operating System)

압축될 당시의 OS를 나타냄. 파일의 end-of-line을 결정하는 데 유용.

  0 - FAT filesystem (MS-DOS, OS/2, NT/Win32)

  1 - Amiga

  2 - VMS (or OpenVMS)

  3 - Unix

  4 - VM/CMS

  5 - Atari TOS

  6 - HPFS filesystem (OS/2, NT)

  7 - Macintosh

  8 - Z-System

  9 - CP/M

 10 - TOPS-20

 11 - NTFS filesystem (NT)

 12 - QDOS

 13 - Acorn RISCOS

255 - unknown


[XLEN] (eXtra LENgth)

FLG.FEXTRA 플래그가 set 되어 있다면, optional extra field의 길이를 나타냄.


[CRC32] (CRC-32)

This contains a Cyclic Redundancy Check value of the uncompressed data computed according to CRC-32 algorithm used in the ISO 3309 standard and in section 8.1.1.6.2 of ITU-T recommendation V.42. (See http://www.iso.ch for ordering ISO documents. See gopher://info.itu.ch for an online version of ITU-T V.42.)

CRC32를 통해 계산된 압축되기 전의 데이터의 CRC value.


[ISIZE] (Input SIZE)

압축되기 전의 원래 파일의 길이를 modulo 2^32를 통해 나타냄. (나머지 계산법)


반응형

'취약점 분석 > 여러가지 구조 형식' 카테고리의 다른 글

EXIF Format  (0) 2018.11.28
JPEG 헤더 구조  (0) 2018.11.21
ZIP Archive file format  (0) 2018.09.19