文/Yue CHEN
地址空間布局隨機(jī)化(ASLR)增強(qiáng)研究綜述
文/Yue CHEN
Address Space Layout Randomization (ASLR) 是什么?一些攻擊,比如returnoriented programming (ROP)之類的代碼復(fù)用攻擊,會(huì)試圖得到被攻擊者的內(nèi)存布局信息。這樣就可以知道代碼或者數(shù)據(jù)放在哪里,來(lái)定位并進(jìn)行攻擊。比如可以找到ROP里面的gadget。而ASLR讓這些內(nèi)存區(qū)域隨機(jī)分布,來(lái)提高攻擊者成功難度,讓他們只能通過猜測(cè)來(lái)進(jìn)行不斷試錯(cuò)的攻擊(理想狀況下),圖1為ASLR示例。
在出現(xiàn)了某些漏洞,比如內(nèi)存信息泄露的情況下,攻擊者會(huì)得到部分內(nèi)存信息,比如某些代碼指針。傳統(tǒng)的ASLR只能隨機(jī)化整個(gè)segment,比如棧、堆、或者代碼區(qū)。這時(shí)攻擊者可以通過泄露的地址信息來(lái)推導(dǎo)別的信息,如另外一個(gè)函數(shù)的地址等。這樣整個(gè)segment的地址都可以推導(dǎo)出來(lái),進(jìn)而得到更多信息,如圖2所示,大大增加了攻擊利用的成功率。在32位系統(tǒng)中,由于隨機(jī)的熵值不高,攻擊者也容易通過窮舉法猜出地址。
圖1 ASLR示例
圖2 目前ASLR的問題
主要的改進(jìn)方法有兩種:一是防止內(nèi)存信息泄露,二是增強(qiáng)ASLR本身。本文主要討論后者。
1.隨機(jī)化的粒度可以改進(jìn)。粒度小了,熵值增加,就很難猜出ROP gadget之類的內(nèi)存塊在哪里。ASLP[1]在函數(shù)級(jí)進(jìn)行隨機(jī)化,binary stirring[2]在basic block級(jí)進(jìn)行隨機(jī)化,ILR[3]和IPR[4]在指令級(jí)。[3]將指令地址進(jìn)行隨機(jī)化;而[4]把指令串進(jìn)行重寫,來(lái)替換成同樣長(zhǎng)度,并且相同語(yǔ)義的指令串。
2.隨機(jī)化的方式可以改進(jìn)。Oxymoron[5]解決了庫(kù)函數(shù)隨機(jī)化的重復(fù)問題: 原先假如每個(gè)進(jìn)程的library都進(jìn)行fine-grained的ASLR,會(huì)導(dǎo)致memory開銷很大。該文用了X86的segmentation巧妙地解決了這個(gè)問題;并且由于其分段特性,JITROP[6]之類的攻擊也很難有效讀取足夠多的memory。Isomeron[7]利用兩份differently structured but semantically identical的程序copy,在ret的時(shí)候來(lái)隨機(jī)化execution path,隨機(jī)決定跳到哪個(gè)程序copy,有極大的概率可以讓JIT-ROP攻擊無(wú)效。
3.隨機(jī)化的時(shí)間(timing)可以改進(jìn)。假如程序中存在能泄露內(nèi)存的漏洞,那這種傳統(tǒng)的、一次性的隨機(jī)化就白費(fèi)了。所以需要運(yùn)行時(shí)動(dòng)態(tài)ASLR。[8]解決了fork出來(lái)的子進(jìn)程內(nèi)存布局和父進(jìn)程一樣的缺陷。其思路是在每次fork時(shí)都進(jìn)行一次隨機(jī)化。方法是用Pin進(jìn)行taint跟蹤,找到ASLR之后要修復(fù)的指針并進(jìn)行修復(fù)。為了降低把數(shù)據(jù)當(dāng)成指針的false positive,一個(gè)daemon進(jìn)程會(huì)跑多次來(lái)提取出重合的部分。
圖3 Remix:一種ASLR增強(qiáng)的方向
Remix[9]提出了一種在運(yùn)行時(shí)細(xì)粒度隨機(jī)化的方法。該方法以basic block為單位,經(jīng)過一個(gè)隨機(jī)的時(shí)間對(duì)進(jìn)程(或kernel module)本身進(jìn)行一次隨機(jī)化,如圖3所示。由于函數(shù)指針很難完全確認(rèn)(比如被轉(zhuǎn)換成數(shù)據(jù),或者是union類型),該方法只能打亂函數(shù)內(nèi)部的basic blocks。該方法的另一個(gè)好處是保留了代碼塊的局部性(locality),因?yàn)楸淮騺y的basic blocks位置都靠得很近。打亂后,需要update指令,以及指向basic block的指針,來(lái)讓程序繼續(xù)正確運(yùn)行。假如需要增加更多的熵值,可以在basic blocks之間插入更多的NOP指令(或者別的garbage data)。
另一種方法[10]是用編譯器來(lái)幫助定位要migrate的內(nèi)存位置(指針),并且在每次有輸出時(shí)進(jìn)行動(dòng)態(tài)隨機(jī)化。該方法對(duì)于網(wǎng)絡(luò)應(yīng)用比如服務(wù)器,由于其是I/ O-intensive的應(yīng)用,可能會(huì)導(dǎo)致隨機(jī)化間隔極短而性能開銷巨大。
(作者單位為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.