Capabilities and Stack Strings in Mac Malware
How Mach-O Parser reads arm64 and x86_64 code: function discovery, named calls, capability rules mapped to ATT&CK, PT_DENY_ATTACH and stack strings.
TL;DR. Imports and strings say what a binary contains. The code says how those pieces fit together. Mach-O Parser disassembles arm64 and x86_64 slices in the browser:
- it finds every function, even in stripped binaries;
- it names each call after the import, Objective-C selector or string it reaches;
- it matches every function against capability rules mapped to MITRE ATT&CK and the Malware Behavior Catalog;
- it rebuilds strings written onto the stack.
Nothing is executed. Each match names the function where the evidence sits, so the next step is one click away in the disassembly.
Why imports and strings are not enough
Static triage of a Mach-O file starts with its imports and strings, and they go a long way. Three habits of Mac malware get past them:
- Objective-C hides the calls. Every method call goes through one import,
objc_msgSend. What is actually called is the selector, a string passed alongside:writeToFile:atomically:,dataTaskWithURL:. Since Xcode 14, arm64 binaries call per-selector stubs namedobjc_msgSend$selectorinstead, which helps, but only if something reads them. - Dynamic resolution.
dlopenanddlsymfetch functions by name at run time, so the import table shows only those two calls. - Text that never exists as a string. Commands, paths and URLs built on the stack, or decoded from XOR-ed bytes, are invisible to
strings.
Finding the functions
A disassembly is only as good as its function list. The analysis collects start addresses from:
LC_FUNCTION_STARTS, a compact list of every function the linker saw;- the symbol table, the exports and the entry point;
- the implementations of Objective-C methods.
Stripped binaries sometimes drop the function-start list too. The analysis then scans the code for call instructions (BL on arm64, CALL on x86) and treats every target as a function. On a large app like Google Chrome's framework, that recovers over a hundred thousand functions.
Each function is then walked once. Every call is named:
- through the stubs and the GOT, after the imported symbol;
- through the chained fixups, after the bound symbol;
- through
objc_msgSend$…stubs or selector references, after the selector.
Every address the code loads is resolved to a C string, a CFString, a selector or a class where possible. The Code tab shows the same names in its listing, so evidence in the analysis and instructions in the listing line up.
Capability rules
Each function produces a set of features: the APIs it calls, the selectors it sends, the classes it uses, the strings and constants it references, the system calls it makes, and characteristics such as loops and XOR instructions. Rules combine features. A few of the macOS rules:
| Capability | Evidence the rule looks for | ATT&CK |
|---|---|---|
| Prevent debugger attach | ptrace with constant 31 (PT_DENY_ATTACH), or system call 26 directly | T1622 |
| Check for a debugger via sysctl | sysctl with the KERN_PROC (14) query and the P_TRACED flag (0x800) | T1622 |
| Check for a debugger via exception ports | task_get_exception_ports | T1622 |
| Check for a virtual machine | kern.hv_vmm_present, "VMware", "VirtualBox", hardware-model queries | T1497.001 |
| Invoke a system call directly | svc #0x80 (arm64) or syscall with 0x2000000 + n (x86_64) | T1106 |
| Read keychain items | SecItemCopyMatching, security find-generic-password | T1555.001 |
| Capture keystrokes | CGEventTapCreate, HID input callbacks, global event monitors | T1056.001 |
| Capture the screen | CGWindowListCreateImage, ScreenCaptureKit classes, screencapture | T1113 |
| Load a Mach-O image from memory | NSCreateObjectFileImageFromMemory, NSLinkModule | T1620 |
| Transform data with XOR in a loop | A loop containing XOR of two different registers or with memory | — |
| Contain crypto constants | The AES S-box, the ChaCha / Salsa20 constant, SHA-256, MD5 or CRC32 tables | — |
There are 64 rules in all. They cover persistence (LaunchAgents, login items, cron, shell start-up files) and credential access (keychain, browser stores, fake password dialogs). They also cover collection, discovery, command-and-control, Gatekeeper and quarantine tampering, privilege escalation and process injection.
A function match means the evidence sits in one function: the call to ptrace and the constant 31 in the same body. A whole-file match means the imports or strings are present, but no single walked function ties them together. That is common when the code is tiny, or when the strings are only passed around as data. The five sample files only print a greeting, so all their matches are whole-file: their infostealer strings are inert data that no code uses.
Anti-debugging, a worked example
PT_DENY_ATTACH is the oldest anti-debugging trick on macOS, and it shows why rules need more than the import table.
- The plain version imports
ptraceand calls it with31. Both features are in one function, so the rule matches at function level. - The evasive version never imports
ptrace. It loads the system-call number 26 intox16and executessvc #0x80on arm64, or puts0x2000000 + 26inraxand executessyscallon x86_64. The analysis tracks the register and reports both "invoke a system call directly" and the debugger rule.
The same register tracking resolves sysctl queries. A function that builds the query {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()} and then tests bit 11 of the result is checking whether a debugger is attached.
Stack strings
A stack string is text written into a function's stack frame with immediate values: four or eight bytes per store instruction on x86_64, assembled in registers first on arm64. The analysis follows the stores, rebuilds the buffer and keeps the results that look like text: at least six printable characters, at least four distinct ones, including a letter.
Not every stack string is hidden on purpose. Compilers initialise short local strings the same way, so the Code analysis tab hides results that look like data and offers to show them. Found stack strings also feed the IOC list, so a URL or path rebuilt this way is extracted like any other. Each result links to its function in the Code tab.
What decoding cannot do
Following instructions without running them has limits:
- Strings decrypted by a loop at run time stay encrypted, though the loop itself often matches the XOR rule.
- Packed code (UPX) and FairPlay-encrypted code have to be unpacked or decrypted first.
- Very large binaries are analysed up to a budget of three million instructions. The listing itself always covers everything.
The best-known open-source tools for this job, capa and FLOSS, were built for Windows PE files first. A browser-based analyser for the Mach-O side means a Mac sample gets the same first look, from any machine, without leaving it.
From a match to an answer
- Open Code analysis (or run it for the whole batch) and read the capabilities grouped by namespace.
- Prefer function matches: they name an address. Click it to open the function in Code.
- In the listing, follow calls and references: every import, selector and string is named.
- Export the ATT&CK Navigator layer: it combines what the file declares (entitlements, libraries, strings) with what the code does.
The indicators that come out of this, stack strings included, flow into the IOC exports: see from a Mach-O file to IOCs.
Frequently asked questions
What is a stack string?
Text that a function writes into its own stack frame a few bytes at a time, with immediate values in store instructions, before using it. The text never appears whole in the file, so a strings tool misses it. A disassembler that follows those stores can put it back together.
What is PT_DENY_ATTACH?
Request 31 of ptrace on macOS. A process that calls ptrace(PT_DENY_ATTACH, 0, 0, 0) can no longer be attached by a debugger, and if one is already attached the process exits. Malware uses it, often through a raw system call so that ptrace never appears among its imports.
Does the code analysis run the program?
No. It decodes instructions and follows them statically: it never executes, maps or emulates the code. Strings that are only decrypted at run time stay hidden, and that is the trade-off for analysing an unknown file safely in a browser.