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

Better Codedirectory Parsing and Added Requirements(_Code) Parsing #195

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

abpolym
Copy link

@abpolym abpolym commented Feb 14, 2016

The current CodeDirectory Parsing is not sufficient.

I used freely accessible information from the opensourced source code:

You have to modify the Parser, though.

My current Parser Version looks like this:

[...]
        if sig['type'] == MachOEntity.CODE_DIRECTORY:
            print "        [-] Length: %s" % sig['length']
            print "        [-] Version: %s" % sig['version']
            print "        [+] nSpecialSlots: %s" % sig['nSpecialSlots']
            for (slotname, hash) in sig['specialSlots']:
                print "          [-] %s: %s" % (slotname, hash)
            print "        [+] nCodeSlots: %s" % sig['nCodeSlots']
            for (slotname, hash) in sig['codeSlots']:
                print "          [-] %s: %s" % (slotname, hash)
            print "        [-] Identifier: %s" % sig['identifier']
            print "        [-] Hash type: %s" % sig['hashtype']
            print "        [-] Hash: %s" % sig['hash']
[...]

Edit: I've also implemented requirements parsing.

Source Code:

The Parser Version thus looks like this:

        if sig['type'] == MachOEntity.REQUIREMENT_SET:
            print "        [+] nRequirements"
            for r in sig['requirements']:
                for e in r['requirement']:
                    print "          [-] %s => %s" % (r['type'], e['expr'])

The Requirements Parsing still needs a lot of boundary checks and some parsing for the OP_CERTGENERIC and OP_CERTPOLICY is missing (and breaks the parsing if it is encountered)

Match expressions also don't seem to work right now.

@abpolym abpolym changed the title Better Codedirectory Parsing Better Codedirectory Parsing and Added Requirements(_Code) Parsing Feb 15, 2016
@mgoffin
Copy link
Contributor

mgoffin commented Feb 16, 2016

I'll try to get to checking this out when I can :) When you say you had to modify the Parser, which parser are you referring to? Is that something you have to do on top of accepting these changes to make stuff work?

@abpolym
Copy link
Author

abpolym commented Feb 16, 2016

What I mean is this script - you have to edit this file if you want to display the information that can be extracted using the new Parser methods. I mixed up some terminology here. The stuff I implemented works so far, however it still has some flaws (mentioned above) that I or someone else has to fix or have a look into. I can try to add it in the coming days, but I got a lot of other workload that I have to finish first.

@mgoffin
Copy link
Contributor

mgoffin commented Aug 4, 2016

Sorry this took ages to get back to. I can run this and I do get some output. But it errors out and in the log it says Error running service: 'ver'. Any ideas?

@abpolym
Copy link
Author

abpolym commented Nov 10, 2016

@mgoffin Can you give me the/an example MACH-O file, in which this error occurs, for me to reproduce?

@mgoffin
Copy link
Contributor

mgoffin commented Nov 10, 2016

I believe i used /bin/ls

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