Skip to content
KitploitKITPLOIT
도구블로그
제출
도구블로그
제출

해킹, 침투 테스트 및 사이버 보안 도구를 당신의 보안 무기고에!

Kitploit은 해킹, 사이버 보안 및 침투 테스트 도구 디렉토리입니다. 최신 프로젝트 업데이트를 발견하여 취약점을 찾고, 시스템을 분석하고, 테스트를 자동화하고, 보안을 강화하세요.

··피드·문의·개인정보·© 2026 Kitploit

도구 디렉토리

카테고리

모든 카테고리 보기
Loading categories
machofile — machofile is a module to parse Mach-O binary files | Kitploit
도구/GitHubGitHub/pstirparo/machofile
Static AnalysisReverse EngineeringForensicsMalware AnalysisBinary Analysis
GitHubpstirparo/machofile

machofile

machofile is a module to parse Mach-O binary files

저장소 보기
9956개월 전Kitploit 검토 완료

인기

모두 보기 →

커뮤니티에서 가장 많이 사용되는 도구를 찾아보세요.

모든 도구 탐색

도구 컬렉션을 둘러보세요

모든 도구 보기 →
공유
웹사이트

machofile

Downloads

machofile은 Mach-O 바이너리 파일을 파싱하기 위한 모듈로, 악성코드 분석과 리버스 엔지니어링에 중점을 둡니다.

Ero Carrera의 pefile에서 영감을 얻은 이 모듈은 Mach-O 바이너리에 대해 유사한 기능을 제공하는 것을 목표로 합니다. 파일 형식 지식, 기본 구조 및 상수를 얻는 데 사용된 참고 자료와 문서는 아래 나열된 리소스에서 가져왔습니다.

machofile은 자체 포함되어 있습니다. 이 모듈은 의존성이 없으며, 엔디안 독립적이고 macOS, Windows, Linux에서 작동합니다.

다른 Mach-O 파싱 모듈도 있지만, 이 모듈을 개발하게 된 동기는 다음과 같습니다:

  • 무엇보다도 저에게는 Mach-O 형식과 구조를 깊이 파고들어 배울 수 있는 좋은 기회였습니다.
  • 분석을 위해 Mach-O 파일을 간단하게 파싱할 수 있는 방법을 제공하기 위함입니다.
  • 외부 모듈(예: lief, macholib, macho 등)에 의존하지 않기 위함입니다. 모든 것이 파일에서 직접 추출되며 순수 파이썬으로 구현되어 있습니다.

사용해 보시거나 버그를 발견하시면 알려주세요. 하지만 너그럽게 봐주세요 ;) 코드는 최적화되고 더 많은 기능이 추가될 예정입니다.

현재 기능:

  • Mach-O 헤더 파싱
  • 로드 명령 파싱
  • 파일 세그먼트 파싱
  • Dylib 명령 파싱
  • Dylib 목록 파싱
  • 임포트된 함수 추출
  • 내보낸 심볼 추출
  • 해시: dylib 해시, import 해시, export 해시, entitlement 해시, symhash
  • 세그먼트 엔트로피 계산
  • 엔트리 포인트 추출
  • UUID 추출
  • 버전 정보 추출
  • 기본 코드 서명 정보 파싱
  • FAT(Universal) 바이너리 지원
  • FAT(Universal) 바이너리에서 개별 Mach-O 슬라이스 덤프
  • JSON 출력 지원(사람이 읽을 수 있는 형식 및 원시 형식)

참고: 현재까지 이 모듈은 x86, x86_64, arm64, arm64e Mach-O 샘플을 대상으로 초기 테스트되었습니다.

구현 예정 기능(순서 무작위):

  • 임베디드 문자열
  • 파일 속성
  • 의심스러운 라이브러리 플래그
  • 패커 탐지
  • ...

사용법 및 예제

명령줄에서 사용하거나 Python 코드에서 모듈로 임포트하여 관심 있는 구조만 파싱하도록 각 함수를 개별적으로 호출할 수 있습니다. pip로 직접 설치한 후 프로그래밍 방식으로 또는 명령줄에서 사용하거나, 독립 실행 스크립트로 사용할 수도 있습니다.

root@kitploit:~
pip install machofile

모듈 사용

이 모듈은 파싱할 파일 경로 또는 데이터 버퍼를 입력으로 받습니다.

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

이미 데이터 버퍼가 준비되어 있다면 다음과 같이 직접 전달할 수 있습니다:

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

API에 대한 자세한 사용법은 전용 API 문서 페이지를 참조하세요.

명령줄 버전

pip로 설치했다면 machofile을 CLI 도구로 직접 사용할 수 있으며, python3 machofile.py 형태의 독립 실행 도구로도 사용할 수 있습니다. 모듈에서 제공되는 모든 기능을 명령줄 도구에서도 동일하게 사용할 수 있습니다.

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

예제 출력:

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

Universal(FAT) 바이너리에서 슬라이스 덤프

Universal(FAT) 바이너리를 다룰 때 --dump-dir 옵션을 사용하여 각 아키텍처 슬라이스를 독립적인 Mach-O 파일로 추출할 수 있습니다:

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

덤프된 각 파일은 유효한 독립형 Mach-O 바이너리입니다. 출력 디렉터리가 없으면 자동으로 생성됩니다. 출력 파일 이름은 <original_filename>.<arch_name> 형식입니다.

JSON 출력

machofile은 파싱된 데이터를 프로그램에서 사용할 수 있도록 JSON 출력을 지원합니다. JSON 출력은 두 가지 형식으로 제공됩니다:

사람이 읽을 수 있는 JSON(기본값)

기본 JSON 출력은 적절한 형식이 적용된 사람이 읽을 수 있는 값을 제공합니다:

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"
  ]
}

원시 JSON 출력

원시 숫자 값을 처리해야 하는 애플리케이션의 경우 --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"
  ]
}

JSON 출력 옵션

  • -j, --json: 데이터를 JSON 형식으로 출력합니다(기본값은 사람이 읽을 수 있는 형식).
  • --raw: 형식화된 문자열 대신 원시 숫자 값을 출력합니다(-j와 함께 사용해야 함).

JSON 출력은 표준 출력과 동일한 모든 분석 옵션(-a, -hd, -l, -sg 등)을 지원하며 단일 아키텍처 및 Universal(FAT) 바이너리 모두에서 작동합니다.

후원

RationalEdge

machofile의 개발은 RationalEdge의 후원으로 이루어졌습니다.

크레딧

이 모듈을 작성하게 된 영감을 준 분들께 감사의 말씀을 전합니다:

  • Ero Carrera (@erocarrera): pefile 모듈을 작성하고 유지 관리해 주셨습니다.
  • Patrick Wardle (@patrickwardle): macOS 악성코드 분석과 연구를 공유해 주신 훌륭한 작업과 OBTS를 만들어 주신 것에 감사드립니다 :)
  • Greg Lesnewich (@greg-l.bsky.social) 및 Jacob Latonis (@jacoblatonis.me): Mach-O 유사성에 대한 작업과 Mach-O 바이너리 형식에 대한 지속적이고 열정적이며 통찰력 있는 브레인스토밍 세션에 감사드립니다. OBTS v7 발표 자료는 YouTube에서 확인하세요.

참고/문서 링크:

  • 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
도구 다운로드