Skip to content
KitploitKITPLOIT
StrumentiBlog
Invia
StrumentiBlog
Invia

Strumenti di Hacking, PenTest e Cybersecurity per il tuo Arsenale di Sicurezza!

Kitploit è una directory di strumenti di hacking, cybersecurity e pentesting. Scopri gli ultimi aggiornamenti dei progetti per trovare vulnerabilità, analizzare sistemi, automatizzare i test e rafforzare la tua sicurezza.

··Feed·Contatto·Privacy·© 2026 Kitploit

Directory degli strumenti

Categorie

Vedi tutte le categorie
Loading categories
machofile — machofile is a module to parse Mach-O binary files | Kitploit
Strumenti/GitHubGitHub/pstirparo/machofile
Static AnalysisReverse EngineeringForensicsMalware AnalysisBinary Analysis
GitHubpstirparo/machofile

machofile

machofile is a module to parse Mach-O binary files

Vedi Repository
9956 mesi faRevisionato da Kitploit

Più Popolari

Vedi tutti →

Scopri gli strumenti più utilizzati dalla nostra community.

Esplora tutti gli strumenti

Sfoglia la nostra collezione di strumenti

Vedi tutti gli strumenti →
Condividi
Sito web

machofile

Downloads

machofile è un modulo per analizzare file binari Mach-O, con particolare attenzione all'analisi di malware e al reverse engineering.

Ispirato a pefile di Ero Carrera, questo modulo mira a fornire capacità simili ma per binari Mach-O. Il materiale di riferimento e la documentazione usati per acquisire la conoscenza del formato file, le strutture di base e le costanti sono tratti dalle risorse elencate di seguito.

machofile è autonomo. Il modulo non ha dipendenze; è indipendente dall'endianness; e funziona su macOS, Windows e Linux.

Anche se esistono altri moduli per il parsing di Mach-O, le motivazioni alla base dello sviluppo di questo sono:

  • prima di tutto, per me è stato un ottimo modo per approfondire e imparare di più sul formato e sulle strutture Mach-O
  • fornire un modo semplice per analizzare file Mach-O per scopi di analisi
  • non dipendere da moduli esterni (es. lief, macholib, macho, ecc.), poiché tutto viene estratto direttamente dal file ed è tutto in puro Python.

Fammi sapere se lo provi o se trovi bug ma... sii gentile ;) il codice verrà ottimizzato e verranno aggiunte altre funzionalità.

Funzionalità attuali:

  • Parsing dell'header Mach-O
  • Parsing dei Load Commands
  • Parsing dei segmenti di file
  • Parsing dei comandi Dylib
  • Parsing della lista Dylib
  • Estrazione delle funzioni importate
  • Estrazione dei simboli esportati
  • Hash: dylib hash, import hash, export hash, entitlement hash, symhash
  • Calcolo dell'entropia dei segmenti
  • Estrazione del punto di ingresso
  • Estrazione UUID
  • Estrazione delle informazioni di versione
  • Parsing delle informazioni di base della Code Signature
  • Supporto per binari FAT (Universal)
  • Dump delle singole slice Mach-O da binari FAT (Universal)
  • Supporto output JSON (sia in formato leggibile sia grezzo)

Nota: al momento, è stato inizialmente testato su campioni Mach-O x86, x86_64, arm64 e arm64e.

Prossime funzionalità da implementare (in ordine casuale):

  • Stringhe incorporate
  • Attributi dei file
  • flag per librerie sospette
  • Rilevamento packer
  • ...

Utilizzo ed esempi

Puoi usarlo da riga di comando oppure importarlo come modulo nel tuo codice Python e chiamare ciascuna funzione singolarmente per analizzare solo le strutture che ti interessano. Puoi installarlo direttamente con pip e usarlo programmaticamente o da riga di comando, oppure usarlo come script autonomo.

root@kitploit:~
pip install machofile

Versione del modulo

Il modulo prevede che gli venga fornito un percorso file o un buffer di dati da analizzare.

root@kitploit:~
import machofile
macho = machofile.UniversalMachO(file_path='/path/to/machobinary')
macho.parse()

Se il buffer di dati è già disponibile, può essere fornito direttamente con:

root@kitploit:~
import machofile
with open(file_path, 'rb') as f:
    data = f.read()
macho = machofile.UniversalMachO(data=data)
macho.parse()

Per un utilizzo dettagliato dell'API, consulta la pagina di documentazione API dedicata.

Versione da riga di comando

Puoi usare machofile anche direttamente come strumento CLI se lo hai installato via pip, oppure come strumento autonomo con python3 machofile.py. Tutte le stesse funzionalità sono disponibili sia come modulo sia come strumento da riga di comando.

root@kitploit:~
% machofile -h
usage: machofile [-h] -f FILE [-j] [--raw] [-a] [-d] [-e] [-ep] [-g]
                    [-hdr] [-i] [-l] [-seg] [-sig] [-sim] [-u] [-v]
                    [--arch ARCH] [--dump-dir DUMP_DIR]

Parse Mach-O binary structures. (version 2026.02.04)

options:
  -h, --help          show this help message and exit

required arguments:
  -f, --file FILE     Path to the file to be parsed

output format options:
  -j, --json          Output data in JSON format
  --raw               Output raw values in JSON format (use with -j/--json)

data extraction options:
  -a, --all           Print all info about the file
  -d, --dylib         Print Dylib Command Table and Dylib list
  -e, --exports       Print exported symbols
  -ep, --entry-point  Print entry point information
  -g, --general_info  Print general info about the file
  -hdr, --header      Print Mach-O header info
  -i, --imports       Print imported symbols
  -l, --load_cmd_t    Print Load Command Table and Command list
  -seg, --segments    Print File Segments info
  -sig, --signature   Print code signature and entitlements information
  -sim, --similarity  Print similarity hashes
  -u, --uuid          Print UUID
  -v, --version       Print version information

filter options:
  --arch ARCH         Show info for specific architecture only (for Universal binaries)

dump options:
  --dump-dir DUMP_DIR Dump individual Mach-O slices from a FAT/Universal binary
                      to the specified directory

Output di esempio:

root@kitploit:~
% machofile -a -f b4f68a58658ceceb368520dafc35b270272ac27b8890d5b3ff0b968170471e2b

[General File Info]
        Filename:         b4f68a58658ceceb368520dafc35b270272ac27b8890d5b3ff0b968170471e2b
        Filesize:         54240
        MD5:              20ffe440e4f557b9e03855b5da2b3c9c
        SHA1:             1bf61ecad8568a774f9fba726a254a9603d09f33
        SHA256:           b4f68a58658ceceb368520dafc35b270272ac27b8890d5b3ff0b968170471e2b

[Mach-O Header]
        magic:            MH_MAGIC (32-bit), 0xFEEDFACE
        cputype:          Intel i386
        cpusubtype:       X86_ALL
        filetype:         EXECUTE
        ncmds:            13
        sizeofcmds:       1180
        flags:            NOUNDEFS, DYLDLINK, TWOLEVEL

[Load Cmd table]
        {'cmd': 'LC_SEGMENT', 'cmdsize': 56}
        {'cmd': 'LC_SEGMENT', 'cmdsize': 192}
        {'cmd': 'LC_SEGMENT', 'cmdsize': 328}
        {'cmd': 'LC_SEGMENT', 'cmdsize': 192}
        {'cmd': 'LC_SEGMENT', 'cmdsize': 56}
        {'cmd': 'LC_SYMTAB', 'cmdsize': 24}
        {'cmd': 'LC_DYSYMTAB', 'cmdsize': 80}
        {'cmd': 'LC_LOAD_DYLINKER', 'cmdsize': 28}
        {'cmd': 'LC_UUID', 'cmdsize': 24}
        {'cmd': 'LC_UNIXTHREAD', 'cmdsize': 80}
        {'cmd': 'LC_LOAD_DYLIB', 'cmdsize': 52}
        {'cmd': 'LC_LOAD_DYLIB', 'cmdsize': 52}
        {'cmd': 'LC_CODE_SIGNATURE', 'cmdsize': 16}

[Load Commands]
        LC_CODE_SIGNATURE
        LC_DYSYMTAB
        LC_LOAD_DYLIB
        LC_LOAD_DYLINKER
        LC_SEGMENT
        LC_SYMTAB
        LC_UNIXTHREAD
        LC_UUID

[File Segments]
        SEGNAME    VADDR VSIZE OFFSET SIZE  MAX_VM_PROTECTION INITIAL_VM_PROTECTION NSECTS FLAGS ENTROPY            
        ------------------------------------------------------------------------------------------------------------
        __PAGEZERO 0     4096  0      0     0                 0                     0      0     0.0                
        __TEXT     4096  28672 0      28672 7                 5                     2      0     5.080680410706916  
        __DATA     32768 4096  28672  4096  7                 3                     4      0     0.1261649636134924 
        __IMPORT   36864 4096  32768  4096  7                 7                     2      0     0.21493796627555234
        __LINKEDIT 40960 20480 36864  17376 7                 1                     0      0     6.637864516225949  

[Dylib Commands]
        DYLIB_NAME_OFFSET DYLIB_TIMESTAMP DYLIB_CURRENT_VERSION DYLIB_COMPAT_VERSION DYLIB_NAME                   
        ----------------------------------------------------------------------------------------------------------
        24                2               65536                 65536                b'/usr/lib/libgcc_s.1.dylib' 
        24                2               7274759               65536                b'/usr/lib/libSystem.B.dylib'

[Dylib Names]
        b'/usr/lib/libgcc_s.1.dylib'
        b'/usr/lib/libSystem.B.dylib'

[UUID]
        d691c242-da49-1081-50d5-4f8991924b06

[Entry Point]
        type:             LC_UNIXTHREAD
        entry_address:    9200
        thread_data_size: 72

[Version Information]
        No version information found

[Code Signature]
        signed:           True
        signing_status:   Apple signed
        certificates_info:
            count:            3
            certificates:
              index:            0
              size:             4815
              subject:          Contains: Developer ID Certification Authority
              issuer:           Unable to parse
              is_apple_cert:    True
              type:             Developer ID Certification Authority

              index:            1
              size:             1215
              subject:          Contains: Apple Root CA
              issuer:           Unable to parse
              is_apple_cert:    True
              type:             Apple Root CA

              index:            2
              size:             1385
              subject:          Contains: Developer ID Application:
              issuer:           Unable to parse
              is_apple_cert:    False
              type:             Developer ID Application Certificate
        entitlements_info:
            count:            0
            entitlements:
        code_directory:
            version:          131328
            flags:            0
            hash_offset:      144
            identifier_offset:48
            special_slots:    3
            signing_flags:
                None
            code_slots:       11
            hash_size:        44640
            hash_type:        335609868
            hash_algorithm:   Unknown (335609868)
            identifier:       onmac.unspecified.installer

[Imported Libraries]
        /usr/lib/libgcc_s.1.dylib
        /usr/lib/libSystem.B.dylib

[Imported Functions]
        (Sources: CF=chained_fixups, BO=bind, WB=weak_bind, LB=lazy_bind, ST=symtab)
        /usr/lib/libSystem.B.dylib:
                __NSGetExecutablePath [ST]
                ___stderrp [ST]
                _dlerror [ST]
                _dlopen [ST]
                _dlsym [ST]
                _exit [ST]
                _fclose [ST]
                _fopen [ST]
                _fprintf [ST]
                _fputs$UNIX2003 [ST]
                _free [ST]
                _fwrite$UNIX2003 [ST]
                _getenv [ST]
                _getpid [ST]
                _getpwnam [ST]
                _lstat [ST]
                _mbstowcs [ST]
                _memcpy [ST]
                _memset [ST]
                _setenv$UNIX2003 [ST]
                _setlocale [ST]
                _snprintf [ST]
                _stat [ST]
                _strchr [ST]
                _strdup [ST]
                _strlen [ST]
                _unsetenv$UNIX2003 [ST]

[Exported Symbols]
        <unknown>:
                _NXArgc
                _NXArgv
                ___progname
                _environ
                _main
                start

[Similarity Hashes]
        dylib_hash:       0556bed5dc31bddaee73f3234b3c577b
        export_hash:      824e359e3d0ad7283d0982bd5da2e8fd
        import_hash:      0bae89995ad3900987c49c0bea1d17fe
        symhash:          15e6c1aeba01be1404901f7152213779

Dump delle slice da binari Universal (FAT)

Quando si lavora con binari Universal (FAT), è possibile estrarre ogni slice dell'architettura in un proprio file Mach-O autonomo usando --dump-dir:

root@kitploit:~
# Dump all slices
% machofile -f universal_binary --dump-dir ./output
Dumped x86_64 -> ./output/universal_binary.x86_64
Dumped arm64 -> ./output/universal_binary.arm64

# Dump only a specific architecture (combine with --arch)
% machofile -f universal_binary --dump-dir ./output --arch arm64
Dumped arm64 -> ./output/universal_binary.arm64

Ogni file estratto è un binario Mach-O autonomo valido. La directory di output viene creata automaticamente se non esiste. I file di output sono nominati <original_filename>.<arch_name>.

Output JSON

machofile supporta l'output JSON per il consumo programmatico dei dati analizzati. L'output JSON è disponibile in due formati:

JSON leggibile (predefinito)

L'output JSON predefinito fornisce valori leggibili con una formattazione appropriata:

root@kitploit:~
% python3 machofile.py -j -hdr -f dec750b9d596b14aeab1ed6f6d6d370022443ceceb127e7d2468b903c2d9477a 
{
  "header": {
    "x86_64": {
      "magic": "MH_MAGIC_64 (64-bit), 0xFEEDFACF",
      "cputype": "x86_64",
      "cpusubtype": "x86_ALL",
      "filetype": "EXECUTE",
      "ncmds": 41,
      "sizeofcmds": 5024,
      "flags": "NOUNDEFS, DYLDLINK, TWOLEVEL, BINDS_TO_WEAK, PIE"
    },
    "arm64": {
      "magic": "MH_MAGIC_64 (64-bit), 0xFEEDFACF",
      "cputype": "ARM 64-bit",
      "cpusubtype": "ARM_ALL",
      "filetype": "EXECUTE",
      "ncmds": 41,
      "sizeofcmds": 5104,
      "flags": "NOUNDEFS, DYLDLINK, TWOLEVEL, BINDS_TO_WEAK, PIE"
    }
  },
  "architectures": [
    "x86_64",
    "arm64"
  ]
}

Output JSON grezzo

Per applicazioni che devono elaborare valori numerici grezzi, usa il flag --raw:

root@kitploit:~
% python3 machofile.py -j --raw -hdr -f dec750b9d596b14aeab1ed6f6d6d370022443ceceb127e7d2468b903c2d9477a
{
  "header": {
    "x86_64": {
      "magic": 4277009103,
      "cputype": 16777223,
      "cpusubtype": 3,
      "filetype": 2,
      "ncmds": 41,
      "sizeofcmds": 5024,
      "flags": 2162821
    },
    "arm64": {
      "magic": 4277009103,
      "cputype": 16777228,
      "cpusubtype": 0,
      "filetype": 2,
      "ncmds": 41,
      "sizeofcmds": 5104,
      "flags": 2162821
    }
  },
  "architectures": [
    "x86_64",
    "arm64"
  ]
}

Opzioni di output JSON

  • -j, --json: Output dei dati in formato JSON (leggibile per impostazione predefinita)
  • --raw: Output dei valori numerici grezzi invece di stringhe formattate (deve essere usato con -j)

L'output JSON supporta tutte le stesse opzioni di analisi dell'output standard (-a, -hd, -l, -sg, ecc.) e funziona sia con binari a architettura singola sia con binari Universal (FAT).

Sponsorizzato da

RationalEdge

Lo sviluppo di machofile è sponsorizzato da RationalEdge.

Crediti

Queste sono le persone che vorrei ringraziare per essere state l'ispirazione che mi ha portato a scrivere questo modulo:

  • Ero Carrera (@erocarrera) per aver scritto e mantenuto il modulo pefile
  • Patrick Wardle (@patrickwardle) per il grande lavoro nel condividere le sue ricerche e analisi di malware macOS, e per aver dato vita a OBTS :)
  • Greg Lesnewich (@greg-l.bsky.social) e Jacob Latonis (@jacoblatonis.me) per il loro lavoro sulla similarità Mach-O e per le continue, nerd e illuminanti sessioni di brainstorming sul formato binario Mach-O. Date un'occhiata alla loro presentazione OBTS v7 su YT.

Link di riferimento/documentazione:

  • https://opensource.apple.com/source/xnu/xnu-2050.18.24/EXTERNAL_HEADERS/mach-o/loader.h
  • https://github.com/apple-oss-distributions/lldb/blob/10de1840defe0dff10b42b9c56971dbc17c1f18c/llvm/include/llvm/Support/MachO.h
  • https://github.com/apple-oss-distributions/dyld/tree/main
  • https://iphonedev.wiki/Mach-O_File_Format
  • https://lowlevelbits.org/parsing-mach-o-files/
  • https://github.com/aidansteele/osx-abi-macho-file-format-reference
  • https://lief-project.github.io/doc/latest/tutorials/11_macho_modification.html
  • https://github.com/VirusTotal/yara/blob/master/libyara/include/yara/macho.h
  • https://github.com/corkami/pics/blob/master/binary/README.md
  • https://github.com/qyang-nj/llios/tree/main
  • https://github.com/threatstream/symhash
Scarica lo strumento