본문 바로가기
개인 공부/WEB

[웹해킹] dreamhack file-download

by 아메리카노와떡볶이 2021. 7. 26.
728x90
dreamhack file download

file download 취약점을 이용해서 flag.py를 다운받아야한다

 

문제 풀이

위와 같은 사이트에 접속되는데, 내 메모를 업로드 할 수 있게 구현되어있다. 임의로 hello.txt 파일을 업로드 해보았다.

 

이렇게 내가 만든 파일이 업로드된다.

파일을 읽어보면, 내가 만든 제목과 내용에 맞게 메모가 만들어져있고 url을 보면 name 변수에 get 방식으로 파일의 이름을 받고 있다.

flag.py를 다운로드 해야하기때문에 name변수에 flag.py를 써볼까 생각이 들었다.

안된다. 

문제 파일의 소스코드를 한번 살펴보자

def upload_memo():
    if request.method == 'POST':
        filename = request.form.get('filename')
        content = request.form.get('content').encode('utf-8')

        if filename.find('..') != -1:
            return render_template('upload_result.html', data='bad characters,,')

        with open(f'{UPLOAD_DIR}/{filename}', 'wb') as f:
            f.write(content)

        return redirect('/')

    return render_template('upload.html')

upload 의 코드를 살펴보면 .. 에 대한 필터링이 걸려있다. 처음에는 왜 ..에 필터링이 있나 생각했는데 살펴보니 메모를 업로드하면 uploads directory에 올라가게 된다. 근데 flag.py는 uploads에 있는게 아니라 상위폴더에 있기때문에 ../ 키워드가 쓰이게 되는데 upload 에서 그걸 필터링 한 것이다.

하지만 read 부분을 보면

def read_memo():
    error = False
    data = b''

    filename = request.args.get('name', '')

    try:
        with open(f'{UPLOAD_DIR}/{filename}', 'rb') as f:
            data = f.read()
    except (IsADirectoryError, FileNotFoundError):
        error = True


    return render_template('read.html',
                           filename=filename,
                           content=data.decode('utf-8'),
                           error=error)

필터링이 따로 없는 모습이다. 따라서 아까 name에 flag.py 가 아니라 ../flag.py를 줘보자

 

플래그 획득 성공

728x90

'개인 공부 > WEB' 카테고리의 다른 글

burp suite로 nikto 동작 살펴보기 -1  (0) 2022.11.12
beautiful soup을 활용한 웹 스크래핑  (0) 2022.03.07
[웹해킹] dreamhack image-storage  (0) 2021.07.26
[웹해킹] dreamhack php-1  (0) 2021.07.26
[웹해킹] dreamhack cookie  (1) 2021.07.26

댓글