• Stars
    star
    132
  • Rank 265,041 (Top 6 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 1 year ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

XNU kernel, Kernel Collection and CodeQL build scripts

darwin-xnu-build

XNU CodeQL GitHub Downloads (all assets, all releases) LICENSE

This repository contains scripts to build xnu as well as generate a kernel collection and CodeQL databases.


Supported OS Versions

Version Compiles CodeQL Boots (arm64/x86_64)
macOS 13.0 βœ… DB ❔ / ❔
macOS 13.1 βœ… DB ❔ / ❔
macOS 13.2 βœ… DB ❔ / ❔
macOS 13.3 βœ… DB ❔ / ❔
macOS 13.4 βœ… DB ❔ / ❔
macOS 13.5 βœ… DB ❔ / ❔
macOS 14.0 βœ… DB ❔ / ❔
macOS 14.1 βœ… DB ❔ / ❔
macOS 14.2 βœ… DB ❔ / ❔
macOS 14.3 βœ… DB βœ… / βœ…
macOS 14.4 ❌ ❌ ❌ / ❌

Note

CodeQL DBs built with MACHINE_CONFIG=VMAPPLE
MacOS 14.3 booted:

  • via Virtualization.framework with MACHINE_CONFIG=VMAPPLE
  • via qemu with ARCH_CONFIG=x86_64
  • via ASi tested with MACHINE_CONFIG=T8101 and MACHINE_CONFIG=T6000

Known Issue ⚠️

Currently MACHINE_CONFIG=T8103 is not correctly building for at least 14.3

Note

When attempting to boot try adding the boot-arg: sudo nvram boot-args="-unsafe_kernel_text"

Why? πŸ€”

I'm hoping to patch and build the xnu source in interesting ways to aid in research and development of macOS/iOS security research tools as well as generate CodeQL databases for the community to use.

Getting Started

Dependencies

Note

The build.sh script will install all these for you if you are connected to the internet.

Clone the repo

git clone https://github.com/blacktop/darwin-xnu-build.git
cd darwin-xnu-build
❯ ./build.sh --help

Usage: build.sh [-h] [--clean] [--kc]

This script builds the macOS XNU kernel

Where:
    -h|--help       show this help text
    -c|--clean      cleans build artifacts and cloned repos
    -k|--kc         create kernel collection (via kmutil create)

Build the kernel and kernel Collection

KERNEL_CONFIG=RELEASE ARCH_CONFIG=ARM64 MACHINE_CONFIG=T6000 ./build.sh --kc

Note

Supported KERNEL_CONFIG include:

  • RELEASE
  • DEVELOPMENT

Supported MACHINE_CONFIG include:

  • T8101
  • T8103
  • T6000
  • VMAPPLE
<SNIP>
 β‡’ πŸ“¦ Building kernel collection for 'kernel.release.t6000'
   β€’ Decompressing KernelManagement kernelcache
Merged LINKEDIT:
  weak bindings size:          0KB
  exports info size:           0KB
  bindings size:               0KB
  lazy bindings size:          0KB
  function starts size:       41KB
  data in code size:           0KB
  symbol table size:        3702KB (85348 exports, 87979 imports)
  symbol string pool size:  6465KB
LINKEDITS optimized from 30MB to 10MB
time to layout cache: 0ms
time to copy cached dylibs into buffer: 1ms
time to adjust segments for new split locations: 2ms
time to bind all images: 8ms
time to optimize Objective-C: 0ms
time to do stub elimination: 0ms
time to optimize LINKEDITs: 2ms
time to compute slide info: 1ms
time to compute UUID and codesign cache file: 1ms
  πŸŽ‰ XNU Build Done!

Check that the output contains all the KEXTs

❯ ipsw macho info build/oss-xnu.kc | head
Magic         = 64-bit MachO
Type          = FILESET
CPU           = AARCH64, ARM64e
Commands      = 241 (Size: 17160)
Flags         = None
000: LC_UUID                     67DF7148-8EEC-B1A6-5F51-7502DADF2264
001: LC_BUILD_VERSION            Platform: unknown, SDK: 0.0
002: LC_UNIXTHREAD               Threads: 1, ARM64 EntryPoint: 0xfffffe0007ad1488
003: LC_DYLD_CHAINED_FIXUPS      offset=0x003690000  size=0x444
004: LC_SEGMENT_64 sz=0x00008000 off=0x00000000-0x00008000 addr=0xfffffe0007004000-0xfffffe000700c000 r--/r--   __TEXT
<SNIP>

Clean rebuild the kernel and kernel collection

KERNEL_CONFIG=RELEASE ARCH_CONFIG=ARM64 MACHINE_CONFIG=T6000 ./build.sh --clean --kc

Generate a CodeQL database

./codeql.sh
<SNIP>
[2023-03-03 22:33:20] [build-stdout]   πŸŽ‰ XNU Build Done!
Finalizing database at darwin-xnu-build/xnu-codeql.
Running TRAP import for CodeQL database at darwin-xnu-build/xnu-codeql...
TRAP import complete (1m46s).
Successfully created database at darwin-xnu-build/xnu-codeql.
[info] Deleting log files...
[info] Zipping the CodeQL database...
  πŸŽ‰ CodeQL Database Create Done!

Script builds and zips up the CodeQL database

❯ ll xnu-codeql.zip
-rw-r--r--@ 1 blacktop  staff   219M Mar  3 22:35 xnu-codeql.zip

Generate a CodeQL database (in a local Tart VM)

Install deps: packer, tart and cirrus

make deps

Build VM image

make build-vm

Create CodeQL DB

make codeql-db
 > Building CodeQL Database
πŸ•“ 'Build' Task 08:22
   βœ… pull virtual machine 0.0s
βœ… 'Build' Task 47:59
 πŸŽ‰ Done! πŸŽ‰
πŸ•’ 'Build' Task 46:28
βœ… 'Build' Task 48:15
❯ tree artifacts/

artifacts/
└── Build
    └── binary
        └── xnu-codeql.zip

3 directories, 1 file

TODO

  • Auto build xnu with Github Actions
  • Auto generate CodeQL database with Github Actions

NOTES

To see kernel logs

log show --debug --last boot --predicate 'process == "kernel"'

Credit

More Repositories

1

ipsw

iOS/macOS Research Swiss Army Knife
Go
1,372
star
2

docker-cuckoo

Cuckoo Sandbox Dockerfile
Shell
320
star
3

lporg

Organize Your macOS Launchpad Apps
Go
218
star
4

docker-elasticsearch-alpine

Alpine Linux based Elasticsearch Docker Image
Shell
191
star
5

docker-elastic-stack

ELK Stack Dockerfile
Shell
190
star
6

docker-ghidra

Ghidra Client/Server Docker Image
Dockerfile
182
star
7

go-macho

Package macho implements access to and creation of Mach-O object files.
Go
162
star
8

docker-bro

Bro IDS Dockerfile
Zeek
129
star
9

docker-zeek

Zeek IDS Dockerfile
Zeek
96
star
10

docker-idapro

IDA Pro Docker Image
Dockerfile
79
star
11

graboid

Clientless Docker Image Downloader
Go
78
star
12

docker-kibana-alpine

Alpine Linux based Kibana Docker Image
Dockerfile
73
star
13

docker-kafka-alpine

Alpine Linux based Kafka Docker Image
Shell
62
star
14

go-apfs

APFS parser written in pure Go
Go
62
star
15

docker-logstash-alpine

Alpine Linux based Logstash Docker Image
Dockerfile
50
star
16

docker-yara

Yara Dockerfile
YARA
47
star
17

seccomp-gen

Docker Secure Computing Profile Generator
Go
43
star
18

presentations

Slides and resources for talks I've given
HTML
38
star
19

docker-volatility

Volatility Dockerfile
Dockerfile
29
star
20

language-yara

Yara syntax highlighting
24
star
21

ipsw-py

A Python library for the ipsw daemon API
Python
23
star
22

ghidra-app

Ghidra CI/CD to build and host a universal macOS Ghidra.app
Shell
18
star
23

go-dev

Golang Dev Env Dockerfile
Vim Script
17
star
24

go-arm64

Pure Go AARCH64 architecture disassembler
Go
17
star
25

vm-proxy

VBoxManage/vmrun proxy to allow communication from within a VM to the hypervisor running the VM.
Go
17
star
26

scifgif

Humorous image microservice for isolated networks
Go
17
star
27

partialzip

Partial Implementation of PartialZip in Go
Go
16
star
28

atom-python-yapf

Atom.io plugin to format for Python files using Google's YAPF
CoffeeScript
14
star
29

darwin-webkit-build

WebKit CodeQL Databases
Shell
13
star
30

httpie

Docker image with httpie and jq installed
Makefile
12
star
31

lzfse-cgo

Go bindings for lzfse compression
C
11
star
32

arm64-cgo

Golang bindings for the Binary Ninja Arm64 Disassembler.
C
11
star
33

yardens-sb-profs

Output from running Yarden's sandblaster on an iPhone15,2's iOS17 kernelcaches
10
star
34

docker-filebeat

Alpine Linux based Filebeat Docker Image
Shell
10
star
35

kibana-plugin-builder

Malice Kibana Plugin Builder
Makefile
9
star
36

homebrew-tap

Blacktop's Homebrew Formulas
Ruby
9
star
37

dotfiles

My personal .files
Shell
8
star
38

language-bro

Bro syntax highlighting
8
star
39

go-vboxapi

Go interface to VirtualBox's remote API
Go
8
star
40

dbg

Docker gdb/lldb images
Makefile
7
star
41

how-ya-doing

Monitor your Github repos activity
Go
7
star
42

get-latest-version-action

Get LATEST version Github Action
Dockerfile
7
star
43

swift-demangle-cgo

Golang bindings for the Swift Demangler.
C++
7
star
44

lzss

LZSS compression package for Go.
C
6
star
45

docker-kaitai

Kaitai Struct Docker Image
Python
6
star
46

docker-webkit

Dockerized WebKit Dev/Research Environment
Python
6
star
47

go-dwarf

Package dwarf provides access to DWARF debugging information loaded from executable files, as defined in the DWARF 2.0 Standard at http://dwarfstd.org/doc/dwarf-2.0.0.pdf
Go
6
star
48

dyld-src-fixes

Just some fixes to dyld so you can build some of the utils
C
6
star
49

docker-retdec

RetDec Dockerfile
Makefile
6
star
50

docker-images

List of all my docker images
6
star
51

wait-for-es

Wait until Elasticsearch become available.
Go
5
star
52

go-lzfse

Pure Go LZFSE compression library
C
5
star
53

frida-scripts

This'll be the year I finally learn Frida 🀞
JavaScript
4
star
54

ports

Blacktop's MacPorts Ports
Tcl
4
star
55

disasster

Golang AARCH64 Disassembler
Go
4
star
56

get-vine

Vine Video Downloader
Go
4
star
57

barcode

Create barcodes (QR/Code128)
Go
3
star
58

vscode-terminal-highlighter

Visual Studio Code Extension to highlight words in integrated terminal
TypeScript
3
star
59

x86-cgo

Golang bindings for the Binary Ninja x86/x64 Disassembler.
C
3
star
60

SwiftMachO

Swift MachO Parser
3
star
61

go-llvm-mc

Go wrapper for llvm-mc
Go
3
star
62

scoop-bucket

Scoop bucket for `ipsw` binaries
2
star
63

configs

Private Configs
2
star
64

dreadnought

Rust
2
star
65

sentry-quick-start

Sentry Docker Quick Start
Python
2
star
66

clt

Command Line Tools
1
star
67

go-coresymbolication

CoreSymbolication Framework Go Wrapper
C
1
star
68

darwin-xnu

The Darwin Kernel
C
1
star
69

now

Now Test
1
star
70

homebrew-chopshop

ChopShop homebrew formula
Ruby
1
star
71

ios-pocs

iOS POCs and Ideas
C
1
star
72

async_wake

iOS 11.1.2 kernel exploit and PoC local kernel debugger by @i41nbeer
C
1
star
73

nur

nix user repository for Blacktop
Nix
1
star