1
2
Fork 0
mirror of https://github.com/carlospolop/hacktricks.git synced 2023-12-14 19:12:55 +01:00
hacktricks/forensics/basic-forensics-esp/README.md
2021-05-27 18:08:10 +00:00

34 KiB
Raw Blame History

Basic Forensics ESP

  • Collect
  • Preserve
  • Analyze
  • Present

Cuando hagas reboot a una máquina afectada hay que iniciarla desde nuestro propio USB booteado. Pues usar el SO de la maquina modificara metadata de algunos archivos como access time y las herramientas de dicha máquina no son confiables.

Linux/Unix

En linux cualquier cosa es un archivo. Por ejemplo la RAM es un archivo llamado /dev/mem

lsof —> Open files belonging to any process
lsof -i 4 —> Todos los archivos relacionados con conexiones IPv4
lsof -i 4 -a -p 1234 —> List all open IPV4 network files in use by the preocess 1234
lsof /dev/hda3 lista todos los archivos abiertos en /dev/hda3
lsof -t /u/ade/foo encuentra el proceso que tiene /u/abe/foo abierto
lsof +D /directory/path Busca que procesos tienen abiertos dicho directorio y archivos de dicho directorio
lsof -i :1-1024 Archivos que usan dichos puertos
lsof -i udp Archivos que usan UDP -uid 0
lsof -p 3 - R Muestra del proceso nº3 también su proceso padre
date —> Hora del ordenador actual
uptime —> Rebooted
uname -a —> System information
ifconfig —> Ver si esta en modo promiscuo
ps -eaf —> Procesos y servicios inusuales
netstat -punta
lsof +L1 —> Muestra todos los archivos abiertos con un contador de link menor de 1. Esto es para los procesos que eliminan el archivo del que vienen pero siguen ejecutandose porque ya están en memoria. Es decir lista todos los procesos que tienen su archivo borrado.
w who users —> Info de usuarios
find / -uid 0 -perm -4000 2>/dev/null —> Sirve para encontrar todos los archivos que tienen de permiso la s
find /directory -type f -mtime -1 -print —> Encuentra todos los archivos dentro de ese directorio modificados hace menos de 1 día
last —> Último usuario loggeado
df —> Free space
free —> free y used physical y swap memory

Toda la info obtenida de la máquina infectada NO debe ser guardada en la máquina sino enviada a otra con netcat

MemoryDump

memdmp

Linux Memory Extractor (LiME) —> Kernel module —> Descargar de git y hacer make —> insmod ./lime-3.13.0-44-generic.ko "path=/home/sansforensics/Desktop/mem_dump.bin format=padded" —> Inserta el modulo en el kernel el cual puede ser visto con lsmod —> rmmod lime —> Para eliminarlo
strings -n 8 mem_dump.bin —> Da todas las strings de tamaño igual o superior a 8
Fmem —> Kernel Module
live response from E-FENSE —> Insertar un USB y vas seleccionando los datos que quieres
F-Response —> Remotely

Copy Hard Drive

DD —> Coge bloques de memoria, les aplica el cambio que necesita y los coloca en su sitio. Por defecto bloques de 512B

dd if=INPUT_FILE of=OUTPUT_FILE bs=Nk (N es el numero de Kilobytes) —> Un bs mayor de 8KB puede hacer que vaya más lento
count=s —> s es el numero de bloques a copiar
skip=n —> n es el numero de bloques de los que pasar
seek=n —> n es el número de de bloques del outputfile

Un problema con DD es que no da feedback y si encuentra un error se queda parado sin que tu lo sepas una seccion no puede leerla y se para para eso se puede usar:

conv=noerror,sync —> Pasa de los errores y sigue y rellena con 0s lo que no pudo copiar
dd if=/dev/zero of=/dev/hdb —> Lo pone a cero 3-7 veces para dejarlo limpio
dd if=/dev/zero of/path/file count=1 —> Si no ponemos un count nunca parará de copiar 0s
dd if=/dev/hdb of=/dev/hda —> Hay que tener cuidado pues lo que sobre del disco serán 0s y esto hará que el hash sea distinto. Hay que averiguar el número de bloques para calcular el hash solo de ese número de bloques
dd if=/dev/hda of=/cas1/evidence.dd
ssh pi@10.10.10.48 “sudo dcfldd if=/dev/sbd | gzip -1 -” | dcfldd of=pi.dd.gz
Forensic listen: nc -l -p 8888 > /dev/hdg
Infected device: dd if/dev/hda | nc IPADDR 8888 -w 3 —> La opción w le dice que si no se envía nada en 3 segundo, se desconecta
DD no checkea hashes, hay que hacerlo de forma manual
sdd —> DD para forensia, da más datos y puede ser un poco más rápido

http://malwarefieldguide.com/LinuxChapter1.html

BOOT LINUX

La MBR master boot record está en el sector 0, se crea al particionar el disco y es siempre de 512B. 446B son el boot code, 64B de la tabla de partición y 2B son de la firma 55AA.

La firma del offset 01B8 identifica el disco al SO.

La tabla de partición contiene las 4 primeras particiones en 16B cada especificando el inicio y el fin. También indica si la partición es la que hay que bootear y el tamaño.

Cuando identifica la active partition carga un copia del boot sector de la active partition en memoria y pasa el control al código ejecutable.

EFI usa GUID globally unique identification compuesto por GPT(puede tener hasta 128 primary partitions) y jumps.

Linux usa EXT file system basado en el de UNIX . Un sistema con este particionado tiene un optional boot block y un superblock. El superblock define las estructuras de datos y los limites del sistema de ficheros. Contiene información de:

Magic number

Mount count and maximum mount count

block size 4096B —> Un bloque es la unidad mínima para guardar info

INODE count y block count

number of free disk blocks

number of free INODEs on the system

first INODE —> INODE number del first INODE en l file system en un EXT2,3,4 sería / del directorio

Un INODE contiene metadata de un archivo uno o varios files tienen por lo menos un INODE: tipo, dueño, permiso, tiempos ultima modif, aceso.., links al file y data block addresses.

Cómo encuentra /etc/myconfig

Primero va al INODE de / del cual saca la info de que es un directorio y dónde tiene el contenido. El contenido es una lista de archivos y subdirs que están en /. El subdirectorio etc debe de estar en esta lista con su INODE. Por lo tanto se mira su INODE, se averigua que es un directorio y se va donde tenga el contenido. En este contenido se busca myconfig junto con su número de INODE. Del INODE sacamos que myconfig es un archivo y su contenido son los block addresses donde lo guarda.

Pasted Graphic.tiff ¬

Cada archivo tiene su contenido almacenado en bloques, metadata en el INODE y el nombre e INODE number en el directorio dentro del que está. Cada vez que se crea, el numero de INODES decrementa en 1.

Cuando se elimina un archivo y el numero de Link-Count del INODE llega a 0 en EXT2:

los data blocks del block bitmap son marcados como libres

el INODE en el INODE bitmap se marca como libre

el deletion Time se pone en el INODE

el directory entry se marca como unused

Las conexiones entre la entrada del directorio, INODE, y los data blocks seguirán ahí hasta que se sobreescriban.

Como la informacion del directory entry aún está disponible, puedes encontrar la relacion entre el file name y su INODE.

Cambios en EXT3 y 4:

EL file size en el INODE se pone a 0

Los datos sobre los bloques son limpiados, por lo que no hay LINK entre INODE y los data blocks. Aun así, hay algunas formas de recuperar la info.

Los comandos SRM o shred borran intencionadamente el contenido.

Un Hard link tendrá el mismo INODE que el orginial por lo tanto comparten metadata y apuntan a los mismos bloques. Es decir un archivo con otro nombre que apunta a lo mismo.

Un Soft link tendrá distinto INODE y solo guardará la información de a qué archivo apunta.

Directory Content
/bin Common programs, shared by the system, the system administrator and the users.
/boot The startup files and the kernel, vmlinuz. In some recent distributions also grub data. Grub is the GRand Unified Boot loader and is an attempt to get rid of the many different boot-loaders we know today.
/dev Contains references to all the CPU peripheral hardware, which are represented as files with special properties.
/etc Most important system configuration files are in /etc, this directory contains data similar to those in the Control Panel in Windows
/home Home directories of the common users.
/initrd on some distributions Information for booting. Do not remove!
/lib Library files, includes files for all kinds of programs needed by the system and the users.
/lost+found Every partition has a lost+found in its upper directory. Files that were saved during failures are here.
/misc For miscellaneous purposes.
/mnt Standard mount point for external file systems, e.g. a CD-ROM or a digital camera.
/net Standard mount point for entire remote file systems
/opt Typically contains extra and third party software.
/proc A virtual file system containing information about system resources. More information about the meaning of the files in proc is obtained by entering the command man proc in a terminal window. The file proc.txt discusses the virtual file system in detail.
/root The administrative user's home directory. Mind the difference between /, the root directory and /root, the home directory of the root user.
/sbin Programs for use by the system and the system administrator.
/tmp Temporary space for use by the system, cleaned upon reboot, so don't use this for saving any work!
/usr Programs, libraries, documentation etc. for all user-related programs.
/var Storage for all variable files and temporary files created by users, such as log files, the mail queue, the print spooler area, space for temporary storage of files downloaded from the Internet, or to keep an image of a CD before burning it.

Sleuthkit y Autopsy

Lo primero que tenemos que hacer es encontrar el inicio de la partición. Para eso podemos usar fdisk o mmls. mmls PATH_IMAGEN mmls da la info en base a bloques de 512B y fdisk da la info en base a cilindros, se suele usar mmls porque te interesan los Bytes para sleuthkit

De esta forma encontramos el offset en la que comienza el SO. Conociendo en offset con el que empieza podemos empezar a usar Sleuthkit.

Con fsstat podemos encontrar el tipo de partición que es. fsstat -o OFFSET IMAGEN

fls -o OFFSET -f FS_TYPE -m “/“ -r PATH_IMAGEN > flsBody —> Da todos los archivos encontrados que aun tienen el nombre puesto desde / en formato MACTIME

ils -o OFFSET -f FS_TYPE -m PATH_IMAGEM > ilsBody —> Da todos los INODES que encuentra en formato MACTIME

Autopsy es la GUI de Sleuth Kit.

Los SDD complican el rescatar información.

File system layer tools start with FS

File name layer tools starts with F

Metadata layer tools strat with I

Data layer tools start with BLK

Todos los comandos necesitan por lo menos el nombre de la imagen:

-f <fs_type> —> EXT2,3 FAT12,16,32…

-o imgoffset —> Sector offset where the file system starts in the image

BLK —>Block

blkstat —> Muestra información del bloque como si está allocated

blkstat -f ext2 myImage.img 300 —> Muestra info del bloque 300

blkls —> Muestra toda la Unallocated Data útil para recuperar info

-e —> Lista todos los datos

-s —> liste the slack ntfs o fat

blkcat —> Muestra el contenido de un bloque

-h -> Para mostrarlo en hexadecimal

blkcat -f ext2 myImage.img 200 —> Muestra lo que hay en el bloque 200

I —> INODE(Meta data)

istat —> Info de un INODE: INODE number, mac time, permission, file size, allocation status o allocated data blocks number, number of links…

istat -f ext2 myImage.img INODENUMBER

ifind —> De un block number a un INODE number. Si encuentras un bloque interesante así puedes encontrar los demás.

ifind -f ext2 -d DATABLOCKNUMBER myImage.img

ils —> List all inodes and info. Included deleted files and unlinked but opened files

Por defecto solo muestra los de archivos borrados

-e —> Muestra todos

-m —> crea un archivo para MACTIME —> Organiza el resultado y presenta un timeline de actividades. Pone un 127 al INODE si ela rchivo ha sido borrado.

-o —> Open but no filename

-z —> INODE with zero status time change never used

icat —> Dada la imagen sospechosa y el INODE, saca el contenido, puede recuperar archivos perdidos. Debemos encontrar el INODE number con ils.

icat -f ext2 /image 20

F —> File name

fls —> Lista los nombres y subdirs de un directorio. Por defecto los del root. Deleted files have a * before them. Si el nombre fue sobreescrito, no lo encontrará, pero ILS sí.

-a —> Display all

-d —> Deleted only

-u —> undeleted

-D —> Directories

-F —> File entries only

-r —> Recursive on subdirs

-p —> Full path

-m output —> TIMELINE format

-l —> Long version information

-s —> Skew in seconds combined with -l and/or -m

fls -r image 12

fls -f ext3 -m “/” -r imaes/root.dd

fls -o 2048 -f ext2 -m "/" -r '/home/sansforensics/Desktop/LinuxFinancialCase.001' > flsBody

ffind —> Filename de un INODE. Busca por todas partes hasta encontrar a qué filename apunta el INODE

-a —> Coge todos los nombres que apuntan al INODE

ffind -f ext2 myImage.img INODENUMBER

Mount -o ro,loop /my_hda1.dd /mnt/hacked —> Siempre se debe montar con ro read only, loop es por si lo que montas no es un disco sino un archivo una imagen por ejemplo

MACTIME:

M —> Last time files data block changed Modification

A —> Last time files data block accessed Access

C —> Last time inodes content changed in windows, this is creation time Change time

mactime -b FLSbodymac -d > MACtimeFLS.csv

En linux usar touch modifica los 2 primeros. En windows hay un programa que modifica los 3 todo se modifica muy facilmente.

touch -a -d 2017-01-03 08:46:23 FILE —> Modifica el access según la hora dada

Comando stat da los tres valores MAC del archivo.

Conseguir el archivo en formato MACTIME

fls -f ext3 -m “/“ -r images/root.dd > data/body

ils -f openbsd -m images/root.dd > data/body

Binary files modified in 1 day: find /directory_path -type f -a=x -mtime -1 -print

Files created in 1 day: find /directory_path -type f -a=x -bmin -24 -print

Se pueden guardar todo el raw data unallocated de la imagen usando dls myImage > unallocated el contenido de estos datos puede ser cualquier cosa: .jpeg, .pdf …

Se puede saber qué datos son usando programas de data carving se basan en headers, footers para saber que tipo de archivo es, dónde empieza y dónde acaba.

Data carving tools: Foremost, Scalpel, Magic Rescue, Photorec, TestDisk, etc

Foremost

Para user Foremost tenemos que ir a su archivo de configuración find / -name foremost.comf y descomentar las líneas de los tipos de archivo que nos interesen.

foremost -c fremost.conf -T -i FILE La T es para que vaya asginando nombres unicos

BOOTABLES

CAINE

HELIXS/HELIX3 PRO

KALI

PENGUIN SLEUTH

F.I.R.E

SNARL

BUILT-IN FUNCTIONALITIES

Deleted file recovery

Keyword search

Hash Analysis

Data carving

Graphic view

Email view

Analysis procedure

Create a case

Add evidence to a case

Perform throrough analysis

Obtain basic analysis data

Export files

Generate report

WINDOWS

Volatile Information

System Information

Processes information

Network information

Logged on users

Clipboard contents

Command history - doskey/history

MACTime

Comandos para obtener esta info:

date /T; time /T

uptime

ipconfig

tasklist /svc

openfiles

netstat

Helix:

Primer apartado: Info del sistema

Procesos corriendo

Segundo apartado: Permite crear copias del disco y memoria, primero usando dd mejor usar os otros

En la segunda página usando FTK imager

Es la tercera página, RAM usando Winen o MDD

Tercer apartado: Incident response

Cuarto apartado: Navegación por el disco, no usar mucho porque cambian los tiempos de acceso

Quinto apartado: Saca todas las imagenes

Cold Boot Attack:

En el caso en el que el sistema esté cifrado y encendido pero no se tenga la contraseña para entrar se realiza este tipo de ataque.

Este ataque se basa en la posibilidad de que el delincuente ya accediese antes al sistema y se desloggeara, de forma que la contraseña del cifrado aún pudiese estar en memoria pero no se puede hacer un dump de la memoria pues no se puede loggear uno como el usuario pues no se tiene la contraseña.

El ataque cold boot consiste en que la memoria RAM no se elimina en cuanto se apaga el ordenador y si se le aplica frío puede durar varios minutos, de esta forma para intentar extraerla:

1) Hacer que la BIOS inicie desde usb

2) Conectar el USB especial scraper.bin que hace un copiado de la memoria

3) El USB ha copiado la memoria

High speed forensics imagers

Logicubes Forensic Falcon —> 30GB por minuto

Mediaclones Superimager —> de 29 a 31 GB por minuto

En Windows un Block es llamado Cluster. En este sistema operativo cuando un cluster no se llena el espacio vacio se queda sin usar, lo cual es util pues puede contener datos eliminados. En linux la parte que no se llena de un block se rellena con ceros.

****

Borrado de datos: https://github.com/Claudio-C/awesome-data-sanitization

recuperacion de datos: https://github.com/Claudio-C/awesome-datarecovery

Partitions

A hard drive or a SSD disk can contain different partitions with the goal of separating data physically.
The minimum unit of a disk is the sector normally composed by 512B. So, each partition size needs to be multiple of that size.

MBR master Boot Record

It's allocated in the first sector of the disk after the 446B of the boot code. It contains the partitions table there can be up to **4 primary partitions**. The final byte of this first sector is the boot record signature 0x55AA. Only one partition can be marked as active.
MBR allows max 2.2TB.

From the bytes 440 to the 443 of the MBR you can find the Windows Disk Signature if Windows is used. The logical drive letters of the hard disk depend on the Windows Disk Signature. Changing this signature could prevent Windows from booting.

LBA Logical block addressing

Logical block addressing **LBA** is a common scheme used for specifying the location of blocks of data stored on computer storage devices, generally secondary storage systems such as hard disk drives. LBA is a particularly simple linear addressing scheme; blocks are located by an integer index, with the first block being LBA 0, the second LBA 1, and so on.

GPT GUID Partition Table

Its called GUID Partition Table because every partition on your drive has a globally unique identifier.

Just like MBR it starts in the sector 0. The MBR occupies 32bits while GPT uses 64bits.
GPT allows up to 128 partitions in Windows and up to 9.4ZB.
Also, partitions can have a 36 character Unicode name.

On an MBR disk, the partitioning and boot data is stored in one place. If this data is overwritten or corrupted, youre in trouble. In contrast, GPT stores multiple copies of this data across the disk, so its much more robust and can recover if the data is corrupted.

GPT also stores cyclic redundancy check (CRC) values to check that its data is intact. If the data is corrupted, GPT can notice the problem and attempt to recover the damaged data from another location on the disk.

Protective MBR LBA0

For limited backward compatibility, the space of the legacy MBR is still reserved in the GPT specification, but it is now used in a way that prevents MBR-based disk utilities from misrecognizing and possibly overwriting GPT disks. This is referred to as a protective MBR.

Hybrid MBR LBA 0 + GPT

In operating systems that support GPT-based boot through BIOS services rather than EFI, the first sector may also still be used to store the first stage of the bootloader code, but modified to recognize GPT partitions. The bootloader in the MBR must not assume a sector size of 512 bytes.

Partition table header LBA 1

The partition table header defines the usable blocks on the disk. It also defines the number and size of the partition entries that make up the partition table offsets 80 and 84 in the table.

Offset Length Contents
0 0x00 8 bytes Signature "EFI PART", 45h 46h 49h 20h 50h 41h 52h 54h or 0x5452415020494645ULL[ ](https://en.wikipedia.org/wiki/GUID_Partition_Table#cite_note-8)on little-endian machines
8 0x08 4 bytes Revision 1.0 00h 00h 01h 00h for UEFI 2.8
12 0x0C 4 bytes Header size in little endian in bytes, usually 5Ch 00h 00h 00h or 92 bytes
16 0x10 4 bytes CRC32 of header offset +0 up to header size in little endian, with this field zeroed during calculation
20 0x14 4 bytes Reserved; must be zero
24 0x18 8 bytes Current LBA location of this header copy
32 0x20 8 bytes Backup LBA location of the other header copy
40 0x28 8 bytes First usable LBA for partitions primary partition table last LBA + 1
48 0x30 8 bytes Last usable LBA secondary partition table first LBA 1
56 0x38 16 bytes Disk GUID in mixed endian
72 0x48 8 bytes Starting LBA of array of partition entries always 2 in primary copy
80 0x50 4 bytes Number of partition entries in array
84 0x54 4 bytes Size of a single partition entry usually 80h or 128
88 0x58 4 bytes CRC32 of partition entries array in little endian
92 0x5C * Reserved; must be zeroes for the rest of the block 420 bytes for a sector size of 512 bytes; but can be more with larger sector sizes

Partition entries LBA 233

GUID partition entry format
Offset Length Contents
0 0x00 16 bytes Partition type GUID mixed endian
16 0x10 16 bytes Unique partition GUID mixed endian
32 0x20 8 bytes First LBA [little endian](https://en.wikipedia.org/wiki/Little_endian)
40 0x28 8 bytes Last LBA inclusive, usually odd
48 0x30 8 bytes Attribute flags e.g. bit 60 denotes read-only
56 0x38 72 bytes Partition name 36 [UTF-16](https://en.wikipedia.org/wiki/UTF-16)LE code units

Partitions Types

More partition types in https://en.wikipedia.org/wiki/GUID_Partition_Table

Inspecting

After mounting the forensics image with ArsenalImageMounter, you can inspect the first sector using the Windows tool Active Disk Editor. In the following image a MBR was detected on the sector 0 and interpreted:

If it was a GPT table instead of a MBR it should appear the signature EFI PART in the sector 1 which in the previous image is empty.

File-Systems

Windows file-systems list

  • FAT12/16: MSDOS, WIN95/98/NT/200
  • FAT32: 95/2000/XP/2003/VISTA/7/8/10
  • ExFAT: 2008/2012/2016/VISTA/7/8/10
  • NTFS: XP/2003/2008/2012/VISTA/7/8/10
  • ReFS: 2012/2016

FAT

The FAT (File Allocation Table) file system is named for its method of organization, the file allocation table, which resides at the beginning of the volume. To protect the volume, two copies of the table are kept, in case one becomes damaged. In addition, the file allocation tables and the root folder must be stored in a fixed location so that the files needed to start the system can be correctly located.

The minimum space unit used by this file-system is a cluster, typically 512B which is composed by a number of sectors.

The earlier FAT12 had a cluster addresses to 12-bit values with up to 4078 clusters; it allowed up to 4084 clusters with UNIX. The more efficient FAT16 increased to 16-bit cluster address allowing up to 65,517 clusters per volume. FAT32 uses 32-bit cluster address allowing up to 268,435,456 clusters per volume

The maximum file-size allowed by FAT is 4GB minus one byte because the file system uses a 32-bit field to store the file size in bytes, and 2^32 bytes = 4 GiB. This happens for FAT12, FAT16 and FAT32.

The root directory occupies a specific position for both FAT12 and FAT16 in FAT32 it occupies a position like any other folder. Each file/folder entry contains this information:

  • Name of the file/folder 8 chars max
  • Attributes
  • Date of creation
  • Date of modification
  • Date of last access
  • Address of the FAT table where the first cluster of the file starts
  • Size

When a file is "deleted" using a FAT file system, the directory entry remains almost unchanged except for the first character of the file name modified to ****0xE5, preserving most of the "deleted" file's name, along with its time stamp, file length and — most importantly — its physical location on the disk. The list of disk clusters occupied by the file will, however, be erased from the File Allocation Table, marking those sectors available for use by other files created or modified thereafter. In case of FAT32, it is additionally erased field responsible for upper 16 bits of file start cluster value.

NTFS

NTFS **New Technology File System** is a proprietary journaling file system developed by Microsoft.

The cluster is the minimum size unit of NTFS and the size of the cluster depends on the size of a partition.

Partition size Sectors per cluster Cluster size
512MB or less 1 512 bytes
513MB-1024MB 1GB 2 1KB
1025MB-2048MB 2GB 4 2KB
2049MB-4096MB 4GB 8 4KB
4097MB-8192MB 8GB 16 8KB
8193MB-16,384MB 16GB 32 16KB
16,385MB-32,768MB 32GB 64 32KB
Greater than 32,768MB 128 64KB

Slack-Space

As the minimum size unit of NTFS is a cluster. Each file will be occupying a number of complete clusters. Then, it's highly probable that each file occupies more space than necessary. These unused spaces booked by a file which is called slacking space. And people could take advantage of this technique to hide information.

NTFS boot sector

When you format an NTFS volume, the format program allocates the first 16 sectors for the $Boot metadata file. First sector, in fact, is a boot sector with a "bootstrap" code and the following 15 sectors are the boot sector's IPL initial program loader. To increase file system reliability the very last sector an NTFS partition contains a spare copy of the boot sector.

Master File Table o $MFT

The NTFS file system contains a file called the master file table, or MFT. There is at least one entry in the MFT for every file on an NTFS file system volume, including the MFT itself. All information about a file, including its size, time and date stamps, permissions, and data content, is stored either in MFT entries, or in space outside the MFT that is described by MFT entries.

As files are added to an NTFS file system volume, more entries are added to the MFT and the MFT increases in size. When files are deleted from an NTFS file system volume, their MFT entries are marked as free and may be reused. However, disk space that has been allocated for these entries is not reallocated, and the size of the MFT does not decrease.

The NTFS file system reserves space for the MFT to keep the MFT as contiguous as possible as it grows. The space reserved by the NTFS file system for the MFT in each volume is called the MFT zone. Space for file and directories are also allocated from this space, but only after all of the volume space outside of the MFT zone has been allocated.

Depending on the average file size and other variables, either the reserved MFT zone or the unreserved space on the disk may be allocated first as the disk fills to capacity. Volumes with a small number of relatively large files will allocate the unreserved space first, while volumes with a large number of relatively small files allocate the MFT zone first. In either case, fragmentation of the MFT starts to take place when one region or the other becomes fully allocated. If the unreserved space is completely allocated, space for user files and directories will be allocated from the MFT zone. If the MFT zone is completely allocated, space for new MFT entries will be allocated from the unreserved space.

NTFS file systems also generate a $MFTMirror. This is a copy of the first 4 entries of the MFT: $MFT, $MFT Mirror, $Log, $Volume.

NTFS reserves the first 16 records of the table for special information:

System File File Name MFT Record Purpose of the File
Master file table $Mft 0 Contains one base file record for each file and folder on an NTFS volume. If the allocation information for a file or folder is too large to fit within a single record, other file records are allocated as well.
Master file table 2 $MftMirr 1 A duplicate image of the first four records of the MFT. This file guarantees access to the MFT in case of a single-sector failure.
Log file $LogFile 2 Contains a list of transaction steps used for NTFS recoverability. Log file size depends on the volume size and can be as large as 4 MB. It is used by Windows NT/2000 to restore consistency to NTFS after a system failure.
Volume $Volume 3 Contains information about the volume, such as the volume label and the volume version.
Attribute definitions $AttrDef 4 A table of attribute names, numbers, and descriptions.
Root file name index $ 5 The root folder.
Cluster bitmap $Bitmap 6 A representation of the volume showing which clusters are in use.
Boot sector $Boot 7 Includes the BPB used to mount the volume and additional bootstrap loader code used if the volume is bootable.
Bad cluster file $BadClus 8 Contains bad clusters for the volume.
Security file $Secure 9 Contains unique security descriptors for all files within a volume.
Upcase table $Upcase 10 Converts lowercase characters to matching Unicode uppercase characters.
NTFS extension file $Extend 11 Used for various optional extensions such as quotas, reparse point data, and object identifiers.
12-15 Reserved for future use.
Quota management file $Quota 24 Contains user assigned quota limits on the volume space.
Object Id file $ObjId 25 Contains file object IDs.
Reparse point file $Reparse 26 This file contains information about files and folders on the volume include reparse point data.

Each entry of the MFT looks like the following:

Note how each entry starts with "FILE". Each entry occupies 1024 bits. So after 1024 bit from the start of a MFT entry you will find the next one.

Using the Active Disk Editor it's very easy to inspect the entry of a file in the MFT. Just right click on the file and then click "Inspect File Record"

Checking the "In use" flag it's very easy to know if a file was deleted a value of 0x0 means deleted.

It's also possible to recover deleted files using FTKImager:

El tamaño de un cluster es de 64kB, aunque se pueden crear clusters mas pequeños o más grandes. 64bits para la dirección de cada cluster

BOOT RECORD:

Puede usar hasta 16 sectores, tiene el cluster size, dirección de MFT(master file table), el mirror de MFT(4 primeras entradas) y el código si es booteable.

MASTER FILE TABLE se puede ver con EnCase

Su nombre comienza con $ y se crea cuando el NTFS es formateado. Cada archivo usa uno o mas MFT records para guardar info: $file record head(MFT nº, link count, tipo de archivo, tamaño, etc), $standard information, $filename, $data y $attribute.

Si el metadata de un archivo es mayor que un MFT record, se usan mas.

El primer archivo es $MFT

$BITMAP guarda el estado de cada cluster, si está usado vale 1, sino vale 0.

Cuando se elimina algo, el pone el cluster a 0 unallocated la entrada de $index es eliminada el MTF padre, pero no se borran los datos.

References