macOS Apps - Inspecting, debugging and Fuzzing

Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks

์ •์  ๋ถ„์„

otool & objdump & nm

otool -L /bin/ls #List dynamically linked libraries
otool -tv /bin/ps #Decompile application
objdump -m --dylibs-used /bin/ls #List dynamically linked libraries
objdump -m -h /bin/ls # Get headers information
objdump -m --syms /bin/ls # Check if the symbol table exists to get function names
objdump -m --full-contents /bin/ls # Dump every section
objdump -d /bin/ls # Dissasemble the binary
objdump --disassemble-symbols=_hello --x86-asm-syntax=intel toolsdemo #Disassemble a function using intel flavour
nm -m ./tccd # List of symbols

jtool2 & Disarm

You can ์—ฌ๊ธฐ์—์„œ disarm์„ ๋‹ค์šด๋กœ๋“œํ•˜์„ธ์š”.

ARCH=arm64e disarm -c -i -I --signature /path/bin # Get bin info and signature
ARCH=arm64e disarm -c -l /path/bin # Get binary sections
ARCH=arm64e disarm -c -L /path/bin # Get binary commands (dependencies included)
ARCH=arm64e disarm -c -S /path/bin # Get symbols (func names, strings...)
ARCH=arm64e disarm -c -d /path/bin # Get disasembled
jtool2 -d __DATA.__const myipc_server | grep MIG # Get MIG info

์—ฌ๊ธฐ์—์„œ jtool2๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜์„ธ์š” ๋˜๋Š” brew๋กœ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

# Install
brew install --cask jtool2

jtool2 -l /bin/ls # Get commands (headers)
jtool2 -L /bin/ls # Get libraries
jtool2 -S /bin/ls # Get symbol info
jtool2 -d /bin/ls # Dump binary
jtool2 -D /bin/ls # Decompile binary

# Get signature information
ARCH=x86_64 jtool2 --sig /System/Applications/Automator.app/Contents/MacOS/Automator

# Get MIG information
jtool2 -d __DATA.__const myipc_server | grep MIG

jtool์€ disarm์„ ์œ„ํ•ด ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค

Codesign / ldid

**Codesign**์€ macOS์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ **ldid**๋Š” iOS์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค

# Get signer
codesign -vv -d /bin/ls 2>&1 | grep -E "Authority|TeamIdentifier"

# Check if the appโ€™s contents have been modified
codesign --verify --verbose /Applications/Safari.app

# Get entitlements from the binary
codesign -d --entitlements :- /System/Applications/Automator.app # Check the TCC perms

# Check if the signature is valid
spctl --assess --verbose /Applications/Safari.app

# Sign a binary
codesign -s <cert-name-keychain> toolsdemo

# Get signature info
ldid -h <binary>

# Get entitlements
ldid -e <binary>

# Change entilements
## /tmp/entl.xml is a XML file with the new entitlements to add
ldid -S/tmp/entl.xml <binary>

SuspiciousPackage

SuspiciousPackage๋Š” .pkg ํŒŒ์ผ(์„ค์น˜ ํ”„๋กœ๊ทธ๋žจ)์„ ๊ฒ€์‚ฌํ•˜๊ณ  ์„ค์น˜ํ•˜๊ธฐ ์ „์— ๋‚ด๋ถ€ ๋‚ด์šฉ์„ ํ™•์ธํ•˜๋Š” ๋ฐ ์œ ์šฉํ•œ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค. ์ด ์„ค์น˜ ํ”„๋กœ๊ทธ๋žจ์—๋Š” ๋งฌ์›จ์–ด ์ž‘์„ฑ์ž๊ฐ€ ์ผ๋ฐ˜์ ์œผ๋กœ ๋งฌ์›จ์–ด๋ฅผ ์ง€์†ํ•˜๊ธฐ ์œ„ํ•ด ์•…์šฉํ•˜๋Š” preinstall ๋ฐ postinstall bash ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

hdiutil

์ด ๋„๊ตฌ๋Š” Apple ๋””์Šคํฌ ์ด๋ฏธ์ง€(.dmg) ํŒŒ์ผ์„ ๋งˆ์šดํŠธํ•˜์—ฌ ์‹คํ–‰ํ•˜๊ธฐ ์ „์— ๊ฒ€์‚ฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค:

hdiutil attach ~/Downloads/Firefox\ 58.0.2.dmg

It will be mounted in /Volumes

Packed binaries

  • ๋†’์€ ์—”ํŠธ๋กœํ”ผ ํ™•์ธ

  • ๋ฌธ์ž์—ด ํ™•์ธ (์ดํ•ดํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ž์—ด์ด ๊ฑฐ์˜ ์—†์œผ๋ฉด, ํŒจํ‚น๋จ)

  • MacOS์šฉ UPX ํŒจ์ปค๋Š” "__XHDR"๋ผ๋Š” ์„น์…˜์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

Static Objective-C analysis

Metadata

Objective-C๋กœ ์ž‘์„ฑ๋œ ํ”„๋กœ๊ทธ๋žจ์€ Mach-O binaries๋กœ ์ปดํŒŒ์ผ๋  ๋•Œ ํด๋ž˜์Šค ์„ ์–ธ์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ํด๋ž˜์Šค ์„ ์–ธ์—๋Š” ๋‹ค์Œ์˜ ์ด๋ฆ„๊ณผ ์œ ํ˜•์ด ํฌํ•จ๋ฉ๋‹ˆ๋‹ค:

  • ์ •์˜๋œ ์ธํ„ฐํŽ˜์ด์Šค

  • ์ธํ„ฐํŽ˜์ด์Šค ๋ฉ”์„œ๋“œ

  • ์ธํ„ฐํŽ˜์ด์Šค ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜

  • ์ •์˜๋œ ํ”„๋กœํ† ์ฝœ

์ด ์ด๋ฆ„๋“ค์€ ์ด์ง„ ํŒŒ์ผ์˜ ๋ฆฌ๋ฒ„์‹ฑ์„ ๋” ์–ด๋ ต๊ฒŒ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด ๋‚œ๋…ํ™”๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Function calling

Objective-C๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์ง„ ํŒŒ์ผ์—์„œ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ, ์ปดํŒŒ์ผ๋œ ์ฝ”๋“œ๋Š” ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋Œ€์‹  **objc_msgSend**๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ตœ์ข… ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค:

์ด ํ•จ์ˆ˜๊ฐ€ ๊ธฐ๋Œ€ํ•˜๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

  • ์ฒซ ๋ฒˆ์งธ ๋งค๊ฐœ๋ณ€์ˆ˜ (self)๋Š” "๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ›์„ ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” ํฌ์ธํ„ฐ"์ž…๋‹ˆ๋‹ค. ๋” ๊ฐ„๋‹จํžˆ ๋งํ•˜๋ฉด, ๋ฉ”์„œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋˜๋Š” ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค. ๋ฉ”์„œ๋“œ๊ฐ€ ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ์ธ ๊ฒฝ์šฐ, ์ด๋Š” ํด๋ž˜์Šค ๊ฐ์ฒด์˜ ์ธ์Šคํ„ด์Šค(์ „์ฒด)์ด๋ฉฐ, ์ธ์Šคํ„ด์Šค ๋ฉ”์„œ๋“œ์˜ ๊ฒฝ์šฐ, self๋Š” ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šคํ™”๋œ ๊ฐ์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚ต๋‹ˆ๋‹ค.

  • ๋‘ ๋ฒˆ์งธ ๋งค๊ฐœ๋ณ€์ˆ˜ (op)๋Š” "๋ฉ”์‹œ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฉ”์„œ๋“œ์˜ ์„ ํƒ์ž"์ž…๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋งํ•ด, ์ด๋Š” ๋‹จ์ˆœํžˆ ๋ฉ”์„œ๋“œ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

  • ๋‚˜๋จธ์ง€ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋ฉ”์„œ๋“œ(op)์— ์˜ํ•ด ํ•„์š”ํ•œ ๊ฐ’๋“ค์ž…๋‹ˆ๋‹ค.

์ด ์ •๋ณด๋ฅผ ARM64์—์„œ lldb๋กœ ์‰ฝ๊ฒŒ ์–ป๋Š” ๋ฐฉ๋ฒ•์€ ์ด ํŽ˜์ด์ง€๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”:

Introduction to ARM64v8

x64:

Argument

Register

(for) objc_msgSend

1st argument

rdi

self: ๋ฉ”์„œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋˜๋Š” ๊ฐ์ฒด

2nd argument

rsi

op: ๋ฉ”์„œ๋“œ์˜ ์ด๋ฆ„

3rd argument

rdx

๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ 1๋ฒˆ์งธ ์ธ์ˆ˜

4th argument

rcx

๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ 2๋ฒˆ์งธ ์ธ์ˆ˜

5th argument

r8

๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ 3๋ฒˆ์งธ ์ธ์ˆ˜

6th argument

r9

๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ 4๋ฒˆ์งธ ์ธ์ˆ˜

7th+ argument

rsp+ (์Šคํƒ์—์„œ)

๋ฉ”์„œ๋“œ์— ๋Œ€ํ•œ 5๋ฒˆ์งธ+ ์ธ์ˆ˜

Dump ObjectiveC metadata

Dynadump

Dynadump๋Š” Objective-C ์ด์ง„ ํŒŒ์ผ์„ ํด๋ž˜์Šค ๋คํ”„ํ•˜๋Š” ๋„๊ตฌ์ž…๋‹ˆ๋‹ค. GitHub์—์„œ๋Š” dylibs๋ฅผ ๋ช…์‹œํ•˜์ง€๋งŒ, ์‹คํ–‰ ํŒŒ์ผ์—๋„ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

./dynadump dump /path/to/bin

At the time of the writing, this is ํ˜„์žฌ ๊ฐ€์žฅ ์ž˜ ์ž‘๋™ํ•˜๋Š” ๊ฒƒ.

์ผ๋ฐ˜ ๋„๊ตฌ

nm --dyldinfo-only /path/to/bin
otool -ov /path/to/bin
objdump --macho --objc-meta-data /path/to/bin

class-dump

class-dump๋Š” ObjetiveC ํ˜•์‹์˜ ์ฝ”๋“œ์—์„œ ํด๋ž˜์Šค, ์นดํ…Œ๊ณ ๋ฆฌ ๋ฐ ํ”„๋กœํ† ์ฝœ์— ๋Œ€ํ•œ ์„ ์–ธ์„ ์ƒ์„ฑํ•˜๋Š” ์›๋ž˜ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.

์˜ค๋ž˜๋˜์—ˆ๊ณ  ์œ ์ง€ ๊ด€๋ฆฌ๋˜์ง€ ์•Š์•„์„œ ์ œ๋Œ€๋กœ ์ž‘๋™ํ•˜์ง€ ์•Š์„ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’์Šต๋‹ˆ๋‹ค.

ICDump

iCDump๋Š” ํ˜„๋Œ€์ ์ด๊ณ  ํฌ๋กœ์Šค ํ”Œ๋žซํผ Objective-C ํด๋ž˜์Šค ๋คํ”„์ž…๋‹ˆ๋‹ค. ๊ธฐ์กด ๋„๊ตฌ์™€ ๋น„๊ตํ•  ๋•Œ, iCDump๋Š” Apple ์ƒํƒœ๊ณ„์™€ ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ Python ๋ฐ”์ธ๋”ฉ์„ ๋…ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

import icdump
metadata = icdump.objc.parse("/path/to/bin")

print(metadata.to_decl())

Static Swift analysis

Swift ๋ฐ”์ด๋„ˆ๋ฆฌ์˜ ๊ฒฝ์šฐ, Objective-C ํ˜ธํ™˜์„ฑ ๋•๋ถ„์— ๋•Œ๋•Œ๋กœ class-dump๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์„ ์–ธ์„ ์ถ”์ถœํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ํ•ญ์ƒ ๊ฐ€๋Šฅํ•œ ๊ฒƒ์€ ์•„๋‹™๋‹ˆ๋‹ค.

jtool -l ๋˜๋Š” otool -l ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด __swift5 ์ ‘๋‘์‚ฌ๋กœ ์‹œ์ž‘ํ•˜๋Š” ์—ฌ๋Ÿฌ ์„น์…˜์„ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

jtool2 -l /Applications/Stocks.app/Contents/MacOS/Stocks
LC 00: LC_SEGMENT_64              Mem: 0x000000000-0x100000000    __PAGEZERO
LC 01: LC_SEGMENT_64              Mem: 0x100000000-0x100028000    __TEXT
[...]
Mem: 0x100026630-0x100026d54        __TEXT.__swift5_typeref
Mem: 0x100026d60-0x100027061        __TEXT.__swift5_reflstr
Mem: 0x100027064-0x1000274cc        __TEXT.__swift5_fieldmd
Mem: 0x1000274cc-0x100027608        __TEXT.__swift5_capture
[...]

์ด ์„น์…˜์— ์ €์žฅ๋œ ์ •๋ณด์— ๋Œ€ํ•œ ์ถ”๊ฐ€ ์ •๋ณด๋Š” ์ด ๋ธ”๋กœ๊ทธ ๊ฒŒ์‹œ๋ฌผ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฒŒ๋‹ค๊ฐ€, Swift ๋ฐ”์ด๋„ˆ๋ฆฌ๋Š” ๊ธฐํ˜ธ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค (์˜ˆ: ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋  ์ˆ˜ ์žˆ๋„๋ก ๊ธฐํ˜ธ๋ฅผ ์ €์žฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค). **๊ธฐํ˜ธ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ํ•จ์ˆ˜ ์ด๋ฆ„๊ณผ ์†์„ฑ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋ณด๊ธฐ ์ข‹์ง€ ์•Š๊ฒŒ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฏ€๋กœ ๋งค์šฐ ์œ ์šฉํ•˜๋ฉฐ, ์›๋ž˜ ์ด๋ฆ„์„ ์–ป์„ ์ˆ˜ ์žˆ๋Š” "๋””๋ง๊ธ€๋Ÿฌ"๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค:

# Ghidra plugin
https://github.com/ghidraninja/ghidra_scripts/blob/master/swift_demangler.py

# Swift cli
swift demangle

๋™์  ๋ถ„์„

์ด์ง„ ํŒŒ์ผ์„ ๋””๋ฒ„๊น…ํ•˜๋ ค๋ฉด SIP๋ฅผ ๋น„ํ™œ์„ฑํ™”ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค (csrutil disable ๋˜๋Š” csrutil enable --without debug) ๋˜๋Š” ์ด์ง„ ํŒŒ์ผ์„ ์ž„์‹œ ํด๋”๋กœ ๋ณต์‚ฌํ•˜๊ณ  ์„œ๋ช…์„ ์ œ๊ฑฐํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค codesign --remove-signature <binary-path> ๋˜๋Š” ์ด์ง„ ํŒŒ์ผ์˜ ๋””๋ฒ„๊น…์„ ํ—ˆ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค ( ์ด ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค).

macOS์—์„œ ์‹œ์Šคํ…œ ์ด์ง„ ํŒŒ์ผ(์˜ˆ: cloudconfigurationd)์„ ๊ณ„์ธกํ•˜๋ ค๋ฉด SIP๋ฅผ ๋น„ํ™œ์„ฑํ™”ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค (์„œ๋ช…๋งŒ ์ œ๊ฑฐํ•˜๋Š” ๊ฒƒ์œผ๋กœ๋Š” ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค).

API

macOS๋Š” ํ”„๋กœ์„ธ์Šค์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋Š” ๋ช‡ ๊ฐ€์ง€ ํฅ๋ฏธ๋กœ์šด API๋ฅผ ๋…ธ์ถœํ•ฉ๋‹ˆ๋‹ค:

  • proc_info: ๊ฐ ํ”„๋กœ์„ธ์Šค์— ๋Œ€ํ•œ ๋งŽ์€ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๋Š” ์ฃผ์š” API์ž…๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค ์ •๋ณด๋ฅผ ์–ป์œผ๋ ค๋ฉด root ๊ถŒํ•œ์ด ํ•„์š”ํ•˜์ง€๋งŒ ํŠน๋ณ„ํ•œ ๊ถŒํ•œ์ด๋‚˜ mach ํฌํŠธ๋Š” ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

  • libsysmon.dylib: XPC๋กœ ๋…ธ์ถœ๋œ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ํ”„๋กœ์„ธ์Šค์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ์ง€๋งŒ, com.apple.sysmond.client ๊ถŒํ•œ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

์Šคํƒ์ƒท ๋ฐ ๋งˆ์ดํฌ๋กœ์Šคํƒ์ƒท

์Šคํƒ์ƒทํŒ…์€ ํ”„๋กœ์„ธ์Šค์˜ ์ƒํƒœ๋ฅผ ์บก์ฒ˜ํ•˜๋Š” ๊ธฐ์ˆ ๋กœ, ๋ชจ๋“  ์‹คํ–‰ ์ค‘์ธ ์Šค๋ ˆ๋“œ์˜ ํ˜ธ์ถœ ์Šคํƒ์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ๋””๋ฒ„๊น…, ์„ฑ๋Šฅ ๋ถ„์„ ๋ฐ ํŠน์ • ์‹œ์ ์—์„œ ์‹œ์Šคํ…œ์˜ ๋™์ž‘์„ ์ดํ•ดํ•˜๋Š” ๋ฐ ํŠนํžˆ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. iOS ๋ฐ macOS์—์„œ๋Š” sample ๋ฐ **spindump**์™€ ๊ฐ™์€ ์—ฌ๋Ÿฌ ๋„๊ตฌ์™€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํƒ์ƒทํŒ…์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Sysdiagnose

์ด ๋„๊ตฌ (/usr/bini/ysdiagnose)๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ps, zprint์™€ ๊ฐ™์€ ์ˆ˜์‹ญ ๊ฐœ์˜ ๋‹ค์–‘ํ•œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜์—ฌ ์ปดํ“จํ„ฐ์—์„œ ๋งŽ์€ ์ •๋ณด๋ฅผ ์ˆ˜์ง‘ํ•ฉ๋‹ˆ๋‹ค.

root๋กœ ์‹คํ–‰ํ•ด์•ผ ํ•˜๋ฉฐ, ๋ฐ๋ชฌ /usr/libexec/sysdiagnosed๋Š” com.apple.system-task-ports ๋ฐ get-task-allow์™€ ๊ฐ™์€ ๋งค์šฐ ํฅ๋ฏธ๋กœ์šด ๊ถŒํ•œ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ์˜ plist๋Š” /System/Library/LaunchDaemons/com.apple.sysdiagnose.plist์— ์œ„์น˜ํ•˜๋ฉฐ, 3๊ฐœ์˜ MachServices๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค:

  • com.apple.sysdiagnose.CacheDelete: /var/rmp์˜ ์˜ค๋ž˜๋œ ์•„์นด์ด๋ธŒ๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.

  • com.apple.sysdiagnose.kernel.ipc: ํŠน๋ณ„ ํฌํŠธ 23 (์ปค๋„)

  • com.apple.sysdiagnose.service.xpc: Libsysdiagnose Obj-C ํด๋ž˜์Šค๋ฅผ ํ†ตํ•œ ์‚ฌ์šฉ์ž ๋ชจ๋“œ ์ธํ„ฐํŽ˜์ด์Šค. ์‚ฌ์ „ ์ •์˜๋œ ์„ธ ๊ฐ€์ง€ ์ธ์ˆ˜(compress, display, run)๋ฅผ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ†ตํ•ฉ ๋กœ๊ทธ

MacOS๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•  ๋•Œ ๋ฌด์—‡์„ ํ•˜๊ณ  ์žˆ๋Š”์ง€ ์ดํ•ดํ•˜๋Š” ๋ฐ ๋งค์šฐ ์œ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋งŽ์€ ๋กœ๊ทธ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

๊ฒŒ๋‹ค๊ฐ€, <private> ํƒœ๊ทธ๊ฐ€ ํฌํ•จ๋œ ๋กœ๊ทธ๊ฐ€ ์žˆ์–ด ์‚ฌ์šฉ์ž ๋˜๋Š” ์ปดํ“จํ„ฐ ์‹๋ณ„ ๊ฐ€๋Šฅํ•œ ์ •๋ณด๋ฅผ ์ˆจ๊น๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ด ์ •๋ณด๋ฅผ ๊ณต๊ฐœํ•˜๊ธฐ ์œ„ํ•ด ์ธ์ฆ์„œ๋ฅผ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์—์„œ ์„ค๋ช…์„ ๋”ฐ๋ฅด์„ธ์š”.

ํ˜ธํผ

์™ผ์ชฝ ํŒจ๋„

ํ˜ธํผ์˜ ์™ผ์ชฝ ํŒจ๋„์—์„œ๋Š” ์ด์ง„ ํŒŒ์ผ์˜ ๊ธฐํ˜ธ(Labels), ์ ˆ์ฐจ ๋ฐ ํ•จ์ˆ˜ ๋ชฉ๋ก(Proc), ๋ฌธ์ž์—ด(Str)์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋“ค์€ ๋ชจ๋“  ๋ฌธ์ž์—ด์ด ์•„๋‹ˆ๋ผ Mac-O ํŒŒ์ผ์˜ ์—ฌ๋Ÿฌ ๋ถ€๋ถ„(์˜ˆ: cstring ๋˜๋Š” objc_methname)์— ์ •์˜๋œ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค.

์ค‘๊ฐ„ ํŒจ๋„

์ค‘๊ฐ„ ํŒจ๋„์—์„œ๋Š” ๋””์Šค์–ด์…ˆ๋ธ”๋œ ์ฝ”๋“œ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์›์‹œ ๋””์Šค์–ด์…ˆ๋ธ”, ๊ทธ๋ž˜ํ”„, ๋””์ปดํŒŒ์ผ๋œ ์ฝ”๋“œ ๋ฐ ์ด์ง„ ํŒŒ์ผ๋กœ ๊ฐ๊ฐ์˜ ์•„์ด์ฝ˜์„ ํด๋ฆญํ•˜์—ฌ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

์ฝ”๋“œ ๊ฐ์ฒด๋ฅผ ์˜ค๋ฅธ์ชฝ ํด๋ฆญํ•˜๋ฉด ํ•ด๋‹น ๊ฐ์ฒด์— ๋Œ€ํ•œ ์ฐธ์กฐ๋ฅผ ๋ณด๊ฑฐ๋‚˜ ์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค (์ด๊ฒƒ์€ ๋””์ปดํŒŒ์ผ๋œ ์˜์‚ฌ ์ฝ”๋“œ์—์„œ๋Š” ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค):

๋˜ํ•œ, ์ค‘๊ฐ„ ํ•˜๋‹จ์—์„œ ํŒŒ์ด์ฌ ๋ช…๋ น์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ค๋ฅธ์ชฝ ํŒจ๋„

์˜ค๋ฅธ์ชฝ ํŒจ๋„์—์„œ๋Š” ํƒ์ƒ‰ ๊ธฐ๋ก(ํ˜„์žฌ ์ƒํ™ฉ์— ๋„๋‹ฌํ•œ ๋ฐฉ๋ฒ•์„ ์•Œ ์ˆ˜ ์žˆ์Œ), ํ˜ธ์ถœ ๊ทธ๋ž˜ํ”„(์ด ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋ชจ๋“  ํ•จ์ˆ˜์™€ ์ด ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœํ•˜๋Š” ๋ชจ๋“  ํ•จ์ˆ˜), ์ง€์—ญ ๋ณ€์ˆ˜ ์ •๋ณด๋ฅผ ํฌํ•จํ•œ ํฅ๋ฏธ๋กœ์šด ์ •๋ณด๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

dtrace

dtrace๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋งค์šฐ ์ €์ˆ˜์ค€์œผ๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋ฉฐ, ์‚ฌ์šฉ์ž๊ฐ€ ํ”„๋กœ๊ทธ๋žจ์„ ์ถ”์ ํ•˜๊ณ  ์‹คํ–‰ ํ๋ฆ„์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. Dtrace๋Š” ํ”„๋กœ๋ธŒ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ, ์ด๋Š” ์ปค๋„ ์ „์—ญ์— ๋ฐฐ์น˜๋˜์–ด ์‹œ์Šคํ…œ ํ˜ธ์ถœ์˜ ์‹œ์ž‘๊ณผ ๋๊ณผ ๊ฐ™์€ ์œ„์น˜์— ์žˆ์Šต๋‹ˆ๋‹ค.

DTrace๋Š” ๊ฐ ์‹œ์Šคํ…œ ํ˜ธ์ถœ์— ๋Œ€ํ•œ ํ”„๋กœ๋ธŒ๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด dtrace_probe_create ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ํ”„๋กœ๋ธŒ๋Š” ๊ฐ ์‹œ์Šคํ…œ ํ˜ธ์ถœ์˜ ์ง„์ž… ๋ฐ ์ข…๋ฃŒ ์ง€์ ์—์„œ ๋ฐœ์‚ฌ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. DTrace์™€์˜ ์ƒํ˜ธ์ž‘์šฉ์€ /dev/dtrace๋ฅผ ํ†ตํ•ด ์ด๋ฃจ์–ด์ง€๋ฉฐ, ์ด๋Š” root ์‚ฌ์šฉ์ž๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

SIP ๋ณดํ˜ธ๋ฅผ ์™„์ „ํžˆ ๋น„ํ™œ์„ฑํ™”ํ•˜์ง€ ์•Š๊ณ  Dtrace๋ฅผ ํ™œ์„ฑํ™”ํ•˜๋ ค๋ฉด ๋ณต๊ตฌ ๋ชจ๋“œ์—์„œ ๋‹ค์Œ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: csrutil enable --without dtrace

๋˜ํ•œ dtrace ๋˜๋Š” dtruss ์ด์ง„ ํŒŒ์ผ์„ ์ปดํŒŒ์ผํ•œ ๊ฒฝ์šฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

dtrace์˜ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ํ”„๋กœ๋ธŒ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

dtrace -l | head
ID   PROVIDER            MODULE                          FUNCTION NAME
1     dtrace                                                     BEGIN
2     dtrace                                                     END
3     dtrace                                                     ERROR
43    profile                                                     profile-97
44    profile                                                     profile-199

ํ”„๋กœ๋ธŒ ์ด๋ฆ„์€ ๋„ค ๋ถ€๋ถ„์œผ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค: ์ œ๊ณต์ž, ๋ชจ๋“ˆ, ํ•จ์ˆ˜ ๋ฐ ์ด๋ฆ„ (fbt:mach_kernel:ptrace:entry). ์ด๋ฆ„์˜ ์ผ๋ถ€๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด, Dtrace๋Š” ํ•ด๋‹น ๋ถ€๋ถ„์„ ์™€์ผ๋“œ์นด๋“œ๋กœ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.

DTrace๋ฅผ ๊ตฌ์„ฑํ•˜์—ฌ ํ”„๋กœ๋ธŒ๋ฅผ ํ™œ์„ฑํ™”ํ•˜๊ณ  ํ”„๋กœ๋ธŒ๊ฐ€ ์ž‘๋™ํ•  ๋•Œ ์ˆ˜ํ–‰ํ•  ์ž‘์—…์„ ์ง€์ •ํ•˜๋ ค๋ฉด D ์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ž์„ธํ•œ ์„ค๋ช…๊ณผ ๋” ๋งŽ์€ ์˜ˆ์ œ๋Š” https://illumos.org/books/dtrace/chp-intro.html์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์ œ

man -k dtrace๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ DTrace ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋‚˜์—ดํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ: sudo dtruss -n binary

#Count the number of syscalls of each running process
sudo dtrace -n 'syscall:::entry {@[execname] = count()}'
  • ์Šคํฌ๋ฆฝํŠธ

syscall:::entry
/pid == $1/
{
}

#Log every syscall of a PID
sudo dtrace -s script.d 1234
syscall::open:entry
{
printf("%s(%s)", probefunc, copyinstr(arg0));
}
syscall::close:entry
{
printf("%s(%d)\n", probefunc, arg0);
}

#Log files opened and closed by a process
sudo dtrace -s b.d -c "cat /etc/hosts"
syscall:::entry
{
;
}
syscall:::return
{
printf("=%d\n", arg1);
}

#Log sys calls with values
sudo dtrace -s syscalls_info.d -c "cat /etc/hosts"

dtruss

dtruss -c ls #Get syscalls of ls
dtruss -c -p 1000 #get syscalls of PID 1000

kdebug

์ปค๋„ ์ถ”์  ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค. ๋ฌธ์„œํ™”๋œ ์ฝ”๋“œ๋Š” **/usr/share/misc/trace.codes**์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

latency, sc_usage, fs_usage ๋ฐ trace์™€ ๊ฐ™์€ ๋„๊ตฌ๋Š” ๋‚ด๋ถ€์ ์œผ๋กœ ์ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

kdebug์™€ ์ธํ„ฐํŽ˜์ด์Šคํ•˜๊ธฐ ์œ„ํ•ด sysctl์€ kern.kdebug ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ๋˜๋ฉฐ, ์‚ฌ์šฉํ•  MIB๋Š” bsd/kern/kdebug.c์— ๊ตฌํ˜„๋œ ํ•จ์ˆ˜๊ฐ€ ์žˆ๋Š” sys/sysctl.h์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ปค์Šคํ…€ ํด๋ผ์ด์–ธํŠธ๋กœ kdebug์™€ ์ƒํ˜ธ์ž‘์šฉํ•˜๊ธฐ ์œ„ํ•œ ์ผ๋ฐ˜์ ์ธ ๋‹จ๊ณ„๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

  • KERN_KDSETREMOVE๋กœ ๊ธฐ์กด ์„ค์ • ์ œ๊ฑฐ

  • KERN_KDSETBUF ๋ฐ KERN_KDSETUP์œผ๋กœ ์ถ”์  ์„ค์ •

  • KERN_KDGETBUF๋กœ ๋ฒ„ํผ ํ•ญ๋ชฉ ์ˆ˜ ๊ฐ€์ ธ์˜ค๊ธฐ

  • KERN_KDPINDEX๋กœ ์ถ”์ ์—์„œ ์ž์‹ ์˜ ํด๋ผ์ด์–ธํŠธ ๊ฐ€์ ธ์˜ค๊ธฐ

  • KERN_KDENABLE๋กœ ์ถ”์  ํ™œ์„ฑํ™”

  • KERN_KDREADTR ํ˜ธ์ถœ๋กœ ๋ฒ„ํผ ์ฝ๊ธฐ

  • ๊ฐ ์Šค๋ ˆ๋“œ๋ฅผ ํ”„๋กœ์„ธ์Šค์™€ ๋งค์นญํ•˜๊ธฐ ์œ„ํ•ด KERN_KDTHRMAP ํ˜ธ์ถœ.

์ด ์ •๋ณด๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด Apple ๋„๊ตฌ trace ๋˜๋Š” ์ปค์Šคํ…€ ๋„๊ตฌ kDebugView (kdv)๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Kdebug๋Š” ํ•œ ๋ฒˆ์— 1๋ช…์˜ ๊ณ ๊ฐ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋™์‹œ์— ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” k-debug ๊ธฐ๋ฐ˜ ๋„๊ตฌ๋Š” ํ•˜๋‚˜๋ฟ์ž…๋‹ˆ๋‹ค.

ktrace

ktrace_* API๋Š” libktrace.dylib์—์„œ ์ œ๊ณต๋˜๋ฉฐ, ์ด๋Š” Kdebug์˜ ๋ž˜ํผ์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฐ ๋‹ค์Œ ํด๋ผ์ด์–ธํŠธ๋Š” ktrace_session_create ๋ฐ ktrace_events_[single/class]๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ํŠน์ • ์ฝ”๋“œ์— ๋Œ€ํ•œ ์ฝœ๋ฐฑ์„ ์„ค์ •ํ•˜๊ณ  ktrace_start๋กœ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

SIP๊ฐ€ ํ™œ์„ฑํ™”๋œ ์ƒํƒœ์—์„œ๋„ ์ด ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํด๋ผ์ด์–ธํŠธ๋กœ๋Š” ์œ ํ‹ธ๋ฆฌํ‹ฐ ktrace๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

ktrace trace -s -S -t c -c ls | grep "ls("

Or tailspin.

kperf

์ด๊ฒƒ์€ ์ปค๋„ ์ˆ˜์ค€ ํ”„๋กœํŒŒ์ผ๋ง์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋ฉฐ Kdebug ํ˜ธ์ถœ์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌ์ถ•๋ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ, ์ „์—ญ ๋ณ€์ˆ˜ kernel_debug_active๊ฐ€ ํ™•์ธ๋˜๊ณ  ์„ค์ •๋˜๋ฉด Kdebug ์ฝ”๋“œ์™€ ํ˜ธ์ถœํ•˜๋Š” ์ปค๋„ ํ”„๋ ˆ์ž„์˜ ์ฃผ์†Œ๋กœ kperf_kdebug_handler๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. Kdebug ์ฝ”๋“œ๊ฐ€ ์„ ํƒ๋œ ๊ฒƒ๊ณผ ์ผ์น˜ํ•˜๋ฉด ๋น„ํŠธ๋งต์œผ๋กœ ๊ตฌ์„ฑ๋œ "์ž‘์—…"์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค(์˜ต์…˜์€ osfmk/kperf/action.h๋ฅผ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค).

Kperf์—๋Š” sysctl MIB ํ…Œ์ด๋ธ”๋„ ์žˆ์Šต๋‹ˆ๋‹ค: (๋ฃจํŠธ๋กœ) sysctl kperf. ์ด ์ฝ”๋“œ๋Š” osfmk/kperf/kperfbsd.c์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฒŒ๋‹ค๊ฐ€, Kperf์˜ ๊ธฐ๋Šฅ์˜ ์ผ๋ถ€๋Š” kpc์— ์กด์žฌํ•˜๋ฉฐ, ์ด๋Š” ๋จธ์‹  ์„ฑ๋Šฅ ์นด์šดํ„ฐ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

ProcessMonitor

ProcessMonitor๋Š” ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ˆ˜ํ–‰ํ•˜๋Š” ํ”„๋กœ์„ธ์Šค ๊ด€๋ จ ์ž‘์—…์„ ํ™•์ธํ•˜๋Š” ๋ฐ ๋งค์šฐ ์œ ์šฉํ•œ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค(์˜ˆ: ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ƒ์„ฑํ•˜๋Š” ์ƒˆ๋กœ์šด ํ”„๋กœ์„ธ์Šค๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋ง).

SpriteTree

SpriteTree๋Š” ํ”„๋กœ์„ธ์Šค ๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋„๊ตฌ์ž…๋‹ˆ๋‹ค. **sudo eslogger fork exec rename create > cap.json**์™€ ๊ฐ™์€ ๋ช…๋ น์œผ๋กœ Mac์„ ๋ชจ๋‹ˆํ„ฐ๋งํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค(์ด๋ฅผ ์‹คํ–‰ํ•˜๋Š” ํ„ฐ๋ฏธ๋„์€ FDA๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค). ๊ทธ๋Ÿฐ ๋‹ค์Œ ์ด ๋„๊ตฌ์—์„œ json์„ ๋กœ๋“œํ•˜์—ฌ ๋ชจ๋“  ๊ด€๊ณ„๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

FileMonitor

FileMonitor๋Š” ํŒŒ์ผ ์ด๋ฒคํŠธ(์ƒ์„ฑ, ์ˆ˜์ • ๋ฐ ์‚ญ์ œ์™€ ๊ฐ™์€)๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜์—ฌ ์ด๋Ÿฌํ•œ ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Crescendo

Crescendo๋Š” Microsoft Sysinternal์˜ _Procmon_์—์„œ Windows ์‚ฌ์šฉ์ž๊ฐ€ ์•Œ ์ˆ˜ ์žˆ๋Š” ๋ชจ์–‘๊ณผ ๋Š๋‚Œ์„ ๊ฐ€์ง„ GUI ๋„๊ตฌ์ž…๋‹ˆ๋‹ค. ์ด ๋„๊ตฌ๋Š” ๋‹ค์–‘ํ•œ ์ด๋ฒคํŠธ ์œ ํ˜•์˜ ๊ธฐ๋ก์„ ์‹œ์ž‘ํ•˜๊ณ  ์ค‘์ง€ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํŒŒ์ผ, ํ”„๋กœ์„ธ์Šค, ๋„คํŠธ์›Œํฌ ๋“ฑ๊ณผ ๊ฐ™์€ ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„๋กœ ์ด๋Ÿฌํ•œ ์ด๋ฒคํŠธ๋ฅผ ํ•„ํ„ฐ๋งํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ณ , ๊ธฐ๋ก๋œ ์ด๋ฒคํŠธ๋ฅผ json ํ˜•์‹์œผ๋กœ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Apple Instruments

Apple Instruments๋Š” Xcode์˜ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์˜ ์ผ๋ถ€๋กœ, ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„ฑ๋Šฅ ๋ชจ๋‹ˆํ„ฐ๋ง, ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜ ์‹๋ณ„ ๋ฐ ํŒŒ์ผ ์‹œ์Šคํ…œ ํ™œ๋™ ์ถ”์ ์— ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

fs_usage

ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ˆ˜ํ–‰ํ•˜๋Š” ์ž‘์—…์„ ์ถ”์ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

fs_usage -w -f filesys ls #This tracks filesystem actions of proccess names containing ls
fs_usage -w -f network curl #This tracks network actions

TaskExplorer

Taskexplorer๋Š” ์ด์ง„ ํŒŒ์ผ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, ์‚ฌ์šฉ ์ค‘์ธ ํŒŒ์ผ ๋ฐ ๋„คํŠธ์›Œํฌ ์—ฐ๊ฒฐ์„ ํ™•์ธํ•˜๋Š” ๋ฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ์ด์ง„ ํ”„๋กœ์„ธ์Šค๋ฅผ virustotal๊ณผ ๋Œ€์กฐํ•˜์—ฌ ์ด์ง„ ํŒŒ์ผ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

PT_DENY_ATTACH

์ด ๋ธ”๋กœ๊ทธ ๊ฒŒ์‹œ๋ฌผ์—์„œ๋Š” **SIP๊ฐ€ ๋น„ํ™œ์„ฑํ™”๋˜๋”๋ผ๋„ ๋””๋ฒ„๊น…์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด PT_DENY_ATTACH**๋ฅผ ์‚ฌ์šฉํ•œ ์‹คํ–‰ ์ค‘์ธ ๋ฐ๋ชฌ์„ ๋””๋ฒ„๊น…ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์˜ˆ์ œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

lldb

lldb๋Š” macOS ์ด์ง„ ๋””๋ฒ„๊น…์„ ์œ„ํ•œ ์‚ฌ์‹ค์ƒ์˜ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค.

lldb ./malware.bin
lldb -p 1122
lldb -n malware.bin
lldb -n malware.bin --waitfor

๋‹น์‹ ์€ ํ™ˆ ํด๋”์— ๋‹ค์Œ ์ค„์„ ํฌํ•จํ•œ **.lldbinit**๋ผ๋Š” ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜์—ฌ lldb๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ intel ๋ง›์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

settings set target.x86-disassembly-flavor intel

lldb ๋‚ด๋ถ€์—์„œ process save-core๋กœ ํ”„๋กœ์„ธ์Šค๋ฅผ ๋คํ”„ํ•ฉ๋‹ˆ๋‹ค.

(lldb) ๋ช…๋ น์–ด

์„ค๋ช…

run (r)

์ค‘๋‹จ์ ์— ๋„๋‹ฌํ•˜๊ฑฐ๋‚˜ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ข…๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ๊ณ„์† ์‹คํ–‰์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

process launch --stop-at-entry

์ง„์ž…์ ์—์„œ ์ค‘๋‹จํ•˜๋ฉฐ ์‹คํ–‰์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

continue (c)

๋””๋ฒ„๊น… ์ค‘์ธ ํ”„๋กœ์„ธ์Šค์˜ ์‹คํ–‰์„ ๊ณ„์†ํ•ฉ๋‹ˆ๋‹ค.

nexti (n / ni)

๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. ์ด ๋ช…๋ น์–ด๋Š” ํ•จ์ˆ˜ ํ˜ธ์ถœ์„ ๊ฑด๋„ˆ๋œ๋‹ˆ๋‹ค.

stepi (s / si)

๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. nexti ๋ช…๋ น์–ด์™€ ๋‹ฌ๋ฆฌ ์ด ๋ช…๋ น์–ด๋Š” ํ•จ์ˆ˜ ํ˜ธ์ถœ๋กœ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค.

finish (f)

ํ˜„์žฌ ํ•จ์ˆ˜(โ€œํ”„๋ ˆ์ž„โ€)์˜ ๋‚˜๋จธ์ง€ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ๋ฐ˜ํ™˜ ํ›„ ์ค‘๋‹จํ•ฉ๋‹ˆ๋‹ค.

control + c

์‹คํ–‰์„ ์ผ์‹œ ์ค‘์ง€ํ•ฉ๋‹ˆ๋‹ค. ํ”„๋กœ์„ธ์Šค๊ฐ€ ์‹คํ–‰(run)๋˜์—ˆ๊ฑฐ๋‚˜ ๊ณ„์†(continue)๋˜์—ˆ๋‹ค๋ฉด, ํ˜„์žฌ ์‹คํ–‰ ์ค‘์ธ ์œ„์น˜์—์„œ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ค‘๋‹จ๋ฉ๋‹ˆ๋‹ค.

breakpoint (b)

b main # main์ด๋ผ๋Š” ์ด๋ฆ„์˜ ํ•จ์ˆ˜

b <binname>`main # ๋ฐ”์ด๋„ˆ๋ฆฌ์˜ main ํ•จ์ˆ˜

b set -n main --shlib <lib_name> # ์ง€์ •๋œ ๋ฐ”์ด๋„ˆ๋ฆฌ์˜ main ํ•จ์ˆ˜

breakpoint set -r '\[NSFileManager .*\]$' # ๋ชจ๋“  NSFileManager ๋ฉ”์„œ๋“œ

breakpoint set -r '\[NSFileManager contentsOfDirectoryAtPath:.*\]$'

break set -r . -s libobjc.A.dylib # ํ•ด๋‹น ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜ ๋ชจ๋“  ํ•จ์ˆ˜์—์„œ ์ค‘๋‹จ

b -a 0x0000000100004bd9

br l # ์ค‘๋‹จ์  ๋ชฉ๋ก

br e/dis <num> # ์ค‘๋‹จ์  ํ™œ์„ฑํ™”/๋น„ํ™œ์„ฑํ™”

breakpoint delete <num>

help

help breakpoint # ์ค‘๋‹จ์  ๋ช…๋ น์–ด ๋„์›€๋ง

help memory write # ๋ฉ”๋ชจ๋ฆฌ์— ์“ฐ๊ธฐ ์œ„ํ•œ ๋„์›€๋ง

reg

reg read

reg read $rax

reg read $rax --format <format>

reg write $rip 0x100035cc0

x/s <reg/memory address>

๋ฉ”๋ชจ๋ฆฌ๋ฅผ null๋กœ ์ข…๋ฃŒ๋œ ๋ฌธ์ž์—ด๋กœ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

x/i <reg/memory address>

๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์–ด์…ˆ๋ธ”๋ฆฌ ๋ช…๋ น์–ด๋กœ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

x/b <reg/memory address>

๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋ฐ”์ดํŠธ๋กœ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

print object (po)

์ด ๋ช…๋ น์–ด๋Š” ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฐธ์กฐ๋œ ๊ฐ์ฒด๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

po $raw

{

dnsChanger = {

"affiliate" = "";

"blacklist_dns" = ();

๋Œ€๋ถ€๋ถ„์˜ Apple์˜ Objective-C API ๋˜๋Š” ๋ฉ”์„œ๋“œ๋Š” ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฏ€๋กœ โ€œprint objectโ€ (po) ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ‘œ์‹œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. po๊ฐ€ ์˜๋ฏธ ์žˆ๋Š” ์ถœ๋ ฅ์„ ์ƒ์„ฑํ•˜์ง€ ์•Š์œผ๋ฉด x/b๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”.

memory

memory read 0x000.... memory read $x0+0xf2a memory write 0x100600000 -s 4 0x41414141 # ํ•ด๋‹น ์ฃผ์†Œ์— AAAA ์“ฐ๊ธฐ memory write -f s $rip+0x11f+7 "AAAA" # ํ•ด๋‹น ์ฃผ์†Œ์— AAAA ์“ฐ๊ธฐ

disassembly

dis # ํ˜„์žฌ ํ•จ์ˆ˜์˜ ๋””์Šค์–ด์…ˆ๋ธ”๋ฆฌ

dis -n <funcname> # ํ•จ์ˆ˜์˜ ๋””์Šค์–ด์…ˆ๋ธ”๋ฆฌ

dis -n <funcname> -b <basename> # ํ•จ์ˆ˜์˜ ๋””์Šค์–ด์…ˆ๋ธ”๋ฆฌ dis -c 6 # 6์ค„ ๋””์Šค์–ด์…ˆ๋ธ”๋ฆฌ dis -c 0x100003764 -e 0x100003768 # ํ•œ ์ฃผ์†Œ์—์„œ ๋‹ค๋ฅธ ์ฃผ์†Œ๊นŒ์ง€ dis -p -c 4 # ํ˜„์žฌ ์ฃผ์†Œ์—์„œ ๋””์Šค์–ด์…ˆ๋ธ”๋ฆฌ ์‹œ์ž‘

parray

parray 3 (char **)$x1 # x1 ๋ ˆ์ง€์Šคํ„ฐ์˜ 3๊ฐœ ๊ตฌ์„ฑ ์š”์†Œ ๋ฐฐ์—ด ํ™•์ธ

image dump sections

ํ˜„์žฌ ํ”„๋กœ์„ธ์Šค ๋ฉ”๋ชจ๋ฆฌ์˜ ๋งต์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.

image dump symtab <library>

image dump symtab CoreNLP # CoreNLP์˜ ๋ชจ๋“  ๊ธฐํ˜ธ ์ฃผ์†Œ ๊ฐ€์ ธ์˜ค๊ธฐ

objc_sendMsg ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ, rsi ๋ ˆ์ง€์Šคํ„ฐ๋Š” null๋กœ ์ข…๋ฃŒ๋œ (โ€œCโ€) ๋ฌธ์ž์—ด๋กœ์„œ ๋ฉ”์„œ๋“œ์˜ ์ด๋ฆ„์„ ๋ณด์œ ํ•ฉ๋‹ˆ๋‹ค. lldb๋ฅผ ํ†ตํ•ด ์ด๋ฆ„์„ ์ถœ๋ ฅํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•˜์„ธ์š”:

(lldb) x/s $rsi: 0x1000f1576: "startMiningWithPort:password:coreCount:slowMemory:currency:"

(lldb) print (char*)$rsi: (char *) $1 = 0x00000001000f1576 "startMiningWithPort:password:coreCount:slowMemory:currency:"

(lldb) reg read $rsi: rsi = 0x00000001000f1576 "startMiningWithPort:password:coreCount:slowMemory:currency:"

๋™์  ๋ถ„์„ ๋ฐฉ์ง€

VM ํƒ์ง€

  • sysctl hw.model ๋ช…๋ น์–ด๋Š” ํ˜ธ์ŠคํŠธ๊ฐ€ MacOS์ผ ๋•Œ "Mac"์„ ๋ฐ˜ํ™˜ํ•˜์ง€๋งŒ VM์ผ ๋•Œ๋Š” ๋‹ค๋ฅธ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

  • hw.logicalcpu ๋ฐ **hw.physicalcpu**์˜ ๊ฐ’์„ ์กฐ์ž‘ํ•˜์—ฌ ์ผ๋ถ€ ์•…์„ฑ์ฝ”๋“œ๋Š” VM์ธ์ง€ ๊ฐ์ง€ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

  • ์ผ๋ถ€ ์•…์„ฑ์ฝ”๋“œ๋Š” MAC ์ฃผ์†Œ(00:50:56)๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ VMware์ธ์ง€๋„ ํƒ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๊ฐ„๋‹จํ•œ ์ฝ”๋“œ๋กœ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋””๋ฒ„๊น…๋˜๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

  • if(P_TRACED == (info.kp_proc.p_flag & P_TRACED)){ //๋””๋ฒ„๊น… ์ค‘์ธ ํ”„๋กœ์„ธ์Šค }

  • ptrace ์‹œ์Šคํ…œ ํ˜ธ์ถœ์„ PT_DENY_ATTACH ํ”Œ๋ž˜๊ทธ์™€ ํ•จ๊ป˜ ํ˜ธ์ถœํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ๋””๋ฒ„๊ฑฐ๊ฐ€ ์—ฐ๊ฒฐํ•˜๊ณ  ์ถ”์ ํ•˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•ฉ๋‹ˆ๋‹ค.

  • sysctl ๋˜๋Š” ptrace ํ•จ์ˆ˜๊ฐ€ ๊ฐ€์ ธ์™€์ง€๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค (ํ•˜์ง€๋งŒ ์•…์„ฑ์ฝ”๋“œ๋Š” ๋™์ ์œผ๋กœ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค).

  • ์ด ๊ธ€์—์„œ ์–ธ๊ธ‰๋œ ๋ฐ”์™€ ๊ฐ™์ด, โ€œ๋””๋ฒ„๊ทธ ๋ฐฉ์ง€ ๊ธฐ์ˆ  ๋ฌด๋ ฅํ™”: macOS ptrace ๋ณ€ํ˜•โ€ : โ€œ๋ฉ”์‹œ์ง€ Process # exited with **status = 45 (0x0000002d)**๋Š” ๋””๋ฒ„๊ทธ ๋Œ€์ƒ์ด PT_DENY_ATTACH๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค๋Š” ์‹ ํ˜ธ์ž…๋‹ˆ๋‹ค.โ€

์ฝ”์–ด ๋คํ”„

์ฝ”์–ด ๋คํ”„๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฝ์šฐ์— ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค:

  • kern.coredump sysctl์ด 1๋กœ ์„ค์ •๋˜์–ด ์žˆ์„ ๋•Œ (๊ธฐ๋ณธ๊ฐ’)

  • ํ”„๋กœ์„ธ์Šค๊ฐ€ suid/sgid๊ฐ€ ์•„๋‹ˆ๊ฑฐ๋‚˜ kern.sugid_coredump๊ฐ€ 1์ผ ๋•Œ (๊ธฐ๋ณธ๊ฐ’์€ 0)

  • AS_CORE ์ œํ•œ์ด ์ž‘์—…์„ ํ—ˆ์šฉํ•  ๋•Œ. ulimit -c 0์„ ํ˜ธ์ถœํ•˜์—ฌ ์ฝ”๋“œ ๋คํ”„ ์ƒ์„ฑ์„ ์–ต์ œํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ulimit -c unlimited๋กœ ๋‹ค์‹œ ํ™œ์„ฑํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ๊ฒฝ์šฐ ์ฝ”์–ด ๋คํ”„๋Š” kern.corefile sysctl์— ๋”ฐ๋ผ ์ƒ์„ฑ๋˜๋ฉฐ ์ผ๋ฐ˜์ ์œผ๋กœ /cores/core/.%P์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.

ํผ์ง•

ReportCrash๋Š” ์ถฉ๋Œํ•˜๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ ๋ถ„์„ํ•˜๊ณ  ์ถฉ๋Œ ๋ณด๊ณ ์„œ๋ฅผ ๋””์Šคํฌ์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. ์ถฉ๋Œ ๋ณด๊ณ ์„œ๋Š” ๊ฐœ๋ฐœ์ž๊ฐ€ ์ถฉ๋Œ ์›์ธ์„ ์ง„๋‹จํ•˜๋Š” ๋ฐ ๋„์›€์ด ๋˜๋Š” ์ •๋ณด๋ฅผ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๋ณ„ launchd ์ปจํ…์ŠคํŠธ์—์„œ ์‹คํ–‰๋˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐ ๊ธฐํƒ€ ํ”„๋กœ์„ธ์Šค์— ๋Œ€ํ•ด ReportCrash๋Š” LaunchAgent๋กœ ์‹คํ–‰๋˜๋ฉฐ ์‚ฌ์šฉ์ž์˜ ~/Library/Logs/DiagnosticReports/์— ์ถฉ๋Œ ๋ณด๊ณ ์„œ๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. ๋ฐ๋ชฌ, ์‹œ์Šคํ…œ launchd ์ปจํ…์ŠคํŠธ์—์„œ ์‹คํ–‰๋˜๋Š” ๊ธฐํƒ€ ํ”„๋กœ์„ธ์Šค ๋ฐ ๊ธฐํƒ€ ๊ถŒํ•œ ์žˆ๋Š” ํ”„๋กœ์„ธ์Šค์— ๋Œ€ํ•ด ReportCrash๋Š” LaunchDaemon์œผ๋กœ ์‹คํ–‰๋˜๋ฉฐ ์‹œ์Šคํ…œ์˜ /Library/Logs/DiagnosticReports์— ์ถฉ๋Œ ๋ณด๊ณ ์„œ๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

์ถฉ๋Œ ๋ณด๊ณ ์„œ๊ฐ€ Apple๋กœ ์ „์†ก๋˜๋Š” ๊ฒƒ์ด ๊ฑฑ์ •๋œ๋‹ค๋ฉด ์ด๋ฅผ ๋น„ํ™œ์„ฑํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์ถฉ๋Œ ๋ณด๊ณ ์„œ๋Š” ์„œ๋ฒ„๊ฐ€ ์–ด๋–ป๊ฒŒ ์ถฉ๋Œํ–ˆ๋Š”์ง€ ํŒŒ์•…ํ•˜๋Š” ๋ฐ ์œ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

#To disable crash reporting:
launchctl unload -w /System/Library/LaunchAgents/com.apple.ReportCrash.plist
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.ReportCrash.Root.plist

#To re-enable crash reporting:
launchctl load -w /System/Library/LaunchAgents/com.apple.ReportCrash.plist
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.ReportCrash.Root.plist

Sleep

MacOS์—์„œ ํผ์ง•ํ•  ๋•Œ Mac์ด ์ž ๋“ค์ง€ ์•Š๋„๋ก ํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค:

  • systemsetup -setsleep Never

  • pmset, ์‹œ์Šคํ…œ ํ™˜๊ฒฝ์„ค์ •

SSH Disconnect

SSH ์—ฐ๊ฒฐ์„ ํ†ตํ•ด ํผ์ง•ํ•˜๋Š” ๊ฒฝ์šฐ ์„ธ์…˜์ด ์ข…๋ฃŒ๋˜์ง€ ์•Š๋„๋ก ํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ sshd_config ํŒŒ์ผ์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณ€๊ฒฝํ•˜์‹ญ์‹œ์˜ค:

  • TCPKeepAlive Yes

  • ClientAliveInterval 0

  • ClientAliveCountMax 0

sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

Internal Handlers

๋‹ค์Œ ํŽ˜์ด์ง€๋ฅผ ํ™•์ธํ•˜์„ธ์š” ์–ด๋–ค ์•ฑ์ด ์ง€์ •๋œ ์Šคํ‚ด ๋˜๋Š” ํ”„๋กœํ† ์ฝœ์„ ์ฒ˜๋ฆฌํ•˜๋Š”์ง€ ์ฐพ๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ณด์„ธ์š”:

macOS File Extension & URL scheme app handlers

Enumerating Network Processes

๋„คํŠธ์›Œํฌ ๋ฐ์ดํ„ฐ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ ์ฐพ๋Š” ๊ฒƒ์€ ํฅ๋ฏธ๋กญ์Šต๋‹ˆ๋‹ค:

dtrace -n 'syscall::recv*:entry { printf("-> %s (pid=%d)", execname, pid); }' >> recv.log
#wait some time
sort -u recv.log > procs.txt
cat procs.txt

๋˜๋Š” netstat ๋˜๋Š” lsof๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”.

Libgmalloc

lldb -o "target create `which some-binary`" -o "settings set target.env-vars DYLD_INSERT_LIBRARIES=/usr/lib/libgmalloc.dylib" -o "run arg1 arg2" -o "bt" -o "reg read" -o "dis -s \$pc-32 -c 24 -m -F intel" -o "quit"

ํผ์ €

CLI ๋„๊ตฌ์— ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

macOS GUI ๋„๊ตฌ์™€ "๊ทธ๋ƒฅ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค". ์ผ๋ถ€ macOS ์•ฑ์€ ๊ณ ์œ ํ•œ ํŒŒ์ผ ์ด๋ฆ„, ์˜ฌ๋ฐ”๋ฅธ ํ™•์žฅ์ž์™€ ๊ฐ™์€ ํŠน์ • ์š”๊ตฌ ์‚ฌํ•ญ์ด ์žˆ์œผ๋ฉฐ, ์ƒŒ๋“œ๋ฐ•์Šค์—์„œ ํŒŒ์ผ์„ ์ฝ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค (~/Library/Containers/com.apple.Safari/Data)...

๋ช‡ ๊ฐ€์ง€ ์˜ˆ:

# iBooks
litefuzz -l -c "/System/Applications/Books.app/Contents/MacOS/Books FUZZ" -i files/epub -o crashes/ibooks -t /Users/test/Library/Containers/com.apple.iBooksX/Data/tmp -x 10 -n 100000 -ez

# -l : Local
# -c : cmdline with FUZZ word (if not stdin is used)
# -i : input directory or file
# -o : Dir to output crashes
# -t : Dir to output runtime fuzzing artifacts
# -x : Tmeout for the run (default is 1)
# -n : Num of fuzzing iterations (default is 1)
# -e : enable second round fuzzing where any crashes found are reused as inputs
# -z : enable malloc debug helpers

# Font Book
litefuzz -l -c "/System/Applications/Font Book.app/Contents/MacOS/Font Book FUZZ" -i input/fonts -o crashes/font-book -x 2 -n 500000 -ez

# smbutil (using pcap capture)
litefuzz -lk -c "smbutil view smb://localhost:4455" -a tcp://localhost:4455 -i input/mac-smb-resp -p -n 100000 -z

# screensharingd (using pcap capture)
litefuzz -s -a tcp://localhost:5900 -i input/screenshared-session --reportcrash screensharingd -p -n 100000

๋” ๋งŽ์€ ํผ์ง• MacOS ์ •๋ณด

์ฐธ๊ณ ๋ฌธํ—Œ

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE) GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ

Last updated