Skip to content

Instantly share code, notes, and snippets.

@lichengwu
Last active January 4, 2016 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lichengwu/8644806 to your computer and use it in GitHub Desktop.
Save lichengwu/8644806 to your computer and use it in GitHub Desktop.
利用反射,攻击JVM

Java中,Integer,Long等都是有-127~128的缓存的,利用反射: 可以达到攻击目的

Field value = Integer.class.getDeclaredField("value");
value.setAccessible(true);
value.set(42, 43);

同样,String这个“不变”对象也可以:

Field value = String.class.getDeclaredField("value");
 value.setAccessible(true);
 value.set("hello!", "cheers".toCharArray());
 System.out.println("hello!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment