본 포스팅은 문제 풀이가 아닌 힌트 및 접근 방법에 대해서만 간단하게 설명합니다.

 

#!/usr/bin/python3
from flask import Flask, request, render_template, make_response, redirect, url_for
import socket

app = Flask(__name__)

try:
    FLAG = open('./flag.txt', 'r').read()
except:
    FLAG = '[**FLAG**]'

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/socket', methods=['GET', 'POST'])
def login():
    if request.method == 'GET':
        return render_template('socket.html')
    elif request.method == 'POST':
        host = request.form.get('host')
        port = request.form.get('port', type=int)
        data = request.form.get('data')

        retData = ""
        try:
            with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
                s.settimeout(3)
                s.connect((host, port))
                s.sendall(data.encode())
                while True:
                    tmpData = s.recv(1024)
                    retData += tmpData.decode()
                    if not tmpData: break
            
        except Exception as e:
            return render_template('socket_result.html', data=e)
        
        return render_template('socket_result.html', data=retData)


@app.route('/admin', methods=['POST'])
def admin():
    if request.remote_addr != '127.0.0.1':
        return 'Only localhost'

    if request.headers.get('User-Agent') != 'Admin Browser':
        return 'Only Admin Browser'

    if request.headers.get('DreamhackUser') != 'admin':
        return 'Only Admin'

    if request.cookies.get('admin') != 'true':
        return 'Admin Cookie'

    if request.form.get('userid') != 'admin':
        return 'Admin id'

    return FLAG

app.run(host='0.0.0.0', port=8000)

admin 함수 조건들만 충족하면 문제를 풀 수 있다.
/socket 페이지를 잘 이용하면 된다.

'Web Hacking > Dreamhack.io' 카테고리의 다른 글

command-injection-1  (0) 2020.09.13
image-storage  (0) 2020.09.13

본 포스팅은 문제 풀이가 아닌 힌트 및 접근 방법에 대해서만 간단하게 설명합니다.

사용자 입력 값 검증과 사용자 입력 값을 어떻게 처리하는지 잘 확인해보면 풀 수 있다.

 

'Web Hacking > Dreamhack.io' 카테고리의 다른 글

Proxy-1  (0) 2020.09.19
image-storage  (0) 2020.09.13

본 포스팅은 문제 풀이가 아닌 힌트 및 접근 방법에 대해서만 간단하게 설명합니다.

간단한 웹쉘을 만들어서 업로드 한 뒤 이를 이용해 문제를 풀 수 있다.

더보기
<?php
system($_GET['cmd']);
?>

 

'Web Hacking > Dreamhack.io' 카테고리의 다른 글

Proxy-1  (0) 2020.09.19
command-injection-1  (0) 2020.09.13

+ Recent posts