-
Notifications
You must be signed in to change notification settings - Fork 274
Fix section type identifing in mach-o view #7842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Based on opensource code [`loader.h`](https://github.com/apple-oss-distributions/xnu/blob/f6217f891ac0bb64f3d375211650a4c1ff8ca1ea/EXTERNAL_HEADERS/mach-o/loader.h#L470) and [`dyld`](https://github.com/apple-oss-distributions/dyld), the lowest byte in `sect.flags` stands for section type. | section name | section type | value | | :---------------------: | :------------------------: | :---: | | `__auth_got` or `__got` | S_NON_LAZY_SYMBOL_POINTERS | 0x6 | | `__init_offsets` | S_INIT_FUNC_OFFSETS | 0x16 | The problem for `sect.flags & S_NON_LAZY_SYMBOL_POINTERS` is that if `flags` is `S_INIT_FUNC_OFFSETS`, mach-o view will confuse `__init_offsets` with `__auth_got`(or `__got`). The checks for other section types have also been improved.
|
Thank you for sending this PR. The change seems correct, but I do want to look into why this existing code was matching on section names before I merge it. Is there a particular Mach-O binary on which you noticed the incorrect section type handling causing a problem? |
|
The mach-o I analyzed is a 2023 iOS in-the-wild (ITW) malware sample called Predator. It was uploaded and shared by Google GTIG/TAG; their blog post is available here. The sample can be downloaded here. I loaded the sample into Binary Ninja and noticed that the entire Support for the One more issue is that I missed |
|
Thank you again for the PR, and for your patience as I followed up on it. A bug was reported via Slack (#7891) that looks like it requires a change in how we classify sections, and it took some time to make sure I understood how a fix for it would interact with the changes proposed here. Additionally, I noticed that your second commit introduced a bug due to operator precedence: is interpreted as: which is What I propose doing is:
Something like this: I'm happy to make these changes myself on your branch prior to merging, or for you to make them. |
The patch is only tested on 5.2.8614.
Based on opensource code
loader.handdyld, the lowest byte insect.flagsstands for section type.__auth_gotor__got__init_offsetsThe problem for
sect.flags & S_NON_LAZY_SYMBOL_POINTERSis that ifflagsisS_INIT_FUNC_OFFSETS, mach-o view will confuse__init_offsetswith__auth_got(or__got). The checks for other section types have also been improved.