我喜欢Android App安全模型的一件事是,对于给定的应用程序,它向用户提供权限,而用户必须接受它们。这样做的好处是,用户可以控制它所运行的软件,并且是使用应用程序而无需授予应用程序过多访问权限而不必放弃使用该应用程序的宝贵工具。
幸运的是,就恶意软件而言,Linux世界是一个更加友好的环境。造成这种情况的一个重要原因是,软件由发行版程序包维护人员进行审核和策划。我建议 这个有趣的帖子 就此主题而言。
甚至最好的书面软件也可能包含可以利用的漏洞。随着诸如docker,flatpak或LXC之类的容器技术的出现,许多人建议使用它们将软件与系统的其余部分隔离开来,从而减轻可能的破坏的危害。
通过这种方式的沙箱软件,您可以对其功能进行更多的控制,从而有效地接近Android安全模型。
一些选择
嗯,容器在Linux上实际上不是一流的公民,因此只是个流行词。没有概念 容器 在Linux内核中。相反,容器是现有内核技术的巧妙组合,可帮助隔离系统的各个部分。的巨大贡献 容器技术 是为了更轻松地使用此Linux功能。还有其他我没有测试过的,例如 沙尘暴 和 运行.
码头工人
码头工人 是这种情况下最杰出的演员。尽管Docker安全性在过去几年中有了很大改善,但您可以使用它来运行包含的图形应用程序 通过安装X服务器插槽,要求docker守护程序更安全地运行firefox似乎是过大的选择。
在其他最近的安全性改进中,Docker现在支持 用户名称空间,允许映射 根 用户,以便容器内的特权进程在其外部以普通用户身份运行。
此外,随着docker守护进程与 根 特权,并且它是一个功能非常强大的软件,它只是提供沙箱就不必要地扩展了攻击面。一定有更好的方法。
泡沫包装
我们也可以看看 泡沫包装 来自ProjectAtomic。它源自 Flatpak 项目,并且与Docker相比,它被设计为由没有特权的用户进程运行,例如桌面应用程序。
这种软件是Flatpak项目的重点,而Docker是针对服务器,守护程序,云以及整个系统而设计的 IaaS 事情。
对于普通的,注重安全性的用户来说,似乎很难管理和设置。只需看一下(总是很棒的)Arch Wiki页面,然后 你自己看.
它是三个中最小的一个,在攻击面方面是有好处的。不利的一面是它不能涵盖所有内容,也不能尝试涵盖所有情况,因此在Pulseaudio,X11或DBus上不能很好地播放。泡泡纸设计师 认为这更安全,因此Flatpak试图使Wayland之类的软件能够识别沙箱。
简而言之,它不适用于所有软件。
火狱
最后,我要推荐Firejail,这是我个人使用的产品。它易于使用,易于安装和配置,并且带有一组非常好的常用软件配置文件。如果您想进步,它也有。
它试图覆盖所有软件,所以它要复杂得多。许多人认为这是一件坏事,因为保护复杂的SUID程序确实很困难。好处是它将可以轻松地与您当前使用的所有软件一起使用。
但是在我们学习如何使用它之前,让’s see how these “sandboxes” work.
How do 沙箱 work
如前所述,所谓的 货柜 仅使用一些现有的Linux功能。所有 容器技术 我知道以这些为基础。
Linux名称空间
Linux内核的概念是 命名空间。这些名称空间代表系统不同部分的不同视图。
例如,仅当两个进程同时运行 文件名称空间 他们将能够看到相同的文件和目录树,并能够访问相同的文件。其他名称空间中的文件将对它们不可见且不可访问。
Linux中有7个名称空间,例如 文件名称空间, 网络名称空间, cgroup命名空间, 用户名称空间, pid名称空间 等等。例如,我们可以让两个进程使用相同的网络接口,而又无法看到彼此(净 命名空间), 或对pid树或用户ID具有不同的视图(pid和uid 命名空间).
我们可以使用以下命令查看系统中可用的名称空间
$ ls /proc/self/ns cgroup ipc mnt 净 pid pid_for_children uts
Linux功能
传统上,Linux具有全功能的概念。 根 特权用户。该用户拥有无限的权力,可以访问系统的所有部分。即使由未特权用户运行,SUID程序也被允许具有所有这些特权。
尽管在某些情况下确实有此需要,但它也是危险和不必要的。例如,许多人会惊讶地发现简单 ping 命令需要访问 原始套接字 为了发送ICMP程序包。
Linux功能使我们能够改善这种黑白情况。我们可以限制 根 用户可以通过非正式设置来执行 能力。 诸如 wn 文件,忽略 数模转换器 权限,更改网络配置或终止进程可以针对给定进程单独确定。
这里 是功能的完整列表。例如,我们可以检查 ping 可执行 得到cap.
$ 得到cap /usr/bin/ping /usr/bin/ping = cap_net_raw+ep
沙箱通常使我们能够决定我们赋予特权进程哪些功能,从而提供了额外的控制级别。
Seccomp过滤器
即使我们不这样做,大多数用户空间进程也需要与内核进行交互’t realize it. 的re’程序在不访问文件,网络或标准输出的情况下可以做的很少的有趣事情。
用户空间程序通过以下方式使用内核功能 系统调用。有 超过300个系统调用 在Linux中。这些通常用于尝试利用内核错误和提升权限,不用说,大多数userland软件都不会这样做。’t need 所有 其中。
seccomp-bpf 是内核的一项功能,允许我们使用 BPF过滤器,以指定我们允许进程使用的系统调用。
如果程序是文本处理器,为什么需要访问网络?我们可以控制。
火狱的基本用法
现在我们了解了基础知识,让’s了解如何使用Firejail。
从发行版存储库安装软件包,即可开始使用。
如果要运行沙盒程序,只需在之后运行命令 火狱
$ 火狱 program_name
它支持一个时间标记,例如—seccomp 过滤系统调用,或 –private 为了甚至隐藏主文件夹的过程。
您要浏览私人广场吗?
$ 火狱 --private firefox --private window

要进行更精细的控制, 个人资料 可以使用配置文件,但是很少需要创建一个。 火狱随附了一组不错的预配置文件,您可以在其中找到 / etc / 火狱
ls / etc / 火狱/ 2.12 L ✓ 0ad.profile clementine.profile feh.profile google-chrome-unstable.profile konversation.profile neverball.profile seamonkey-bin.profile viewnior.profile 2048-qt.profile clipit.profile file-roller.profile google-chrome.profile ktorrent.profile nolocal.net seamonkey.profile viking.profile 7z.profile cmus.profile file.profile google-play-music-desktop-player.profile kwrite.profile nylas.profile server.profile vim.profile Cryptocat.profile conkeror.profile filezilla.profile gpa.profile leafpad.profile obs.profile silentarmy.profile virtualbox.profile Cyberfox.profile corebird.profile firefox-esr.profile gpg-agent.profile less.profile odt2txt.profile simple-scan.profile vivaldi-beta.profile FossaMail.profile cpio.profile firefox-nightly.profile gpg.profile libreoffice.profile okular.profile simutrans.profile vivaldi-stable.profile Gitter.profile cryptocat.profile firefox.profile gpicview.profile liferea.profile open-invaders.profile skanlite.profile vivaldi.profile Mathematica.profile curl.profile 火狱.config gpredict.profile localc.profile openbox.profile skype.profile vlc.profile Telegram.profile cvlc.profile flashpeak-slimjet.profile gtar.profile lodraw.profile openshot.profile skypeforlinux.profile vym.profile Thunar.profile cyberfox.profile flowblade.profile gthumb.profile loffice.profile opera-beta.profile slack.profile w3m.profile VirtualBox.profile darktable.profile fontforge.profile guayadeque.profile lofromtemplate.profile opera.profile smplayer.profile warzone2100.profile Wire.profile deadbeef.profile fossamail.profile gucharmap.profile login.users 要么 age.profile snap.profile waterfox.profile Xephyr.profile default.profile franz.profile gwenview.profile loimpress.profile palemoon.profile soffice.profile webserver.net Xvfb.profile deluge.profile frozen-bubble.profile gzip.profile lollypop.profile parole.profile soundconverter.profile weechat-curses.profile abrowser.profile dex2jar.profile gajim.profile handbrake-gtk.profile lomath.profile pcmanfm.profile spotify.profile weechat.profile akregator.profile dia.profile galculator.profile handbrake.profile loweb.profile pdfsam.profile sqlitebrowser.profile wesnoth.profile amarok.profile digikam.profile geany.profile hashcat.profile lowriter.profile pdftotext.profile ssh-agent.profile wget.profile android-studio.profile dillo.profile geary.profile hedgewars.profile luminance-hdr.profile peek.profile ssh.profile whitelist-common.inc apktool.profile dino.profile gedit.profile hexchat.profile lximage-qt.profile picard.profile start-tor-browser.profile wine.profile arduino.profile disable-common.inc geeqie.profile highlight.profile lxmusic.profile pidgin.profile steam.profile wire.profile ark.profile disable-devel.inc ghb.profile hugin.profile lxterminal.profile pingus.profile stellarium.profile Wireshark-gtk.profile arm.profile disable-passwdmgr.inc gimp-2.8.profile icecat.profile lynx.profile pithos.profile strings.profile Wireshark-qt.profile atom-beta.profile disable-programs.inc gimp.profile icedove.profile mate-calc.profile pix.profile supertux2.profile Wireshark.profile atom.profile display.profile 吉特.profile iceweasel.profile mate-calculator.profile pluma.profile synfigstudio.profile xchat.profile atool.profile dnscrypt-proxy.profile 吉特g.profile idea.sh.profile mate-color-select.profile polari.profile tar.profile xed.profile atril.profile dnsmasq.profile 吉特ter.profile img2txt.profile mate-dictionary.profile psi-plus.profile telegram-desktop.profile xfburn.profile audacious.profile dolphin.profile gjs.profile inkscape.profile mathematica.profile qbittorrent.profile telegram.profile xfce4-dict.profile audacity.profile dosbox.profile globaltime.profile inox.profile mcabber.profile e木-launcher.profile thunar.profile xfce4-notes.profile aweather.profile dragon.profile gnome-2048.profile iridium-browser.profile mediainfo.profile e木-system-x86_64.profile thunderbird.profile xiphos.profile baloo_file.profile dropbox.profile gnome-books.profile iridium.profile mediathekview.profile qlipper.profile torbrowser-launcher.profile xmms.profile baobab.profile ebook-viewer.profile gnome-calculator.profile itch.profile 融合.profile qpdfview.profile totem.profile xonotic-glx.profile bibletime.profile electron.profile gnome-chess.profile jd-gui.profile midori.profile qtox.profile tracker.profile xonotic-sdl.profile bitlbee.profile elinks.profile gnome-clocks.profile jitsi.profile minetest.profile quassel.profile transmission-cli.profile xonotic.profile bleachbit.profile emacs.profile gnome-contacts.profile k3b.profile mousepad.profile quiterss.profile transmission-gtk.profile xpdf.profile blender.profile empathy.profile gnome-documents.profile kate.profile mplayer.profile qupzilla.profile transmission-qt.profile xplayer.profile bless.profile enchant.profile gnome-font-viewer.profile kcalc.profile mpv.profile qutebrowser.profile transmission-show.profile xpra.profile brasero.profile engrampa.profile gnome-maps.profile keepass.profile multimc5.profile rambox.profile truecraft.profile xreader.profile brave.profile eog.profile gnome-mplayer.profile keepass2.profile mumble.profile ranger.profile tuxguitar.profile xviewer.profile caja.profile eom.profile gnome-music.profile keepassx.profile mupdf.profile remmina.profile uget-gtk.profile xz.profile calibre.profile epiphany.profile gnome-photos.profile keepassx2.profile mupen64plus.profile rhythmbox.profile unbound.profile xzdec.profile catfish.profile etr.profile gnome-twitch.profile keepassxc.profile musescore.profile riot-web.profile unknown-horizons.profile yandex-browser.profile cherrytree.profile evince.profile gnome-weather.profile kino.profile mutt.profile ristretto.profile unrar.profile youtube-dl.profile chromium-browser.profile evolution.profile goobox.profile kmail.profile nautilus.profile rtorrent.profile unzip.profile zathura.profile chromium.profile exiftool.profile google-chrome-beta.profile knotes.profile nemo.profile scribus.profile uudeview.profile zoom.profile claws-mail.profile fbreader.profile google-chrome-stable.profile kodi.profile 净surf.profile sdat2img.profile uzbl-browser.profile
总是摆在前面变得很麻烦 火狱 命令,因此您可以轻松地将系统配置为对您拥有配置文件的所有内容进行监视。命令
$ 须藤 firecfg Configuring symlinks in / usr / local / bin audacious created audacity created brasero created cvlc created display created dnsmasq created evince created feh created filezilla created firefox created ghb created gimp created gimp-2.8 created 吉特g created gthumb created img2txt created inkscape created k3b created keepassxc created less created libreoffice created localc created lodraw created loffice created lofromtemplate created loimpress created lomath created loweb created lowriter created 融合 created mplayer created pdftotext created pidgin created simple-scan created soffice created ssh created ssh-agent created strings created telegram-desktop created tracker created transmission-gtk created vlc created wget created Wireshark-gtk created
将在其中创建符号链接 / usr / local / bin 用于配置文件文件夹中存在的程序,以便firejail将其打开。
此外,它还具有桌面集成功能,以及一个名为 消防工具
您可以创建符号链接以将firejail与其他任何程序一起使用
$ 须藤 ln -s /usr/bin/firejail / usr / local / bin/<program name>
有时,您只想运行一次没有沙箱的程序。例如,您可能要使用 融合 在任意路径上。无需编辑配置文件,您只需找到二进制文件即可
$ which -a 融合 /usr/local/bin/meld /usr/bin/meld /usr/local/bin/meld /usr/bin/meld
,并且知道其中一个 / usr / local / bin 是符号链接,我们可以将其作为
$ /usr/bin/meld
火狱的高级用法
您可以检查沙盒中使用了哪些应用程序
$ 火狱 --list 738:nacho:firejail --list 26599:nacho:firejail /usr/bin/filezilla 30047:nacho:/usr/bin/firejail /usr/bin/keepassxc 31180:nacho:/usr/bin/firejail /usr/bin/firefox
同样,您可以使用以下命令检查沙箱中的进程
$ 火狱 --tree 2126:nacho:/usr/bin/firejail /usr/bin/firefox 2140:nacho:/usr/bin/firejail /usr/bin/firefox 2201:nacho:/usr/lib/firefox/firefox 2129:nacho:/usr/bin/firejail /usr/bin/mumble 2145:nacho:/usr/bin/firejail /usr/bin/mumble 2221:nacho:/usr/bin/mumble 2131:nacho:/usr/bin/firejail /usr/bin/thunderbird 2152:nacho:/usr/bin/firejail /usr/bin/thunderbird 2225:nacho:/usr/lib/thunderbird/thunderbird 3286:nacho:gpg-agent --homedir /home/nacho/.gnupg --use-standard-socket --daemon 2738:nacho:/usr/bin/firejail /usr/bin/keepassxc 2739:nacho:/usr/bin/firejail /usr/bin/keepassxc 2745:nacho:/usr/bin/keepassxc
或监视资源 –top 要么 –netstats
$firejail --top PID User RES(KiB) SHR(KiB) CPU% Prcs Uptime Command 26599 nacho 59236 44404 13.0 3 00:07:33 火狱 /usr/bin/filezilla 31180 nacho 761036 132316 12.0 3 00:02:14 火狱 /usr/bin/firefox 369 nacho 2192 1940 0.0 1 00:00:09 火狱 --top 30047 nacho 76340 56716 0.0 3 00:03:10 火狱 /usr/bin/keepassxc
您可以使用以下命令将文件复制到沙箱中或从沙箱中复制文件: –ls, –put 和 –get
$ 火狱 --name=mybrowser --private firefox $ 火狱 --ls=mybrowser ~/Downloads drwxr-xr-x 净blue 净blue 4096 . drwxr-xr-x 净blue 净blue 4096 .. -rw-r--r-- 净blue 净blue 7847 x11-x305.png -rw-r--r-- 净blue 净blue 6800 x11-x642.png -rw-r--r-- 净blue 净blue 34139 xpra-clipboard.png $ 火狱 --get=mybrowser ~/Downloads/xpra-clipboard.png $ 火狱 --put=mybrowser xpra-clipboard.png ~/Downloads/xpra-clipboard.png
您可以通过 –bandwidth (下载/上传80KBps / 20KBps)
火狱 --bandwidth=mybrowser set eth0 80 20
您甚至可以使用 –join,就像 码头工人 exec -ti容器bash
其他很酷的选择是 –disable-mnt 这是不言而喻的, –chroot=dirname 将安装 目录名 只读。
的 手册页 包含出色的信息。
玩弄
我们可以使用以下命令检查当前的名称空间
$ lsns NS TYPE NPROCS PID USER COMMAND 4026531835 cgroup 75 592 nacho /usr/lib/systemd/systemd --user 4026531836 pid 74 592 nacho /usr/lib/systemd/systemd --user 4026531838 uts 70 592 nacho /usr/lib/systemd/systemd --user 4026531839 ipc 74 592 nacho /usr/lib/systemd/systemd --user 4026531840 mnt 70 592 nacho /usr/lib/systemd/systemd --user 4026531993 净 75 592 nacho /usr/lib/systemd/systemd --user 4026532421 mnt 1 2201 nacho /usr/lib/firefox/firefox 4026532422 uts 1 2201 nacho /usr/lib/firefox/firefox 4026532423 pid 1 2201 nacho /usr/lib/firefox/firefox 4026532424 mnt 1 2221 nacho /usr/bin/mumble 4026532425 uts 1 2221 nacho /usr/bin/mumble 4026532426 pid 2 2221 nacho /usr/bin/mumble 4026532487 mnt 2 2225 nacho /usr/lib/thunderbird/thunderbird 4026532488 uts 2 2225 nacho /usr/lib/thunderbird/thunderbird 4026532489 pid 2 2225 nacho /usr/lib/thunderbird/thunderbird 4026532633 mnt 1 2266 nacho /usr/bin/ssh -Y xxxx@xxxxx.xxxx
,并提高了功能
$ pscap ppid pid name command capabilities 1 266 根 systemd-journal chown, dac_override, dac_read_search, fowner, setgid, setuid, sys_ptrace, sys_admin, audit_control, mac_override, syslog, audit_read 1 286 根 systemd-udevd full 1 431 根 systemd-logind chown, dac_override, dac_read_search, fowner, kill, sys_admin, sys_tty_config, audit_control, mac_admin 1 432 根 码头工人d full 1 441 根 login full 432 450 根 码头工人-containe full 1 732 rtkit rtkit-daemon dac_read_search, sys_ptrace, sys_nice 1 2984 根 udisksd full 450 4405 根 码头工人-containe full 4405 4423 根 bash chown, dac_override, fowner, fsetid, kill, setgid, setuid, setpcap, 净_bind_service, 净_raw, sys_chroot, mknod, audit_write, setfcap 15942 8107 根 须藤 full 8107 8122 根 wpa_supplicant full 1 10113 根 upowerd full 450 10710 根 码头工人-containe full 10710 10727 根 run.sh full 10727 10814 根 nginx full 10814 10815 根 nginx full 10814 10816 根 nginx full 10814 10817 根 nginx full 10814 10819 根 nginx full 10814 10820 根 nginx full 10814 10821 根 nginx full 10814 10822 根 nginx full 10814 10823 根 nginx full 10727 10830 根 php5-fpm full 10727 10834 根 nxlog full 10727 10835 根 ntpd full 10727 10837 根 mysqld full 10727 10842 根 sshd full 10727 10847 根 in.tftpd full 450 10925 根 码头工人-containe full 10925 10946 根 script full 10946 10953 根 sh full 10953 10954 根 bash full 1 17653 根 systemd-hostnam sys_admin 10727 18157 根 sleep full 450 21275 根 码头工人-containe full 21275 21291 根 bash chown, dac_override, fowner, fsetid, kill, setgid, setuid, setpcap, 净_bind_service, 净_raw, sys_chroot, mknod, audit_write, setfcap
显然,只有特权进程才最先具有功能,因此该列表上没有用户进程。
我们可以跑步 Wireshark 与 须藤 为了使其能够访问网络接口。这是一个坏主意:应该正确设置权限以避免这种情况,但是出于示例的考虑,我们将这样做
$ 须藤 /usr/bin/wireshark $ pscap | grep Wireshark 26219 26221 根 Wireshark-gtk full
我们可以将其与在沙箱中运行相比,将其删除的所有功能进行比较’t need
$ 须藤 火狱 Wireshark-gtk $ pscap | grep Wireshark 26803 26817 根 Wireshark-gtk dac_override, 净_admin, 净_raw
参考文献
对于更高级的配置选项,包括编写和审核配置文件,我通常参考以下站点。
//www.linux.com/news/understanding-and-securing-linux-namespaces
4 评论s