Replies: 5 comments 23 replies
-
Not all heroes wear capes 😢 I very much appreciate your interest and help ❤️ I'll take a look at this ASAP. I got a bit side tracked by my APFS parser and the NEW rawimagediff fmt in the OTAs for the systemOS cryptex, but I really need to just finish the sb decompiler. Other than the modifiers I just need to write the NDA regex stuff and convert the operations etc into an acyclic graph aka the most complex parts of sandblaster. |
Beta Was this translation helpful? Give feedback.
-
@0xalsr Have you looked at the iOS16 profile/collection fmt yet? |
Beta Was this translation helpful? Give feedback.
-
@0xalsr do you know what the operation_info "flags" are? I used to call them dependencies, but I see them being referenced in |
Beta Was this translation helpful? Give feedback.
-
One question I have is I've noticed filter aliases having the same IDs, WTF is that all about? For example: {
"id": 11,
"name": "socket-domain",
"category": "socket",
"aliases": [
{
"name": "AF_UNSPEC",
"id": 0
},
{
"name": "AF_UNIX",
"id": 1
},
{
"name": "AF_LOCAL",
"id": 1
}, |
Beta Was this translation helpful? Give feedback.
-
@0xalsr do you understand the terminal node Type or Flags bits? I believe I am not parsing them correctly, do they tell you when you have modifier_info data in the last 4 bytes? |
Beta Was this translation helpful? Give feedback.
-
I see you're working on parsing the Apple sandbox profiles. I don't have any code to share but thought I'd post some of my understanding in case its helpful. I appreciate you may already know this stuff, I'm just going off of whats in the
feature/sandbox_decompiler
branch.Header Type
The header type can also be
0x4000
for profiles. I'm not sure what determines whether the type is0x0000
or0x4000
.This profile when compiled using libsandbox.1 will have
0x0000
:This profile when compiled using libsandbox.1 will have
0x4000
:Policies
This is a minor nitpick but I believe what you've identified as 'modifier descriptors' are actually called policies, based on some error strings in the sandbox KEXT.
Policies are 2 byte values that are indices into the
OpNode
array (more on this below).Modifiers
I think you already get this but the
Action
field is a set of bit flags that indicate the types of actions that the modifier can be applied to. If bit 0 is set then it can be applied to deny actions. If bit 1 is set then it can be applied to allow actions.ipsw/pkg/sandbox/filter.go
Line 313 in 6050bc0
Type
is also a set of bit flags, so far I only understand 2 of the 3 that I've seen. Bit 0 I don't know what it means but its set on almost all modifiers. If bit 1 is set then the modifier has an argument. If its not set then the modifier has an action flag which sets a bit on the terminal node to indicate that the modifier has been applied to the node. If bit 2 is set then modifier is a policy or its argument is a policy, not sure which terminology makes the most sense here.ipsw/pkg/sandbox/filter.go
Line 314 in 6050bc0
Format
Modifiers are 4 bytes and as you seem to already know, they can be inline as the last 4 bytes of a terminal node. They seem to have the following format:
id
is just an index into the modifer info array.policy_op_idx
is used in the case that a modifier is or has a policy (not 100% sure if this is the only purpose of this byte). This value is an index into the operations array. For me, this helped clear up the fact that the KEXT sandbox collection specifies less sandbox operations in profiles than there are in the operations array (on iOS 15 there 188 but profiles only have 182).An example of the
policy_op_idx
in action is the following profile:(iokit-user-client-class "AppleJPEGDriverUserClient")
will be a non-terminal node that when matched points to a terminal node. In this case it will have an inline modifier. The inline modifier will have the following values:id
indicates its adefault-message-filter
modifier.policy_op_idx
indicates that the policy is filteringiokit-external-method
.arg
is the index into the policy array. The element at that offset will be an index into the OpNode array which should have a filter of73
which isiokit-method-number
. This is then just a standard graph of non-terminal nodes leading to terminal nodes.arg
in non-policy cases depend on which modifier it is for. For thesend-signal
modifier it is the number of the signal, but formessage
its an offset into the data section (or whatever its called wherebase_addr
points to at the end of the collection) where there will be a string (2 byte length followed by aNULL
terminated C string of said length).Filter Bitmasks
You mention not being sure how the bitmask stuff works:
ipsw/pkg/sandbox/sandbox.go
Line 574 in 6050bc0
Each bit represents whether a value is set in the filter:
The syscalls have the following numbers:
From what I've seen the number corresponds to the bit index in the bitmask byte array. So the first byte will be
0x28
indicatingSYS_read
andSYS_open
. When parsing the sandbox collection all instances of a syscall mask will be 69 bytes in length.69*8 == 552
, which is enough bits to represented the current syscalls in XNU. The highest syscall number is551
forSYS_freadlink
.Beta Was this translation helpful? Give feedback.
All reactions