• Stars
    star
    181
  • Rank 212,110 (Top 5 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 1 year ago
  • Updated 3 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,757
star
2

docker-cuckoo

Cuckoo Sandbox Dockerfile
Shell
321
star
3

lporg

Organize Your macOS Launchpad Apps
Go
264
star
4

docker-ghidra

Ghidra Client/Server Docker Image
Dockerfile
200
star
5

go-macho

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

docker-elasticsearch-alpine

Alpine Linux based Elasticsearch Docker Image
Shell
191
star
7

docker-elastic-stack

ELK Stack Dockerfile
Shell
190
star
8

docker-bro

Bro IDS Dockerfile
Zeek
129
star
9

docker-zeek

Zeek IDS Dockerfile
Zeek
99
star
10

docker-idapro

IDA Pro Docker Image
Dockerfile
87
star
11

graboid

Clientless Docker Image Downloader
Go
81
star
12

docker-kibana-alpine

Alpine Linux based Kibana Docker Image
Dockerfile
73
star
13

go-apfs

APFS parser written in pure Go
Go
65
star
14

docker-kafka-alpine

Alpine Linux based Kafka Docker Image
Shell
64
star
15

docker-logstash-alpine

Alpine Linux based Logstash Docker Image
Dockerfile
50
star
16

docker-yara

Yara Dockerfile
YARA
49
star
17

seccomp-gen

Docker Secure Computing Profile Generator
Go
46
star
18

presentations

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

docker-volatility

Volatility Dockerfile
Dockerfile
30
star
20

ipsw-diffs

IPSW Diffs
30
star
21

symbolicator

`ipsw` symbolication signatures
Python
25
star
22

language-yara

Yara syntax highlighting
24
star
23

ipsw-py

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

ghidra-app

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

go-arm64

Pure Go AARCH64 architecture disassembler
Go
20
star
26

go-dev

Golang Dev Env Dockerfile
Vim Script
17
star
27

vm-proxy

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

scifgif

Humorous image microservice for isolated networks
Go
17
star
29

yardens-sb-profs

Output from running Yarden's sandblaster on an iPhone15,2's iOS17 kernelcaches
16
star
30

partialzip

Partial Implementation of PartialZip in Go
Go
16
star
31

arm64-cgo

Golang bindings for the Binary Ninja Arm64 Disassembler.
C
14
star
32

atom-python-yapf

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

darwin-webkit-build

WebKit CodeQL Databases
Shell
13
star
34

httpie

Docker image with httpie and jq installed
Makefile
12
star
35

lzfse-cgo

Go bindings for lzfse compression
C
11
star
36

dotfiles

My personal .files
Shell
10
star
37

docker-filebeat

Alpine Linux based Filebeat Docker Image
Shell
10
star
38

dyld-src-fixes

Just some fixes to dyld so you can build some of the utils
C++
10
star
39

kibana-plugin-builder

Malice Kibana Plugin Builder
Makefile
9
star
40

homebrew-tap

Blacktop's Homebrew Formulas
Ruby
9
star
41

language-bro

Bro syntax highlighting
8
star
42

go-vboxapi

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

docker-kaitai

Kaitai Struct Docker Image
Python
7
star
44

docker-webkit

Dockerized WebKit Dev/Research Environment
Python
7
star
45

dbg

Docker gdb/lldb images
Makefile
7
star
46

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
7
star
47

how-ya-doing

Monitor your Github repos activity
Go
7
star
48

get-latest-version-action

Get LATEST version Github Action
Dockerfile
7
star
49

swift-demangle-cgo

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

lzss

LZSS compression package for Go.
C
6
star
51

bottle-bomb

Homebrew Bottle Downloader
Go
6
star
52

disasster

Golang AARCH64 Disassembler
Go
6
star
53

docker-retdec

RetDec Dockerfile
Makefile
6
star
54

docker-images

List of all my docker images
6
star
55

frida-scripts

This'll be the year I finally learn Frida 🀞
JavaScript
5
star
56

wait-for-es

Wait until Elasticsearch become available.
Go
5
star
57

go-lzfse

Pure Go LZFSE compression library
C
5
star
58

ports

Blacktop's MacPorts Ports
Tcl
5
star
59

get-vine

Vine Video Downloader
Go
4
star
60

x86-cgo

Golang bindings for the Binary Ninja x86/x64 Disassembler.
C
4
star
61

barcode

Create barcodes (QR/Code128)
Go
3
star
62

vscode-terminal-highlighter

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

ios-pocs

iOS POCs and Ideas
C
3
star
64

async_wake

iOS 11.1.2 kernel exploit and PoC local kernel debugger by @i41nbeer
C
3
star
65

SwiftMachO

Swift MachO Parser
3
star
66

go-llvm-mc

Go wrapper for llvm-mc
Go
3
star
67

configs

Private Configs
2
star
68

dreadnought

Rust
2
star
69

sentry-quick-start

Sentry Docker Quick Start
Python
2
star
70

nur

nix user repository for Blacktop
Nix
2
star
71

app-icon

Generate App Icons
Go
2
star
72

clt

Command Line Tools
1
star
73

scoop-bucket

Scoop bucket for `ipsw` binaries
1
star
74

go-coresymbolication

CoreSymbolication Framework Go Wrapper
C
1
star
75

darwin-xnu

The Darwin Kernel
C
1
star
76

homebrew-chopshop

ChopShop homebrew formula
Ruby
1
star
77

go-termimg

Go terminal image package
Go
1
star
78

go-template

Go Project Template
Go
1
star
79

blacktop

1
star
80

fluxy

FLUX image generator TUI
Go
1
star