File Systems2010/03/23 02:04
Proneer | Security is a people problem...


MBR (Master Boot Record)


MBR은 저장매체의 첫 번째 섹터(LBA 0)에 위치하는 512 바이트 크기의 영역이다. 다음 그림은 MBR의 기본적인 구조를 보여준다. 처음 446 바이트는 부트 코드(boot code) 영역, 64 바이트는 파티션 테이블(partition table), 마지막 2 바이트는 시그니처(signature)를 나타낸다.



운영체제가 부팅될 때 POST(Power On Self-Test) 과정을 마친 후 저장매체의 첫 번째 섹터를 호출되는데 이때 해당 부트 코드가 수행된다. 부트 코드의 주 역할은 파티션 테이블에서 부팅 가능한 파티션을 찾아 해당 파티션의 부트 섹터(boot sector)를 호출해주는 역할을 한다. 만약, 부팅 가능한 파티션이 없을 경우에는 미리 정의된 에러 메시지를 출력한다.

다음 표는 MBR 각 영역에 대한 세부적인 데이터구조를 나타낸다.
범위 (Byte Range)  설명 (Decription) 크기 (Size)
10 진수 16 진수 
 0 - 445  0x0000 - 0x01BD  Boot code  446 bytes
 446 - 461  0x01BE - 0x01CD  Partition table entry #1  16 bytes
 462 - 477  0x01CE - 0x01DD  Partition table entry #2  16 bytes
 478 - 493  0x01DE - 0x01ED  Partition table entry #3  16 bytes
 494 - 509  0x01EE - 0x01FD  Partition table entry #4  16 bytes
 510 - 511  0x01FE - 0x01FF  Signature (0x55AA)  2 bytes

파티션 테이블은 각각 16 바이트씩 4개의 엔트리를 가지고 있다. 따라서 이러한 구조만 가진다면 하나의 볼륨(MBR을 갖는 볼륨)에서 파티션은 4개 밖에 생성할 수 없을 것이다. 과연 그럴까?

부팅 가능한 주 파티션을 생성한다면 4개 밖에 생성할 수 없다. 따라서, 멀티부팅을 할 경우 총 4개까지 운영체제를 설치 할 수 있을 것이다. 다만, 별도의 프로그램을 통해 MBR 영역이 아닌 볼륨의 다른 영역에 주 파티션 정보를 기록하여 연결해주는 경우도 있지만 사용해본 결과 별로 권하고 싶지는 않다.주 파티션이 아닌 데이터 저장을 위한 논리 파티션은 4개 이상 생성하는 것이 가능하다. 이는 다음 포스팅에서 자세히 살펴볼 것이다.

다음은 16 바이트의 파티션 테이블 엔트리의 세부적인 데이터구조이다.

범위 (Byte Range)  설명 (Decription) 크기 (Size)
10 진수 16 진수 
 0 - 0  0x0000 - 0x0000  Boot Indicator
 00 = do not use for booting
 80 = system partition
 1 byte
 1 - 3  0x0001 - 0x0003  Starting CHS address  3 bytes
 4 - 4  0x0004 - 0x0004  Partition type  1 byte
 5 - 7  0x0005 - 0x0007  Ending CHS address  3 bytes
 8 - 11  0x0008 - 0x000B  Starting LBA address  4 bytes
 12 - 15  0x000C - 0x000F  Total sectors  4 bytes

부트 지시자(boot indecator)는 해당 파티션이 부탕 가능한 파티션인지를 나타낸다. 0x80 값을 가질 경우 부팅 가능한 파티션을 의미하고, 0x00 값을 가질 경우 부팅이 가능하지 않은 파티션을 나타낸다. 그리고 CHS 주소 값이 나오는데 현재는 거의 대부분 LBA 모드를 사용하므로 사용되지 않고 있다. 그리고 해당 파티션의 시작 위치를 가르키는 LBA 주소 값과 파티션 전체의 섹터 수가 나온다. CHS와 다르게 LBA 주소의 마지막을 표시하지 않는 이유는 시작 LBA 주소에 섹터의 크기를 더하면  마지막 주소를 알 수 있기 때문이다.

4번째 바이트는 해당 파티션의 타입을 나타낸다. 4번째 필드를 System ID와 Partition type으로 구분하는 경우도 있지만 여기서는 파티션 타입으로 모두 정의한다.

 16진수  설명 (Description)
 00h  Empty
 01h  DOS 12-bit FAT
 02h  XENIX root file system
 03h  XENIX /usr file system (obsolete)
 04h  DOS 16-bit FAT (up to 32M)
 05h  DOS 3.3+ extended partition
 06h  DOS 3.31+ Large File System (16-bit FAT, over 32M)
 07h  Advanced Unix
 07h  QNX
 07h  OS/2 HPFS
 07h  Windows NT NTFS
 08h  OS/2 (v1.0-1.3 only)
 08h  AIX bootable partition, SplitDrive
 08h  Commodore Dos
 08h  DELL partition spanning multiple drives
 09h  AIX data partition
 0Ah  OPUS
 0Ah  Coherent swap partition
 0Ah  OS/2 Boot Manager
 0Bh  Windows 95 with 32-bit FAT
 0Ch  Windows 95 with 32-bit FAT (using LBA-mode INT 13 extensions)
 0Eh  VFAT logical-block-addressable VFAT (same as 06h but using LBA)
 0Fh  Extended LBA partition (same as 05h but using LBA)
 10h  OPUS
 11h  FAT12 OS/2 Boot Manager hidden 12-bit FAT partition
 12h  Compaq Diagnostics partition
 14h  FAT16 OS/2 Boot Manager hidden sub-32M 16-bit FAT partition
 16h  FAT16 OS/2 Boot Manager hidden over-32M 16-bit FAT partition
 17h  OS/2 Boot Manager hidden HPFS partition
 17h  hidden NTFS partition
 18h  ASTSuspend AST special Windows swap file ("Zoro-Volt Suspend" partition)
 19h  Willowtech Willowtech Photon coS
 1Bh  Windows hidden Windows95 FAT32 partition
 1Ch  Windows hidden Windows 95 FAT32 partition (LBA-mode)
 1Eh  Windows hidden LBA VFAT partition
 20h  Willowsoft Overture File System (OFS1)
 21h  [reserved] officially listed as reserved
 21h  FSo2
 23h  [reserved] officially listed as reserved
 24h  NEC MS-DOS 3.x
 26h  [reserved] officially listed as reserved
 31h  [reserved] officially listed as reserved
 33h  [reserved] officially listed as reserved
 34h  [reserved] officially listed as reserved
 36h  [reserved] officially listed as reserved
 38h  Theos
 3Ch  PowerQuest PartitionMagic recovery partition
 40h  VENIX 80286
 41h  Personal RISC Boot
 41h  PowerPC boot partition
 42h  SFS(Secure File System) by Peter Gutmann
 45h  EUMEL/Elan
 46h  EUMEL/Elan
 47h  EUMEL/Elan
 48h  EUMEL/Elan
 4Fh  Obron boot/data partition
 50h  OnTrack Disk Manager, read-only partition
 51h  OnTrack Disk Manager, read/write partition
 51h  NOVELL
 52h  CP/M
 52h  Microport System V/386
 53h  OnTrack Disk Manager, write-only partition
 54h  OnTrack Disk Manager (DDO)
 55h  EZ-Drive (see also INT 13/AH=FFh "EZ-Drive")
 56h  GoldenBow VFeature
 5Ch  Priam EDISK
 61h  SpeedStor
 63h  Unix SysV/386, 386/ix
 63h  Mach, MtXinu BSD 4.3 on Mach
 63h  GNU-HURD
 64h  Novell Netware 286
 64h  SpeedStore
 65h  Novell NetWare (3.11)
 67h  Novell
 68h  Novell
 69h  Novell NSS Volume
 70h  DiskSecure Multi-Boot
 71h  [reserved] officially listed as reserved
 73h  [reserved] officially listed as reserved
 74h  [reserved] officially listed as reserved
 75h  PC/IX
 76h  [reserved] officially listed as reserved
 7Eh  F.I.X
 80h  Minix v1.1 - 1.4a
 81h  Minix v1.4b+
 81h  Linux
 81h  Mitac Advanced Disk Manager
 82h  Linux Swap partition
 82h  Prime
 82h  Solaris (Unix)
 83h  Linux native file system (ex2fs/xiafs)
 84h  DOS OS/2-renumbered type 04h partition (hiding DOS C: drive)
 85h  Linux EXT
 86h  FAT16 volume/stripe set (Windows NT)
 87h  HPFS Fault-Tolerant mirrored partition
 87h  NTFS volume/stripe set
 93h  Amoeba file system
 94h  Amoeba bad block table
 98h  Datalight ROM-DOS SuperBoot
 99h  Mylex EISA SCSI
 A0h  Phoenix NoteBIOS Power Management "Save-to-Disk" partition
 A1h  [reserved] officially listed as reserved
 A3h  [reserved] officially listed as reserved
 A4h  [reserved] officially listed as reserved
 A5h  FreeBSD, BSD/386
 A6h  OpenBSD
 A9h  NetBSD
 B1h  [reserved] officially listed as reserved
 B3h  [reserved] officially listed as reserved
 B4h  [reserved] officially listed as reserved
 B6h  [reserved] officially listed as reserved
 B6h  Windows NT mirror set (master), FAT16 file system
 B7h  BSDI file system (secondarily swap)
 B7h  Windows NT mirror set (master), NTFS file system
 B8h  BSDI swap partition (secondarily file system)
 BEh  Solaris boot partition
 C0h  CTOS
 C0h  DR-DOS/Novell DOS secured partition
 C1h  DR-DOS6.0 LOGIN.EXE-secured 12-bit FAT partition
 C4h  DR-DOS6.0 LOGIN.EXE-secured 16-bit FAT partition
 C6h  DR-DOS6.0 LOGIN.EXE-secured 12-bit Huge partition
 C6h  corrupted FAT16 volume/stripe set (Windows NT)
 C6h  Windows NT mirror set (slave), FAT16 file system
 C7h  Syurinx Boot
 C7h  corrupted NTFS volume/stripe set
 C7h  Windows NT mirror set (slave), NTFS file system
 CBh  DR-DOS/OpenDOS secured FAT32
 CCh  DR-DOS secured FAT32 (LBA)
 CEh  DR-DOS secured FAT16 (LBA)
 D0h  Multiuser DOS secured FAT12
 D1h  Old Multiuser DOS secured FAT12
 D4h  Old Multiuser DOS secured FAT16 (<=32M)
 D5h  Old Multiuser DOS secured extended partition
 D6h  Old Multiuser DOS secured FAT16 (>32M)
 D8h  CP/M-86
 DBh  Concurrent CP/M, Concurrent DOS
 DBh  CTOS (Convergent Technologies OS)
 E1h  SpeedStor 12-bit FAT extended partition
 E2h  DOS read-only (Florian Painke's XFDISK 1.0.4)
 E3h  DOS read-only
 E3h  Storage Dimensions
 E4h  SpeedStor 16-bit FAT extended partition
 E5h  [reserved] officially listed as reserved
 E6h  [reserved] officially listed as reserved
 EBh  BeOS BFS (BFS1)
 F1h  Storage Dimensions
 F2h  DOS 3.3+ secondary partition
 F3h  [reserved] officially listed as reserved
 F4h  SpeedStor
 F4h  Storage Dimensions
 F5h  Prologue
 F6h  [reserved] officially listed as reserved
 FBh  VMware partition
 FEh  LANstep
 FEh  IBM PS/2 IML (Initial Microcode Load) partition
 FFh  Xenix bad block table
 FMh  VMware raw partition
(http://www.datarecovery.com/hexcodes.asp)

다음은 실제 필자의 MBR영역이다.



가운데 파란색으로 표시된 영역이 부트 코드를 수행하면서 정상적이지 않은 동작이 발생할 경우 출력하는 3가지 종류의 에러 메시지들이다.

  • Invalid partition table
  • Error loading operating system
  • Missing operationg system

다음 초록색으로 표시된 부분은 파티션 테이블을 나타낸다. 현재 해당 볼륨에 두개의 파티션이 존재하며, 첫 번째 파티션은 부팅가능한 파티션임을 알 수 있다. 각 파티션의 용량을 계산하면 다음과 같다.

  • Partition #1 : Total Sectors (07 53 04 62) = 58 GB
  • Partition #2 : Total Sectors (15 C9 40 E0) = 174 GB


각 파티션의 타입과 파티션의 시작위치를 살펴보면 다음과 같다.

  • Partition #1 : Type (07h = Windows NT NTFS), Starting LBA addresses (00 00 00 3F)
  • Partition #2 : Type (05h = DOS extended partition), Starting LBA addresses (07 53 04 A1)

그리고 마지막으로 MBR의 시그니처 값인 0x55AA가 오는 것을 알 수 있다.


그렇다면 파란색과 초록색 사이의 부분은 어떤 역할을 하는 걸까?
결론은 OS 버전에 따라 추가적인 부트 코드와 에러 메시지 지정, 장치의 GUID 값을 저장하고 있다. Windows 2000 (with SP3) 의 경우 해당 영역에 "C:\WINNT\\System32\dmadmin.exe" 파일을 호출하는 코드가 들어간다. 이외에도 각 OS 버전에 따라 추가적인 파일을 호출하는 구문이 들어간다. http://thestarman.narod.ru/asm/mbr/WTC.htm

그리고 추가적인 코드 외에도 기본으로 에러 메시지 지정 코드와 장치의 GUID 값을 저장한다. 위의 MBR 덤프를 살펴보면 오프셋 437 - 439 위치에 "2C 44 64" 값이 오는 것을 알 수 있다. 이것은 부트 코드 수행도중 에러 발생 시 에러 메시지의 위치를 지정하기 위한 것이다. MBR 영역은 부팅과 함께 메모리의 0000:7C00 번지에 로드된 후 0000:0600 번지로 이동한다.

이동한 상태에서 각 값의 위치("072C", "0744", "0763")는 각 에러메시지의 위치를 나타낸다. 이것에 대한 적당한 용어가 없으므로 에러 메시지 네이게이터(Error Message Navigator)라고 하자.
0000:072C : "Invalid partition table"
0000:0744 : "Error loading operating system"
0000:0763 : "Missing operating system"


하지만 이 값은 Windows 영문버전에서만 적용된다. 다음과 같이 독일어 버전에서는 오류메시지의 길이의 변화로 인해 값이 다르다. 그렇다면 한국어 버전에서는 왜 영어가 출력될까? 한글은 2 바이트를 쓰기 때문에 16 비트의 BIOS 상에서 해당 오류메시지를 출력하려면 기존에 설계된 코드 외에 추가적으로 많은 수정이 필요하기 때문일 것이다.

(http://thestarman.narod.ru/asm/mbr/Win2kmbr.htm)

그리고 에러 메시지 네이게이터 다음에 오는 4 바이트 (오프셋 440 - 443)은 마운트된 장치의 GUID 값으로 사용된다. 자세한 내용은 다음을 참조하자. 2009/10/09 - [Storage Forensics] - Mounted Devices GUID Analysis 


저작자 표시 비영리 변경 금지
Creative Commons License
Creative Commons License

'File Systems' 카테고리의 다른 글

NTFS - MFT 소개 (Introduction)  (2) 2010/04/09
MBR - 부트 코드 분석 (Boot Code Analysis)  (0) 2010/03/23
MBR (Master Boot Record)  (4) 2010/03/23
NTFS - VBR (Volume Boot Record)  (0) 2010/03/21
NTFS - 구조 (Structures)  (0) 2010/03/21
NTFS - 소개 (Introduction)  (0) 2010/03/20
Posted by Proneer

TRACKBACK http://forensic-proof.com/trackback/53 관련글 쓰기

댓글을 달아 주세요

  1. 유창훈

    안녕하세요 올려주신글 잘 보고있습니다.
    궁금한점이 있는데요 에러메세지 지정코드에 2c 44 63 이 오고 메모리 0000:7c00 에 로드되고 0000:0600 로 이동한다고하셨는데 , 이동한 상태에서 에러메세지 위치가 0000:072c 0000:0744 0000:0763 으로 어떻게 바뀌는 거죠?

    2010/04/16 11:10 [ ADDR : EDIT/ DEL : REPLY ]
    • 아핫.. MBR의 크기가 512(0x200)이 됩니다. 따라서 0600으로 복사가 되면 전체 MBR 영역은 0600~0800영역이 됩니다. 따라서 이때 오류 메시지의 위치가 위와 같습니다.

      2010/04/16 13:52 [ ADDR : EDIT/ DEL ]
  2. 유창훈

    감사합니다. ㅎ 혹시 코드게이트2010 한국팀으로 참가하셨나요?

    2010/04/16 14:51 [ ADDR : EDIT/ DEL : REPLY ]