El Master Boot Record (MBR)

¿Qué es el MBR?:

Un registro de arranque principal, conocido también como registro de arranque maestro (por su nombre en inglés master boot recordMBR) es el primer sector de un dispositivo de almacenamiento de datos, como un disco duro. A veces, se emplea para el arranque del sistema operativo con bootstrap, otras veces es usado para almacenar una tabla de particiones y, en ocasiones, se usa sólo para identificar un dispositivo de disco individual, aunque en algunas máquinas esto último no se usa y es ignorado. (Fuente wikipedia).

Estructura del MBR:

Leyendo el MBR:

#include <stdio.h>
#include <windows.h>

typedef struct {
	BYTE status; // activo? 0=no, 128=yes
	BYTE chsFirst[3]; // starting sector number
	BYTE type; // OS type indicator code
	BYTE chsLast[3]; // ending sector number
	DWORD lbaStart; // first sector relative to start of disk
	DWORD size; // number of sectors in partition
} MBR_PARTITION_TABLE_ENTRY;

typedef struct {
	BYTE bootCode[446]; // space to hold actual boot code
	MBR_PARTITION_TABLE_ENTRY partitionTable[4];
	USHORT mbrSignature; // set to 0xAA55 to indicate PC MBR format
} MASTER_BOOT_RECORD;

int	main(
	HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR     lpCmdLine, int       nCmdShow
)
{
	MASTER_BOOT_RECORD MBR;
	FILE* fp;
	fp = fopen("\\\\.\\PhysicalDrive0","rb");
	fread(&MBR.bootCode, sizeof(BYTE),446, fp);
	fread(&MBR.partitionTable, sizeof(MBR_PARTITION_TABLE_ENTRY), 4, fp);
	fread(&MBR.mbrSignature, sizeof(USHORT), 1, fp);
	if ( MBR.mbrSignature == 0xaa55){
		printf("aca termina el MBR\n");
	}
	

	return 0;
}

Links para seguir jugando con el MBR:

https://github.com/SleepMod

https://github.com/DavidBuchanan314/pwn-mbr

https://github.com/nongiach/snake_boot_sector