File-Download

2026. 6. 11. 13:09카테고리 없음

File Download 취약점이 존재하는 웹 서비스이다.

flag.py 다운로드 받으면 되는 문제이다.

 

 

1.코드분석

 

  • /upload (파일 생성): filename.find('..') != -1을 사용하여 .. 문자가 포함되어 있으면 강제로 차단한다.
  • /read (파일 읽기): filename을 검증하는 로직이 아예 없다.

 

@APP.route('/upload', methods=['GET', 'POST'])
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')


@APP.route('/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)

 

 

2.검증

1.)메모를 업로드 하는 페이지( /upload)

 

-/upload경로는    ../ 문자로 인하여 필터링이 된다.

 

 

 

2)메모를 읽는 페이지( /read)

 

-메모 읽는 페이지에서 아무런 메모를 클릭한다.

 

 

-name파라미터에  ../flag.py로 수정하여 요청한다. 

 

 

-flag.py값이 출력된다.