文/Yue CHEN
地址空間布局隨機化(ASLR)增強研究綜述
文/Yue CHEN
Address Space Layout Randomization (ASLR) 是什么?一些攻擊,比如returnoriented programming (ROP)之類的代碼復用攻擊,會試圖得到被攻擊者的內存布局信息。這樣就可以知道代碼或者數據放在哪里,來定位并進行攻擊。比如可以找到ROP里面的gadget。而ASLR讓這些內存區域隨機分布,來提高攻擊者成功難度,讓他們只能通過猜測來進行不斷試錯的攻擊(理想狀況下),圖1為ASLR示例。
在出現了某些漏洞,比如內存信息泄露的情況下,攻擊者會得到部分內存信息,比如某些代碼指針。傳統的ASLR只能隨機化整個segment,比如棧、堆、或者代碼區。這時攻擊者可以通過泄露的地址信息來推導別的信息,如另外一個函數的地址等。這樣整個segment的地址都可以推導出來,進而得到更多信息,如圖2所示,大大增加了攻擊利用的成功率。在32位系統中,由于隨機的熵值不高,攻擊者也容易通過窮舉法猜出地址。

圖1 ASLR示例

圖2 目前ASLR的問題
主要的改進方法有兩種:一是防止內存信息泄露,二是增強ASLR本身。本文主要討論后者。
1.隨機化的粒度可以改進。粒度小了,熵值增加,就很難猜出ROP gadget之類的內存塊在哪里。ASLP[1]在函數級進行隨機化,binary stirring[2]在basic block級進行隨機化,ILR[3]和IPR[4]在指令級。[3]將指令地址進行隨機化;而[4]把指令串進行重寫,來替換成同樣長度,并且相同語義的指令串。
2.隨機化的方式可以改進。Oxymoron[5]解決了庫函數隨機化的重復問題: 原先假如每個進程的library都進行fine-grained的ASLR,會導致memory開銷很大。該文用了X86的segmentation巧妙地解決了這個問題;并且由于其分段特性,JITROP[6]之類的攻擊也很難有效讀取足夠多的memory。Isomeron[7]利用兩份differently structured but semantically identical的程序copy,在ret的時候來隨機化execution path,隨機決定跳到哪個程序copy,有極大的概率可以讓JIT-ROP攻擊無效。
3.隨機化的時間(timing)可以改進。假如程序中存在能泄露內存的漏洞,那這種傳統的、一次性的隨機化就白費了。所以需要運行時動態ASLR。[8]解決了fork出來的子進程內存布局和父進程一樣的缺陷。其思路是在每次fork時都進行一次隨機化。方法是用Pin進行taint跟蹤,找到ASLR之后要修復的指針并進行修復。為了降低把數據當成指針的false positive,一個daemon進程會跑多次來提取出重合的部分。

圖3 Remix:一種ASLR增強的方向
Remix[9]提出了一種在運行時細粒度隨機化的方法。該方法以basic block為單位,經過一個隨機的時間對進程(或kernel module)本身進行一次隨機化,如圖3所示。由于函數指針很難完全確認(比如被轉換成數據,或者是union類型),該方法只能打亂函數內部的basic blocks。該方法的另一個好處是保留了代碼塊的局部性(locality),因為被打亂的basic blocks位置都靠得很近。打亂后,需要update指令,以及指向basic block的指針,來讓程序繼續正確運行。假如需要增加更多的熵值,可以在basic blocks之間插入更多的NOP指令(或者別的garbage data)。
另一種方法[10]是用編譯器來幫助定位要migrate的內存位置(指針),并且在每次有輸出時進行動態隨機化。該方法對于網絡應用比如服務器,由于其是I/ O-intensive的應用,可能會導致隨機化間隔極短而性能開銷巨大。
(作者單位為Florida State University)
[1] C. Kil, J. Jun, C. Bookholt, J. Xu, and P. Ning. Address Space Layout Permutation (ASLP): Towards Fine-Grained Randomization of Commodity Software. In Proceedings of the 22nd Annual Computer Security Applications Conference, 2006.
[2] R. Wartell, V. Mohan, K. W. Hamlen, and Z. Lin. Binary Stirring: Self-randomizing Instruction Addresses of Legacy x86 Binary Code. In Proceedings of the 19th ACM Conference on Computer and Communications Security, 2012.
[3] J. Hiser, A. Nguyen-Tuong, M. Co, M. Hall, and J. W. Davidson. ILR: Where'd My Gadgets Go? In Proceedings of the 33rd IEEE Symposium on Security and Privacy, 2012.
[4] V. Pappas, M. Polychronakis, and A. D. Keromytis. Smashing the Gadgets: Hindering Return-Oriented Programming Using In-place Code Randomization. In Proceedings of the 33rd IEEE Symposium on Security and Privacy, 2012.
[5] M. Backes and S. Nurnberger. Oxymoron: Making fine-grained memory randomization practical by allowing code sharing. In Proceedings of the 23rd USENIX Security Symposium, 2014.
[6] K. Z. Snow, F. Monrose, L. Davi, A. Dmitrienko, C. Liebchen, and A.-R. Sadeghi. Just-in-time Code Reuse: On the Effectiveness of Fine-grained Address Space Layout Randomization. In Proceedings of the 34th IEEE Symposium on Security and Privacy, 2013.
[7] L. Davi, C. Liebchen, A.-R. Sadeghi, K. Z. Snow, and F. Monrose. Isomeron: Code randomization resilient to (just-intime) return-oriented programming. In Proceedings of the 22nd Network and Distributed Systems Security Symposium, 2015.
[8] K. Lu, S. Nurnberger, M. Backes and W. Lee. How to Make ASLR Win the Clone Wars: Runtime Re-Randomization. In Proceedings of the 23rd Network and Distributed Systems Security Symposium, 2016.
[9] Y. Chen, Z. Wang, D. Whalley and L. Lu. Remix: On-demand live randomization. In Proceedings of the Sixth ACM Conference on Data and Application Security and Privacy, 2016.
[10] D. Bigelow, T. Hobson, R. Rudd, W. Streilein, and H. Okhravi. Timely rerandomization for mitigating memory disclosures. In ACM SIGSAC Conference on Computer and Communications Security, 2015.