1、Java反序列化漏洞的挖掘html
一、黑盒流量分析:java
在Java反序列化傳送的包中,通常有兩種傳送方式,在TCP報文中,通常二進制流方式傳輸,在HTTP報文中,則大多以base64傳輸。於是在流量中有一些特徵:socket
(1)TCP:必有aced0005,這個16進制流基本上也意味者java反序列化的開始;ide
(2)HTTP:必有rO0AB,其實這就是aced0005的base64編碼的結果;函數
以上意味着存在Java反序列化,可嘗試構造payload進行攻擊。編碼
二、黑盒java的RMI:spa
rmi是java的一種遠程對象(類)調用的服務端,默認於1099端口,基予socket通訊,該通訊實現遠程調用徹底基於序列化以及反序列化。code
三、白盒代碼審計:htm
(1)觀察實現了Serializable接口的類是否存在問題。對象
(2)觀察重寫了readObject方法的函數邏輯是否存在問題。
2、Java反序列化的攻擊:
參見個人博客:
3、Java反序列化漏洞的防護:
一、類的白名單校驗機制:
實際上原理很簡單,就是對全部傳入的反序列化對象,在反序列化過程開始前,對類型名稱作一個檢查,不符合白名單的類不進行反序列化操做。很顯然,這個白名單確定是不存在Runtime的。
二、禁止JVM執行外部命令Runtime.exec
這個措施能夠經過擴展 SecurityManager 能夠實現。
1 SecurityManager originalSecurityManager = System.getSecurityManager(); 2 if (originalSecurityManager == null) { 3 // 建立本身的SecurityManager 4 SecurityManager sm = new SecurityManager() { 5 private void check(Permission perm) { 6 // 禁止exec 7 if (perm instanceof java.io.FilePermission) { 8 String actions = perm.getActions(); 9 if (actions != null && actions.contains("execute")) { 10 throw new SecurityException("execute denied!"); 11 } 12 } 13 // 禁止設置新的SecurityManager,保護本身 14 if (perm instanceof java.lang.RuntimePermission) { 15 String name = perm.getName(); 16 if (name != null && name.contains("setSecurityManager")) { 17 throw new SecurityException("System.setSecurityManager denied!"); 18 } 19 } 20 } 21 22 @Override 23 public void checkPermission(Permission perm) { 24 check(perm); 25 } 26 27 @Override 28 public void checkPermission(Permission perm, Object context) { 29 check(perm); 30 } 31 }; 32 33 System.setSecurityManager(sm); 34 }
4、參考文獻:
https://paper.seebug.org/312/