用 try 來看檔案系統的改變

Hacker News Daily 上看到這則:「Try: run a command and inspect its effects before changing your live system (github.com/binpash)」,這是一個 GitHub 專案:「binpash/try」。

整包軟體意外的簡單,是一隻 shell script,透過 OverlayFS 取得改變的部分:

try lets you run a command and inspect its effects before changing your live system. try uses Linux's namespaces (via unshare) and the overlayfs union filesystem.

記得 OverlayFS 在 Docker 用的很多,所以穩定性應該是沒什麼問題,不過專案開頭也有提到,這只是把 filesystem 層拆出來,不是很嚴謹的 sandbox 環境,像是 /dev 這邊的東西還是有穿透性,不要跑不信任的程式:

Please note that try is a prototype and not a full sandbox, and should not be used to execute commands that you don't already trust on your system, (i.e. devices in /dev are mounted in the sandbox, and network calls are all allowed.) Please do not attempt any commands that will remove everything in /dev or write zeros to your disks.

我覺得這個很適合拿來跑各種 install.sh 這種東西?有些 install.sh 不知道塞了多少垃圾 (像是 .bashrc 或是 .profile 都有可能會被動),可以知道有哪些檔案要清會比較好。

把裡面的 try 這個檔案丟到自己的可執行目錄就裝好了,像是 ~/.local/bin 或是 ~/bin 之類的地方,看你的 $PATH 設定決定。

另外也可以從 subcommands 裡面的指令看到你可以用 try explore 啟動 shell 跑進去看:

Subcommands:
  try summary DIR   show the summary for the overlay in DIR
  try commit DIR    commit the overlay in DIR
  try explore DIR   start a shell inside the overlay in DIR

GitHub 上面的範例是用 pip 示範,同樣道理應該也可以看 npm 與其他套件。

用 Flatpak 跑 Zoom,限制 Zoom 的存取

昨天在 Hacker News Daily 上看到的討論,有人發現 ZoomLinux 版掃了所有 process 的資訊:「Ask HN: Why does Zoom Desktop examine all processes and arguments?」。

twic 給了個建議,用 Flatpak 在 sandbox 裡面跑 Zoom:

I run Zoom from flatpak, which runs it in a container, and sandboxes it to some extent [1]

This probably explains why, when i try to screenshare a single application window, not every application shows up! I can share my browser, file manager, and various other things, but not windows for games started by Steam.

[1] I followed these instructions https://www.mayrhofer.eu.org/post/zoom-flatpak-sandboxing/

測了一下沒什麼問題,應用程式安裝完後可以直接用 flatpak run us.zoom.Zoom 跑,但如果想要直接在 launch menu 叫出來的話 (在 Xfce 叫 whiskermenu),需要重開機 (看起來至少要 relogin)。

應該就會先暫時這樣,稍微擋一些 Zoom 可以看到的資訊。而且 Zoom 本身的安裝一直都沒有更新機制,透過 flatpak 包起來反而可以跑 flatpak update 更新,目前感覺應該是 Z >> B...

Sandboxie 決定開源

Sandboxie 目前是 Sophos 旗下的產品,主要的功能是在 Windows 下產生一個獨立的環境 (沙箱) 執行某些應用程式,而這些應用程式的變更雖然會被記錄起來,但不會影響到系統本體,所以先前也買了一套起來拿來跑一些程式...

剛剛看到消息提到 Sandboxie 決定要 open source:

Sophos is excited to announce that we are making Sandboxie a free tool, with plans to transition it to an open source tool.

然後目前看起來還在整理程式碼,在整理完之前會直接先解放目前的版本,讓所有功能都免費使用:

Until the open source transition is completed we have decided to make all restricted features of Sandboxie completely free.

不過沒看懂 open source 的原因...

Google 推出 gVisor 強化 Container 的安全性

Google 發表了 gVisor,針對 Linux 所使用的 container 技術強化安全的部份:「Open-sourcing gVisor, a sandboxed container runtime」。

依照 Google 的說法,一般 container 的架構是這樣:

而具有強隔離性的 VM 技術則是這樣:

在 VM 的 overhead 偏重,但一般的 container 安全性又不夠。而 gVisor 則是這樣:

對於目前最常見的 Docker 系統上,在安裝 gVisor 後只需要指定 --runtime=runsc 就可以使用 (預設是 --runtime=runc),像是這樣:

$ docker run --runtime=runsc hello-world
$ docker run --runtime=runsc -p 3306:3306 mysql

其中 runsc 的意思是「run Sandboxed Container」。

另外而因為 gVisor 卡在中間,不認識的 syscall 都會被擋下來,所以目前並不是所有的應用程式都可以跑,但開發團隊已經測了不少應用程式可以在上面運作,算是堪用的程度:

gVisor implements a large part of the Linux system API (200 system calls and counting), but not all. Some system calls and arguments are not currently supported, as are some parts of the /proc and /sys filesystems. As a result, not all applications will run inside gVisor, but many will run just fine, including Node.js, Java 8, MySQL, Jenkins, Apache, Redis, MongoDB, and many more.

值得一提的是,雖然是處理 syscall,但是是用 Go 開發的,而不是 C 或是 C++,這點頗特殊的...

Firefox 48 將引入 Multi-process 模式

現在是 Firefox 47,也就是下個版本就會引入 Multi-process 模式了:「Firefox 48 finally enables Electrolysis for multi-process goodness」。

Multi-process 模式也就是 Electrolysis,這對權限的分離 (sandbox) 以及效能的提昇有著顯著的幫助:

Electrolysis functionality hosts, renders, or executes web related content in background child processes which communicate with the "parent" Firefox browser via various ipdl protocols. The two major advantages of this model are security and performance. Security improvements are accomplished through security sandboxing, performance improvements are born out of the fact that multiple processes better leverage available client computing power.

這算是個開頭,地基打出來以後,之後就可以拆更多東西到其他的 child process。

把 Google Chrome 預設的 JavaScript 關閉,開白名單...

就如同標題寫得,把 Google Chrome 的 JavaScript 關閉,然後開白名單,這樣的好處有不少:

  • 大幅增加載入的速度:即使用了 Ghostery,還是有不少 JavaScript 的程式被執行到。
  • 增加網站安全性:雖然 Google Chrome 的 sandbox 不算差,但完全不要跑 JavaScript 可以擋下很多安全性問題。
  • 對 anti-adblock 機制的抵抗力:意外的發現不少 anti-adblock 機制都是透過 JavaScript 偵測,而這個方法直接擋下來了。
  • 對 infinite-scrolling 機制的抵抗力:有不少新聞網站拉到最底端會自動讀取相關的新聞 (或是類似的機制),我其實很不喜歡這樣的機制... 直接省下來 XD

另外就是透過 Google Chrome 本身的同步機制,其實可以設一次所有機器都生效,不算太麻煩。沒意外的話應該會一直用下去...

AWS Lambda 的本地端測試工具

Twitter 上看到的工具:「Run AWS Lambda Functions on your local computers, for testing purposes」。可以在本地端測試 AWS Lambda 的程式碼:

在瀏覽器上面用 JavaScript 進行 Side-channel attack

用 JavaScript 就可以攻擊 L3 cache,進而取得資料:「JavaScript CPU cache snooper tells crooks EVERYTHING you do online」。

論文出自「The Spy in the Sandbox – Practical Cache Attacks in Javascript」(PDF) 這篇。

不需要任何外掛或 exploit,就純粹是利用 cache 反應時間的 side-channel attack。另外由於 AMD 的 cache 架構不同,這次的攻擊實作僅對 Intel 有效:

The Intel cache micro-architecture isinclusive– all elements in the L1 cache must also exist in the L2 and L3 caches. Conversely, if a memory element is evicted fromthe L3 cache, it is also immediately evicted from the L2 and L1 cache. It should be noted that the AMD cachemicro-architecture is exclusive, and thus the attacks described in this report are not immediately applicable tothat platform.

這次的攻擊方法真變態...

Rowhammer Bug:攻擊記憶體的值...

GoogleProject Zero 實做 Rowhammer Bug:「Exploiting the DRAM rowhammer bug to gain kernel privileges」。

開頭就很科幻:

“Rowhammer” is a problem with some recent DRAM devices in which repeatedly accessing a row of memory can cause bit flips in adjacent rows.

然後就提到實做了:

We tested a selection of laptops and found that a subset of them exhibited the problem. We built two working privilege escalation exploits that use this effect.

給出了 NaCl sandbox escape 與 Kernel privilege escalation 兩種方式。

這頭快炸了...

iframe 的 sandbox 功能...

在「Play safely in sandboxed IFrames」這篇文章提到 HTML5 有對 iframe 制定 sandbox 屬性,這可以讓開發者比較容易處理安全性問題。

比較讓我驚訝是開頭的 browser support 清單是主流全部支援,但又沒寫版號:

不過實際到「Can I use sandbox attribute for iframes?」查,發現沒那麼美好 XD

主要的瀏覽器中,IE 要到 10 才有支援,另外 Firefox 剛支援沒多久 (17 以及之後的版本,目前是 18),看起來要等 Windows 7 的 IE8 被淘汰?