mirror of
https://github.com/netblue30/firejail.git
synced 2026-05-15 14:16:14 -06:00
[GH-ISSUE #472] Can escape jail with mate-terminal #338
Labels
No labels
LTS merge
LTS merge
bug
bug
converted-to-discussion
doc-todo
documentation
duplicate
enhancement
file-transfer
firecfg
firejail-in-firejail
firetools
graphics
help wanted
information_old
installation
invalid
modif
moved
needinfo
networking
notabug
notourbug
old-version
overlayfs
packaging
profile-request
pull-request
question
question_old
removal
runtime-permissions
sandbox-ipc
security
stale
wiki
wiki
wontfix
wordpress
workaround
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/firejail#338
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Fred-Barclay on GitHub (Apr 22, 2016).
Original GitHub issue: https://github.com/netblue30/firejail/issues/472
This is somewhat similar to #471 but works from inside the jail:
I can blacklist a directory, start a terminal (I've tried mate-terminal) from inside the firejail, and then escape the jail completely with that separate terminal. I can even gain root privs via sudo, which is normally impossible inside the jail:
As you can see, I can't get into
secretand have done nothing unusual from terminal (so none of themkdir...cdand having another, un-jailed terminal mv the directory, as in #471 ).Having started a terminal, I can now have the real fun:
I can even create and delete files, and change their permissions
All of this, again, was done from a terminal started inside firejail. So this isn't being "sabotaged from the outside" as was #471. While I don't have any additional privileges, I'm still able to run as a normal user without any jailing.
A friend pointed out that this was already blocked for several terminals by /etc/disable-common.inc, which blacklists gnome-terminal and xfce4-terminal. And indeed, starting gnome-terminal from inside firejail fails:
However, certain other terminals, such as xterm, can be started from inside firejail, but do not have access to blacklisted directories:
I've noticed that xterm doesn't seem to "detach" from the launching jail, while mate-terminal does. (Can't think of how to describe it exactly, but "xterm" is the running command in the jail, while mate-terminal launches and then you're given a free terminal input.) While mate-terminal is the only terminal I've tried that behaves like this, it's entirely possible it's not the only one.
An easy fix would be to blacklist mate-terminal (in fact, I'm about to submit a pull request for that), but that seems like a bit of a patch instead of a true fix. An attacker--even a malicious script--could use the same system calls that mate-terminal uses to gain a shell, and then what?
Cheers!
Fred
@netblue30 commented on GitHub (Apr 22, 2016):
Merged and fixed. This was a cool one! Thanks.
@Fred-Barclay commented on GitHub (Apr 22, 2016):
A friend (xenopeek on the Linux Mint forums) found several more terminals that can do this. I'm waiting on him to get back with me on something and then I'll have a new pull request blacklisting them. :)
EDIT: These are the terminals:
lilyterm
pantheon-terminal
roxterm
terminix
I've submitted a patching pull request. :)
@reinerh commented on GitHub (Apr 22, 2016):
rxvt-unicode also has a server mode. The client (urxvtc) for opening new windows should also be blacklisted.
@lepasserby commented on GitHub (Apr 22, 2016):
I wonder if this can be mitigated by some syscall filter or other (seccomp?)
@Fred-Barclay commented on GitHub (Apr 22, 2016):
I'm looking at that now (though this is a really bad time). I mean, we can blacklist all the terminals we want, but that's only patching things. A malicious script could use the same calls as mate-terminal or any of the others, and would work just fine since it's not actually calling mate-terminal.
@lepasserby commented on GitHub (Apr 24, 2016):
Okay, given that this has pretty far-reaching implications that go beyond mere terminal concern (one could craft a custom malicious file that won't fall under mate-terminal's "escape blacklist" while using same method) this issue, IMVHO, should be reopened.
@netblue30 ?
@netblue30 commented on GitHub (Apr 24, 2016):
The only way to get rid of this problem is a network namespace:
net=none would also do it for programs that have no network access. Another command would be --protocol where you leave out "unix" - this is handled by seccomp.
By blacklisting terminal programs we make it more difficult for an intruder to get access outside the sandbox. The guy would need to work hard to figure out how to connect to the socket and what data to send over it.
@Fred-Barclay commented on GitHub (Apr 24, 2016):
That's true (about blacklisting) but if any malicious third party is reading this thread... well, they won't have to guess as much. :) They'll know to avoid these terminals and will have a pretty good idea which system calls to use.
@lepasserby commented on GitHub (Apr 24, 2016):
Well, that sounds like a pretty solid mitigation right there, "critical need-to-know information" as Burt Gummer would have said :)
@netblue30 perhaps this should be added to manpage or some other prominent place?
Note to self: use network namespaces as much as possible
@ruany commented on GitHub (Apr 25, 2016):
I've looked further into this using strace.
This looks interesting:
Looks like it's forking a process using dbus, somehow.
Running firejail with "--blacklist=/run/user/1000/bus" prevents mate-terminal from launching, but other applications seem to work fine (assuming they don't use dbus).
I think something could be achieved if dbus-daemon itself is sandboxed more strictly than any other applications. This also goes for any other application that accepts IPC which could allow programs to escape jails. If they can only jump from one jail into another, more secure jail, then there is no point in escaping the jail in the first place.
@lepasserby commented on GitHub (Apr 25, 2016):
@ruany
Does the network namespace based mitigation work for you in this case? What would strace look like then ?
P.S.:
I jail linux-skype with firejail and network namespace, and occasionally get weird DBUS-related messages (everything works fine though), wonder if it's somehow related... Skype's a naughty little thing.
@ruany commented on GitHub (Apr 25, 2016):
@lepasserby
Doesn't seem to work if I use firejail's network namespaces (--net=eth0). A regular network namespace works though (ip netns exec). Only seems to work on one of my namespaces though, vpn works, empty namespace doesn't.
I suspect that the clone() system call is also involved here.
[pid 1192712] <... clone resumed> child_stack=0x7fe3477fddf0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7fe3477fe9d0, tls=0x7fe3477fe700, child_tidptr=0x7fe3477fe9d0) = 15Running "dbus-monitor" also gives some interesting results:
CloneCommand appears to be in /usr/include/X11/SM/SM.h, I could only find this by reading mate-terminal's source code, since it doesn't appear to be documented anywhere.
mate-terminal sends a CloneCommand and then a RestartCommand through dbus.
I'm not sure if sandboxing the user's dbus is actually a good idea, since this might also affect the user's terminals, unless firejail launched its own dbus instance for each application and blocked access for applications that don't use it.
I'm also not sure if the clone() syscall itself isn't the mechanism for escaping from jails, I don't have a way to test whether this is the case.
@lepasserby commented on GitHub (Apr 26, 2016):
@ruany
could you also try it for firejail's namespace with bridge interfaces only (--net=br1)?
My SOP now will _probably _ be confining programs to bridge interlaces and using iptables to get the traffic going in the right manner but I wanna make sure it works
@ruany commented on GitHub (Apr 26, 2016):
@lepasserby
It's simple to test that yourself, just run mate-terminal from inside the jail and then try to use a blacklisted command (e.g. ping)
Creating a bridge interface breaks my network and VPN setup, I use a veth device and NAT it through iptables. I used to use bridges for my VPN network namespace but that prevented applications from binding to a local port, so I switched to a NAT setup.
@netblue30 commented on GitHub (Apr 27, 2016):
I don't think I have a full solution for it, people will run into problems trying to set a network namespace, and it breaks dbus.
Maybe the best way to handle it is to use a terminal such as xterm or (KDE) konsole, and get rid of gnome-terminal, xfce-terminal, lxde-terminal and so on. This guys open a socket and accept bash commands over the socket from everybody. It is really bad, and no amount of grsecurity, selinux or firejail will ever fix it.