Skip to content

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

Open
abpolym wants to merge 6 commits into
crits:masterfrom
abpolym:codedirectory
Open

Better Codedirectory Parsing and Added Requirements(_Code) Parsing#195
abpolym wants to merge 6 commits into
crits:masterfrom
abpolym:codedirectory

Conversation

@abpolym

@abpolym abpolym commented Feb 14, 2016

Copy link
Copy Markdown

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

mgoffin commented Feb 16, 2016

Copy link
Copy Markdown
Contributor

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

abpolym commented Feb 16, 2016

Copy link
Copy Markdown
Author

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

mgoffin commented Aug 4, 2016

Copy link
Copy Markdown
Contributor

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

abpolym commented Nov 10, 2016

Copy link
Copy Markdown
Author

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

@mgoffin

mgoffin commented Nov 10, 2016

Copy link
Copy Markdown
Contributor

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