elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  necesito ayuda sobre MFT y su analisis en C
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: necesito ayuda sobre MFT y su analisis en C  (Leído 1,312 veces)
Belial & Grimoire


Desconectado Desconectado

Mensajes: 559


Tea_Madhatter


Ver Perfil
necesito ayuda sobre MFT y su analisis en C
« en: 26 Enero 2014, 06:33 am »

hola

Estoy tratando de crear un codigo para recuperar archivos borrados, vengo leyendo varios documentos y viendo varios codigos, poco a poco estoy comprendiendo como funciona, hasta ahora he logrado comprender en donde se encuentra la informacion de los archivos, sobre NTFS, MFT y clusters, y mas o menos como encontrar los archivos borrados, sobre sus atributos y despues de eso me faltaria saber como restaurar los archivos

he practicado y mas abajo pondre un codigo que hice analizando codigos que hay en la red, desafortunadamente para mi, la mayoria en funcionamiento los encuentro para VB, hay otros pero son muy elaborados usando incluso clases, pero a la mayoria he visto lo mismo

Ahora... mi problema es el siguiente, ¿de que forma puedo leer los datos de MFT?, ya tengo una forma de acceso pero no logro entender como hacen ese escaneo por los datos del archivo MFT para analizar los archivos que se encuentran en mi computadora, asi como los borrados

espero alguien me pueda ayudar diciendo que API, estructura o que operacion tendria que usar ahora para empezar el analisis en MFT, porfavor, porque ya no se por donde seguir o que mas se deba hacer

dejo el codigo que mencione, pero despues de aprender esto, que mas sigue?, perdon si estan mal escrito los printf pero los escribi asi de mal porque solo fue para entender de que sirve la estructura

por cierto, he visto que algunos utilizan DISK_GEOMETRY pero yo no lo vi necesario

tambien hay unas API que vi que utilizan por ejemplo FSCTL_ENUM_USN_DATA, FSCTL_QUERY_USN_JOURNAL

Esto es lo que he logrado entender y es parecido a una parte de VB.net

Código
  1. #include <Windows.h>
  2. #include <winioctl.h>
  3. #include <stdio.h>
  4.  
  5. #define FSCTL_GET_NTFS_VOLUME_DATA CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 25, METHOD_BUFFERED, FILE_ANY_ACCESS)
  6. #define zwpath L"\\\\.\\PhysicalDrive0"
  7.  
  8. int main(int argc, char *argv[]){
  9.  
  10.    HANDLE hDevice = INVALID_HANDLE_VALUE;
  11.    BOOL bresul = FALSE;
  12.    DWORD junk = 0;
  13.  
  14.    hDevice = CreateFileW(zwpath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
  15.  
  16.    if(hDevice == INVALID_HANDLE_VALUE){
  17.  
  18.        printf("error device\n");
  19.    }
  20.  
  21.    NTFS_VOLUME_DATA_BUFFER ntfsData;
  22.  
  23.    bresul = DeviceIoControl(hDevice,FSCTL_GET_NTFS_VOLUME_DATA, NULL, 0, &ntfsData, sizeof(NTFS_VOLUME_DATA_BUFFER), &junk, (LPOVERLAPPED)NULL );
  24.  
  25.    printf("Numero de serie = %ld\n", ntfsData.VolumeSerialNumber);
  26.    printf("Numero de sectores = %ld\n", ntfsData.NumberSectors);
  27.    printf("Total clusters = %ld\n", ntfsData.TotalClusters);
  28.    printf("Clusters libres = %ld\n", ntfsData.FreeClusters);
  29.    printf("Total reservados = %ld\n", ntfsData.TotalReserved);
  30.    printf("Bytes por sector = %ld\n", ntfsData.BytesPerSector);
  31.    printf("Bytes por cluster = %ld\n", ntfsData.BytesPerCluster);
  32.    printf("Bytes por segmeto de archivo = %ld\n", ntfsData.BytesPerFileRecordSegment);
  33.    printf("Cluster por segmento de archivo = %ld\n", ntfsData.ClustersPerFileRecordSegment);
  34.    printf("Longitud de datos validos MFT = %ld\n", ntfsData.MftValidDataLength);
  35.    printf("Inicio de LCN = %ld\n", ntfsData.MftStartLcn);
  36.    printf("Inicio mirror de LCN = %ld\n", ntfsData.Mft2StartLcn);
  37.    printf("Zona de Inicio MFT= %ld\n", ntfsData.MftZoneStart);
  38.    printf("Zona final MFT = %ld\n", ntfsData.MftZoneEnd);
  39.  
  40.    getchar();
  41. }


O si alguien tiene conocimientos en VB.NET que me pueda ayudar a traducir el codigo a C tambien me ayudaria bastante

Código
  1.  Public Sub FindHDFiles(ByVal Drive As String)
  2.        Drive = Drive.TrimEnd("\")
  3.        Try
  4.            Dim dinfo = My.Computer.FileSystem.GetDriveInfo(Drive & "\")
  5.            If Not dinfo.IsReady Then
  6.                MsgBox("Drive not ready.", MsgBoxStyle.Critical, "ERROR")
  7.                Exit Sub
  8.            End If
  9.            If dinfo.DriveFormat <> "NTFS" Then
  10.                MsgBox("This feature only works on NTFS volumes.", MsgBoxStyle.Critical, "ERROR")
  11.                Exit Sub
  12.            End If
  13.            ARKDDA = New DirectDriveIO(Drive & "\")
  14.        Catch
  15.            MsgBox("Could not access drive.", MsgBoxStyle.Critical, "ERROR")
  16.            Exit Sub
  17.        End Try
  18.        Drive = Drive.TrimEnd("\")
  19.        Dim diskhandle = CreateFile("\\?\" & Drive, EFileAccess.GENERIC_READ + EFileAccess.GENERIC_WRITE, EFileShare.FILE_SHARE_READ + EFileShare.FILE_SHARE_WRITE, Nothing, ECreationDisposition.OPEN_EXISTING, 0, Nothing)
  20.        If diskhandle = 0 Then
  21.            diskhandle = CreateFile("\\.\" & Drive, EFileAccess.GENERIC_READ + EFileAccess.GENERIC_WRITE, EFileShare.FILE_SHARE_READ + EFileShare.FILE_SHARE_WRITE, Nothing, ECreationDisposition.OPEN_EXISTING, 0, Nothing)
  22.            If diskhandle = 0 Then
  23.                MsgBox("Could not access drive.", MsgBoxStyle.Critical, "ERROR")
  24.                Exit Sub
  25.            End If
  26.        End If
  27.        Dim FSCTL_GET_NFTS_VOLUME_DATA = CTL_CODE(FILE_DEVICE.FILE_DEVICE_FILE_SYSTEM, 25, METHOD_BUFFERED, FILE_ANY_ACCESS)
  28.        Dim buffer As NTFS_VOLUME_DATA_BUFFER
  29.        DeviceIoControlNTFS(diskhandle, FSCTL_GET_NFTS_VOLUME_DATA, 0, 0, buffer, SizeOf(buffer), 0, 0)
  30.        CloseHandle(diskhandle)
  31.        Dim MFTAddress As Long = buffer.MftStartLcn * CLng(buffer.BytesPerCluster / buffer.BytesPerSector)
  32.        Dim MFTEntrySize As Integer = buffer.BytesPerFileRecordSegment / buffer.BytesPerSector
  33.        Dim NumberOfEntries As Long = buffer.MftValidDataLength / MFTEntrySize
  34.        Dim Bytes(buffer.BytesPerCluster) As Byte
  35.        Dim CurrEntryBytes(MFTEntrySize * buffer.BytesPerSector) As Byte
  36.        Dim CurrEntry As New STANDARD_MFT_ENTRY
  37.        Dim Type As Byte
  38.        Dim Name As String
  39.        Dim BaseAddr As Long
  40.        Dim Parent As Integer
  41.        Dim DoEventsCounter As Integer = 0
  42.        ListView1.Items.Clear()
  43.        ListView2.Items.Clear()
  44.        ProgressBar1.Value = 0
  45.        ProgressBar1.Maximum = buffer.MftValidDataLength / buffer.BytesPerFileRecordSegment
  46.        ToolStripStatusLabel1.Text = "Finding files in " & Drive & "\..."
  47.        Button1.Enabled = False
  48.        Button2.Enabled = False
  49.        ComboBox1.Enabled = False
  50.        Button3.Enabled = False
  51.        CheckBox2.Enabled = False
  52.        LastDrive = Drive
  53.        If CheckBox2.Checked Then Bitmap = ReadBitmap(Drive)
  54.        Dim BitmapBase As Long = MFTAddress + (MFTEntrySize * 0)
  55.        Bytes = ARKDDA.ReadSectors(BitmapBase, MFTEntrySize)
  56.        BaseAddr = MergeToInt(Bytes, &H14, &H15) 'The offset the the first attribute
  57.        While Bytes(baseaddr) <> &H80
  58.            baseaddr = baseaddr + MergeToInt(Bytes, baseaddr + &H4, baseaddr + &H7) 'Add the length of the attribute to the base address to find the next attribute
  59.        End While
  60.        baseaddr = baseaddr + &H40
  61.        Dim Length As ULong = 0
  62.        Dim LenLen As Byte = 0
  63.        Dim Offset As ULong = 0
  64.        Dim OffLen As Byte = 0
  65.        Dim Path As String = ""
  66.        Dim BaseAddr2 As ULong = 0
  67.        Dim FileSize As ULong = 0
  68.        Dim LoopCount As Integer = 0
  69.        Dim PartNum As Integer = 0
  70.        While Bytes(baseaddr) > 0
  71.            LenLen = Bytes(BaseAddr) And &HF
  72.            OffLen = (Bytes(BaseAddr) And &HF0) / &H10
  73.            Length = MergeToInt(Bytes, BaseAddr + 1, BaseAddr + LenLen)
  74.            Offset = Offset + MergeToInt(Bytes, BaseAddr + 1 + LenLen, BaseAddr + LenLen + OffLen)
  75.            For Record = 0 To ((Length * buffer.BytesPerCluster) / buffer.BytesPerFileRecordSegment) - 1
  76.                DoEventsCounter = DoEventsCounter + 1
  77.                If DoEventsCounter >= 100 Then
  78.                    Application.DoEvents()
  79.                    DoEventsCounter = 0
  80.                End If
  81.                Try
  82.                    If (PartNum + 1) >= (CurrEntryBytes.Count / buffer.BytesPerFileRecordSegment) Then
  83.                        CurrEntryBytes = ARKDDA.ReadSectors((Record * MFTEntrySize) + (Offset * (buffer.BytesPerCluster / buffer.BytesPerSector)), MFTEntrySize * 1024)
  84.                        BaseAddr2 = 0
  85.                        PartNum = 0
  86.                    Else
  87.                        'CurrEntryBytes = ByteArrayPart(CurrEntryBytes, buffer.BytesPerFileRecordSegment, UBound(CurrEntryBytes))
  88.                        'BaseAddr2 = (((BaseAddr2 \ buffer.BytesPerFileRecordSegment) + 1) * buffer.BytesPerFileRecordSegment)
  89.                        PartNum = PartNum + 1
  90.                        BaseAddr2 = PartNum * buffer.BytesPerFileRecordSegment
  91.                    End If
  92.                    If CurrEntryBytes(BaseAddr2) <> Asc("F") Then
  93.                        'If CurrEntryBytes(0) <> Asc("F") Then
  94.                        GoTo dn
  95.                    End If
  96.                    Name = ""
  97.                    Parent = 5
  98.                    Path = ""
  99.                    FileSize = 0
  100.                    'Type = CurrEntryBytes(&H16)
  101.                    Type = CurrEntryBytes(&H16 + BaseAddr2)
  102.                    'If Type = MFT_ENTRY_FILE_TYPE_FLAGS.DeletedDirectory Or Type = MFT_ENTRY_FILE_TYPE_FLAGS.DeletedFile Then
  103.                    If Type = MFT_ENTRY_FILE_TYPE_FLAGS.DeletedFile Then
  104.                        'BaseAddr2 = BaseAddr2 + MergeToInt(CurrEntryBytes, &H14, &H15) 'The offset the the first attribute
  105.                        BaseAddr2 = BaseAddr2 + MergeToInt(CurrEntryBytes, BaseAddr2 + &H14, BaseAddr2 + &H15) 'The offset the the first attribute
  106.                        BaseAddr2 = BaseAddr2 + MergeToInt(CurrEntryBytes, BaseAddr2 + &H4, BaseAddr2 + &H7) 'Add the length of the attribute to the base address to find the next attribute
  107.                        Try
  108.                            Parent = MergeToInt(CurrEntryBytes, BaseAddr2 + &H18, BaseAddr2 + &H1D)
  109.                        Catch
  110.                        End Try
  111.                        Try
  112.                            If FileSize = 0 Then FileSize = MergeToInt(CurrEntryBytes, BaseAddr2 + &H48, BaseAddr2 + &H4F)
  113.                            If FileSize > 2 ^ 30 Then FileSize = 0
  114.                            'If FileSize = 0 Then FileSize = MergeToInt(CurrEntryBytes, BaseAddr2 + &H40, BaseAddr2 + &H47)
  115.                        Catch
  116.                        End Try
  117.                        Try
  118.                            Name = System.Text.UnicodeEncoding.Unicode.GetString(ByteArrayPart(CurrEntryBytes, BaseAddr2 + &H5A, (BaseAddr2 + &H5A) + ((2 * CurrEntryBytes(BaseAddr2 + &H58)) - 2)))
  119.                        Catch
  120.                        End Try
  121.                        Try
  122.                            If Name.Contains("~") Then
  123.                                BaseAddr2 = BaseAddr2 + MergeToInt(CurrEntryBytes, BaseAddr2 + &H4, BaseAddr2 + &H7) 'Add the length of the attribute to the base address to find the next attribute
  124.                                If FileSize = 0 Then FileSize = MergeToInt(CurrEntryBytes, BaseAddr2 + &H48, BaseAddr2 + &H4F)
  125.                                If FileSize > 2 ^ 30 Then FileSize = 0
  126.                                'If FileSize = 0 Then FileSize = MergeToInt(CurrEntryBytes, BaseAddr2 + &H40, BaseAddr2 + &H47)
  127.                                Name = System.Text.UnicodeEncoding.Unicode.GetString(ByteArrayPart(CurrEntryBytes, BaseAddr2 + &H5A, (BaseAddr2 + &H5A) + ((2 * CurrEntryBytes(BaseAddr2 + &H58)) - 2)))
  128.                            End If
  129.                        Catch
  130.                        End Try
  131.                        If Name.Length >= 75 Then Name = Mid(Name, 1, 74) & Mid(Name, 76, Name.Length - 75)
  132.                        If CheckBox1.Checked Then
  133.                            Try
  134.                                Path = GetFullPath2(Parent, MFTAddress, MFTEntrySize, buffer.BytesPerCluster) & "\" & Name
  135.                            Catch
  136.                            End Try
  137.                        End If
  138.                        If FileSize = 0 Then
  139.                            Try
  140.                                LoopCount = 0
  141.                                While CurrEntryBytes(BaseAddr2) <> &H80 And LoopCount < 5
  142.                                    LoopCount = LoopCount + 1
  143.                                    BaseAddr2 = BaseAddr2 + MergeToInt(CurrEntryBytes, BaseAddr2 + &H4, BaseAddr2 + &H7) 'Add the length of the attribute to the base address to find the next attribute
  144.                                End While
  145.                                'FileSize = MergeToInt(CurrEntryBytes, BaseAddr2 + &H28, BaseAddr2 + &H2F)
  146.                                'If FileSize > 2 ^ 30 Then FileSize = MergeToInt(CurrEntryBytes, BaseAddr2 + &H38, BaseAddr2 + &H3F)
  147.                                If MergeToInt(CurrEntryBytes, BaseAddr2 + &HE, BaseAddr2 + &HF) = 1 Then
  148.                                    'It is recycled (filename at offset 0x30,file size at offset 0x10)
  149.                                    FileSize = MergeToInt(CurrEntryBytes, BaseAddr2 + &H10, BaseAddr2 + &H13)
  150.                                    'Path = ""
  151.                                    'BaseAddr2 = BaseAddr2 + &H30
  152.                                    'While CurrEntryBytes(BaseAddr2) > 0
  153.                                    'Path = Path + ChrW(MergeToInt(CurrEntryBytes, BaseAddr2, BaseAddr2 + 1))
  154.                                    'Path = Path + ChrW(CurrEntryBytes(BaseAddr2))
  155.                                    'BaseAddr2 = BaseAddr2 + 2
  156.                                    'End While
  157.                                Else
  158.                                    'FileSize = 0
  159.                                    FileSize = MergeToInt(CurrEntryBytes, BaseAddr2 + &H30, BaseAddr2 + &H37)
  160.                                End If
  161.                                If FileSize > 2 ^ 30 Then FileSize = 0
  162.                            Catch
  163.                            End Try
  164.                        End If
  165.                        If FileSize > 0 Then
  166.                            With ListView1.Items.Add(Name)
  167.                                If Not Path.Contains("SKIPTHISFILE") Then
  168.                                    .SubItems.Add(Path)
  169.                                Else
  170.                                    .SubItems.Add("")
  171.                                End If
  172.                                .SubItems.Add(FileSize)
  173.                                .SubItems.Add((Record * MFTEntrySize) + (Offset * (buffer.BytesPerCluster / buffer.BytesPerSector)))
  174.                                If CheckBox2.Checked Then
  175.                                    Try
  176.                                        .SubItems.Add(GetFileIntegrity((Record * MFTEntrySize) + (Offset * (buffer.BytesPerCluster / buffer.BytesPerSector)), buffer.BytesPerSector, buffer.BytesPerFileRecordSegment))
  177.                                    Catch
  178.                                        .SubItems.Add("Unknown")
  179.                                    End Try
  180.                                Else
  181.                                    .SubItems.Add("")
  182.                                End If
  183.                                ListView2.Items.Add(.Clone)
  184.                            End With
  185.                        End If
  186.                        GoTo dn
  187.                    End If
  188.                Catch
  189.                End Try
  190. dn:
  191.                Try
  192.                    ProgressBar1.Value = ProgressBar1.Value + 1
  193.                Catch
  194.                End Try
  195.            Next Record
  196.            BaseAddr = BaseAddr + (1 + LenLen + OffLen)
  197.        End While
  198.        ProgressBar1.Value = 0
  199.        ToolStripStatusLabel1.Text = ""
  200.        Button1.Enabled = True
  201.        Button2.Enabled = True
  202.        ComboBox1.Enabled = True
  203.        Button3.Enabled = True
  204.        CheckBox2.Enabled = True
  205.    End Sub


En línea

.                                 
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Necesito ayuda sobre un programa
Ingeniería Inversa
Jmjm 2 1,920 Último mensaje 20 Diciembre 2005, 01:04 am
por Jmjm
LIbro Sobre Analisis Matematico
Electrónica
davinci21 1 2,809 Último mensaje 10 Enero 2007, 03:34 am
por D1e6o!
me podrian ayudar a conocer mas sobre analisis forense?
Seguridad
Belial & Grimoire 2 3,423 Último mensaje 10 Septiembre 2012, 00:02 am
por Belial & Grimoire
necesito ayuda sobre pinguear
Redes
Pedriitop 1 1,578 Último mensaje 17 Julio 2014, 01:10 am
por MCKSys Argentina
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines