baby-linux

2023. 8. 18. 11:34· 보안/Dreamhack
반응형
  • Level 1

    • Baby-Linux

Untitled.png

#!/usr/bin/env python3
import subprocess
from flask import Flask, request, render_template

APP = Flask(__name__)

@APP.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        user_input = request.form.get('user_input')
        cmd = f'echo $({user_input})'
        if 'flag' in cmd:
            return render_template('index.html', result='No!')

        try:
            output = subprocess.check_output(['/bin/sh', '-c', cmd], timeout=5)
            return render_template('index.html', result=output.decode('utf-8'))
        except subprocess.TimeoutExpired:
            return render_template('index.html', result='Timeout')
        except subprocess.CalledProcessError:
            return render_template('index.html', result='Error')

    return render_template('index.html')

if __name__ == '__main__':
    APP.run(host='0.0.0.0', port=8000)

Untitled.png

  • echo $() <- input 태그에 입력값이 들어오고 그 입력값으로 /bin/sh 의 경로에 있는 배시셀이 작동됨
  • 만약에 입력된 값에서 “flag” 라는 값이 들어있으면 result에 No!라는 값으로 대치됨.
  • 문제에서 “flag.txt” 라는 파일명이 제시되어있기 때문에 find 명령을 통해 txt 확장자의 파일들을 찾아주었음.

Untitled.png

  • flag.txt는 /dream/hack/hello 경로에 위치한것을 확인
  • flag 라는 단어는 검증식이 있기때문에 사용하지 못함
  • cat 명령어를 이용하여 flag.txt의 파일 내부를 살펴봄
    • cat dream/hack/hello/* - 해당 경로의 모든 파일의 내용을 봄
    • cat dream/hack/hello/*.txt - 해당 경로의 txt파일들의 내용을 봄
    • cat dream/hack/hello/fl* - “fl”로 시작하는 파일의 내용을 봄

결과값

Untitled.png

반응형
'보안/Dreamhack' 카테고리의 다른 글
  • PHPreg
  • command-injection-1
  • amocafe_2
Future0_
Future0_
rm -rf /
Future0_
Luna Developer Blog
Future0_
전체
오늘
어제
  • 분류 전체보기 (112)
    • 프로그래밍 (4)
      • 알고리즘 (4)
    • 보안 (14)
      • Dreamhack (4)
      • Hackthebox (1)
      • Webhacking (9)
    • 프로젝트 (4)
    • 공부 (80)
      • Database (2)
      • Python (11)
      • System (4)
      • Java (13)
      • JSP (13)
      • Spring (11)
      • Kotlin (16)
      • 자료구조 (10)
      • 기계학습 (0)
    • Docker (4)
    • Github (2)
    • Tip (1)
    • 잡담 (2)

블로그 메뉴

  • 홈
  • 태그

공지사항

인기 글

태그

  • 컴퓨터
  • SpringBoot
  • spring
  • docker
  • Python
  • android studio 삭제
  • Kotlin
  • jsp
  • 자바빈즈
  • Computer science
  • 키 해시
  • 코틀린기본문법
  • 자료구조
  • 디버깅키해시
  • 프로그래밍
  • api 통신
  • 알고리즘
  • shared preference
  • webhacking
  • React
  • cs
  • Android Studio
  • 상속
  • 보안
  • Database
  • Java
  • ViewModel
  • dreamhack
  • native app
  • 1.9.22

최근 댓글

최근 글

hELLO · Designed By 정상우.v4.2.0
Future0_
baby-linux
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.