Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upBypass Santa By Overwriting a Binary #15
Comments
|
Thanks for the report. Write events are generated for more than just opening a file but there are certain situations where it's possible to overwrite a file without triggering a write event. However, in 10333bb I changed the cache-removal mechanism to protect when dirty blocks are present, which I believe removes these cases (though I'm still verifying). |
|
Do you know if this can be subverted because of time-to-check-time-to-use? I'm not sure how the exec and kauth work in the kernel. But if it is something like: user execv() then it seems that this ordering is possible: user execv() i don't see where there is protection against the binary changing after hasdirtyblks has returned true. i guess the only thing is it would be hard for the attacker to win the race. |
|
Theoretically, yes. The process is this (from http://www.opensource.apple.com/source/xnu/xnu-2782.1.97/bsd/kern/kern_exec.c): __mac_execve() / posix_spawn() However, there's other locking happening that may or may not affect whether the exec would proceed and the gap between the authorize and vn_rdwr would make this very difficult to exploit. Moreover, exploiting that would require being able to execute something in the first place which is, to some extent, outside of scope. |
i think you can copy a signed binary to somewhere you can modify it. open the signed binary with write access. execute the signed binary. change the signed binary to do bad stuff. then execute the binary again. this is my understanding of this code because the write event is only created when you open a file for writing:
santa/Source/santa-driver/SantaDecisionManager.cc
Line 377 in 41d1d7e
Here is the santa logs for two scenarios. One is executing a binary. Overwriting the binary. Then executing the binary again. This generates two log entries.
The other opens the binary. Then executes the binary. Then overwrites the binary using the fd generated before executing the binary. This generates only one log entry. I think this is bypassing santa. However, I'm running in MONITOR mode so I'm not 100% sure.