Skip to content
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

codesign: add support for RUNTIME flag and minimum runtime version #37

Merged
merged 3 commits into from
Apr 5, 2024

Conversation

jkt-signal
Copy link
Contributor

This change adds support for the RUNTIME code signature flag, which requires a hardened runtime and allows the binary to require a particular runtime version.

@@ -434,6 +435,7 @@ type Config struct {
EntitlementsDER []byte
ResourceDirSlotHash []byte
SlotHashes slotHashes
RuntimeVersion mtypes.Version
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you running gofmt? this doesn't look aligned

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

everything else looks good

@blacktop
Copy link
Owner

I understand that you are solving for a particular use case w/ Signal or something else, but there is an issue w/ the MachOs generated by the export.go Export func where it produces MachOs that IDA Pro doesn't like and complains about the Segment/Sections boundaries being wrong?

As I mentioned I understand if you are doing this for work and don't have time, but these have been some VERY clean and well done PRs and was curious if you'd take a look.

It's something I've had on the TODO list for a long time and would really appreciate some help. I know the code is pretty gross and prob needs to be re-written :(

Either way, thanks for all your help w/ these PRs.

Cheers

@jkt-signal
Copy link
Contributor Author

I understand that you are solving for a particular use case w/ Signal or something else, but there is an issue w/ the MachOs generated by the export.go Export func where it produces MachOs that IDA Pro doesn't like and complains about the Segment/Sections boundaries being wrong?

I'm happy to take a look! I'll have a bit less time (as you infer, my earlier contributions have been for use at Signal and were fixing gaps that blocked me) but I've greatly appreciated all the time you saved me by having this here, so happy to pay that forward a bit. Do you happen to have a useful repro/test case? I don't have IDA Pro, but if you could send me some simple binary you generated with Export and the same one made the official way, I can try to understand the difference.

As I mentioned I understand if you are doing this for work and don't have time, but these have been some VERY clean and well done PRs and was curious if you'd take a look.

glad you liked them 💜

It's something I've had on the TODO list for a long time and would really appreciate some help. I know the code is pretty gross and prob needs to be re-written :(

A fair amount of this could probably use a refactoring pass or two—I'm afraid I didn't improve things much in that respect with the last several contributions, I may do so with the next few.

@jkt-signal jkt-signal requested a review from blacktop April 4, 2024 19:34
@blacktop
Copy link
Owner

blacktop commented Apr 5, 2024

I understand that you are solving for a particular use case w/ Signal or something else, but there is an issue w/ the MachOs generated by the export.go Export func where it produces MachOs that IDA Pro doesn't like and complains about the Segment/Sections boundaries being wrong?

I'm happy to take a look! I'll have a bit less time (as you infer, my earlier contributions have been for use at Signal and were fixing gaps that blocked me) but I've greatly appreciated all the time you saved me by having this here, so happy to pay that forward a bit. Do you happen to have a useful repro/test case? I don't have IDA Pro, but if you could send me some simple binary you generated with Export and the same one made the official way, I can try to understand the difference.

So the most popular use case is to extract DYLIBs from the dyld_shared_cache to RE purposes (to make them actually linkable/usable would be a stretch goal for sure 😉 In ipsw I have a currently hidden command that does it. ipsw dsc extract It is called here *(the second would be extracting KEXTs from the kernelcache, and I guess 3rd would be to make crazy malformed MachOs for security research 😈 )

A source of truth would be what XCode does which can be invoked by calling ipsw dsc split dyld_shared_cache docs this uses the same lib as XCode to pull out DYLIBs (this is to support lldb and does a minimal amount of fixups required) I wrote my Export function by looking at the source for the lib and REing it's binary etc. Found here

Incase you were unaware, the process of creating the shared_cache throws away a lot of information when combining the dylibs togethers to the process of 'extracting' them back out isn't trivial.

So far the best project to do this is https://github.com/arandomdev/DyldExtractor

My solution if also very close, I think only missing the ObjC runtime info fixups, but there is some error in the logic of the go-macho Export function that people have reported to me saying Ghidra/IDA complain about the MachO's header and Segment/Section boundaries??

So I guess the test rig would be using ipsw where you can clone go-macho to a folder next to it and uncomment this line in the go.mod to test out fixes etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants