Skip to main content

8 posts tagged with "CTF"

View All Tags

ISITDTU CTF 2024 - Writeup Web Challenges

· 7 min read

Writeup​

Another one​

image For this challenge, at first glance, I'm looking at this part:

@app.route('/render', methods=['POST'])
def dynamic_template():
token = request.cookies.get('jwt_token')
if token:
try:
decoded = jwt.decode(token, app.config['SECRET_KEY'], algorithms=['HS256'])
role = decoded.get('role')

if role != "admin":
return jsonify(message="Admin only"), 403

data = request.get_json()
template = data.get("template")
rendered_template = render_template_string(template)

return jsonify(message="Done")

except jwt.ExpiredSignatureError:
return jsonify(message="Token has expired."), 401
except jwt.InvalidTokenError:
return jsonify(message="Invalid JWT."), 401
except Exception as e:
return jsonify(message=str(e)), 500
else:
return jsonify(message="Where is your token?"), 401

ISITDTU CTF 2023

· 7 min read

thru_the_filter_test_flag​

Author: onsra Description: This challenge gives us a website that can be exploited by SSTI.

Review code:

from flask import Flask, request, render_template_string,redirect

app = Flask(__name__)
def check_payload(payload):
blacklist = ['import', 'request', 'init', '_', 'b', 'lipsum', 'os', 'globals', 'popen', 'mro', 'cycler', 'joiner', 'u','x','g','args', 'get_flashed_messages', 'base', '[',']','builtins', 'namespace', 'self', 'url_for', 'getitem','.','eval','update','config','read','dict']
for bl in blacklist:
if bl in payload:
return True
return False
@app.route("/")
def home():
if request.args.get('c'):
if(check_payload(ssti)):
return "HOLD UP !!!"
else:
return render_template_string(request.args.get('c'))
else:
return redirect("""/?c={{ 7*7 }}""")


if __name__ == "__main__":
app.run()