Ano*_*ror 0 java security reflection exploit
我可以获取受保护字段的值,但私有字段会抛出java.lang.IllegalAccessException.我想我知道为什么我会得到这个例外,但是如何使用反射来利用私有字段的内容,我该如何解决这个问题呢?
程序员帽是在
我已经在netbeans项目中创建了以下弱势类.我已经制作了一个Jar文件来分发它.
public class Vulnerable {
private int privateSecret;
protected int protectedSecret;
int secret;
public Vulnerable() {
this.protectedSecret = 11;
this.privateSecret = 22;
this.secret = 33;
}
}
Run Code Online (Sandbox Code Playgroud)
恶意黑客帽子现在开启
我想知道私人隐藏的领域,我想知道它们包含什么.
我有Jar文件,我已将其导入我的Exploit项目.
以下类扩展了Vulnerable并使用反射列出字段并尝试访问这些值.
public class ExpliotSubClass extends VulnerableCode.Vulnerable {
public List<Field> protectedList = new LinkedList<Field>();
public List<Field> privateList = new LinkedList<Field>();
public void lists() {
Field[] declaredFields = this.getClass().getSuperclass().getDeclaredFields();
for (Field field : declaredFields) {
int modifiers = field.getModifiers();
if (Modifier.isPrivate(modifiers)) {
privateList.add(field);
System.out.println("Private = " + field.getName());
} else if (Modifier.isProtected(modifiers)) {
protectedList.add(field);
System.out.println("Protected= " + field.getName());
}
}
}
public Object get(Field field) {
try {
return field.get(this);
} catch (IllegalArgumentException ex) {
Logger.getLogger(ExpliotSubClass.class.getName()).log(Level.SEVERE,
null,
ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(ExpliotSubClass.class.getName()).log(Level.SEVERE,
null,
ex);
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)