How to FreeBSD mdo
May 8, 2026•379 words
FreeBSD Foundation came out with a great (brief) tutorial video "FreeBSD Privilege Escalation out-of-the-box" this extends their tutorial incorporating command auditing (as one would expect from sudo historically) using the native audit subsystem.
You'll need to be root (or equivalent) for most of this. Get there however you would like!
I did this all on an up-to-date FreeBSD 15 system, but 14.2 and later should work.
Set-up auditd
This will log a lot of audit logging, maybe you want it, maybe you don't! If you know how, and why you don't: cool, do that! If you're ever anticipate doing post-incident forensics for yourself, or having someone else do it, you probably want this!
- Enable the service in
/etc/rc.conf:sysrc auditd_enable="YES"and start itservice auditd start - Edit these lines in
/etc/security/audit_control-- refer toman audit_controlfor more options, butpcis process auditing, andexfor exec, argv for process arguments, as well as a more nuanced expiry policy (for me I choose to expire audit logs after they reach 112d of age and at least 1G in size, the logic available here also permits OR):
flags:lo,aa,pc,ex
policy:cnt,argv
expire-after: 112d AND 1G
- Reboot.
Consider checking out the FreeBSD Handbook Audit section for more.
On to the main course: leveraging FreeBSD's included (since 14.2) privilege transition tool built on top of the MAC framework.
Set-up the mac_do module
- Enable
mac_doby addingmac_do_load="YES"to/boot/loader.conf kldload mac_doto avoid rebooting again- Add a policy for the
mac_domodule to/etc/sysctl.conffor example:security.mac.do.rules=uid=1001>uid=0,gid=*,+gid=*this will allow uid=1001 (probably you, on a single user system) to transition to root (uid 0) or any group (±their current groups), orgid=0if you just wanted to extend this to all of the wheel group. - Load the policy
sysctl -f /etc/sysctl.conf - Try it out:
mdo whoami(should say root)
Do some crap and then check it out: mdo praudit -l /var/audit/current in theory auditreduce has filtration, but there's a bug in how it interfaces with capsicum but .
You might want to remove sudo or doas later if you hate having extra packages, but since this is kinda bleeding edge... maybe hold on to them for a while before ditching them!