BypassIF

2026. 2. 9. 00:48·Dreamhack 워게임/Lv.1
반응형

문제설명

Admin의 KEY가 필요합니다! 알맞은 KEY값을 입력하여 플래그를 획득하세요.

 

플래그 형식은 DH{...} 입니다.


코드 분석

KEY = hashlib.md5(FLAG.encode()).hexdigest()
guest_key = hashlib.md5(b"guest").hexdigest()
  • 키와 guest_key정의
def filter_cmd(cmd):
    alphabet = list(string.ascii_lowercase)
    alphabet.extend([' '])
    num = '0123456789'
    alphabet.extend(num)
    command_list = ['flag','cat','chmod','head','tail','less','awk','more','grep']

    for c in command_list:
        if c in cmd:
            return True
    for c in cmd:
        if c not in alphabet:
            return True
  • a ~ z 소문자만 허용 그리고 0 ~ 9까지 숫자만 허용
  • flag, cat, chmod, head, tail, less, awk, more, grep 특정 문자열만 허용
@app.route('/flag', methods=['POST'])
def flag():
     # POST request
    if request.method == 'POST':
        key = request.form.get('key', '')
        cmd = request.form.get('cmd_input', '')
        if cmd == '' and key == KEY:
            return render_template('flag.html', txt=FLAG)
        elif cmd == '' and key == guest_key:
            return render_template('guest.html', txt=f"guest key: {guest_key}")
        if cmd != '' or key == KEY:
            if not filter_cmd(cmd):
                try:
                    output = subprocess.check_output(['/bin/sh', '-c', cmd], timeout=5)
                    return render_template('flag.html', txt=output.decode('utf-8'))
                except subprocess.TimeoutExpired:
                    return render_template('flag.html', txt=f'Timeout! Your key: {KEY}')
                except subprocess.CalledProcessError:
                    return render_template('flag.html', txt="Error!")
            return render_template('flag.html')
        else:
            return redirect('/')
    else: 
        return render_template('flag.html')
  • key와 cmd_input을 이용자로부터 입력받음
  • cmd가 공백이고 key가 KEY라면 FLAG 나옴
  • cmd가 공백이고 key가 Guest_key 라면 guest.html 반환하고 내용은 guest_key
  • cmd 공백이 아니거나 key=Key일 때
    • 시간 안에 나오면 flag.html 반환
    • 시간아웃되면 KEY 반환
    • Error발생 시 Error 출력

취약점분석

  • 문자열을 특정 문자만 필터링함
  • 조건에서 or 로 잘못 설정해 KEY 노출이 됨

익스플로잇

이번 문제를 풀기 위해 Burpsuite을 이용하겠다.

먼저 문제화면을 보면 key 입력칸 밖에 없다.

key에 아무거나 입력해보자

aaa를 입력했는데 인덱스 화면으로 넘어가는 것을 확인할 수 있다.

요청 응답을 살펴보면 key에 aaa를 입력하고 받은 응답 내용을 확인할 수 있다.

 

근데 코드에선 cmd_input도 입력 받는다고 했다. 요청 내용을 수정해보자

  • key=aaa 내용을 cmd_input=ls로 변경했더니 flag.html을 반환하는 것을 볼 수 있다.

그다음 timeout이 되면 KEY를 반환한다고 했으니 Sleep 10으로 10초 동안 지연을 시켜보자.

key를 획득했다 이걸로 로그인을 하면 Flag를 획득할 수 있다.

반응형

'Dreamhack 워게임 > Lv.1' 카테고리의 다른 글

baby-Case  (0) 2026.02.09
simple-phparse  (0) 2026.02.09
Type c-j  (0) 2026.02.08
baby-union  (0) 2026.02.08
amocafe  (0) 2026.02.08
'Dreamhack 워게임/Lv.1' 카테고리의 다른 글
  • baby-Case
  • simple-phparse
  • Type c-j
  • baby-union
y3onbug5
y3onbug5
y3onbug5 님의 블로그 입니다.
  • y3onbug5
    y3onbug5 님의 블로그
    y3onbug5
  • 전체
    오늘
    어제
    • 분류 전체보기 (167) N
      • Alpacahack (19) N
      • Dreamhack 워게임 (49)
        • Lv.1 (40)
        • Lv.0 (4)
        • LV.2 (3)
        • LV.3 (2)
      • [Dreamhack] Web Beginner (3)
      • [Dreamhack] Web Hacking (17)
        • 웹 기초 지식 (4)
        • Cookie & Session (2)
        • Cross-Site Scripting(XSS) (1)
        • Cross-Site Request Forgery (1)
        • SQL Injection (4)
        • NoSQL Injection (2)
        • Command Injection (1)
        • File Vulnerability (1)
        • Server-Side Request Forgery (1)
      • [Dreamhack] Web Hacking Client-Side (10)
        • XSS Filtering Bypass (2)
        • Content Security Policy (CSP) (2)
        • CSRF,CORS Bypass (2)
        • Client-Side Template Injection (CSTI) (1)
        • CSS Injection (1)
        • Relative Path Overwrite (RPO) (1)
        • DOM Vulnerability (1)
      • [Dreamhack] Web Hacking Server-Side (15)
        • SQL Injection Advanced (4)
        • SQL Injection Advanced - Fingerprinting (2)
        • NoSQL Injection Advanced (3)
        • Command Injection Advanced - Web Servers (3)
        • File Vulnerability Advanced - Web Server (3)
      • [Dreamhack]Black-Box Penetration Testing (15)
        • DreamCommunity Penetration Testing (11)
      • [Dreamhack] LLM (2)
        • [Dreamhack] LLM과 프롬프트 엔지니어링 (2)
      • Web 공부 (4)
      • Web Study (15)
      • JavaScript (17)
        • 기초 (12)
        • 중급 (4)
      • 웹 개발(Flask) (0)
      • [Security First] web 기초교육 (1) N
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    webstudy
    DreamHack
    드림핵
    CSRF
    xss
    webhacking
    web
    alpacahack
    hacking
    LLM
    cve
    JS
    JavaScript
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
y3onbug5
BypassIF
상단으로

티스토리툴바