攻擊者能夠建立一個在開發者意料之外的、不可預測的控制流程,貫穿應用程序始終。
這種形式的攻擊能夠使得攻擊者避開身份鑒定,或者訪問控制檢測,或者使得應用程序以一種意料之外的方式運行。
如果攻擊者能夠將文件上傳到應用程序的classpath或者添加一個classpath的新入口,那么這將導致應用程序陷入完全的困境。
無論是上面哪種情況,攻擊者都能使用反射將新的、多數情況下惡意的行為引入應用程序。
應對措施:
開發者可以定制一份白名單,通過關鍵字關聯需要實例化的類,http請求中傳遞是不是實際的類名,而是關鍵字,開發者得到關鍵字后在白名單中尋找需要的信息,進行實例化。
一開始看到上面的解釋我也是感覺比較抽象,很難理解。讓我們先看下面這一段代碼:
1 public static Map<String, Object> beanToMap(Object obj) { 2 3 if (obj == null) { 4 return null; 5 } 6 Map<String, Object> map = new HashMap<String, Object>(); 7 try { 8 BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass()); 9 PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); 10 for (PropertyDescriptor property : propertyDescriptors) { 11 String key = property.getName(); 12 // 過濾class屬性 13 if (!key.equals("class")) { 14 // 得到property對應的getter方法 15 Method getter = property.getReadMethod(); 16 Object value = getter.invoke(obj); 17 map.put(key, value); 18 } 19 20 } 21 } catch (Exception e) { 22 23 logger.error("transBean2Map Error ", e); 24 } 25 return map; 26 }