Lulu firewall hardening

26 Feb 2022 21:21 | macOS | security

I'm a big fan of Patrick Wardle's free mac utilities but I noticed something odd
about LuLu recently. It seems that it only filters egress traffic when
is running. Since it normally runs as the local user rather than root, this
makes it somewhat trivial for malware to defeat as it can simply kill the
process and then connect to whatever it wants.

This can be mitigated by running the app as root, but since it's not installed
root-owned the first thing to do is change that:

$ sudo chown -R root:wheel /Applications/

Then we need to create an suid loader binary to load it with. This needs to
execute via the LaunchAgents mechanism in order for the application to work
properly. So something like:

$ cat >lulu-as-root.c <<EOF
> #include <unistd.h>
> int main() {
>   if (getuid() != 501) {   # replace this with your user's uid
>     return 0;
>   }
>   setuid(0);
>   seteuid(0);
>   execl("/Applications/", "/Applications/", NULL);
>   return 0;
> }
$ sudo gcc -o /usr/local/bin/lulu-as-root lulu-as-root.c
$ sudo chmod 4755 /usr/local/bin/lulu-as-root

Then we need a LaunchAgent script to load it:

$ cat >~/Library/LaunchAgents/com.m4rkw.lulu.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Then kill the non-root process and re-launch LuLu as root:

$ killall LuLu
$ launchctl load -w ~/Library/LaunchAgents/com.m4rkw.lulu.plist